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