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