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