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 org.forgerock.opendj.config.AdministratorAction;
021import org.forgerock.opendj.config.BooleanPropertyDefinition;
022import org.forgerock.opendj.config.ClassPropertyDefinition;
023import org.forgerock.opendj.config.client.ConcurrentModificationException;
024import org.forgerock.opendj.config.client.ManagedObject;
025import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
026import org.forgerock.opendj.config.client.OperationRejectedException;
027import org.forgerock.opendj.config.IntegerPropertyDefinition;
028import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
029import org.forgerock.opendj.config.ManagedObjectDefinition;
030import org.forgerock.opendj.config.PropertyOption;
031import org.forgerock.opendj.config.PropertyProvider;
032import org.forgerock.opendj.config.server.ConfigurationChangeListener;
033import org.forgerock.opendj.config.server.ServerManagedObject;
034import org.forgerock.opendj.config.Tag;
035import org.forgerock.opendj.config.TopCfgDefn;
036import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider;
037import org.forgerock.opendj.ldap.DN;
038import org.forgerock.opendj.ldap.LdapException;
039import org.forgerock.opendj.server.config.client.EntryCacheCfgClient;
040import org.forgerock.opendj.server.config.server.EntryCacheCfg;
041
042
043
044/**
045 * An interface for querying the Entry Cache managed object definition
046 * meta information.
047 * <p>
048 * Entry Caches are responsible for caching entries which are likely
049 * to be accessed by client applications in order to improve OpenDJ
050 * directory server performance.
051 */
052public final class EntryCacheCfgDefn extends ManagedObjectDefinition<EntryCacheCfgClient, EntryCacheCfg> {
053
054  /** The singleton configuration definition instance. */
055  private static final EntryCacheCfgDefn INSTANCE = new EntryCacheCfgDefn();
056
057
058
059  /** The "cache-level" property definition. */
060  private static final IntegerPropertyDefinition PD_CACHE_LEVEL;
061
062
063
064  /** The "enabled" property definition. */
065  private static final BooleanPropertyDefinition PD_ENABLED;
066
067
068
069  /** The "java-class" property definition. */
070  private static final ClassPropertyDefinition PD_JAVA_CLASS;
071
072
073
074  /** Build the "cache-level" property definition. */
075  static {
076      IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "cache-level");
077      builder.setOption(PropertyOption.MANDATORY);
078      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "cache-level"));
079      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Integer>());
080      builder.setLowerLimit(1);
081      PD_CACHE_LEVEL = builder.getInstance();
082      INSTANCE.registerPropertyDefinition(PD_CACHE_LEVEL);
083  }
084
085
086
087  /** Build the "enabled" property definition. */
088  static {
089      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled");
090      builder.setOption(PropertyOption.MANDATORY);
091      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled"));
092      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>());
093      PD_ENABLED = builder.getInstance();
094      INSTANCE.registerPropertyDefinition(PD_ENABLED);
095  }
096
097
098
099  /** Build the "java-class" property definition. */
100  static {
101      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
102      builder.setOption(PropertyOption.MANDATORY);
103      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
104      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
105      builder.addInstanceOf("org.opends.server.api.EntryCache");
106      PD_JAVA_CLASS = builder.getInstance();
107      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
108  }
109
110
111
112  // Register the tags associated with this managed object definition.
113  static {
114    INSTANCE.registerTag(Tag.valueOf("database"));
115  }
116
117
118
119  /**
120   * Get the Entry Cache configuration definition singleton.
121   *
122   * @return Returns the Entry Cache configuration definition
123   *         singleton.
124   */
125  public static EntryCacheCfgDefn getInstance() {
126    return INSTANCE;
127  }
128
129
130
131  /**
132   * Private constructor.
133   */
134  private EntryCacheCfgDefn() {
135    super("entry-cache", TopCfgDefn.getInstance());
136  }
137
138
139
140  /** {@inheritDoc} */
141  public EntryCacheCfgClient createClientConfiguration(
142      ManagedObject<? extends EntryCacheCfgClient> impl) {
143    return new EntryCacheCfgClientImpl(impl);
144  }
145
146
147
148  /** {@inheritDoc} */
149  public EntryCacheCfg createServerConfiguration(
150      ServerManagedObject<? extends EntryCacheCfg> impl) {
151    return new EntryCacheCfgServerImpl(impl);
152  }
153
154
155
156  /** {@inheritDoc} */
157  public Class<EntryCacheCfg> getServerConfigurationClass() {
158    return EntryCacheCfg.class;
159  }
160
161
162
163  /**
164   * Get the "cache-level" property definition.
165   * <p>
166   * Specifies the cache level in the cache order if more than one
167   * instance of the cache is configured.
168   *
169   * @return Returns the "cache-level" property definition.
170   */
171  public IntegerPropertyDefinition getCacheLevelPropertyDefinition() {
172    return PD_CACHE_LEVEL;
173  }
174
175
176
177  /**
178   * Get the "enabled" property definition.
179   * <p>
180   * Indicates whether the Entry Cache is enabled.
181   *
182   * @return Returns the "enabled" property definition.
183   */
184  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
185    return PD_ENABLED;
186  }
187
188
189
190  /**
191   * Get the "java-class" property definition.
192   * <p>
193   * Specifies the fully-qualified name of the Java class that
194   * provides the Entry Cache implementation.
195   *
196   * @return Returns the "java-class" property definition.
197   */
198  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
199    return PD_JAVA_CLASS;
200  }
201
202
203
204  /**
205   * Managed object client implementation.
206   */
207  private static class EntryCacheCfgClientImpl implements
208    EntryCacheCfgClient {
209
210    /** Private implementation. */
211    private ManagedObject<? extends EntryCacheCfgClient> impl;
212
213
214
215    /** Private constructor. */
216    private EntryCacheCfgClientImpl(
217        ManagedObject<? extends EntryCacheCfgClient> impl) {
218      this.impl = impl;
219    }
220
221
222
223    /** {@inheritDoc} */
224    public Integer getCacheLevel() {
225      return impl.getPropertyValue(INSTANCE.getCacheLevelPropertyDefinition());
226    }
227
228
229
230    /** {@inheritDoc} */
231    public void setCacheLevel(int value) {
232      impl.setPropertyValue(INSTANCE.getCacheLevelPropertyDefinition(), value);
233    }
234
235
236
237    /** {@inheritDoc} */
238    public Boolean isEnabled() {
239      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
240    }
241
242
243
244    /** {@inheritDoc} */
245    public void setEnabled(boolean value) {
246      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
247    }
248
249
250
251    /** {@inheritDoc} */
252    public String getJavaClass() {
253      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
254    }
255
256
257
258    /** {@inheritDoc} */
259    public void setJavaClass(String value) {
260      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
261    }
262
263
264
265    /** {@inheritDoc} */
266    public ManagedObjectDefinition<? extends EntryCacheCfgClient, ? extends EntryCacheCfg> definition() {
267      return INSTANCE;
268    }
269
270
271
272    /** {@inheritDoc} */
273    public PropertyProvider properties() {
274      return impl;
275    }
276
277
278
279    /** {@inheritDoc} */
280    public void commit() throws ManagedObjectAlreadyExistsException,
281        MissingMandatoryPropertiesException, ConcurrentModificationException,
282        OperationRejectedException, LdapException {
283      impl.commit();
284    }
285
286
287
288    /** {@inheritDoc} */
289    public String toString() {
290      return impl.toString();
291    }
292  }
293
294
295
296  /**
297   * Managed object server implementation.
298   */
299  private static class EntryCacheCfgServerImpl implements
300    EntryCacheCfg {
301
302    /** Private implementation. */
303    private ServerManagedObject<? extends EntryCacheCfg> impl;
304
305    /** The value of the "cache-level" property. */
306    private final int pCacheLevel;
307
308    /** The value of the "enabled" property. */
309    private final boolean pEnabled;
310
311    /** The value of the "java-class" property. */
312    private final String pJavaClass;
313
314
315
316    /** Private constructor. */
317    private EntryCacheCfgServerImpl(ServerManagedObject<? extends EntryCacheCfg> impl) {
318      this.impl = impl;
319      this.pCacheLevel = impl.getPropertyValue(INSTANCE.getCacheLevelPropertyDefinition());
320      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
321      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
322    }
323
324
325
326    /** {@inheritDoc} */
327    public void addChangeListener(
328        ConfigurationChangeListener<EntryCacheCfg> listener) {
329      impl.registerChangeListener(listener);
330    }
331
332
333
334    /** {@inheritDoc} */
335    public void removeChangeListener(
336        ConfigurationChangeListener<EntryCacheCfg> listener) {
337      impl.deregisterChangeListener(listener);
338    }
339
340
341
342    /** {@inheritDoc} */
343    public int getCacheLevel() {
344      return pCacheLevel;
345    }
346
347
348
349    /** {@inheritDoc} */
350    public boolean isEnabled() {
351      return pEnabled;
352    }
353
354
355
356    /** {@inheritDoc} */
357    public String getJavaClass() {
358      return pJavaClass;
359    }
360
361
362
363    /** {@inheritDoc} */
364    public Class<? extends EntryCacheCfg> configurationClass() {
365      return EntryCacheCfg.class;
366    }
367
368
369
370    /** {@inheritDoc} */
371    public DN dn() {
372      return impl.getDN();
373    }
374
375
376
377    /** {@inheritDoc} */
378    public String toString() {
379      return impl.toString();
380    }
381  }
382}