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