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.SoftReferenceEntryCacheCfgClient;
055import org.forgerock.opendj.server.config.server.EntryCacheCfg;
056import org.forgerock.opendj.server.config.server.SoftReferenceEntryCacheCfg;
057
058
059
060/**
061 * An interface for querying the Soft Reference Entry Cache managed
062 * object definition meta information.
063 * <p>
064 * The Soft Reference Entry Cache is a directory server entry cache
065 * implementation that uses soft references to manage objects to allow
066 * them to be freed if the JVM is running low on memory.
067 */
068public final class SoftReferenceEntryCacheCfgDefn extends ManagedObjectDefinition<SoftReferenceEntryCacheCfgClient, SoftReferenceEntryCacheCfg> {
069
070  // The singleton configuration definition instance.
071  private static final SoftReferenceEntryCacheCfgDefn INSTANCE = new SoftReferenceEntryCacheCfgDefn();
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  // Build the "exclude-filter" property definition.
096  static {
097      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "exclude-filter");
098      builder.setOption(PropertyOption.MULTI_VALUED);
099      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "exclude-filter"));
100      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
101      PD_EXCLUDE_FILTER = builder.getInstance();
102      INSTANCE.registerPropertyDefinition(PD_EXCLUDE_FILTER);
103  }
104
105
106
107  // Build the "include-filter" property definition.
108  static {
109      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "include-filter");
110      builder.setOption(PropertyOption.MULTI_VALUED);
111      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "include-filter"));
112      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
113      PD_INCLUDE_FILTER = builder.getInstance();
114      INSTANCE.registerPropertyDefinition(PD_INCLUDE_FILTER);
115  }
116
117
118
119  // Build the "java-class" property definition.
120  static {
121      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
122      builder.setOption(PropertyOption.MANDATORY);
123      builder.setOption(PropertyOption.ADVANCED);
124      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
125      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.SoftReferenceEntryCache");
126      builder.setDefaultBehaviorProvider(provider);
127      builder.addInstanceOf("org.opends.server.api.EntryCache");
128      PD_JAVA_CLASS = builder.getInstance();
129      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
130  }
131
132
133
134  // Build the "lock-timeout" property definition.
135  static {
136      DurationPropertyDefinition.Builder builder = DurationPropertyDefinition.createBuilder(INSTANCE, "lock-timeout");
137      builder.setOption(PropertyOption.ADVANCED);
138      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "lock-timeout"));
139      DefaultBehaviorProvider<Long> provider = new DefinedDefaultBehaviorProvider<Long>("3000ms");
140      builder.setDefaultBehaviorProvider(provider);
141      builder.setAllowUnlimited(true);
142      builder.setBaseUnit("ms");
143      builder.setLowerLimit("0");
144      PD_LOCK_TIMEOUT = builder.getInstance();
145      INSTANCE.registerPropertyDefinition(PD_LOCK_TIMEOUT);
146  }
147
148
149
150  // Register the tags associated with this managed object definition.
151  static {
152    INSTANCE.registerTag(Tag.valueOf("database"));
153  }
154
155
156
157  /**
158   * Get the Soft Reference Entry Cache configuration definition
159   * singleton.
160   *
161   * @return Returns the Soft Reference Entry Cache configuration
162   *         definition singleton.
163   */
164  public static SoftReferenceEntryCacheCfgDefn getInstance() {
165    return INSTANCE;
166  }
167
168
169
170  /**
171   * Private constructor.
172   */
173  private SoftReferenceEntryCacheCfgDefn() {
174    super("soft-reference-entry-cache", EntryCacheCfgDefn.getInstance());
175  }
176
177
178
179  /**
180   * {@inheritDoc}
181   */
182  public SoftReferenceEntryCacheCfgClient createClientConfiguration(
183      ManagedObject<? extends SoftReferenceEntryCacheCfgClient> impl) {
184    return new SoftReferenceEntryCacheCfgClientImpl(impl);
185  }
186
187
188
189  /**
190   * {@inheritDoc}
191   */
192  public SoftReferenceEntryCacheCfg createServerConfiguration(
193      ServerManagedObject<? extends SoftReferenceEntryCacheCfg> impl) {
194    return new SoftReferenceEntryCacheCfgServerImpl(impl);
195  }
196
197
198
199  /**
200   * {@inheritDoc}
201   */
202  public Class<SoftReferenceEntryCacheCfg> getServerConfigurationClass() {
203    return SoftReferenceEntryCacheCfg.class;
204  }
205
206
207
208  /**
209   * Get the "cache-level" property definition.
210   * <p>
211   * Specifies the cache level in the cache order if more than one
212   * instance of the cache is configured.
213   *
214   * @return Returns the "cache-level" property definition.
215   */
216  public IntegerPropertyDefinition getCacheLevelPropertyDefinition() {
217    return EntryCacheCfgDefn.getInstance().getCacheLevelPropertyDefinition();
218  }
219
220
221
222  /**
223   * Get the "enabled" property definition.
224   * <p>
225   * Indicates whether the Soft Reference Entry Cache is enabled.
226   *
227   * @return Returns the "enabled" property definition.
228   */
229  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
230    return EntryCacheCfgDefn.getInstance().getEnabledPropertyDefinition();
231  }
232
233
234
235  /**
236   * Get the "exclude-filter" property definition.
237   * <p>
238   * The set of filters that define the entries that should be
239   * excluded from the cache.
240   *
241   * @return Returns the "exclude-filter" property definition.
242   */
243  public StringPropertyDefinition getExcludeFilterPropertyDefinition() {
244    return PD_EXCLUDE_FILTER;
245  }
246
247
248
249  /**
250   * Get the "include-filter" property definition.
251   * <p>
252   * The set of filters that define the entries that should be
253   * included in the cache.
254   *
255   * @return Returns the "include-filter" property definition.
256   */
257  public StringPropertyDefinition getIncludeFilterPropertyDefinition() {
258    return PD_INCLUDE_FILTER;
259  }
260
261
262
263  /**
264   * Get the "java-class" property definition.
265   * <p>
266   * Specifies the fully-qualified name of the Java class that
267   * provides the Soft Reference Entry Cache implementation.
268   *
269   * @return Returns the "java-class" property definition.
270   */
271  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
272    return PD_JAVA_CLASS;
273  }
274
275
276
277  /**
278   * Get the "lock-timeout" property definition.
279   * <p>
280   * Specifies the length of time in milliseconds to wait while
281   * attempting to acquire a read or write lock.
282   *
283   * @return Returns the "lock-timeout" property definition.
284   */
285  public DurationPropertyDefinition getLockTimeoutPropertyDefinition() {
286    return PD_LOCK_TIMEOUT;
287  }
288
289
290
291  /**
292   * Managed object client implementation.
293   */
294  private static class SoftReferenceEntryCacheCfgClientImpl implements
295    SoftReferenceEntryCacheCfgClient {
296
297    // Private implementation.
298    private ManagedObject<? extends SoftReferenceEntryCacheCfgClient> impl;
299
300
301
302    // Private constructor.
303    private SoftReferenceEntryCacheCfgClientImpl(
304        ManagedObject<? extends SoftReferenceEntryCacheCfgClient> impl) {
305      this.impl = impl;
306    }
307
308
309
310    /**
311     * {@inheritDoc}
312     */
313    public Integer getCacheLevel() {
314      return impl.getPropertyValue(INSTANCE.getCacheLevelPropertyDefinition());
315    }
316
317
318
319    /**
320     * {@inheritDoc}
321     */
322    public void setCacheLevel(int value) {
323      impl.setPropertyValue(INSTANCE.getCacheLevelPropertyDefinition(), value);
324    }
325
326
327
328    /**
329     * {@inheritDoc}
330     */
331    public Boolean isEnabled() {
332      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
333    }
334
335
336
337    /**
338     * {@inheritDoc}
339     */
340    public void setEnabled(boolean value) {
341      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
342    }
343
344
345
346    /**
347     * {@inheritDoc}
348     */
349    public SortedSet<String> getExcludeFilter() {
350      return impl.getPropertyValues(INSTANCE.getExcludeFilterPropertyDefinition());
351    }
352
353
354
355    /**
356     * {@inheritDoc}
357     */
358    public void setExcludeFilter(Collection<String> values) {
359      impl.setPropertyValues(INSTANCE.getExcludeFilterPropertyDefinition(), values);
360    }
361
362
363
364    /**
365     * {@inheritDoc}
366     */
367    public SortedSet<String> getIncludeFilter() {
368      return impl.getPropertyValues(INSTANCE.getIncludeFilterPropertyDefinition());
369    }
370
371
372
373    /**
374     * {@inheritDoc}
375     */
376    public void setIncludeFilter(Collection<String> values) {
377      impl.setPropertyValues(INSTANCE.getIncludeFilterPropertyDefinition(), values);
378    }
379
380
381
382    /**
383     * {@inheritDoc}
384     */
385    public String getJavaClass() {
386      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
387    }
388
389
390
391    /**
392     * {@inheritDoc}
393     */
394    public void setJavaClass(String value) {
395      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
396    }
397
398
399
400    /**
401     * {@inheritDoc}
402     */
403    public long getLockTimeout() {
404      return impl.getPropertyValue(INSTANCE.getLockTimeoutPropertyDefinition());
405    }
406
407
408
409    /**
410     * {@inheritDoc}
411     */
412    public void setLockTimeout(Long value) {
413      impl.setPropertyValue(INSTANCE.getLockTimeoutPropertyDefinition(), value);
414    }
415
416
417
418    /**
419     * {@inheritDoc}
420     */
421    public ManagedObjectDefinition<? extends SoftReferenceEntryCacheCfgClient, ? extends SoftReferenceEntryCacheCfg> definition() {
422      return INSTANCE;
423    }
424
425
426
427    /**
428     * {@inheritDoc}
429     */
430    public PropertyProvider properties() {
431      return impl;
432    }
433
434
435
436    /**
437     * {@inheritDoc}
438     */
439    public void commit() throws ManagedObjectAlreadyExistsException,
440        MissingMandatoryPropertiesException, ConcurrentModificationException,
441        OperationRejectedException, LdapException {
442      impl.commit();
443    }
444
445  }
446
447
448
449  /**
450   * Managed object server implementation.
451   */
452  private static class SoftReferenceEntryCacheCfgServerImpl implements
453    SoftReferenceEntryCacheCfg {
454
455    // Private implementation.
456    private ServerManagedObject<? extends SoftReferenceEntryCacheCfg> impl;
457
458    // The value of the "cache-level" property.
459    private final int pCacheLevel;
460
461    // The value of the "enabled" property.
462    private final boolean pEnabled;
463
464    // The value of the "exclude-filter" property.
465    private final SortedSet<String> pExcludeFilter;
466
467    // The value of the "include-filter" property.
468    private final SortedSet<String> pIncludeFilter;
469
470    // The value of the "java-class" property.
471    private final String pJavaClass;
472
473    // The value of the "lock-timeout" property.
474    private final long pLockTimeout;
475
476
477
478    // Private constructor.
479    private SoftReferenceEntryCacheCfgServerImpl(ServerManagedObject<? extends SoftReferenceEntryCacheCfg> impl) {
480      this.impl = impl;
481      this.pCacheLevel = impl.getPropertyValue(INSTANCE.getCacheLevelPropertyDefinition());
482      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
483      this.pExcludeFilter = impl.getPropertyValues(INSTANCE.getExcludeFilterPropertyDefinition());
484      this.pIncludeFilter = impl.getPropertyValues(INSTANCE.getIncludeFilterPropertyDefinition());
485      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
486      this.pLockTimeout = impl.getPropertyValue(INSTANCE.getLockTimeoutPropertyDefinition());
487    }
488
489
490
491    /**
492     * {@inheritDoc}
493     */
494    public void addSoftReferenceChangeListener(
495        ConfigurationChangeListener<SoftReferenceEntryCacheCfg> listener) {
496      impl.registerChangeListener(listener);
497    }
498
499
500
501    /**
502     * {@inheritDoc}
503     */
504    public void removeSoftReferenceChangeListener(
505        ConfigurationChangeListener<SoftReferenceEntryCacheCfg> listener) {
506      impl.deregisterChangeListener(listener);
507    }
508    /**
509     * {@inheritDoc}
510     */
511    public void addChangeListener(
512        ConfigurationChangeListener<EntryCacheCfg> listener) {
513      impl.registerChangeListener(listener);
514    }
515
516
517
518    /**
519     * {@inheritDoc}
520     */
521    public void removeChangeListener(
522        ConfigurationChangeListener<EntryCacheCfg> listener) {
523      impl.deregisterChangeListener(listener);
524    }
525
526
527
528    /**
529     * {@inheritDoc}
530     */
531    public int getCacheLevel() {
532      return pCacheLevel;
533    }
534
535
536
537    /**
538     * {@inheritDoc}
539     */
540    public boolean isEnabled() {
541      return pEnabled;
542    }
543
544
545
546    /**
547     * {@inheritDoc}
548     */
549    public SortedSet<String> getExcludeFilter() {
550      return pExcludeFilter;
551    }
552
553
554
555    /**
556     * {@inheritDoc}
557     */
558    public SortedSet<String> getIncludeFilter() {
559      return pIncludeFilter;
560    }
561
562
563
564    /**
565     * {@inheritDoc}
566     */
567    public String getJavaClass() {
568      return pJavaClass;
569    }
570
571
572
573    /**
574     * {@inheritDoc}
575     */
576    public long getLockTimeout() {
577      return pLockTimeout;
578    }
579
580
581
582    /**
583     * {@inheritDoc}
584     */
585    public Class<? extends SoftReferenceEntryCacheCfg> configurationClass() {
586      return SoftReferenceEntryCacheCfg.class;
587    }
588
589
590
591    /**
592     * {@inheritDoc}
593     */
594    public DN dn() {
595      return impl.getDN();
596    }
597
598  }
599}