ExamplePlugin.java revision 98a1007979c3bb0ffa38f3eecff66b174172be67
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift/*
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * CDDL HEADER START
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift *
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * The contents of this file are subject to the terms of the
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * Common Development and Distribution License, Version 1.0 only
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * (the "License"). You may not use this file except in compliance
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * with the License.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift *
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * You can obtain a copy of the license at
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * trunk/opends/resource/legal-notices/OpenDS.LICENSE
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * See the License for the specific language governing permissions
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * and limitations under the License.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift *
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * When distributing Covered Code, include this CDDL HEADER in each
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * file and include the License file at
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * add the following below this CDDL HEADER, with the fields enclosed
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * by brackets "[]" replaced with your own identifying information:
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * Portions Copyright [yyyy] [name of copyright owner]
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift *
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * CDDL HEADER END
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift *
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift *
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * Portions Copyright 2006-2007 Sun Microsystems, Inc.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift */
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swiftpackage com.example.opends;
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift
bedb386242727f98834c64397487f48d5eb6116cboliimport static org.opends.server.loggers.ErrorLogger.logError;
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swiftimport java.util.List;
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swiftimport java.util.Set;
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swiftimport org.opends.server.api.plugin.PluginType;
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swiftimport org.opends.server.api.plugin.StartupPluginResult;
98a1007979c3bb0ffa38f3eecff66b174172be67treydrakeimport org.opends.server.api.plugin.DirectoryServerPlugin;
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swiftimport org.opends.server.config.ConfigException;
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swiftimport org.opends.server.types.ConfigChangeResult;
53247d28ba99538f841a13ea2cde01c3faa3ef36kenneth_suter
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swiftimport org.opends.server.types.ResultCode;
98a1007979c3bb0ffa38f3eecff66b174172be67treydrakeimport org.opends.server.types.InitializationException;
98a1007979c3bb0ffa38f3eecff66b174172be67treydrakeimport org.opends.server.admin.server.ConfigurationChangeListener;
98a1007979c3bb0ffa38f3eecff66b174172be67treydrakeimport org.opends.messages.Message;
98a1007979c3bb0ffa38f3eecff66b174172be67treydrakeimport org.opends.messages.Category;
98a1007979c3bb0ffa38f3eecff66b174172be67treydrakeimport org.opends.messages.Severity;
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swiftimport com.example.opends.server.ExamplePluginCfg;
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift/**
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * The example plugin implementation class. This plugin will output
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * the configured message to the error log during server start up.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift */
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swiftpublic class ExamplePlugin extends
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake DirectoryServerPlugin<ExamplePluginCfg> implements
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake ConfigurationChangeListener<ExamplePluginCfg> {
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift // The current configuration.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift private ExamplePluginCfg config;
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift /**
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift * Default constructor.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift */
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift public ExamplePlugin() {
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift super();
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift }
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift /**
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * Performs any initialization necessary for this plugin. This will
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * be called as soon as the plugin has been loaded and before it is
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * registered with the server.
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake *
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * @param pluginTypes The set of plugin types that indicate the
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * ways in which this plugin will be invoked.
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * @param configuration The configuration for this plugin.
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake *
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * @throws ConfigException If the provided entry does not contain
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * a valid configuration for this plugin.
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake *
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * @throws InitializationException If a problem occurs while
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * initializing the plugin that is
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * not related to the server
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * configuration.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift */
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift @Override()
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift public void initializePlugin(Set<PluginType> pluginTypes,
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ExamplePluginCfg configuration)
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake throws ConfigException, InitializationException {
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift // This plugin may only be used as a server startup plugin.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift for (PluginType t : pluginTypes) {
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift switch (t) {
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift case STARTUP:
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift // This is fine.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift break;
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift default:
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake throw new ConfigException(Message.raw("Invalid plugin type " + t
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake + " for the example plugin."));
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift }
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift }
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift // Register change listeners. These are not really necessary for
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift // this plugin since it is only used during server start-up.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift configuration.addExampleChangeListener(this);
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift // Save the configuration.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift this.config = configuration;
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift }
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift /**
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * Performs any processing that should be done when the Directory
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * Server is in the process of starting. This method will be called
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * after virtually all other initialization has been performed but
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * before the connection handlers are started.
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake *
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * @return The result of the startup plugin processing.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift */
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift @Override
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift public StartupPluginResult doStartup() {
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift // Log the provided message.
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake logError(Message.raw(Category.CONFIG, Severity.NOTICE,
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake "Example plugin message '" + config.getMessage() + "'."));
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift return StartupPluginResult.SUCCESS;
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift }
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift /**
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * Applies the configuration changes to this change listener.
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake *
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * @param config
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * The new configuration containing the changes.
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * @return Returns information about the result of changing the
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * configuration.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift */
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift public ConfigChangeResult applyConfigurationChange(
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift ExamplePluginCfg config) {
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift // The new configuration has already been validated.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift // Log a message to say that the configuration has changed. This
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift // isn't necessary, but we'll do it just to show that the change
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift // has taken effect.
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake logError(Message.raw(Category.CONFIG, Severity.NOTICE,
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift "Example plugin message has been changed from '"
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift + this.config.getMessage() + "' to '"
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake + config.getMessage() + "'"));
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift // Update the configuration.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift this.config = config;
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift // Update was successfull, no restart required.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift return new ConfigChangeResult(ResultCode.SUCCESS, false);
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift }
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift /**
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * Indicates whether the proposed change to the configuration is
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * acceptable to this change listener.
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake *
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * @param config
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * The new configuration containing the changes.
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * @param messages
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * A list that can be used to hold messages about why the
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * provided configuration is not acceptable.
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * @return Returns <code>true</code> if the proposed change is
98a1007979c3bb0ffa38f3eecff66b174172be67treydrake * acceptable, or <code>false</code> if it is not.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift */
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift public boolean isConfigurationChangeAcceptable(
53247d28ba99538f841a13ea2cde01c3faa3ef36kenneth_suter ExamplePluginCfg config, List<Message> messages) {
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift // The only thing that can be validated here is the plugin's
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift // message. However, it is always going to be valid, so let's
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift // always return true.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift return true;
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift }
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swift}