From efbc2ca28bd36a2f5b712ecd9da9dfead7692614 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Thu, 19 Jul 2007 20:24:00 +0000
Subject: [PATCH] Update the server so that the set of alert handlers are configurable rather than simply using a hard-coded JMX alert handler.

---
 opendj-sdk/opends/src/server/org/opends/server/core/DirectoryServer.java                   |    5 
 opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/AlertHandlerConfiguration.xml |   89 +++++++
 opendj-sdk/opends/src/server/org/opends/server/messages/ConfigMessages.java                |   32 ++
 opendj-sdk/opends/src/server/org/opends/server/api/AlertHandler.java                       |   35 ++
 opendj-sdk/opends/src/server/org/opends/server/core/AlertHandlerConfigManager.java         |  436 ++++++++++++++++++++++++++++++++++++
 opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/RootConfiguration.xml         |   13 +
 opendj-sdk/opends/src/server/org/opends/server/extensions/JMXAlertHandler.java             |   56 ++--
 7 files changed, 624 insertions(+), 42 deletions(-)

diff --git a/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/AlertHandlerConfiguration.xml b/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/AlertHandlerConfiguration.xml
new file mode 100644
index 0000000..f69c666
--- /dev/null
+++ b/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/AlertHandlerConfiguration.xml
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+! CDDL HEADER START
+!
+! The contents of this file are subject to the terms of the
+! Common Development and Distribution License, Version 1.0 only
+! (the "License").  You may not use this file except in compliance
+! with the License.
+!
+! You can obtain a copy of the license at
+! trunk/opends/resource/legal-notices/OpenDS.LICENSE
+! or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+! See the License for the specific language governing permissions
+! and limitations under the License.
+!
+! When distributing Covered Code, include this CDDL HEADER in each
+! file and include the License file at
+! trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+! add the following below this CDDL HEADER, with the fields enclosed
+! by brackets "[]" replaced with your own identifying information:
+!      Portions Copyright [yyyy] [name of copyright owner]
+!
+! CDDL HEADER END
+!
+!
+!      Portions Copyright 2007 Sun Microsystems, Inc.
+! -->
+
+<adm:managed-object name="alert-handler" plural-name="alert-handlers"
+  package="org.opends.server.admin.std"
+  xmlns:adm="http://www.opends.org/admin"
+  xmlns:ldap="http://www.opends.org/admin-ldap">
+
+  <adm:synopsis>
+    <adm:user-friendly-name />
+    are used to notify administrators of significant problems or notable events
+    that occur in the Directory Server.
+  </adm:synopsis>
+
+  <adm:tag name="core"/>
+
+  <adm:profile name="ldap">
+    <ldap:object-class>
+      <ldap:oid>1.3.6.1.4.1.26027.1.2.2</ldap:oid>
+      <ldap:name>ds-cfg-alert-handler</ldap:name>
+      <ldap:superior>top</ldap:superior>
+    </ldap:object-class>
+  </adm:profile>
+
+  <adm:property name="enabled" mandatory="true">
+    <adm:synopsis>
+      Indicate whether the
+      <adm:user-friendly-name />
+      is enabled for use.
+    </adm:synopsis>
+    <adm:syntax>
+      <adm:boolean />
+    </adm:syntax>
+    <adm:profile name="ldap">
+      <ldap:attribute>
+        <ldap:oid>1.3.6.1.4.1.26027.1.1.4</ldap:oid>
+        <ldap:name>ds-cfg-alert-handler-enabled</ldap:name>
+      </ldap:attribute>
+    </adm:profile>
+  </adm:property>
+
+  <adm:property name="alert-handler-class" mandatory="true">
+    <adm:synopsis>
+      The fully-qualified name of the Java class that provides the
+      <adm:user-friendly-name />
+      implementation.
+    </adm:synopsis>
+    <adm:syntax>
+      <adm:java-class>
+        <adm:instance-of>
+          org.opends.server.api.AlertHandler
+        </adm:instance-of>
+      </adm:java-class>
+    </adm:syntax>
+    <adm:profile name="ldap">
+      <ldap:attribute>
+        <ldap:oid>1.3.6.1.4.1.26027.1.1.3</ldap:oid>
+        <ldap:name>ds-cfg-alert-handler-class</ldap:name>
+      </ldap:attribute>
+    </adm:profile>
+  </adm:property>
+
+</adm:managed-object>
+
diff --git a/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/RootConfiguration.xml b/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/RootConfiguration.xml
index df30b76..04a63ba 100644
--- a/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/RootConfiguration.xml
+++ b/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/RootConfiguration.xml
@@ -216,6 +216,19 @@
       </cli:relation>
     </adm:profile>
   </adm:relation>
+  <adm:relation name="alert-handler">
+    <adm:one-to-many />
+    <adm:profile name="ldap">
+      <ldap:rdn-sequence>
+        cn=Alert Handlers,cn=config
+      </ldap:rdn-sequence>
+    </adm:profile>
+    <adm:profile name="cli">
+      <cli:relation>
+        <cli:default-property name="enabled" />
+      </cli:relation>
+    </adm:profile>
+  </adm:relation>
   <adm:relation name="password-storage-scheme">
     <adm:one-to-many />
     <adm:profile name="ldap">
diff --git a/opendj-sdk/opends/src/server/org/opends/server/api/AlertHandler.java b/opendj-sdk/opends/src/server/org/opends/server/api/AlertHandler.java
index 4f29363..a123ec6 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/api/AlertHandler.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/api/AlertHandler.java
@@ -28,7 +28,9 @@
 
 
 
-import org.opends.server.config.ConfigEntry;
+import java.util.List;
+
+import org.opends.server.admin.std.server.AlertHandlerCfg;
 import org.opends.server.config.ConfigException;
 import org.opends.server.types.InitializationException;
 
@@ -39,16 +41,18 @@
  * for a Directory Server alert handler.  Alert handlers are used to
  * present alert notifications in various forms like JMX, e-mail, or
  * paging.
+ *
+ * @param  <T>  The type of configuration handled by this alert
+ *              handler.
  */
-public interface AlertHandler
+public interface AlertHandler<T extends AlertHandlerCfg>
 {
   /**
    * Initializes this alert handler based on the information in the
    * provided configuration entry.
    *
-   * @param  configEntry  The configuration entry that contains the
-   *                      information to use to initialize this alert
-   *                      handler.
+   * @param  configuration  The configuration to use to initialize
+   *                        this alert handler.
    *
    * @throws  ConfigException  If the provided entry does not contain
    *                           a valid configuration for this alert
@@ -59,12 +63,31 @@
    *                                   related to the server
    *                                   configuration.
    */
-  public void initializeAlertHandler(ConfigEntry configEntry)
+  public void initializeAlertHandler(T configuration)
        throws ConfigException, InitializationException;
 
 
 
   /**
+   * Indicates whether the provided configuration is acceptable for
+   * this alert handler.
+   *
+   * @param  configuration        The configuration for which to make
+   *                              tje determination.
+   * @param  unacceptableReasons  A list to which human-readable
+   *                              reasons may be added to explain why
+   *                              the configuration is not acceptable.
+   *
+   * @return  {@code true} if the provided configuration is
+   *          acceptable, or {@code false} if it is not.
+   */
+  public boolean isConfigurationAcceptable(
+                      AlertHandlerCfg configuration,
+                      List<String> unacceptableReasons);
+
+
+
+  /**
    * Performs any necessary cleanup that may be necessary when this
    * alert handler is finalized.
    */
diff --git a/opendj-sdk/opends/src/server/org/opends/server/core/AlertHandlerConfigManager.java b/opendj-sdk/opends/src/server/org/opends/server/core/AlertHandlerConfigManager.java
new file mode 100644
index 0000000..678f020
--- /dev/null
+++ b/opendj-sdk/opends/src/server/org/opends/server/core/AlertHandlerConfigManager.java
@@ -0,0 +1,436 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+ * add the following below this CDDL HEADER, with the fields enclosed
+ * by brackets "[]" replaced with your own identifying information:
+ *      Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ *      Portions Copyright 2006-2007 Sun Microsystems, Inc.
+ */
+package org.opends.server.core;
+
+
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.opends.server.admin.ClassPropertyDefinition;
+import org.opends.server.admin.server.ConfigurationAddListener;
+import org.opends.server.admin.server.ConfigurationChangeListener;
+import org.opends.server.admin.server.ConfigurationDeleteListener;
+import org.opends.server.admin.std.meta.AlertHandlerCfgDefn;
+import org.opends.server.admin.std.server.AlertHandlerCfg;
+import org.opends.server.admin.std.server.RootCfg;
+import org.opends.server.admin.server.ServerManagementContext;
+import org.opends.server.api.AlertHandler;
+import org.opends.server.config.ConfigException;
+import org.opends.server.types.ConfigChangeResult;
+import org.opends.server.types.DN;
+import org.opends.server.types.ErrorLogCategory;
+import org.opends.server.types.ErrorLogSeverity;
+import org.opends.server.types.InitializationException;
+import org.opends.server.types.ResultCode;
+
+import static org.opends.server.loggers.ErrorLogger.*;
+import static org.opends.server.messages.ConfigMessages.*;
+import static org.opends.server.messages.MessageHandler.*;
+import static org.opends.server.util.StaticUtils.*;
+
+
+
+/**
+ * This class defines a utility that will be used to manage the set of alert
+ * handlers defined in the Directory Server.  It will initialize the alert
+ * handlers when the server starts, and then will manage any additions,
+ * removals, or modifications to any alert handlers while the server is running.
+ */
+public class AlertHandlerConfigManager
+       implements ConfigurationChangeListener<AlertHandlerCfg>,
+                  ConfigurationAddListener<AlertHandlerCfg>,
+                  ConfigurationDeleteListener<AlertHandlerCfg>
+
+{
+  // A mapping between the DNs of the config entries and the associated alert
+  // handlers.
+  private ConcurrentHashMap<DN,AlertHandler> alertHandlers;
+
+
+
+  /**
+   * Creates a new instance of this alert handler config manager.
+   */
+  public AlertHandlerConfigManager()
+  {
+    alertHandlers = new ConcurrentHashMap<DN,AlertHandler>();
+  }
+
+
+
+  /**
+   * Initializes all alert handlers currently defined in the Directory Server
+   * configuration.  This should only be called at Directory Server startup.
+   *
+   * @throws  ConfigException  If a configuration problem causes the alert
+   *                           handler initialization process to fail.
+   *
+   * @throws  InitializationException  If a problem occurs while initializing
+   *                                   the alert handlers that is not related to
+   *                                   the server configuration.
+   */
+  public void initializeAlertHandlers()
+         throws ConfigException, InitializationException
+  {
+    // Get the root configuration object.
+    ServerManagementContext managementContext =
+         ServerManagementContext.getInstance();
+    RootCfg rootConfiguration = managementContext.getRootConfiguration();
+
+
+    // Register as an add and delete listener with the root configuration so we
+    // can be notified if any alert handler entries are added or removed.
+    rootConfiguration.addAlertHandlerAddListener(this);
+    rootConfiguration.addAlertHandlerDeleteListener(this);
+
+
+    //Initialize the existing alert handlers.
+    for (String name : rootConfiguration.listAlertHandlers())
+    {
+      AlertHandlerCfg configuration = rootConfiguration.getAlertHandler(name);
+      configuration.addChangeListener(this);
+
+      if (configuration.isEnabled())
+      {
+        String className = configuration.getAlertHandlerClass();
+        try
+        {
+          AlertHandler handler = loadHandler(className, configuration, true);
+          alertHandlers.put(configuration.dn(), handler);
+          DirectoryServer.registerAlertHandler(handler);
+        }
+        catch (InitializationException ie)
+        {
+          logError(ErrorLogCategory.CONFIGURATION,
+                   ErrorLogSeverity.SEVERE_ERROR,
+                   ie.getMessage(), ie.getMessageID());
+          continue;
+        }
+      }
+    }
+  }
+
+
+
+  /**
+   * {@inheritDoc}
+   */
+  public boolean isConfigurationAddAcceptable(AlertHandlerCfg configuration,
+                                              List<String> unacceptableReasons)
+  {
+    if (configuration.isEnabled())
+    {
+      // Get the name of the class and make sure we can instantiate it as an
+      // alert handler.
+      String className = configuration.getAlertHandlerClass();
+      try
+      {
+        loadHandler(className, configuration, false);
+      }
+      catch (InitializationException ie)
+      {
+        unacceptableReasons.add(ie.getMessage());
+        return false;
+      }
+    }
+
+    // If we've gotten here, then it's fine.
+    return true;
+  }
+
+
+
+  /**
+   * {@inheritDoc}
+   */
+  public ConfigChangeResult applyConfigurationAdd(AlertHandlerCfg configuration)
+  {
+    ResultCode        resultCode          = ResultCode.SUCCESS;
+    boolean           adminActionRequired = false;
+    ArrayList<String> messages            = new ArrayList<String>();
+
+    configuration.addChangeListener(this);
+
+    if (! configuration.isEnabled())
+    {
+      return new ConfigChangeResult(resultCode, adminActionRequired, messages);
+    }
+
+    AlertHandler alertHandler = null;
+
+    // Get the name of the class and make sure we can instantiate it as an alert
+    // handler.
+    String className = configuration.getAlertHandlerClass();
+    try
+    {
+      alertHandler = loadHandler(className, configuration, true);
+    }
+    catch (InitializationException ie)
+    {
+      if (resultCode == ResultCode.SUCCESS)
+      {
+        resultCode = DirectoryServer.getServerErrorResultCode();
+      }
+
+      messages.add(ie.getMessage());
+    }
+
+    if (resultCode == ResultCode.SUCCESS)
+    {
+      alertHandlers.put(configuration.dn(), alertHandler);
+      DirectoryServer.registerAlertHandler(alertHandler);
+    }
+
+    return new ConfigChangeResult(resultCode, adminActionRequired, messages);
+  }
+
+
+
+  /**
+   * {@inheritDoc}
+   */
+  public boolean isConfigurationDeleteAcceptable(
+                      AlertHandlerCfg configuration,
+                      List<String> unacceptableReasons)
+  {
+    // FIXME -- We should try to perform some check to determine whether the
+    // alert handler is in use.
+    return true;
+  }
+
+
+
+  /**
+   * {@inheritDoc}
+   */
+  public ConfigChangeResult applyConfigurationDelete(
+                                 AlertHandlerCfg configuration)
+  {
+    ResultCode        resultCode          = ResultCode.SUCCESS;
+    boolean           adminActionRequired = false;
+    ArrayList<String> messages            = new ArrayList<String>();
+
+    AlertHandler alertHandler = alertHandlers.remove(configuration.dn());
+    if (alertHandler != null)
+    {
+      DirectoryServer.deregisterAlertHandler(alertHandler);
+      alertHandler.finalizeAlertHandler();
+    }
+
+    return new ConfigChangeResult(resultCode, adminActionRequired, messages);
+  }
+
+
+
+  /**
+   * {@inheritDoc}
+   */
+  public boolean isConfigurationChangeAcceptable(AlertHandlerCfg configuration,
+                      List<String> unacceptableReasons)
+  {
+    if (configuration.isEnabled())
+    {
+      // Get the name of the class and make sure we can instantiate it as an
+      // alert handler.
+      String className = configuration.getAlertHandlerClass();
+      try
+      {
+        loadHandler(className, configuration, false);
+      }
+      catch (InitializationException ie)
+      {
+        unacceptableReasons.add(ie.getMessage());
+        return false;
+      }
+    }
+
+    // If we've gotten here, then it's fine.
+    return true;
+  }
+
+
+
+  /**
+   * {@inheritDoc}
+   */
+  public ConfigChangeResult applyConfigurationChange(
+                                 AlertHandlerCfg configuration)
+  {
+    ResultCode        resultCode          = ResultCode.SUCCESS;
+    boolean           adminActionRequired = false;
+    ArrayList<String> messages            = new ArrayList<String>();
+
+
+    // Get the existing alert handler if it's already enabled.
+    AlertHandler existingHandler = alertHandlers.get(configuration.dn());
+
+
+    // If the new configuration has the handler disabled, then disable it if it
+    // is enabled, or do nothing if it's already disabled.
+    if (! configuration.isEnabled())
+    {
+      if (existingHandler != null)
+      {
+        DirectoryServer.deregisterAlertHandler(existingHandler);
+
+        AlertHandler alertHandler = alertHandlers.remove(configuration.dn());
+        if (alertHandler != null)
+        {
+          alertHandler.finalizeAlertHandler();
+        }
+      }
+
+      return new ConfigChangeResult(resultCode, adminActionRequired, messages);
+    }
+
+
+    // Get the class for the alert handler.  If the handler is already enabled,
+    // then we shouldn't do anything with it although if the class has changed
+    // then we'll at least need to indicate that administrative action is
+    // required.  If the handler is disabled, then instantiate the class and
+    // initialize and register it as an alert handler.
+    String className = configuration.getAlertHandlerClass();
+    if (existingHandler != null)
+    {
+      if (! className.equals(existingHandler.getClass().getName()))
+      {
+        adminActionRequired = true;
+      }
+
+      return new ConfigChangeResult(resultCode, adminActionRequired, messages);
+    }
+
+    AlertHandler alertHandler = null;
+    try
+    {
+      alertHandler = loadHandler(className, configuration, true);
+    }
+    catch (InitializationException ie)
+    {
+      if (resultCode == ResultCode.SUCCESS)
+      {
+        resultCode = DirectoryServer.getServerErrorResultCode();
+      }
+
+      messages.add(ie.getMessage());
+    }
+
+    if (resultCode == ResultCode.SUCCESS)
+    {
+      alertHandlers.put(configuration.dn(), alertHandler);
+      DirectoryServer.registerAlertHandler(alertHandler);
+    }
+
+    return new ConfigChangeResult(resultCode, adminActionRequired, messages);
+  }
+
+
+
+  /**
+   * Loads the specified class, instantiates it as an alert handler, and
+   * optionally initializes that instance.
+   *
+   * @param  className      The fully-qualified name of the alert handler class
+   *                        to load, instantiate, and initialize.
+   * @param  configuration  The configuration to use to initialize the alert
+   *                        handler.  It must not be {@code null}.
+   * @param  initialize     Indicates whether the alert handler instance should
+   *                        be initialized.
+   *
+   * @return  The possibly initialized alert handler.
+   *
+   * @throws  InitializationException  If a problem occurred while attempting to
+   *                                   initialize the alert handler.
+   */
+  private AlertHandler loadHandler(String className,
+                                   AlertHandlerCfg configuration,
+                                   boolean initialize)
+          throws InitializationException
+  {
+    try
+    {
+      AlertHandlerCfgDefn definition = AlertHandlerCfgDefn.getInstance();
+      ClassPropertyDefinition propertyDefinition =
+           definition.getAlertHandlerClassPropertyDefinition();
+      Class<? extends AlertHandler> handlerClass =
+           propertyDefinition.loadClass(className, AlertHandler.class);
+      AlertHandler handler = handlerClass.newInstance();
+
+      if (initialize)
+      {
+        Method method =
+             handler.getClass().getMethod("initializeAlertHandler",
+                  configuration.definition().getServerConfigurationClass());
+        method.invoke(handler, configuration);
+      }
+      else
+      {
+        Method method =
+             handler.getClass().getMethod("isConfigurationAcceptable",
+                                          AlertHandlerCfg.class, List.class);
+
+        List<String> unacceptableReasons = new ArrayList<String>();
+        Boolean acceptable = (Boolean) method.invoke(handler, configuration,
+                                                     unacceptableReasons);
+        if (! acceptable)
+        {
+          StringBuilder buffer = new StringBuilder();
+          if (! unacceptableReasons.isEmpty())
+          {
+            Iterator<String> iterator = unacceptableReasons.iterator();
+            buffer.append(iterator.next());
+            while (iterator.hasNext())
+            {
+              buffer.append(".  ");
+              buffer.append(iterator.next());
+            }
+          }
+
+          int    msgID   = MSGID_CONFIG_ALERTHANDLER_CONFIG_NOT_ACCEPTABLE;
+          String message = getMessage(msgID, String.valueOf(configuration.dn()),
+                                      buffer.toString());
+          throw new InitializationException(msgID, message);
+        }
+      }
+
+      return handler;
+    }
+    catch (Exception e)
+    {
+      int msgID = MSGID_CONFIG_ALERTHANDLER_INITIALIZATION_FAILED;
+      String message = getMessage(msgID, className,
+                                  String.valueOf(configuration.dn()),
+                                  stackTraceToSingleLineString(e));
+      throw new InitializationException(msgID, message, e);
+    }
+  }
+}
+
diff --git a/opendj-sdk/opends/src/server/org/opends/server/core/DirectoryServer.java b/opendj-sdk/opends/src/server/org/opends/server/core/DirectoryServer.java
index d1ec034..2b0687b 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/core/DirectoryServer.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/core/DirectoryServer.java
@@ -2093,10 +2093,7 @@
   private void initializeAlertHandlers()
           throws ConfigException, InitializationException
   {
-    // FIXME -- Replace this with the real implementation.
-    JMXAlertHandler alertHandler = new JMXAlertHandler();
-    alertHandler.initializeAlertHandler(null);
-    alertHandlers.add(alertHandler);
+    new AlertHandlerConfigManager().initializeAlertHandlers();
   }
 
 
diff --git a/opendj-sdk/opends/src/server/org/opends/server/extensions/JMXAlertHandler.java b/opendj-sdk/opends/src/server/org/opends/server/extensions/JMXAlertHandler.java
index e9ef5d7..9a792db 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/extensions/JMXAlertHandler.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/extensions/JMXAlertHandler.java
@@ -29,6 +29,7 @@
 
 
 import java.util.ArrayList;
+import java.util.List;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicLong;
 import javax.management.Attribute;
@@ -47,19 +48,19 @@
 import javax.management.NotificationBroadcasterSupport;
 import javax.management.ObjectName;
 
+import org.opends.server.admin.std.server.AlertHandlerCfg;
 import org.opends.server.api.AlertGenerator;
 import org.opends.server.api.AlertHandler;
 import org.opends.server.api.DirectoryServerMBean;
-import org.opends.server.config.ConfigEntry;
 import org.opends.server.config.ConfigException;
 import org.opends.server.config.JMXMBean;
 import org.opends.server.core.DirectoryServer;
+import org.opends.server.loggers.debug.DebugTracer;
 import org.opends.server.types.DN;
 import org.opends.server.types.InitializationException;
 import org.opends.server.types.DebugLogLevel;
 
 import static org.opends.server.loggers.debug.DebugLogger.*;
-import org.opends.server.loggers.debug.DebugTracer;
 import static org.opends.server.messages.ConfigMessages.*;
 import static org.opends.server.messages.ExtensionsMessages.*;
 import static org.opends.server.messages.MessageHandler.*;
@@ -68,13 +69,13 @@
 
 
 /**
- * This interface defines the set of methods that must be implemented for a
- * Directory Server alert handler.  Alert handlers are used to present alert
- * notifications in various forms like JMX, e-mail, or paging.
+ * This class provides an implementation of a Directory Server alert handler
+ * that will send alerts using JMX notifications.
  */
 public class JMXAlertHandler
        extends NotificationBroadcasterSupport
-       implements AlertHandler, DynamicMBean, DirectoryServerMBean
+       implements AlertHandler<AlertHandlerCfg>, DynamicMBean,
+                  DirectoryServerMBean
 {
   /**
    * The tracer object for the debug logger.
@@ -109,37 +110,25 @@
   public JMXAlertHandler()
   {
     super();
-
   }
 
 
 
   /**
-   * Initializes this alert handler based on the information in the provided
-   * configuration entry.
-   *
-   * @param  configEntry  The configuration entry that contains the information
-   *                      to use to initialize this alert handler.
-   *
-   * @throws  ConfigException  If the provided entry does not contain a valid
-   *                           configuration for this alert handler.
-   *
-   * @throws  InitializationException  If a problem occurs during initialization
-   *                                   that is not related to the server
-   *                                   configuration.
+   * {@inheritDoc}
    */
-  public void initializeAlertHandler(ConfigEntry configEntry)
+  public void initializeAlertHandler(AlertHandlerCfg configuration)
        throws ConfigException, InitializationException
   {
     sequenceNumber = new AtomicLong(1);
 
-    if (configEntry == null)
+    if (configuration == null)
     {
       configEntryDN = null;
     }
     else
     {
-      configEntryDN = configEntry.getDN();
+      configEntryDN = configuration.dn();
     }
 
     MBeanServer mBeanServer = DirectoryServer.getJMXMBeanServer();
@@ -173,8 +162,18 @@
 
 
   /**
-   * Performs any necessary cleanup that may be necessary when this
-   * alert handler is finalized.
+   * {@inheritDoc}
+   */
+  public boolean isConfigurationAcceptable(AlertHandlerCfg configuration,
+                                           List<String> unacceptableReasons)
+  {
+    return true;
+  }
+
+
+
+  /**
+   * {@inheritDoc}
    */
   public void finalizeAlertHandler()
   {
@@ -196,14 +195,7 @@
 
 
   /**
-   * Sends an alert notification based on the provided information.
-   *
-   * @param  generator     The alert generator that created the alert.
-   * @param  alertType     The alert type name for this alert.
-   * @param  alertID       The alert ID that uniquely identifies the type of
-   *                       alert.
-   * @param  alertMessage  A message (possibly <CODE>null</CODE>) that can
-   *                       provide more information about this alert.
+   * {@inheritDoc}
    */
   public void sendAlertNotification(AlertGenerator generator, String alertType,
                                     int alertID, String alertMessage)
diff --git a/opendj-sdk/opends/src/server/org/opends/server/messages/ConfigMessages.java b/opendj-sdk/opends/src/server/org/opends/server/messages/ConfigMessages.java
index daa7196..daedce5 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/messages/ConfigMessages.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/messages/ConfigMessages.java
@@ -7034,6 +7034,29 @@
 
 
   /**
+   * The message ID for the message that will be used if a proposed
+   * configuration is not acceptable.  This takes two arguments, which are the
+   * DN of the configuration entry and a message explaining why the
+   * configuration is not acceptable.
+   */
+  public static final int MSGID_CONFIG_ALERTHANDLER_CONFIG_NOT_ACCEPTABLE =
+            CATEGORY_MASK_CONFIG | SEVERITY_MASK_MILD_ERROR | 695;
+
+
+
+  /**
+   * The message ID for the message that will be used if an error occurs while
+   * initializing a Directory Server alert handler.  This takes three arguments,
+   * which are the class name for the identity mapper class, the DN of the
+   * configuration entry, and a string representation of the exception that was
+   * caught.
+   */
+  public static final int MSGID_CONFIG_ALERTHANDLER_INITIALIZATION_FAILED =
+            CATEGORY_MASK_CONFIG | SEVERITY_MASK_MILD_ERROR | 696;
+
+
+
+  /**
    * Associates a set of generic messages with the message IDs defined in this
    * class.
    */
@@ -10021,6 +10044,15 @@
                     "configuration, but at least one of the configuration " +
                     "change listeners reported an error when attempting to " +
                     "apply the change:  %s");
+
+
+    registerMessage(MSGID_CONFIG_ALERTHANDLER_CONFIG_NOT_ACCEPTABLE,
+                    "The configuration for the alert handler defined in " +
+                    "configuration entry %s was not acceptable:  %s");
+    registerMessage(MSGID_CONFIG_ALERTHANDLER_INITIALIZATION_FAILED,
+                    "An error occurred while trying to initialize an " +
+                    "instance of class %s as an alert handler as defined " +
+                    "in configuration entry %s:  %s");
   }
 }
 

--
Gitblit v1.10.0