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