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.ClassPropertyDefinition;
033    import org.opends.server.admin.client.AuthorizationException;
034    import org.opends.server.admin.client.CommunicationException;
035    import org.opends.server.admin.client.ConcurrentModificationException;
036    import org.opends.server.admin.client.ManagedObject;
037    import org.opends.server.admin.client.MissingMandatoryPropertiesException;
038    import org.opends.server.admin.client.OperationRejectedException;
039    import org.opends.server.admin.DefaultBehaviorProvider;
040    import org.opends.server.admin.DefinedDefaultBehaviorProvider;
041    import org.opends.server.admin.IntegerPropertyDefinition;
042    import org.opends.server.admin.ManagedObjectAlreadyExistsException;
043    import org.opends.server.admin.ManagedObjectDefinition;
044    import org.opends.server.admin.PropertyOption;
045    import org.opends.server.admin.PropertyProvider;
046    import org.opends.server.admin.server.ConfigurationChangeListener;
047    import org.opends.server.admin.server.ServerManagedObject;
048    import org.opends.server.admin.std.client.FileCountLogRetentionPolicyCfgClient;
049    import org.opends.server.admin.std.server.FileCountLogRetentionPolicyCfg;
050    import org.opends.server.admin.std.server.LogRetentionPolicyCfg;
051    import org.opends.server.admin.Tag;
052    import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
053    import org.opends.server.types.DN;
054    
055    
056    
057    /**
058     * An interface for querying the File Count Log Retention Policy
059     * managed object definition meta information.
060     * <p>
061     * Retention policy based on the number of rotated log files on disk.
062     */
063    public final class FileCountLogRetentionPolicyCfgDefn extends ManagedObjectDefinition<FileCountLogRetentionPolicyCfgClient, FileCountLogRetentionPolicyCfg> {
064    
065      // The singleton configuration definition instance.
066      private static final FileCountLogRetentionPolicyCfgDefn INSTANCE = new FileCountLogRetentionPolicyCfgDefn();
067    
068    
069    
070      // The "java-class" property definition.
071      private static final ClassPropertyDefinition PD_JAVA_CLASS;
072    
073    
074    
075      // The "number-of-files" property definition.
076      private static final IntegerPropertyDefinition PD_NUMBER_OF_FILES;
077    
078    
079    
080      // Build the "java-class" property definition.
081      static {
082          ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
083          builder.setOption(PropertyOption.MANDATORY);
084          builder.setOption(PropertyOption.ADVANCED);
085          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class"));
086          DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.loggers.FileNumberRetentionPolicy");
087          builder.setDefaultBehaviorProvider(provider);
088          builder.addInstanceOf("org.opends.server.loggers.RetentionPolicy");
089          PD_JAVA_CLASS = builder.getInstance();
090          INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
091      }
092    
093    
094    
095      // Build the "number-of-files" property definition.
096      static {
097          IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "number-of-files");
098          builder.setOption(PropertyOption.MANDATORY);
099          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "number-of-files"));
100          builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Integer>());
101          builder.setLowerLimit(1);
102          PD_NUMBER_OF_FILES = builder.getInstance();
103          INSTANCE.registerPropertyDefinition(PD_NUMBER_OF_FILES);
104      }
105    
106    
107    
108      // Register the tags associated with this managed object definition.
109      static {
110        INSTANCE.registerTag(Tag.valueOf("logging"));
111      }
112    
113    
114    
115      /**
116       * Get the File Count Log Retention Policy configuration definition
117       * singleton.
118       *
119       * @return Returns the File Count Log Retention Policy configuration
120       *         definition singleton.
121       */
122      public static FileCountLogRetentionPolicyCfgDefn getInstance() {
123        return INSTANCE;
124      }
125    
126    
127    
128      /**
129       * Private constructor.
130       */
131      private FileCountLogRetentionPolicyCfgDefn() {
132        super("file-count-log-retention-policy", LogRetentionPolicyCfgDefn.getInstance());
133      }
134    
135    
136    
137      /**
138       * {@inheritDoc}
139       */
140      public FileCountLogRetentionPolicyCfgClient createClientConfiguration(
141          ManagedObject<? extends FileCountLogRetentionPolicyCfgClient> impl) {
142        return new FileCountLogRetentionPolicyCfgClientImpl(impl);
143      }
144    
145    
146    
147      /**
148       * {@inheritDoc}
149       */
150      public FileCountLogRetentionPolicyCfg createServerConfiguration(
151          ServerManagedObject<? extends FileCountLogRetentionPolicyCfg> impl) {
152        return new FileCountLogRetentionPolicyCfgServerImpl(impl);
153      }
154    
155    
156    
157      /**
158       * {@inheritDoc}
159       */
160      public Class<FileCountLogRetentionPolicyCfg> getServerConfigurationClass() {
161        return FileCountLogRetentionPolicyCfg.class;
162      }
163    
164    
165    
166      /**
167       * Get the "java-class" property definition.
168       * <p>
169       * Specifies the fully-qualified name of the Java class that
170       * provides the File Count Log Retention Policy implementation.
171       *
172       * @return Returns the "java-class" property definition.
173       */
174      public ClassPropertyDefinition getJavaClassPropertyDefinition() {
175        return PD_JAVA_CLASS;
176      }
177    
178    
179    
180      /**
181       * Get the "number-of-files" property definition.
182       * <p>
183       * Specifies the number of archived log files to retain before the
184       * oldest ones are cleaned.
185       *
186       * @return Returns the "number-of-files" property definition.
187       */
188      public IntegerPropertyDefinition getNumberOfFilesPropertyDefinition() {
189        return PD_NUMBER_OF_FILES;
190      }
191    
192    
193    
194      /**
195       * Managed object client implementation.
196       */
197      private static class FileCountLogRetentionPolicyCfgClientImpl implements
198        FileCountLogRetentionPolicyCfgClient {
199    
200        // Private implementation.
201        private ManagedObject<? extends FileCountLogRetentionPolicyCfgClient> impl;
202    
203    
204    
205        // Private constructor.
206        private FileCountLogRetentionPolicyCfgClientImpl(
207            ManagedObject<? extends FileCountLogRetentionPolicyCfgClient> impl) {
208          this.impl = impl;
209        }
210    
211    
212    
213        /**
214         * {@inheritDoc}
215         */
216        public String getJavaClass() {
217          return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
218        }
219    
220    
221    
222        /**
223         * {@inheritDoc}
224         */
225        public void setJavaClass(String value) {
226          impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
227        }
228    
229    
230    
231        /**
232         * {@inheritDoc}
233         */
234        public Integer getNumberOfFiles() {
235          return impl.getPropertyValue(INSTANCE.getNumberOfFilesPropertyDefinition());
236        }
237    
238    
239    
240        /**
241         * {@inheritDoc}
242         */
243        public void setNumberOfFiles(int value) {
244          impl.setPropertyValue(INSTANCE.getNumberOfFilesPropertyDefinition(), value);
245        }
246    
247    
248    
249        /**
250         * {@inheritDoc}
251         */
252        public ManagedObjectDefinition<? extends FileCountLogRetentionPolicyCfgClient, ? extends FileCountLogRetentionPolicyCfg> definition() {
253          return INSTANCE;
254        }
255    
256    
257    
258        /**
259         * {@inheritDoc}
260         */
261        public PropertyProvider properties() {
262          return impl;
263        }
264    
265    
266    
267        /**
268         * {@inheritDoc}
269         */
270        public void commit() throws ManagedObjectAlreadyExistsException,
271            MissingMandatoryPropertiesException, ConcurrentModificationException,
272            OperationRejectedException, AuthorizationException,
273            CommunicationException {
274          impl.commit();
275        }
276    
277      }
278    
279    
280    
281      /**
282       * Managed object server implementation.
283       */
284      private static class FileCountLogRetentionPolicyCfgServerImpl implements
285        FileCountLogRetentionPolicyCfg {
286    
287        // Private implementation.
288        private ServerManagedObject<? extends FileCountLogRetentionPolicyCfg> impl;
289    
290        // The value of the "java-class" property.
291        private final String pJavaClass;
292    
293        // The value of the "number-of-files" property.
294        private final int pNumberOfFiles;
295    
296    
297    
298        // Private constructor.
299        private FileCountLogRetentionPolicyCfgServerImpl(ServerManagedObject<? extends FileCountLogRetentionPolicyCfg> impl) {
300          this.impl = impl;
301          this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
302          this.pNumberOfFiles = impl.getPropertyValue(INSTANCE.getNumberOfFilesPropertyDefinition());
303        }
304    
305    
306    
307        /**
308         * {@inheritDoc}
309         */
310        public void addFileCountChangeListener(
311            ConfigurationChangeListener<FileCountLogRetentionPolicyCfg> listener) {
312          impl.registerChangeListener(listener);
313        }
314    
315    
316    
317        /**
318         * {@inheritDoc}
319         */
320        public void removeFileCountChangeListener(
321            ConfigurationChangeListener<FileCountLogRetentionPolicyCfg> listener) {
322          impl.deregisterChangeListener(listener);
323        }
324        /**
325         * {@inheritDoc}
326         */
327        public void addChangeListener(
328            ConfigurationChangeListener<LogRetentionPolicyCfg> listener) {
329          impl.registerChangeListener(listener);
330        }
331    
332    
333    
334        /**
335         * {@inheritDoc}
336         */
337        public void removeChangeListener(
338            ConfigurationChangeListener<LogRetentionPolicyCfg> listener) {
339          impl.deregisterChangeListener(listener);
340        }
341    
342    
343    
344        /**
345         * {@inheritDoc}
346         */
347        public String getJavaClass() {
348          return pJavaClass;
349        }
350    
351    
352    
353        /**
354         * {@inheritDoc}
355         */
356        public int getNumberOfFiles() {
357          return pNumberOfFiles;
358        }
359    
360    
361    
362        /**
363         * {@inheritDoc}
364         */
365        public Class<? extends FileCountLogRetentionPolicyCfg> configurationClass() {
366          return FileCountLogRetentionPolicyCfg.class;
367        }
368    
369    
370    
371        /**
372         * {@inheritDoc}
373         */
374        public DN dn() {
375          return impl.getDN();
376        }
377    
378      }
379    }