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