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