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