001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2008 Sun Microsystems, Inc.
015 */
016package org.opends.server.admin.std.meta;
017
018
019
020import org.forgerock.opendj.ldap.DN;
021import org.opends.server.admin.AdministratorAction;
022import org.opends.server.admin.ClassPropertyDefinition;
023import org.opends.server.admin.client.AuthorizationException;
024import org.opends.server.admin.client.CommunicationException;
025import org.opends.server.admin.client.ConcurrentModificationException;
026import org.opends.server.admin.client.ManagedObject;
027import org.opends.server.admin.client.MissingMandatoryPropertiesException;
028import org.opends.server.admin.client.OperationRejectedException;
029import org.opends.server.admin.DefaultBehaviorProvider;
030import org.opends.server.admin.DefinedDefaultBehaviorProvider;
031import org.opends.server.admin.ManagedObjectAlreadyExistsException;
032import org.opends.server.admin.ManagedObjectDefinition;
033import org.opends.server.admin.PropertyOption;
034import org.opends.server.admin.PropertyProvider;
035import org.opends.server.admin.server.ConfigurationChangeListener;
036import org.opends.server.admin.server.ServerManagedObject;
037import org.opends.server.admin.SizePropertyDefinition;
038import org.opends.server.admin.std.client.SizeLimitLogRotationPolicyCfgClient;
039import org.opends.server.admin.std.server.LogRotationPolicyCfg;
040import org.opends.server.admin.std.server.SizeLimitLogRotationPolicyCfg;
041import org.opends.server.admin.Tag;
042import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
043
044
045
046/**
047 * An interface for querying the Size Limit Log Rotation Policy
048 * managed object definition meta information.
049 * <p>
050 * Rotation policy based on the size of the log file.
051 */
052public final class SizeLimitLogRotationPolicyCfgDefn extends ManagedObjectDefinition<SizeLimitLogRotationPolicyCfgClient, SizeLimitLogRotationPolicyCfg> {
053
054  // The singleton configuration definition instance.
055  private static final SizeLimitLogRotationPolicyCfgDefn INSTANCE = new SizeLimitLogRotationPolicyCfgDefn();
056
057
058
059  // The "file-size-limit" property definition.
060  private static final SizePropertyDefinition PD_FILE_SIZE_LIMIT;
061
062
063
064  // The "java-class" property definition.
065  private static final ClassPropertyDefinition PD_JAVA_CLASS;
066
067
068
069  // Build the "file-size-limit" property definition.
070  static {
071      SizePropertyDefinition.Builder builder = SizePropertyDefinition.createBuilder(INSTANCE, "file-size-limit");
072      builder.setOption(PropertyOption.MANDATORY);
073      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "file-size-limit"));
074      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Long>());
075      builder.setLowerLimit("1");
076      PD_FILE_SIZE_LIMIT = builder.getInstance();
077      INSTANCE.registerPropertyDefinition(PD_FILE_SIZE_LIMIT);
078  }
079
080
081
082  // Build the "java-class" property definition.
083  static {
084      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
085      builder.setOption(PropertyOption.MANDATORY);
086      builder.setOption(PropertyOption.ADVANCED);
087      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class"));
088      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.loggers.SizeBasedRotationPolicy");
089      builder.setDefaultBehaviorProvider(provider);
090      builder.addInstanceOf("org.opends.server.loggers.RotationPolicy");
091      PD_JAVA_CLASS = builder.getInstance();
092      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
093  }
094
095
096
097  // Register the tags associated with this managed object definition.
098  static {
099    INSTANCE.registerTag(Tag.valueOf("logging"));
100  }
101
102
103
104  /**
105   * Get the Size Limit Log Rotation Policy configuration definition
106   * singleton.
107   *
108   * @return Returns the Size Limit Log Rotation Policy configuration
109   *         definition singleton.
110   */
111  public static SizeLimitLogRotationPolicyCfgDefn getInstance() {
112    return INSTANCE;
113  }
114
115
116
117  /**
118   * Private constructor.
119   */
120  private SizeLimitLogRotationPolicyCfgDefn() {
121    super("size-limit-log-rotation-policy", LogRotationPolicyCfgDefn.getInstance());
122  }
123
124
125
126  /**
127   * {@inheritDoc}
128   */
129  public SizeLimitLogRotationPolicyCfgClient createClientConfiguration(
130      ManagedObject<? extends SizeLimitLogRotationPolicyCfgClient> impl) {
131    return new SizeLimitLogRotationPolicyCfgClientImpl(impl);
132  }
133
134
135
136  /**
137   * {@inheritDoc}
138   */
139  public SizeLimitLogRotationPolicyCfg createServerConfiguration(
140      ServerManagedObject<? extends SizeLimitLogRotationPolicyCfg> impl) {
141    return new SizeLimitLogRotationPolicyCfgServerImpl(impl);
142  }
143
144
145
146  /**
147   * {@inheritDoc}
148   */
149  public Class<SizeLimitLogRotationPolicyCfg> getServerConfigurationClass() {
150    return SizeLimitLogRotationPolicyCfg.class;
151  }
152
153
154
155  /**
156   * Get the "file-size-limit" property definition.
157   * <p>
158   * Specifies the maximum size that a log file can reach before it is
159   * rotated.
160   *
161   * @return Returns the "file-size-limit" property definition.
162   */
163  public SizePropertyDefinition getFileSizeLimitPropertyDefinition() {
164    return PD_FILE_SIZE_LIMIT;
165  }
166
167
168
169  /**
170   * Get the "java-class" property definition.
171   * <p>
172   * Specifies the fully-qualified name of the Java class that
173   * provides the Size Limit Log Rotation Policy implementation.
174   *
175   * @return Returns the "java-class" property definition.
176   */
177  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
178    return PD_JAVA_CLASS;
179  }
180
181
182
183  /**
184   * Managed object client implementation.
185   */
186  private static class SizeLimitLogRotationPolicyCfgClientImpl implements
187    SizeLimitLogRotationPolicyCfgClient {
188
189    // Private implementation.
190    private ManagedObject<? extends SizeLimitLogRotationPolicyCfgClient> impl;
191
192
193
194    // Private constructor.
195    private SizeLimitLogRotationPolicyCfgClientImpl(
196        ManagedObject<? extends SizeLimitLogRotationPolicyCfgClient> impl) {
197      this.impl = impl;
198    }
199
200
201
202    /**
203     * {@inheritDoc}
204     */
205    public Long getFileSizeLimit() {
206      return impl.getPropertyValue(INSTANCE.getFileSizeLimitPropertyDefinition());
207    }
208
209
210
211    /**
212     * {@inheritDoc}
213     */
214    public void setFileSizeLimit(long value) {
215      impl.setPropertyValue(INSTANCE.getFileSizeLimitPropertyDefinition(), value);
216    }
217
218
219
220    /**
221     * {@inheritDoc}
222     */
223    public String getJavaClass() {
224      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
225    }
226
227
228
229    /**
230     * {@inheritDoc}
231     */
232    public void setJavaClass(String value) {
233      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
234    }
235
236
237
238    /**
239     * {@inheritDoc}
240     */
241    public ManagedObjectDefinition<? extends SizeLimitLogRotationPolicyCfgClient, ? extends SizeLimitLogRotationPolicyCfg> definition() {
242      return INSTANCE;
243    }
244
245
246
247    /**
248     * {@inheritDoc}
249     */
250    public PropertyProvider properties() {
251      return impl;
252    }
253
254
255
256    /**
257     * {@inheritDoc}
258     */
259    public void commit() throws ManagedObjectAlreadyExistsException,
260        MissingMandatoryPropertiesException, ConcurrentModificationException,
261        OperationRejectedException, AuthorizationException,
262        CommunicationException {
263      impl.commit();
264    }
265
266
267
268    /** {@inheritDoc} */
269    public String toString() {
270      return impl.toString();
271    }
272  }
273
274
275
276  /**
277   * Managed object server implementation.
278   */
279  private static class SizeLimitLogRotationPolicyCfgServerImpl implements
280    SizeLimitLogRotationPolicyCfg {
281
282    // Private implementation.
283    private ServerManagedObject<? extends SizeLimitLogRotationPolicyCfg> impl;
284
285    // The value of the "file-size-limit" property.
286    private final long pFileSizeLimit;
287
288    // The value of the "java-class" property.
289    private final String pJavaClass;
290
291
292
293    // Private constructor.
294    private SizeLimitLogRotationPolicyCfgServerImpl(ServerManagedObject<? extends SizeLimitLogRotationPolicyCfg> impl) {
295      this.impl = impl;
296      this.pFileSizeLimit = impl.getPropertyValue(INSTANCE.getFileSizeLimitPropertyDefinition());
297      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
298    }
299
300
301
302    /**
303     * {@inheritDoc}
304     */
305    public void addSizeLimitChangeListener(
306        ConfigurationChangeListener<SizeLimitLogRotationPolicyCfg> listener) {
307      impl.registerChangeListener(listener);
308    }
309
310
311
312    /**
313     * {@inheritDoc}
314     */
315    public void removeSizeLimitChangeListener(
316        ConfigurationChangeListener<SizeLimitLogRotationPolicyCfg> listener) {
317      impl.deregisterChangeListener(listener);
318    }
319    /**
320     * {@inheritDoc}
321     */
322    public void addChangeListener(
323        ConfigurationChangeListener<LogRotationPolicyCfg> listener) {
324      impl.registerChangeListener(listener);
325    }
326
327
328
329    /**
330     * {@inheritDoc}
331     */
332    public void removeChangeListener(
333        ConfigurationChangeListener<LogRotationPolicyCfg> listener) {
334      impl.deregisterChangeListener(listener);
335    }
336
337
338
339    /**
340     * {@inheritDoc}
341     */
342    public long getFileSizeLimit() {
343      return pFileSizeLimit;
344    }
345
346
347
348    /**
349     * {@inheritDoc}
350     */
351    public String getJavaClass() {
352      return pJavaClass;
353    }
354
355
356
357    /**
358     * {@inheritDoc}
359     */
360    public Class<? extends SizeLimitLogRotationPolicyCfg> configurationClass() {
361      return SizeLimitLogRotationPolicyCfg.class;
362    }
363
364
365
366    /**
367     * {@inheritDoc}
368     */
369    public DN dn() {
370      return impl.getDN();
371    }
372
373
374
375    /** {@inheritDoc} */
376    public String toString() {
377      return impl.toString();
378    }
379  }
380}