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