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 java.util.Collection;
021import java.util.SortedSet;
022import org.forgerock.opendj.config.AdministratorAction;
023import org.forgerock.opendj.config.BooleanPropertyDefinition;
024import org.forgerock.opendj.config.ClassPropertyDefinition;
025import org.forgerock.opendj.config.client.ConcurrentModificationException;
026import org.forgerock.opendj.config.client.ManagedObject;
027import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
028import org.forgerock.opendj.config.client.OperationRejectedException;
029import org.forgerock.opendj.config.DefaultBehaviorProvider;
030import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider;
031import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
032import org.forgerock.opendj.config.ManagedObjectDefinition;
033import org.forgerock.opendj.config.PropertyOption;
034import org.forgerock.opendj.config.PropertyProvider;
035import org.forgerock.opendj.config.server.ConfigurationChangeListener;
036import org.forgerock.opendj.config.server.ServerManagedObject;
037import org.forgerock.opendj.config.StringPropertyDefinition;
038import org.forgerock.opendj.config.Tag;
039import org.forgerock.opendj.ldap.DN;
040import org.forgerock.opendj.ldap.LdapException;
041import org.forgerock.opendj.server.config.client.JMXAlertHandlerCfgClient;
042import org.forgerock.opendj.server.config.server.AlertHandlerCfg;
043import org.forgerock.opendj.server.config.server.JMXAlertHandlerCfg;
044
045
046
047/**
048 * An interface for querying the JMX Alert Handler managed object
049 * definition meta information.
050 * <p>
051 * The JMX Alert Handler is used to generate JMX notifications to
052 * alert administrators of significant events that occur within the
053 * server.
054 */
055public final class JMXAlertHandlerCfgDefn extends ManagedObjectDefinition<JMXAlertHandlerCfgClient, JMXAlertHandlerCfg> {
056
057  /** The singleton configuration definition instance. */
058  private static final JMXAlertHandlerCfgDefn INSTANCE = new JMXAlertHandlerCfgDefn();
059
060
061
062  /** The "java-class" property definition. */
063  private static final ClassPropertyDefinition PD_JAVA_CLASS;
064
065
066
067  /** Build the "java-class" property definition. */
068  static {
069      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
070      builder.setOption(PropertyOption.MANDATORY);
071      builder.setOption(PropertyOption.ADVANCED);
072      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
073      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.JMXAlertHandler");
074      builder.setDefaultBehaviorProvider(provider);
075      builder.addInstanceOf("org.opends.server.api.AlertHandler");
076      PD_JAVA_CLASS = builder.getInstance();
077      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
078  }
079
080
081
082  // Register the tags associated with this managed object definition.
083  static {
084    INSTANCE.registerTag(Tag.valueOf("core-server"));
085  }
086
087
088
089  /**
090   * Get the JMX Alert Handler configuration definition singleton.
091   *
092   * @return Returns the JMX Alert Handler configuration definition
093   *         singleton.
094   */
095  public static JMXAlertHandlerCfgDefn getInstance() {
096    return INSTANCE;
097  }
098
099
100
101  /**
102   * Private constructor.
103   */
104  private JMXAlertHandlerCfgDefn() {
105    super("jmx-alert-handler", AlertHandlerCfgDefn.getInstance());
106  }
107
108
109
110  /** {@inheritDoc} */
111  public JMXAlertHandlerCfgClient createClientConfiguration(
112      ManagedObject<? extends JMXAlertHandlerCfgClient> impl) {
113    return new JMXAlertHandlerCfgClientImpl(impl);
114  }
115
116
117
118  /** {@inheritDoc} */
119  public JMXAlertHandlerCfg createServerConfiguration(
120      ServerManagedObject<? extends JMXAlertHandlerCfg> impl) {
121    return new JMXAlertHandlerCfgServerImpl(impl);
122  }
123
124
125
126  /** {@inheritDoc} */
127  public Class<JMXAlertHandlerCfg> getServerConfigurationClass() {
128    return JMXAlertHandlerCfg.class;
129  }
130
131
132
133  /**
134   * Get the "disabled-alert-type" property definition.
135   * <p>
136   * Specifies the names of the alert types that are disabled for this
137   * alert handler.
138   * <p>
139   * If there are any values for this attribute, then no alerts with
140   * any of the specified types are allowed. If there are no values for
141   * this attribute, then only alerts with a type included in the set
142   * of enabled alert types are allowed, or if there are no values for
143   * the enabled alert types option, then all alert types are allowed.
144   *
145   * @return Returns the "disabled-alert-type" property definition.
146   */
147  public StringPropertyDefinition getDisabledAlertTypePropertyDefinition() {
148    return AlertHandlerCfgDefn.getInstance().getDisabledAlertTypePropertyDefinition();
149  }
150
151
152
153  /**
154   * Get the "enabled" property definition.
155   * <p>
156   * Indicates whether the JMX Alert Handler is enabled.
157   *
158   * @return Returns the "enabled" property definition.
159   */
160  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
161    return AlertHandlerCfgDefn.getInstance().getEnabledPropertyDefinition();
162  }
163
164
165
166  /**
167   * Get the "enabled-alert-type" property definition.
168   * <p>
169   * Specifies the names of the alert types that are enabled for this
170   * alert handler.
171   * <p>
172   * If there are any values for this attribute, then only alerts with
173   * one of the specified types are allowed (unless they are also
174   * included in the disabled alert types). If there are no values for
175   * this attribute, then any alert with a type not included in the
176   * list of disabled alert types is allowed.
177   *
178   * @return Returns the "enabled-alert-type" property definition.
179   */
180  public StringPropertyDefinition getEnabledAlertTypePropertyDefinition() {
181    return AlertHandlerCfgDefn.getInstance().getEnabledAlertTypePropertyDefinition();
182  }
183
184
185
186  /**
187   * Get the "java-class" property definition.
188   * <p>
189   * Specifies the fully-qualified name of the Java class that
190   * provides the JMX Alert Handler implementation.
191   *
192   * @return Returns the "java-class" property definition.
193   */
194  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
195    return PD_JAVA_CLASS;
196  }
197
198
199
200  /**
201   * Managed object client implementation.
202   */
203  private static class JMXAlertHandlerCfgClientImpl implements
204    JMXAlertHandlerCfgClient {
205
206    /** Private implementation. */
207    private ManagedObject<? extends JMXAlertHandlerCfgClient> impl;
208
209
210
211    /** Private constructor. */
212    private JMXAlertHandlerCfgClientImpl(
213        ManagedObject<? extends JMXAlertHandlerCfgClient> impl) {
214      this.impl = impl;
215    }
216
217
218
219    /** {@inheritDoc} */
220    public SortedSet<String> getDisabledAlertType() {
221      return impl.getPropertyValues(INSTANCE.getDisabledAlertTypePropertyDefinition());
222    }
223
224
225
226    /** {@inheritDoc} */
227    public void setDisabledAlertType(Collection<String> values) {
228      impl.setPropertyValues(INSTANCE.getDisabledAlertTypePropertyDefinition(), values);
229    }
230
231
232
233    /** {@inheritDoc} */
234    public Boolean isEnabled() {
235      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
236    }
237
238
239
240    /** {@inheritDoc} */
241    public void setEnabled(boolean value) {
242      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
243    }
244
245
246
247    /** {@inheritDoc} */
248    public SortedSet<String> getEnabledAlertType() {
249      return impl.getPropertyValues(INSTANCE.getEnabledAlertTypePropertyDefinition());
250    }
251
252
253
254    /** {@inheritDoc} */
255    public void setEnabledAlertType(Collection<String> values) {
256      impl.setPropertyValues(INSTANCE.getEnabledAlertTypePropertyDefinition(), values);
257    }
258
259
260
261    /** {@inheritDoc} */
262    public String getJavaClass() {
263      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
264    }
265
266
267
268    /** {@inheritDoc} */
269    public void setJavaClass(String value) {
270      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
271    }
272
273
274
275    /** {@inheritDoc} */
276    public ManagedObjectDefinition<? extends JMXAlertHandlerCfgClient, ? extends JMXAlertHandlerCfg> definition() {
277      return INSTANCE;
278    }
279
280
281
282    /** {@inheritDoc} */
283    public PropertyProvider properties() {
284      return impl;
285    }
286
287
288
289    /** {@inheritDoc} */
290    public void commit() throws ManagedObjectAlreadyExistsException,
291        MissingMandatoryPropertiesException, ConcurrentModificationException,
292        OperationRejectedException, LdapException {
293      impl.commit();
294    }
295
296
297
298    /** {@inheritDoc} */
299    public String toString() {
300      return impl.toString();
301    }
302  }
303
304
305
306  /**
307   * Managed object server implementation.
308   */
309  private static class JMXAlertHandlerCfgServerImpl implements
310    JMXAlertHandlerCfg {
311
312    /** Private implementation. */
313    private ServerManagedObject<? extends JMXAlertHandlerCfg> impl;
314
315    /** The value of the "disabled-alert-type" property. */
316    private final SortedSet<String> pDisabledAlertType;
317
318    /** The value of the "enabled" property. */
319    private final boolean pEnabled;
320
321    /** The value of the "enabled-alert-type" property. */
322    private final SortedSet<String> pEnabledAlertType;
323
324    /** The value of the "java-class" property. */
325    private final String pJavaClass;
326
327
328
329    /** Private constructor. */
330    private JMXAlertHandlerCfgServerImpl(ServerManagedObject<? extends JMXAlertHandlerCfg> impl) {
331      this.impl = impl;
332      this.pDisabledAlertType = impl.getPropertyValues(INSTANCE.getDisabledAlertTypePropertyDefinition());
333      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
334      this.pEnabledAlertType = impl.getPropertyValues(INSTANCE.getEnabledAlertTypePropertyDefinition());
335      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
336    }
337
338
339
340    /** {@inheritDoc} */
341    public void addJMXChangeListener(
342        ConfigurationChangeListener<JMXAlertHandlerCfg> listener) {
343      impl.registerChangeListener(listener);
344    }
345
346
347
348    /** {@inheritDoc} */
349    public void removeJMXChangeListener(
350        ConfigurationChangeListener<JMXAlertHandlerCfg> listener) {
351      impl.deregisterChangeListener(listener);
352    }
353    /** {@inheritDoc} */
354    public void addChangeListener(
355        ConfigurationChangeListener<AlertHandlerCfg> listener) {
356      impl.registerChangeListener(listener);
357    }
358
359
360
361    /** {@inheritDoc} */
362    public void removeChangeListener(
363        ConfigurationChangeListener<AlertHandlerCfg> listener) {
364      impl.deregisterChangeListener(listener);
365    }
366
367
368
369    /** {@inheritDoc} */
370    public SortedSet<String> getDisabledAlertType() {
371      return pDisabledAlertType;
372    }
373
374
375
376    /** {@inheritDoc} */
377    public boolean isEnabled() {
378      return pEnabled;
379    }
380
381
382
383    /** {@inheritDoc} */
384    public SortedSet<String> getEnabledAlertType() {
385      return pEnabledAlertType;
386    }
387
388
389
390    /** {@inheritDoc} */
391    public String getJavaClass() {
392      return pJavaClass;
393    }
394
395
396
397    /** {@inheritDoc} */
398    public Class<? extends JMXAlertHandlerCfg> configurationClass() {
399      return JMXAlertHandlerCfg.class;
400    }
401
402
403
404    /** {@inheritDoc} */
405    public DN dn() {
406      return impl.getDN();
407    }
408
409
410
411    /** {@inheritDoc} */
412    public String toString() {
413      return impl.toString();
414    }
415  }
416}