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
010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012 * See the License for the specific language governing permissions
013 * and limitations under the License.
014 *
015 * When distributing Covered Code, include this CDDL HEADER in each
016 * file and include the License file at
017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
018 * add the following below this CDDL HEADER, with the fields enclosed
019 * by brackets "[]" replaced with your own identifying information:
020 * Portions Copyright [yyyy] [name of copyright owner]
021 *
022 * CDDL HEADER END
023 *
024 *
025 * Copyright 2008 Sun Microsystems, Inc.
026 */
027 package org.opends.server.replication.plugin;
028
029 import org.opends.messages.Message;
030
031 import java.util.List;
032
033 import org.opends.server.admin.server.ConfigurationAddListener;
034 import org.opends.server.admin.server.ConfigurationDeleteListener;
035 import org.opends.server.admin.std.server.ReplicationSynchronizationProviderCfg;
036 import org.opends.server.admin.std.server.ReplicationServerCfg;
037 import org.opends.server.config.ConfigException;
038 import org.opends.server.replication.server.ReplicationServer;
039 import org.opends.server.types.ConfigChangeResult;
040 import org.opends.server.types.ResultCode;
041
042
043 /**
044 * This class is used to create and object that can
045 * register in the admin framework as a listener for changes, add and delete
046 * on the ReplicationServer configuration objects.
047 *
048 */
049 public class ReplicationServerListener
050 implements ConfigurationAddListener<ReplicationServerCfg>,
051 ConfigurationDeleteListener<ReplicationServerCfg>
052 {
053 ReplicationServer replicationServer = null;
054
055 /**
056 * Build a ReplicationServer Listener from the given Multimaster
057 * configuration.
058 *
059 * @param configuration The configuration that will be used to listen
060 * for replicationServer configuration changes.
061 *
062 * @throws ConfigException if the ReplicationServerListener can't register for
063 * listening to changes on the provided configuration
064 * object.
065 */
066 public ReplicationServerListener(
067 ReplicationSynchronizationProviderCfg configuration)
068 throws ConfigException
069 {
070 configuration.addReplicationServerAddListener(this);
071 configuration.addReplicationServerDeleteListener(this);
072
073 if (configuration.hasReplicationServer())
074 {
075 ReplicationServerCfg server = configuration.getReplicationServer();
076 replicationServer = new ReplicationServer(server);
077 }
078 }
079
080 /**
081 * {@inheritDoc}
082 */
083 public ConfigChangeResult applyConfigurationAdd(
084 ReplicationServerCfg configuration)
085 {
086 try
087 {
088 replicationServer = new ReplicationServer(configuration);
089 return new ConfigChangeResult(ResultCode.SUCCESS, false);
090 } catch (ConfigException e)
091 {
092 // we should never get to this point because the configEntry has
093 // already been validated in configAddisAcceptable
094 return new ConfigChangeResult(ResultCode.CONSTRAINT_VIOLATION, false);
095 }
096 }
097
098 /**
099 * {@inheritDoc}
100 */
101 public boolean isConfigurationAddAcceptable(
102 ReplicationServerCfg configuration, List<Message> unacceptableReasons)
103 {
104 return ReplicationServer.isConfigurationAcceptable(
105 configuration, unacceptableReasons);
106 }
107
108 /**
109 * Shutdown the replication server.
110 */
111 public void shutdown()
112 {
113 if (replicationServer != null)
114 replicationServer.shutdown();
115 }
116
117 /**
118 * {@inheritDoc}
119 */
120 public ConfigChangeResult applyConfigurationDelete(
121 ReplicationServerCfg configuration)
122 {
123 // There can be only one replicationServer, just shutdown the
124 // replicationServer currently configured.
125 if (replicationServer != null)
126 {
127 replicationServer.remove();
128 }
129 return new ConfigChangeResult(ResultCode.SUCCESS, false);
130 }
131
132 /**
133 * {@inheritDoc}
134 */
135 public boolean isConfigurationDeleteAcceptable(
136 ReplicationServerCfg configuration, List<Message> unacceptableReasons)
137 {
138 return true;
139 }
140
141 /**
142 * Returns the associated Replication Server.
143 * @return The replication server.
144 */
145 public ReplicationServer getReplicationServer()
146 {
147 return replicationServer;
148 }
149 }