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.SizeLimitLogRetentionPolicyCfgClient;
049    import org.opends.server.admin.std.server.LogRetentionPolicyCfg;
050    import org.opends.server.admin.std.server.SizeLimitLogRetentionPolicyCfg;
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 Size Limit Log Retention Policy
059     * managed object definition meta information.
060     * <p>
061     * Retention policy based on the amount of space taken by all the log
062     * files on disk.
063     */
064    public final class SizeLimitLogRetentionPolicyCfgDefn extends ManagedObjectDefinition<SizeLimitLogRetentionPolicyCfgClient, SizeLimitLogRetentionPolicyCfg> {
065    
066      // The singleton configuration definition instance.
067      private static final SizeLimitLogRetentionPolicyCfgDefn INSTANCE = new SizeLimitLogRetentionPolicyCfgDefn();
068    
069    
070    
071      // The "disk-space-used" property definition.
072      private static final SizePropertyDefinition PD_DISK_SPACE_USED;
073    
074    
075    
076      // The "java-class" property definition.
077      private static final ClassPropertyDefinition PD_JAVA_CLASS;
078    
079    
080    
081      // Build the "disk-space-used" property definition.
082      static {
083          SizePropertyDefinition.Builder builder = SizePropertyDefinition.createBuilder(INSTANCE, "disk-space-used");
084          builder.setOption(PropertyOption.MANDATORY);
085          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "disk-space-used"));
086          builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Long>());
087          builder.setLowerLimit("1");
088          PD_DISK_SPACE_USED = builder.getInstance();
089          INSTANCE.registerPropertyDefinition(PD_DISK_SPACE_USED);
090      }
091    
092    
093    
094      // Build the "java-class" property definition.
095      static {
096          ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
097          builder.setOption(PropertyOption.MANDATORY);
098          builder.setOption(PropertyOption.ADVANCED);
099          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class"));
100          DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.loggers.SizeBasedRetentionPolicy");
101          builder.setDefaultBehaviorProvider(provider);
102          builder.addInstanceOf("org.opends.server.loggers.RetentionPolicy");
103          PD_JAVA_CLASS = builder.getInstance();
104          INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
105      }
106    
107    
108    
109      // Register the tags associated with this managed object definition.
110      static {
111        INSTANCE.registerTag(Tag.valueOf("logging"));
112      }
113    
114    
115    
116      /**
117       * Get the Size Limit Log Retention Policy configuration definition
118       * singleton.
119       *
120       * @return Returns the Size Limit Log Retention Policy configuration
121       *         definition singleton.
122       */
123      public static SizeLimitLogRetentionPolicyCfgDefn getInstance() {
124        return INSTANCE;
125      }
126    
127    
128    
129      /**
130       * Private constructor.
131       */
132      private SizeLimitLogRetentionPolicyCfgDefn() {
133        super("size-limit-log-retention-policy", LogRetentionPolicyCfgDefn.getInstance());
134      }
135    
136    
137    
138      /**
139       * {@inheritDoc}
140       */
141      public SizeLimitLogRetentionPolicyCfgClient createClientConfiguration(
142          ManagedObject<? extends SizeLimitLogRetentionPolicyCfgClient> impl) {
143        return new SizeLimitLogRetentionPolicyCfgClientImpl(impl);
144      }
145    
146    
147    
148      /**
149       * {@inheritDoc}
150       */
151      public SizeLimitLogRetentionPolicyCfg createServerConfiguration(
152          ServerManagedObject<? extends SizeLimitLogRetentionPolicyCfg> impl) {
153        return new SizeLimitLogRetentionPolicyCfgServerImpl(impl);
154      }
155    
156    
157    
158      /**
159       * {@inheritDoc}
160       */
161      public Class<SizeLimitLogRetentionPolicyCfg> getServerConfigurationClass() {
162        return SizeLimitLogRetentionPolicyCfg.class;
163      }
164    
165    
166    
167      /**
168       * Get the "disk-space-used" property definition.
169       * <p>
170       * Specifies the maximum total disk space used by the log files.
171       *
172       * @return Returns the "disk-space-used" property definition.
173       */
174      public SizePropertyDefinition getDiskSpaceUsedPropertyDefinition() {
175        return PD_DISK_SPACE_USED;
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 Size Limit 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 SizeLimitLogRetentionPolicyCfgClientImpl implements
198        SizeLimitLogRetentionPolicyCfgClient {
199    
200        // Private implementation.
201        private ManagedObject<? extends SizeLimitLogRetentionPolicyCfgClient> impl;
202    
203    
204    
205        // Private constructor.
206        private SizeLimitLogRetentionPolicyCfgClientImpl(
207            ManagedObject<? extends SizeLimitLogRetentionPolicyCfgClient> impl) {
208          this.impl = impl;
209        }
210    
211    
212    
213        /**
214         * {@inheritDoc}
215         */
216        public Long getDiskSpaceUsed() {
217          return impl.getPropertyValue(INSTANCE.getDiskSpaceUsedPropertyDefinition());
218        }
219    
220    
221    
222        /**
223         * {@inheritDoc}
224         */
225        public void setDiskSpaceUsed(long value) {
226          impl.setPropertyValue(INSTANCE.getDiskSpaceUsedPropertyDefinition(), 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 SizeLimitLogRetentionPolicyCfgClient, ? extends SizeLimitLogRetentionPolicyCfg> 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    
280    
281      /**
282       * Managed object server implementation.
283       */
284      private static class SizeLimitLogRetentionPolicyCfgServerImpl implements
285        SizeLimitLogRetentionPolicyCfg {
286    
287        // Private implementation.
288        private ServerManagedObject<? extends SizeLimitLogRetentionPolicyCfg> impl;
289    
290        // The value of the "disk-space-used" property.
291        private final long pDiskSpaceUsed;
292    
293        // The value of the "java-class" property.
294        private final String pJavaClass;
295    
296    
297    
298        // Private constructor.
299        private SizeLimitLogRetentionPolicyCfgServerImpl(ServerManagedObject<? extends SizeLimitLogRetentionPolicyCfg> impl) {
300          this.impl = impl;
301          this.pDiskSpaceUsed = impl.getPropertyValue(INSTANCE.getDiskSpaceUsedPropertyDefinition());
302          this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
303        }
304    
305    
306    
307        /**
308         * {@inheritDoc}
309         */
310        public void addSizeLimitChangeListener(
311            ConfigurationChangeListener<SizeLimitLogRetentionPolicyCfg> listener) {
312          impl.registerChangeListener(listener);
313        }
314    
315    
316    
317        /**
318         * {@inheritDoc}
319         */
320        public void removeSizeLimitChangeListener(
321            ConfigurationChangeListener<SizeLimitLogRetentionPolicyCfg> listener) {
322          impl.deregisterChangeListener(listener);
323        }
324        /**
325         * {@inheritDoc}
326         */
327        public void addChangeListener(
328            ConfigurationChangeListener<LogRetentionPolicyCfg> listener) {
329          impl.registerChangeListener(listener);
330        }
331    
332    
333    
334        /**
335         * {@inheritDoc}
336         */
337        public void removeChangeListener(
338            ConfigurationChangeListener<LogRetentionPolicyCfg> listener) {
339          impl.deregisterChangeListener(listener);
340        }
341    
342    
343    
344        /**
345         * {@inheritDoc}
346         */
347        public long getDiskSpaceUsed() {
348          return pDiskSpaceUsed;
349        }
350    
351    
352    
353        /**
354         * {@inheritDoc}
355         */
356        public String getJavaClass() {
357          return pJavaClass;
358        }
359    
360    
361    
362        /**
363         * {@inheritDoc}
364         */
365        public Class<? extends SizeLimitLogRetentionPolicyCfg> configurationClass() {
366          return SizeLimitLogRetentionPolicyCfg.class;
367        }
368    
369    
370    
371        /**
372         * {@inheritDoc}
373         */
374        public DN dn() {
375          return impl.getDN();
376        }
377    
378      }
379    }