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.FreeDiskSpaceLogRetentionPolicyCfgClient;
048import org.opends.server.admin.std.server.FreeDiskSpaceLogRetentionPolicyCfg;
049import org.opends.server.admin.std.server.LogRetentionPolicyCfg;
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 Free Disk Space Log Retention Policy
058 * managed object definition meta information.
059 * <p>
060 * Retention policy based on the free disk space available.
061 */
062public final class FreeDiskSpaceLogRetentionPolicyCfgDefn extends ManagedObjectDefinition<FreeDiskSpaceLogRetentionPolicyCfgClient, FreeDiskSpaceLogRetentionPolicyCfg> {
063
064  // The singleton configuration definition instance.
065  private static final FreeDiskSpaceLogRetentionPolicyCfgDefn INSTANCE = new FreeDiskSpaceLogRetentionPolicyCfgDefn();
066
067
068
069  // The "free-disk-space" property definition.
070  private static final SizePropertyDefinition PD_FREE_DISK_SPACE;
071
072
073
074  // The "java-class" property definition.
075  private static final ClassPropertyDefinition PD_JAVA_CLASS;
076
077
078
079  // Build the "free-disk-space" property definition.
080  static {
081      SizePropertyDefinition.Builder builder = SizePropertyDefinition.createBuilder(INSTANCE, "free-disk-space");
082      builder.setOption(PropertyOption.MANDATORY);
083      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "free-disk-space"));
084      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Long>());
085      builder.setLowerLimit("1");
086      PD_FREE_DISK_SPACE = builder.getInstance();
087      INSTANCE.registerPropertyDefinition(PD_FREE_DISK_SPACE);
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.FreeDiskSpaceRetentionPolicy");
099      builder.setDefaultBehaviorProvider(provider);
100      builder.addInstanceOf("org.opends.server.loggers.RetentionPolicy");
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 Free Disk Space Log Retention Policy configuration
116   * definition singleton.
117   *
118   * @return Returns the Free Disk Space Log Retention Policy
119   *         configuration definition singleton.
120   */
121  public static FreeDiskSpaceLogRetentionPolicyCfgDefn getInstance() {
122    return INSTANCE;
123  }
124
125
126
127  /**
128   * Private constructor.
129   */
130  private FreeDiskSpaceLogRetentionPolicyCfgDefn() {
131    super("free-disk-space-log-retention-policy", LogRetentionPolicyCfgDefn.getInstance());
132  }
133
134
135
136  /**
137   * {@inheritDoc}
138   */
139  public FreeDiskSpaceLogRetentionPolicyCfgClient createClientConfiguration(
140      ManagedObject<? extends FreeDiskSpaceLogRetentionPolicyCfgClient> impl) {
141    return new FreeDiskSpaceLogRetentionPolicyCfgClientImpl(impl);
142  }
143
144
145
146  /**
147   * {@inheritDoc}
148   */
149  public FreeDiskSpaceLogRetentionPolicyCfg createServerConfiguration(
150      ServerManagedObject<? extends FreeDiskSpaceLogRetentionPolicyCfg> impl) {
151    return new FreeDiskSpaceLogRetentionPolicyCfgServerImpl(impl);
152  }
153
154
155
156  /**
157   * {@inheritDoc}
158   */
159  public Class<FreeDiskSpaceLogRetentionPolicyCfg> getServerConfigurationClass() {
160    return FreeDiskSpaceLogRetentionPolicyCfg.class;
161  }
162
163
164
165  /**
166   * Get the "free-disk-space" property definition.
167   * <p>
168   * Specifies the minimum amount of free disk space that should be
169   * available on the file system on which the archived log files are
170   * stored.
171   *
172   * @return Returns the "free-disk-space" property definition.
173   */
174  public SizePropertyDefinition getFreeDiskSpacePropertyDefinition() {
175    return PD_FREE_DISK_SPACE;
176  }
177
178
179
180  /**
181   * Get the "java-class" property definition.
182   * <p>
183   * Specifies the fully-qualified name of the Java class that
184   * provides the Free Disk Space Log Retention Policy implementation.
185   *
186   * @return Returns the "java-class" property definition.
187   */
188  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
189    return PD_JAVA_CLASS;
190  }
191
192
193
194  /**
195   * Managed object client implementation.
196   */
197  private static class FreeDiskSpaceLogRetentionPolicyCfgClientImpl implements
198    FreeDiskSpaceLogRetentionPolicyCfgClient {
199
200    // Private implementation.
201    private ManagedObject<? extends FreeDiskSpaceLogRetentionPolicyCfgClient> impl;
202
203
204
205    // Private constructor.
206    private FreeDiskSpaceLogRetentionPolicyCfgClientImpl(
207        ManagedObject<? extends FreeDiskSpaceLogRetentionPolicyCfgClient> impl) {
208      this.impl = impl;
209    }
210
211
212
213    /**
214     * {@inheritDoc}
215     */
216    public Long getFreeDiskSpace() {
217      return impl.getPropertyValue(INSTANCE.getFreeDiskSpacePropertyDefinition());
218    }
219
220
221
222    /**
223     * {@inheritDoc}
224     */
225    public void setFreeDiskSpace(long value) {
226      impl.setPropertyValue(INSTANCE.getFreeDiskSpacePropertyDefinition(), value);
227    }
228
229
230
231    /**
232     * {@inheritDoc}
233     */
234    public String getJavaClass() {
235      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
236    }
237
238
239
240    /**
241     * {@inheritDoc}
242     */
243    public void setJavaClass(String value) {
244      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
245    }
246
247
248
249    /**
250     * {@inheritDoc}
251     */
252    public ManagedObjectDefinition<? extends FreeDiskSpaceLogRetentionPolicyCfgClient, ? extends FreeDiskSpaceLogRetentionPolicyCfg> definition() {
253      return INSTANCE;
254    }
255
256
257
258    /**
259     * {@inheritDoc}
260     */
261    public PropertyProvider properties() {
262      return impl;
263    }
264
265
266
267    /**
268     * {@inheritDoc}
269     */
270    public void commit() throws ManagedObjectAlreadyExistsException,
271        MissingMandatoryPropertiesException, ConcurrentModificationException,
272        OperationRejectedException, AuthorizationException,
273        CommunicationException {
274      impl.commit();
275    }
276
277
278
279    /** {@inheritDoc} */
280    public String toString() {
281      return impl.toString();
282    }
283  }
284
285
286
287  /**
288   * Managed object server implementation.
289   */
290  private static class FreeDiskSpaceLogRetentionPolicyCfgServerImpl implements
291    FreeDiskSpaceLogRetentionPolicyCfg {
292
293    // Private implementation.
294    private ServerManagedObject<? extends FreeDiskSpaceLogRetentionPolicyCfg> impl;
295
296    // The value of the "free-disk-space" property.
297    private final long pFreeDiskSpace;
298
299    // The value of the "java-class" property.
300    private final String pJavaClass;
301
302
303
304    // Private constructor.
305    private FreeDiskSpaceLogRetentionPolicyCfgServerImpl(ServerManagedObject<? extends FreeDiskSpaceLogRetentionPolicyCfg> impl) {
306      this.impl = impl;
307      this.pFreeDiskSpace = impl.getPropertyValue(INSTANCE.getFreeDiskSpacePropertyDefinition());
308      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
309    }
310
311
312
313    /**
314     * {@inheritDoc}
315     */
316    public void addFreeDiskSpaceChangeListener(
317        ConfigurationChangeListener<FreeDiskSpaceLogRetentionPolicyCfg> listener) {
318      impl.registerChangeListener(listener);
319    }
320
321
322
323    /**
324     * {@inheritDoc}
325     */
326    public void removeFreeDiskSpaceChangeListener(
327        ConfigurationChangeListener<FreeDiskSpaceLogRetentionPolicyCfg> listener) {
328      impl.deregisterChangeListener(listener);
329    }
330    /**
331     * {@inheritDoc}
332     */
333    public void addChangeListener(
334        ConfigurationChangeListener<LogRetentionPolicyCfg> listener) {
335      impl.registerChangeListener(listener);
336    }
337
338
339
340    /**
341     * {@inheritDoc}
342     */
343    public void removeChangeListener(
344        ConfigurationChangeListener<LogRetentionPolicyCfg> listener) {
345      impl.deregisterChangeListener(listener);
346    }
347
348
349
350    /**
351     * {@inheritDoc}
352     */
353    public long getFreeDiskSpace() {
354      return pFreeDiskSpace;
355    }
356
357
358
359    /**
360     * {@inheritDoc}
361     */
362    public String getJavaClass() {
363      return pJavaClass;
364    }
365
366
367
368    /**
369     * {@inheritDoc}
370     */
371    public Class<? extends FreeDiskSpaceLogRetentionPolicyCfg> configurationClass() {
372      return FreeDiskSpaceLogRetentionPolicyCfg.class;
373    }
374
375
376
377    /**
378     * {@inheritDoc}
379     */
380    public DN dn() {
381      return impl.getDN();
382    }
383
384
385
386    /** {@inheritDoc} */
387    public String toString() {
388      return impl.toString();
389    }
390  }
391}