001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2008 Sun Microsystems, Inc.
025 */
026package org.opends.server.admin.std.meta;
027
028
029
030import java.util.Collection;
031import java.util.SortedSet;
032import org.opends.server.admin.AdministratorAction;
033import org.opends.server.admin.BooleanPropertyDefinition;
034import org.opends.server.admin.ClassPropertyDefinition;
035import org.opends.server.admin.client.AuthorizationException;
036import org.opends.server.admin.client.CommunicationException;
037import org.opends.server.admin.client.ConcurrentModificationException;
038import org.opends.server.admin.client.ManagedObject;
039import org.opends.server.admin.client.MissingMandatoryPropertiesException;
040import org.opends.server.admin.client.OperationRejectedException;
041import org.opends.server.admin.DefaultBehaviorProvider;
042import org.opends.server.admin.DefinedDefaultBehaviorProvider;
043import org.opends.server.admin.DurationPropertyDefinition;
044import org.opends.server.admin.IntegerPropertyDefinition;
045import org.opends.server.admin.ManagedObjectAlreadyExistsException;
046import org.opends.server.admin.ManagedObjectDefinition;
047import org.opends.server.admin.PropertyOption;
048import org.opends.server.admin.PropertyProvider;
049import org.opends.server.admin.server.ConfigurationChangeListener;
050import org.opends.server.admin.server.ServerManagedObject;
051import org.opends.server.admin.std.client.FIFOEntryCacheCfgClient;
052import org.opends.server.admin.std.server.EntryCacheCfg;
053import org.opends.server.admin.std.server.FIFOEntryCacheCfg;
054import org.opends.server.admin.StringPropertyDefinition;
055import org.opends.server.admin.Tag;
056import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
057import org.opends.server.types.DN;
058
059
060
061/**
062 * An interface for querying the FIFO Entry Cache managed object
063 * definition meta information.
064 * <p>
065 * FIFO Entry Caches use a FIFO queue to keep track of the cached
066 * entries.
067 */
068public final class FIFOEntryCacheCfgDefn extends ManagedObjectDefinition<FIFOEntryCacheCfgClient, FIFOEntryCacheCfg> {
069
070  // The singleton configuration definition instance.
071  private static final FIFOEntryCacheCfgDefn INSTANCE = new FIFOEntryCacheCfgDefn();
072
073
074
075  // The "exclude-filter" property definition.
076  private static final StringPropertyDefinition PD_EXCLUDE_FILTER;
077
078
079
080  // The "include-filter" property definition.
081  private static final StringPropertyDefinition PD_INCLUDE_FILTER;
082
083
084
085  // The "java-class" property definition.
086  private static final ClassPropertyDefinition PD_JAVA_CLASS;
087
088
089
090  // The "lock-timeout" property definition.
091  private static final DurationPropertyDefinition PD_LOCK_TIMEOUT;
092
093
094
095  // The "max-entries" property definition.
096  private static final IntegerPropertyDefinition PD_MAX_ENTRIES;
097
098
099
100  // The "max-memory-percent" property definition.
101  private static final IntegerPropertyDefinition PD_MAX_MEMORY_PERCENT;
102
103
104
105  // Build the "exclude-filter" property definition.
106  static {
107      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "exclude-filter");
108      builder.setOption(PropertyOption.MULTI_VALUED);
109      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "exclude-filter"));
110      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
111      PD_EXCLUDE_FILTER = builder.getInstance();
112      INSTANCE.registerPropertyDefinition(PD_EXCLUDE_FILTER);
113  }
114
115
116
117  // Build the "include-filter" property definition.
118  static {
119      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "include-filter");
120      builder.setOption(PropertyOption.MULTI_VALUED);
121      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "include-filter"));
122      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
123      PD_INCLUDE_FILTER = builder.getInstance();
124      INSTANCE.registerPropertyDefinition(PD_INCLUDE_FILTER);
125  }
126
127
128
129  // Build the "java-class" property definition.
130  static {
131      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
132      builder.setOption(PropertyOption.MANDATORY);
133      builder.setOption(PropertyOption.ADVANCED);
134      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
135      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.FIFOEntryCache");
136      builder.setDefaultBehaviorProvider(provider);
137      builder.addInstanceOf("org.opends.server.api.EntryCache");
138      PD_JAVA_CLASS = builder.getInstance();
139      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
140  }
141
142
143
144  // Build the "lock-timeout" property definition.
145  static {
146      DurationPropertyDefinition.Builder builder = DurationPropertyDefinition.createBuilder(INSTANCE, "lock-timeout");
147      builder.setOption(PropertyOption.ADVANCED);
148      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "lock-timeout"));
149      DefaultBehaviorProvider<Long> provider = new DefinedDefaultBehaviorProvider<Long>("2000.0ms");
150      builder.setDefaultBehaviorProvider(provider);
151      builder.setAllowUnlimited(true);
152      builder.setBaseUnit("ms");
153      builder.setLowerLimit("0");
154      PD_LOCK_TIMEOUT = builder.getInstance();
155      INSTANCE.registerPropertyDefinition(PD_LOCK_TIMEOUT);
156  }
157
158
159
160  // Build the "max-entries" property definition.
161  static {
162      IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "max-entries");
163      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "max-entries"));
164      DefaultBehaviorProvider<Integer> provider = new DefinedDefaultBehaviorProvider<Integer>("2147483647");
165      builder.setDefaultBehaviorProvider(provider);
166      builder.setLowerLimit(0);
167      PD_MAX_ENTRIES = builder.getInstance();
168      INSTANCE.registerPropertyDefinition(PD_MAX_ENTRIES);
169  }
170
171
172
173  // Build the "max-memory-percent" property definition.
174  static {
175      IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "max-memory-percent");
176      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "max-memory-percent"));
177      DefaultBehaviorProvider<Integer> provider = new DefinedDefaultBehaviorProvider<Integer>("90");
178      builder.setDefaultBehaviorProvider(provider);
179      builder.setUpperLimit(100);
180      builder.setLowerLimit(1);
181      PD_MAX_MEMORY_PERCENT = builder.getInstance();
182      INSTANCE.registerPropertyDefinition(PD_MAX_MEMORY_PERCENT);
183  }
184
185
186
187  // Register the tags associated with this managed object definition.
188  static {
189    INSTANCE.registerTag(Tag.valueOf("database"));
190  }
191
192
193
194  /**
195   * Get the FIFO Entry Cache configuration definition singleton.
196   *
197   * @return Returns the FIFO Entry Cache configuration definition
198   *         singleton.
199   */
200  public static FIFOEntryCacheCfgDefn getInstance() {
201    return INSTANCE;
202  }
203
204
205
206  /**
207   * Private constructor.
208   */
209  private FIFOEntryCacheCfgDefn() {
210    super("fifo-entry-cache", EntryCacheCfgDefn.getInstance());
211  }
212
213
214
215  /**
216   * {@inheritDoc}
217   */
218  public FIFOEntryCacheCfgClient createClientConfiguration(
219      ManagedObject<? extends FIFOEntryCacheCfgClient> impl) {
220    return new FIFOEntryCacheCfgClientImpl(impl);
221  }
222
223
224
225  /**
226   * {@inheritDoc}
227   */
228  public FIFOEntryCacheCfg createServerConfiguration(
229      ServerManagedObject<? extends FIFOEntryCacheCfg> impl) {
230    return new FIFOEntryCacheCfgServerImpl(impl);
231  }
232
233
234
235  /**
236   * {@inheritDoc}
237   */
238  public Class<FIFOEntryCacheCfg> getServerConfigurationClass() {
239    return FIFOEntryCacheCfg.class;
240  }
241
242
243
244  /**
245   * Get the "cache-level" property definition.
246   * <p>
247   * Specifies the cache level in the cache order if more than one
248   * instance of the cache is configured.
249   *
250   * @return Returns the "cache-level" property definition.
251   */
252  public IntegerPropertyDefinition getCacheLevelPropertyDefinition() {
253    return EntryCacheCfgDefn.getInstance().getCacheLevelPropertyDefinition();
254  }
255
256
257
258  /**
259   * Get the "enabled" property definition.
260   * <p>
261   * Indicates whether the FIFO Entry Cache is enabled.
262   *
263   * @return Returns the "enabled" property definition.
264   */
265  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
266    return EntryCacheCfgDefn.getInstance().getEnabledPropertyDefinition();
267  }
268
269
270
271  /**
272   * Get the "exclude-filter" property definition.
273   * <p>
274   * The set of filters that define the entries that should be
275   * excluded from the cache.
276   *
277   * @return Returns the "exclude-filter" property definition.
278   */
279  public StringPropertyDefinition getExcludeFilterPropertyDefinition() {
280    return PD_EXCLUDE_FILTER;
281  }
282
283
284
285  /**
286   * Get the "include-filter" property definition.
287   * <p>
288   * The set of filters that define the entries that should be
289   * included in the cache.
290   *
291   * @return Returns the "include-filter" property definition.
292   */
293  public StringPropertyDefinition getIncludeFilterPropertyDefinition() {
294    return PD_INCLUDE_FILTER;
295  }
296
297
298
299  /**
300   * Get the "java-class" property definition.
301   * <p>
302   * Specifies the fully-qualified name of the Java class that
303   * provides the FIFO Entry Cache implementation.
304   *
305   * @return Returns the "java-class" property definition.
306   */
307  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
308    return PD_JAVA_CLASS;
309  }
310
311
312
313  /**
314   * Get the "lock-timeout" property definition.
315   * <p>
316   * Specifies the length of time to wait while attempting to acquire
317   * a read or write lock.
318   *
319   * @return Returns the "lock-timeout" property definition.
320   */
321  public DurationPropertyDefinition getLockTimeoutPropertyDefinition() {
322    return PD_LOCK_TIMEOUT;
323  }
324
325
326
327  /**
328   * Get the "max-entries" property definition.
329   * <p>
330   * Specifies the maximum number of entries that we will allow in the
331   * cache.
332   *
333   * @return Returns the "max-entries" property definition.
334   */
335  public IntegerPropertyDefinition getMaxEntriesPropertyDefinition() {
336    return PD_MAX_ENTRIES;
337  }
338
339
340
341  /**
342   * Get the "max-memory-percent" property definition.
343   * <p>
344   * Specifies the maximum percentage of JVM memory used by the server
345   * before the entry caches stops caching and begins purging itself.
346   * <p>
347   * Very low settings such as 10 or 20 (percent) can prevent this
348   * entry cache from having enough space to hold any of the entries to
349   * cache, making it appear that the server is ignoring or skipping
350   * the entry cache entirely.
351   *
352   * @return Returns the "max-memory-percent" property definition.
353   */
354  public IntegerPropertyDefinition getMaxMemoryPercentPropertyDefinition() {
355    return PD_MAX_MEMORY_PERCENT;
356  }
357
358
359
360  /**
361   * Managed object client implementation.
362   */
363  private static class FIFOEntryCacheCfgClientImpl implements
364    FIFOEntryCacheCfgClient {
365
366    // Private implementation.
367    private ManagedObject<? extends FIFOEntryCacheCfgClient> impl;
368
369
370
371    // Private constructor.
372    private FIFOEntryCacheCfgClientImpl(
373        ManagedObject<? extends FIFOEntryCacheCfgClient> impl) {
374      this.impl = impl;
375    }
376
377
378
379    /**
380     * {@inheritDoc}
381     */
382    public Integer getCacheLevel() {
383      return impl.getPropertyValue(INSTANCE.getCacheLevelPropertyDefinition());
384    }
385
386
387
388    /**
389     * {@inheritDoc}
390     */
391    public void setCacheLevel(int value) {
392      impl.setPropertyValue(INSTANCE.getCacheLevelPropertyDefinition(), value);
393    }
394
395
396
397    /**
398     * {@inheritDoc}
399     */
400    public Boolean isEnabled() {
401      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
402    }
403
404
405
406    /**
407     * {@inheritDoc}
408     */
409    public void setEnabled(boolean value) {
410      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
411    }
412
413
414
415    /**
416     * {@inheritDoc}
417     */
418    public SortedSet<String> getExcludeFilter() {
419      return impl.getPropertyValues(INSTANCE.getExcludeFilterPropertyDefinition());
420    }
421
422
423
424    /**
425     * {@inheritDoc}
426     */
427    public void setExcludeFilter(Collection<String> values) {
428      impl.setPropertyValues(INSTANCE.getExcludeFilterPropertyDefinition(), values);
429    }
430
431
432
433    /**
434     * {@inheritDoc}
435     */
436    public SortedSet<String> getIncludeFilter() {
437      return impl.getPropertyValues(INSTANCE.getIncludeFilterPropertyDefinition());
438    }
439
440
441
442    /**
443     * {@inheritDoc}
444     */
445    public void setIncludeFilter(Collection<String> values) {
446      impl.setPropertyValues(INSTANCE.getIncludeFilterPropertyDefinition(), values);
447    }
448
449
450
451    /**
452     * {@inheritDoc}
453     */
454    public String getJavaClass() {
455      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
456    }
457
458
459
460    /**
461     * {@inheritDoc}
462     */
463    public void setJavaClass(String value) {
464      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
465    }
466
467
468
469    /**
470     * {@inheritDoc}
471     */
472    public long getLockTimeout() {
473      return impl.getPropertyValue(INSTANCE.getLockTimeoutPropertyDefinition());
474    }
475
476
477
478    /**
479     * {@inheritDoc}
480     */
481    public void setLockTimeout(Long value) {
482      impl.setPropertyValue(INSTANCE.getLockTimeoutPropertyDefinition(), value);
483    }
484
485
486
487    /**
488     * {@inheritDoc}
489     */
490    public int getMaxEntries() {
491      return impl.getPropertyValue(INSTANCE.getMaxEntriesPropertyDefinition());
492    }
493
494
495
496    /**
497     * {@inheritDoc}
498     */
499    public void setMaxEntries(Integer value) {
500      impl.setPropertyValue(INSTANCE.getMaxEntriesPropertyDefinition(), value);
501    }
502
503
504
505    /**
506     * {@inheritDoc}
507     */
508    public int getMaxMemoryPercent() {
509      return impl.getPropertyValue(INSTANCE.getMaxMemoryPercentPropertyDefinition());
510    }
511
512
513
514    /**
515     * {@inheritDoc}
516     */
517    public void setMaxMemoryPercent(Integer value) {
518      impl.setPropertyValue(INSTANCE.getMaxMemoryPercentPropertyDefinition(), value);
519    }
520
521
522
523    /**
524     * {@inheritDoc}
525     */
526    public ManagedObjectDefinition<? extends FIFOEntryCacheCfgClient, ? extends FIFOEntryCacheCfg> definition() {
527      return INSTANCE;
528    }
529
530
531
532    /**
533     * {@inheritDoc}
534     */
535    public PropertyProvider properties() {
536      return impl;
537    }
538
539
540
541    /**
542     * {@inheritDoc}
543     */
544    public void commit() throws ManagedObjectAlreadyExistsException,
545        MissingMandatoryPropertiesException, ConcurrentModificationException,
546        OperationRejectedException, AuthorizationException,
547        CommunicationException {
548      impl.commit();
549    }
550
551
552
553    /** {@inheritDoc} */
554    public String toString() {
555      return impl.toString();
556    }
557  }
558
559
560
561  /**
562   * Managed object server implementation.
563   */
564  private static class FIFOEntryCacheCfgServerImpl implements
565    FIFOEntryCacheCfg {
566
567    // Private implementation.
568    private ServerManagedObject<? extends FIFOEntryCacheCfg> impl;
569
570    // The value of the "cache-level" property.
571    private final int pCacheLevel;
572
573    // The value of the "enabled" property.
574    private final boolean pEnabled;
575
576    // The value of the "exclude-filter" property.
577    private final SortedSet<String> pExcludeFilter;
578
579    // The value of the "include-filter" property.
580    private final SortedSet<String> pIncludeFilter;
581
582    // The value of the "java-class" property.
583    private final String pJavaClass;
584
585    // The value of the "lock-timeout" property.
586    private final long pLockTimeout;
587
588    // The value of the "max-entries" property.
589    private final int pMaxEntries;
590
591    // The value of the "max-memory-percent" property.
592    private final int pMaxMemoryPercent;
593
594
595
596    // Private constructor.
597    private FIFOEntryCacheCfgServerImpl(ServerManagedObject<? extends FIFOEntryCacheCfg> impl) {
598      this.impl = impl;
599      this.pCacheLevel = impl.getPropertyValue(INSTANCE.getCacheLevelPropertyDefinition());
600      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
601      this.pExcludeFilter = impl.getPropertyValues(INSTANCE.getExcludeFilterPropertyDefinition());
602      this.pIncludeFilter = impl.getPropertyValues(INSTANCE.getIncludeFilterPropertyDefinition());
603      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
604      this.pLockTimeout = impl.getPropertyValue(INSTANCE.getLockTimeoutPropertyDefinition());
605      this.pMaxEntries = impl.getPropertyValue(INSTANCE.getMaxEntriesPropertyDefinition());
606      this.pMaxMemoryPercent = impl.getPropertyValue(INSTANCE.getMaxMemoryPercentPropertyDefinition());
607    }
608
609
610
611    /**
612     * {@inheritDoc}
613     */
614    public void addFIFOChangeListener(
615        ConfigurationChangeListener<FIFOEntryCacheCfg> listener) {
616      impl.registerChangeListener(listener);
617    }
618
619
620
621    /**
622     * {@inheritDoc}
623     */
624    public void removeFIFOChangeListener(
625        ConfigurationChangeListener<FIFOEntryCacheCfg> listener) {
626      impl.deregisterChangeListener(listener);
627    }
628    /**
629     * {@inheritDoc}
630     */
631    public void addChangeListener(
632        ConfigurationChangeListener<EntryCacheCfg> listener) {
633      impl.registerChangeListener(listener);
634    }
635
636
637
638    /**
639     * {@inheritDoc}
640     */
641    public void removeChangeListener(
642        ConfigurationChangeListener<EntryCacheCfg> listener) {
643      impl.deregisterChangeListener(listener);
644    }
645
646
647
648    /**
649     * {@inheritDoc}
650     */
651    public int getCacheLevel() {
652      return pCacheLevel;
653    }
654
655
656
657    /**
658     * {@inheritDoc}
659     */
660    public boolean isEnabled() {
661      return pEnabled;
662    }
663
664
665
666    /**
667     * {@inheritDoc}
668     */
669    public SortedSet<String> getExcludeFilter() {
670      return pExcludeFilter;
671    }
672
673
674
675    /**
676     * {@inheritDoc}
677     */
678    public SortedSet<String> getIncludeFilter() {
679      return pIncludeFilter;
680    }
681
682
683
684    /**
685     * {@inheritDoc}
686     */
687    public String getJavaClass() {
688      return pJavaClass;
689    }
690
691
692
693    /**
694     * {@inheritDoc}
695     */
696    public long getLockTimeout() {
697      return pLockTimeout;
698    }
699
700
701
702    /**
703     * {@inheritDoc}
704     */
705    public int getMaxEntries() {
706      return pMaxEntries;
707    }
708
709
710
711    /**
712     * {@inheritDoc}
713     */
714    public int getMaxMemoryPercent() {
715      return pMaxMemoryPercent;
716    }
717
718
719
720    /**
721     * {@inheritDoc}
722     */
723    public Class<? extends FIFOEntryCacheCfg> configurationClass() {
724      return FIFOEntryCacheCfg.class;
725    }
726
727
728
729    /**
730     * {@inheritDoc}
731     */
732    public DN dn() {
733      return impl.getDN();
734    }
735
736
737
738    /** {@inheritDoc} */
739    public String toString() {
740      return impl.toString();
741    }
742  }
743}