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 2006-2008 Sun Microsystems, Inc.
015 * Portions Copyright 2014-2016 ForgeRock AS.
016 */
017package org.opends.server.api;
018import org.forgerock.i18n.LocalizableMessage;
019
020
021
022import java.util.List;
023
024import org.forgerock.opendj.server.config.server.AlertHandlerCfg;
025import org.forgerock.opendj.config.server.ConfigException;
026import org.opends.server.types.InitializationException;
027
028
029/**
030 * This interface defines the set of methods that must be implemented
031 * for a Directory Server alert handler.  Alert handlers are used to
032 * present alert notifications in various forms like JMX, e-mail, or
033 * paging.
034 *
035 * @param  <T>  The type of configuration handled by this alert
036 *              handler.
037 */
038@org.opends.server.types.PublicAPI(
039     stability=org.opends.server.types.StabilityLevel.VOLATILE,
040     mayInstantiate=false,
041     mayExtend=true,
042     mayInvoke=false)
043public interface AlertHandler<T extends AlertHandlerCfg>
044{
045  /**
046   * Initializes this alert handler based on the information in the
047   * provided configuration entry.
048   *
049   * @param  configuration  The configuration to use to initialize
050   *                        this alert handler.
051   *
052   * @throws  ConfigException  If the provided entry does not contain
053   *                           a valid configuration for this alert
054   *                           handler.
055   *
056   * @throws  InitializationException  If a problem occurs during
057   *                                   initialization that is not
058   *                                   related to the server
059   *                                   configuration.
060   */
061  void initializeAlertHandler(T configuration)
062       throws ConfigException, InitializationException;
063
064
065
066  /**
067   * Retrieves the current configuration for this alert handler.
068   *
069   * @return  The current configuration for this alert handler.
070   */
071  AlertHandlerCfg getAlertHandlerConfiguration();
072
073
074
075  /**
076   * Indicates whether the provided configuration is acceptable for
077   * this alert handler.
078   *
079   * @param  configuration        The configuration for which to make
080   *                              tje determination.
081   * @param  unacceptableReasons  A list to which human-readable
082   *                              reasons may be added to explain why
083   *                              the configuration is not acceptable.
084   *
085   * @return  {@code true} if the provided configuration is
086   *          acceptable, or {@code false} if it is not.
087   */
088  boolean isConfigurationAcceptable(
089                      AlertHandlerCfg configuration,
090                      List<LocalizableMessage> unacceptableReasons);
091
092
093
094  /**
095   * Performs any necessary cleanup that may be necessary when this
096   * alert handler is finalized.
097   */
098  void finalizeAlertHandler();
099
100
101
102  /**
103   * Sends an alert notification based on the provided information.
104   *
105   * @param  generator     The alert generator that created the alert.
106   * @param  alertType     The alert type name for this alert.
107   * @param  alertMessage  A message (possibly {@code null}) that can
108   *                       provide more information about this alert.
109   */
110  void sendAlertNotification(AlertGenerator generator,
111                                    String alertType,
112                                    LocalizableMessage alertMessage);
113}
114