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