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