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