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