001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2008 Sun Microsystems, Inc.
015 */
016package org.forgerock.opendj.server.config.meta;
017
018
019
020import java.util.Collection;
021import java.util.SortedSet;
022import org.forgerock.opendj.config.AdministratorAction;
023import org.forgerock.opendj.config.BooleanPropertyDefinition;
024import org.forgerock.opendj.config.ClassPropertyDefinition;
025import org.forgerock.opendj.config.client.ConcurrentModificationException;
026import org.forgerock.opendj.config.client.ManagedObject;
027import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
028import org.forgerock.opendj.config.client.OperationRejectedException;
029import org.forgerock.opendj.config.DefaultBehaviorProvider;
030import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider;
031import org.forgerock.opendj.config.DurationPropertyDefinition;
032import org.forgerock.opendj.config.IntegerPropertyDefinition;
033import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
034import org.forgerock.opendj.config.ManagedObjectDefinition;
035import org.forgerock.opendj.config.PropertyOption;
036import org.forgerock.opendj.config.PropertyProvider;
037import org.forgerock.opendj.config.server.ConfigurationChangeListener;
038import org.forgerock.opendj.config.server.ServerManagedObject;
039import org.forgerock.opendj.config.StringPropertyDefinition;
040import org.forgerock.opendj.config.Tag;
041import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider;
042import org.forgerock.opendj.ldap.DN;
043import org.forgerock.opendj.ldap.LdapException;
044import org.forgerock.opendj.server.config.client.SoftReferenceEntryCacheCfgClient;
045import org.forgerock.opendj.server.config.server.EntryCacheCfg;
046import org.forgerock.opendj.server.config.server.SoftReferenceEntryCacheCfg;
047
048
049
050/**
051 * An interface for querying the Soft Reference Entry Cache managed
052 * object definition meta information.
053 * <p>
054 * The Soft Reference Entry Cache is a directory server entry cache
055 * implementation that uses soft references to manage objects to allow
056 * them to be freed if the JVM is running low on memory.
057 */
058public final class SoftReferenceEntryCacheCfgDefn extends ManagedObjectDefinition<SoftReferenceEntryCacheCfgClient, SoftReferenceEntryCacheCfg> {
059
060  /** The singleton configuration definition instance. */
061  private static final SoftReferenceEntryCacheCfgDefn INSTANCE = new SoftReferenceEntryCacheCfgDefn();
062
063
064
065  /** The "exclude-filter" property definition. */
066  private static final StringPropertyDefinition PD_EXCLUDE_FILTER;
067
068
069
070  /** The "include-filter" property definition. */
071  private static final StringPropertyDefinition PD_INCLUDE_FILTER;
072
073
074
075  /** The "java-class" property definition. */
076  private static final ClassPropertyDefinition PD_JAVA_CLASS;
077
078
079
080  /** The "lock-timeout" property definition. */
081  private static final DurationPropertyDefinition PD_LOCK_TIMEOUT;
082
083
084
085  /** Build the "exclude-filter" property definition. */
086  static {
087      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "exclude-filter");
088      builder.setOption(PropertyOption.MULTI_VALUED);
089      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "exclude-filter"));
090      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
091      PD_EXCLUDE_FILTER = builder.getInstance();
092      INSTANCE.registerPropertyDefinition(PD_EXCLUDE_FILTER);
093  }
094
095
096
097  /** Build the "include-filter" property definition. */
098  static {
099      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "include-filter");
100      builder.setOption(PropertyOption.MULTI_VALUED);
101      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "include-filter"));
102      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
103      PD_INCLUDE_FILTER = builder.getInstance();
104      INSTANCE.registerPropertyDefinition(PD_INCLUDE_FILTER);
105  }
106
107
108
109  /** Build the "java-class" property definition. */
110  static {
111      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
112      builder.setOption(PropertyOption.MANDATORY);
113      builder.setOption(PropertyOption.ADVANCED);
114      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
115      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.SoftReferenceEntryCache");
116      builder.setDefaultBehaviorProvider(provider);
117      builder.addInstanceOf("org.opends.server.api.EntryCache");
118      PD_JAVA_CLASS = builder.getInstance();
119      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
120  }
121
122
123
124  /** Build the "lock-timeout" property definition. */
125  static {
126      DurationPropertyDefinition.Builder builder = DurationPropertyDefinition.createBuilder(INSTANCE, "lock-timeout");
127      builder.setOption(PropertyOption.ADVANCED);
128      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "lock-timeout"));
129      DefaultBehaviorProvider<Long> provider = new DefinedDefaultBehaviorProvider<Long>("3000ms");
130      builder.setDefaultBehaviorProvider(provider);
131      builder.setAllowUnlimited(true);
132      builder.setBaseUnit("ms");
133      builder.setLowerLimit("0");
134      PD_LOCK_TIMEOUT = builder.getInstance();
135      INSTANCE.registerPropertyDefinition(PD_LOCK_TIMEOUT);
136  }
137
138
139
140  // Register the tags associated with this managed object definition.
141  static {
142    INSTANCE.registerTag(Tag.valueOf("database"));
143  }
144
145
146
147  /**
148   * Get the Soft Reference Entry Cache configuration definition
149   * singleton.
150   *
151   * @return Returns the Soft Reference Entry Cache configuration
152   *         definition singleton.
153   */
154  public static SoftReferenceEntryCacheCfgDefn getInstance() {
155    return INSTANCE;
156  }
157
158
159
160  /**
161   * Private constructor.
162   */
163  private SoftReferenceEntryCacheCfgDefn() {
164    super("soft-reference-entry-cache", EntryCacheCfgDefn.getInstance());
165  }
166
167
168
169  /** {@inheritDoc} */
170  public SoftReferenceEntryCacheCfgClient createClientConfiguration(
171      ManagedObject<? extends SoftReferenceEntryCacheCfgClient> impl) {
172    return new SoftReferenceEntryCacheCfgClientImpl(impl);
173  }
174
175
176
177  /** {@inheritDoc} */
178  public SoftReferenceEntryCacheCfg createServerConfiguration(
179      ServerManagedObject<? extends SoftReferenceEntryCacheCfg> impl) {
180    return new SoftReferenceEntryCacheCfgServerImpl(impl);
181  }
182
183
184
185  /** {@inheritDoc} */
186  public Class<SoftReferenceEntryCacheCfg> getServerConfigurationClass() {
187    return SoftReferenceEntryCacheCfg.class;
188  }
189
190
191
192  /**
193   * Get the "cache-level" property definition.
194   * <p>
195   * Specifies the cache level in the cache order if more than one
196   * instance of the cache is configured.
197   *
198   * @return Returns the "cache-level" property definition.
199   */
200  public IntegerPropertyDefinition getCacheLevelPropertyDefinition() {
201    return EntryCacheCfgDefn.getInstance().getCacheLevelPropertyDefinition();
202  }
203
204
205
206  /**
207   * Get the "enabled" property definition.
208   * <p>
209   * Indicates whether the Soft Reference Entry Cache is enabled.
210   *
211   * @return Returns the "enabled" property definition.
212   */
213  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
214    return EntryCacheCfgDefn.getInstance().getEnabledPropertyDefinition();
215  }
216
217
218
219  /**
220   * Get the "exclude-filter" property definition.
221   * <p>
222   * The set of filters that define the entries that should be
223   * excluded from the cache.
224   *
225   * @return Returns the "exclude-filter" property definition.
226   */
227  public StringPropertyDefinition getExcludeFilterPropertyDefinition() {
228    return PD_EXCLUDE_FILTER;
229  }
230
231
232
233  /**
234   * Get the "include-filter" property definition.
235   * <p>
236   * The set of filters that define the entries that should be
237   * included in the cache.
238   *
239   * @return Returns the "include-filter" property definition.
240   */
241  public StringPropertyDefinition getIncludeFilterPropertyDefinition() {
242    return PD_INCLUDE_FILTER;
243  }
244
245
246
247  /**
248   * Get the "java-class" property definition.
249   * <p>
250   * Specifies the fully-qualified name of the Java class that
251   * provides the Soft Reference Entry Cache implementation.
252   *
253   * @return Returns the "java-class" property definition.
254   */
255  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
256    return PD_JAVA_CLASS;
257  }
258
259
260
261  /**
262   * Get the "lock-timeout" property definition.
263   * <p>
264   * Specifies the length of time in milliseconds to wait while
265   * attempting to acquire a read or write lock.
266   *
267   * @return Returns the "lock-timeout" property definition.
268   */
269  public DurationPropertyDefinition getLockTimeoutPropertyDefinition() {
270    return PD_LOCK_TIMEOUT;
271  }
272
273
274
275  /**
276   * Managed object client implementation.
277   */
278  private static class SoftReferenceEntryCacheCfgClientImpl implements
279    SoftReferenceEntryCacheCfgClient {
280
281    /** Private implementation. */
282    private ManagedObject<? extends SoftReferenceEntryCacheCfgClient> impl;
283
284
285
286    /** Private constructor. */
287    private SoftReferenceEntryCacheCfgClientImpl(
288        ManagedObject<? extends SoftReferenceEntryCacheCfgClient> impl) {
289      this.impl = impl;
290    }
291
292
293
294    /** {@inheritDoc} */
295    public Integer getCacheLevel() {
296      return impl.getPropertyValue(INSTANCE.getCacheLevelPropertyDefinition());
297    }
298
299
300
301    /** {@inheritDoc} */
302    public void setCacheLevel(int value) {
303      impl.setPropertyValue(INSTANCE.getCacheLevelPropertyDefinition(), value);
304    }
305
306
307
308    /** {@inheritDoc} */
309    public Boolean isEnabled() {
310      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
311    }
312
313
314
315    /** {@inheritDoc} */
316    public void setEnabled(boolean value) {
317      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
318    }
319
320
321
322    /** {@inheritDoc} */
323    public SortedSet<String> getExcludeFilter() {
324      return impl.getPropertyValues(INSTANCE.getExcludeFilterPropertyDefinition());
325    }
326
327
328
329    /** {@inheritDoc} */
330    public void setExcludeFilter(Collection<String> values) {
331      impl.setPropertyValues(INSTANCE.getExcludeFilterPropertyDefinition(), values);
332    }
333
334
335
336    /** {@inheritDoc} */
337    public SortedSet<String> getIncludeFilter() {
338      return impl.getPropertyValues(INSTANCE.getIncludeFilterPropertyDefinition());
339    }
340
341
342
343    /** {@inheritDoc} */
344    public void setIncludeFilter(Collection<String> values) {
345      impl.setPropertyValues(INSTANCE.getIncludeFilterPropertyDefinition(), values);
346    }
347
348
349
350    /** {@inheritDoc} */
351    public String getJavaClass() {
352      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
353    }
354
355
356
357    /** {@inheritDoc} */
358    public void setJavaClass(String value) {
359      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
360    }
361
362
363
364    /** {@inheritDoc} */
365    public long getLockTimeout() {
366      return impl.getPropertyValue(INSTANCE.getLockTimeoutPropertyDefinition());
367    }
368
369
370
371    /** {@inheritDoc} */
372    public void setLockTimeout(Long value) {
373      impl.setPropertyValue(INSTANCE.getLockTimeoutPropertyDefinition(), value);
374    }
375
376
377
378    /** {@inheritDoc} */
379    public ManagedObjectDefinition<? extends SoftReferenceEntryCacheCfgClient, ? extends SoftReferenceEntryCacheCfg> definition() {
380      return INSTANCE;
381    }
382
383
384
385    /** {@inheritDoc} */
386    public PropertyProvider properties() {
387      return impl;
388    }
389
390
391
392    /** {@inheritDoc} */
393    public void commit() throws ManagedObjectAlreadyExistsException,
394        MissingMandatoryPropertiesException, ConcurrentModificationException,
395        OperationRejectedException, LdapException {
396      impl.commit();
397    }
398
399
400
401    /** {@inheritDoc} */
402    public String toString() {
403      return impl.toString();
404    }
405  }
406
407
408
409  /**
410   * Managed object server implementation.
411   */
412  private static class SoftReferenceEntryCacheCfgServerImpl implements
413    SoftReferenceEntryCacheCfg {
414
415    /** Private implementation. */
416    private ServerManagedObject<? extends SoftReferenceEntryCacheCfg> impl;
417
418    /** The value of the "cache-level" property. */
419    private final int pCacheLevel;
420
421    /** The value of the "enabled" property. */
422    private final boolean pEnabled;
423
424    /** The value of the "exclude-filter" property. */
425    private final SortedSet<String> pExcludeFilter;
426
427    /** The value of the "include-filter" property. */
428    private final SortedSet<String> pIncludeFilter;
429
430    /** The value of the "java-class" property. */
431    private final String pJavaClass;
432
433    /** The value of the "lock-timeout" property. */
434    private final long pLockTimeout;
435
436
437
438    /** Private constructor. */
439    private SoftReferenceEntryCacheCfgServerImpl(ServerManagedObject<? extends SoftReferenceEntryCacheCfg> impl) {
440      this.impl = impl;
441      this.pCacheLevel = impl.getPropertyValue(INSTANCE.getCacheLevelPropertyDefinition());
442      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
443      this.pExcludeFilter = impl.getPropertyValues(INSTANCE.getExcludeFilterPropertyDefinition());
444      this.pIncludeFilter = impl.getPropertyValues(INSTANCE.getIncludeFilterPropertyDefinition());
445      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
446      this.pLockTimeout = impl.getPropertyValue(INSTANCE.getLockTimeoutPropertyDefinition());
447    }
448
449
450
451    /** {@inheritDoc} */
452    public void addSoftReferenceChangeListener(
453        ConfigurationChangeListener<SoftReferenceEntryCacheCfg> listener) {
454      impl.registerChangeListener(listener);
455    }
456
457
458
459    /** {@inheritDoc} */
460    public void removeSoftReferenceChangeListener(
461        ConfigurationChangeListener<SoftReferenceEntryCacheCfg> listener) {
462      impl.deregisterChangeListener(listener);
463    }
464    /** {@inheritDoc} */
465    public void addChangeListener(
466        ConfigurationChangeListener<EntryCacheCfg> listener) {
467      impl.registerChangeListener(listener);
468    }
469
470
471
472    /** {@inheritDoc} */
473    public void removeChangeListener(
474        ConfigurationChangeListener<EntryCacheCfg> listener) {
475      impl.deregisterChangeListener(listener);
476    }
477
478
479
480    /** {@inheritDoc} */
481    public int getCacheLevel() {
482      return pCacheLevel;
483    }
484
485
486
487    /** {@inheritDoc} */
488    public boolean isEnabled() {
489      return pEnabled;
490    }
491
492
493
494    /** {@inheritDoc} */
495    public SortedSet<String> getExcludeFilter() {
496      return pExcludeFilter;
497    }
498
499
500
501    /** {@inheritDoc} */
502    public SortedSet<String> getIncludeFilter() {
503      return pIncludeFilter;
504    }
505
506
507
508    /** {@inheritDoc} */
509    public String getJavaClass() {
510      return pJavaClass;
511    }
512
513
514
515    /** {@inheritDoc} */
516    public long getLockTimeout() {
517      return pLockTimeout;
518    }
519
520
521
522    /** {@inheritDoc} */
523    public Class<? extends SoftReferenceEntryCacheCfg> configurationClass() {
524      return SoftReferenceEntryCacheCfg.class;
525    }
526
527
528
529    /** {@inheritDoc} */
530    public DN dn() {
531      return impl.getDN();
532    }
533
534
535
536    /** {@inheritDoc} */
537    public String toString() {
538      return impl.toString();
539    }
540  }
541}