Return-Path: Delivered-To: apmail-tomcat-dev-archive@www.apache.org Received: (qmail 3386 invoked from network); 6 Mar 2010 10:55:22 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 6 Mar 2010 10:55:22 -0000 Received: (qmail 43111 invoked by uid 500); 6 Mar 2010 10:55:04 -0000 Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org Received: (qmail 42794 invoked by uid 500); 6 Mar 2010 10:55:03 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 42785 invoked by uid 99); 6 Mar 2010 10:55:03 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 06 Mar 2010 10:55:03 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 06 Mar 2010 10:55:00 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id D05A423889B3; Sat, 6 Mar 2010 10:54:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r919740 - /tomcat/trunk/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java Date: Sat, 06 Mar 2010 10:54:38 -0000 To: dev@tomcat.apache.org From: markt@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100306105438.D05A423889B3@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: markt Date: Sat Mar 6 10:54:38 2010 New Revision: 919740 URL: http://svn.apache.org/viewvc?rev=919740&view=rev Log: Lifecycle refactoring - Cluster Added toString() for use in Lifecycle error messages Modified: tomcat/trunk/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java Modified: tomcat/trunk/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java?rev=919740&r1=919739&r2=919740&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java (original) +++ tomcat/trunk/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java Sat Mar 6 10:54:38 2010 @@ -29,10 +29,10 @@ import org.apache.catalina.Context; import org.apache.catalina.Engine; import org.apache.catalina.Host; -import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleEvent; import org.apache.catalina.LifecycleException; import org.apache.catalina.LifecycleListener; +import org.apache.catalina.LifecycleState; import org.apache.catalina.Manager; import org.apache.catalina.Valve; import org.apache.catalina.ha.CatalinaCluster; @@ -47,7 +47,7 @@ import org.apache.catalina.tribes.Member; import org.apache.catalina.tribes.MembershipListener; import org.apache.catalina.tribes.group.GroupChannel; -import org.apache.catalina.util.LifecycleSupport; +import org.apache.catalina.util.LifecycleBase; import org.apache.tomcat.util.res.StringManager; import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; @@ -72,8 +72,8 @@ * @author Peter Rossbach * @version $Revision$, $Date$ */ -public class SimpleTcpCluster - implements CatalinaCluster, Lifecycle, LifecycleListener, IDynamicProperty, +public class SimpleTcpCluster extends LifecycleBase + implements CatalinaCluster, LifecycleListener, IDynamicProperty, MembershipListener, ChannelListener{ public static final Log log = LogFactory.getLog(SimpleTcpCluster.class); @@ -138,16 +138,6 @@ protected Container container = null; /** - * The lifecycle event support for this component. - */ - protected LifecycleSupport lifecycle = new LifecycleSupport(this); - - /** - * Has this component been started? - */ - protected boolean started = false; - - /** * The property change support for this component. */ protected PropertyChangeSupport support = new PropertyChangeSupport(this); @@ -535,7 +525,7 @@ ClusterManager cmanager = (ClusterManager) manager ; cmanager.setDistributable(true); // Notify our interested LifecycleListeners - lifecycle.fireLifecycleEvent(BEFORE_MANAGERREGISTER_EVENT, manager); + fireLifecycleEvent(BEFORE_MANAGERREGISTER_EVENT, manager); String clusterName = getManagerName(cmanager.getName(), manager); cmanager.setName(clusterName); cmanager.setCluster(this); @@ -543,7 +533,7 @@ managers.put(clusterName, cmanager); // Notify our interested LifecycleListeners - lifecycle.fireLifecycleEvent(AFTER_MANAGERREGISTER_EVENT, manager); + fireLifecycleEvent(AFTER_MANAGERREGISTER_EVENT, manager); } /** @@ -555,11 +545,11 @@ if (manager != null && manager instanceof ClusterManager ) { ClusterManager cmgr = (ClusterManager) manager; // Notify our interested LifecycleListeners - lifecycle.fireLifecycleEvent(BEFORE_MANAGERUNREGISTER_EVENT,manager); + fireLifecycleEvent(BEFORE_MANAGERUNREGISTER_EVENT,manager); managers.remove(getManagerName(cmgr.getName(),manager)); cmgr.setCluster(null); // Notify our interested LifecycleListeners - lifecycle.fireLifecycleEvent(AFTER_MANAGERUNREGISTER_EVENT, manager); + fireLifecycleEvent(AFTER_MANAGERUNREGISTER_EVENT, manager); } } @@ -609,35 +599,6 @@ if ( isHeartbeatBackgroundEnabled() && channel !=null ) channel.heartbeat(); } - /** - * Add a lifecycle event listener to this component. - * - * @param listener - * The listener to add - */ - public void addLifecycleListener(LifecycleListener listener) { - lifecycle.addLifecycleListener(listener); - } - - /** - * Get the lifecycle listeners associated with this lifecycle. If this - * Lifecycle has no listeners registered, a zero-length array is returned. - */ - public LifecycleListener[] findLifecycleListeners() { - - return lifecycle.findLifecycleListeners(); - - } - - /** - * Remove a lifecycle event listener from this component. - * - * @param listener - * The listener to remove - */ - public void removeLifecycleListener(LifecycleListener listener) { - lifecycle.removeLifecycleListener(listener); - } /** * Use as base to handle start/stop/periodic Events from host. Currently @@ -653,26 +614,17 @@ // ------------------------------------------------------ public /** - * Prepare for the beginning of active use of the public methods of this - * component. This method should be called after configure(), - * and before any of the public methods of the component are utilized.
- * Starts the cluster communication channel, this will connect with the - * other nodes in the cluster, and request the current session state to be - * transferred to this node. - * - * @exception IllegalStateException - * if this component has already been started - * @exception LifecycleException - * if this component detects a fatal error that prevents this - * component from being used - */ - public void start() throws LifecycleException { - if (started) - throw new LifecycleException(sm.getString("cluster.alreadyStarted")); + * Start Cluster and implement the requirements + * of {@link LifecycleBase#startInternal()}. + * + * @exception LifecycleException if this component detects a fatal error + * that prevents this component from being used + */ + @Override + protected void startInternal() throws LifecycleException { + if (log.isInfoEnabled()) log.info("Cluster is about to start"); - // Notify our interested LifecycleListeners - lifecycle.fireLifecycleEvent(BEFORE_START_EVENT, this); try { checkDefaults(); registerClusterValve(); @@ -680,15 +632,15 @@ channel.addChannelListener(this); channel.start(channelStartOptions); if (clusterDeployer != null) clusterDeployer.start(); - this.started = true; //register JMX objects ClusterJmxHelper.registerDefaultCluster(this); // Notify our interested LifecycleListeners - lifecycle.fireLifecycleEvent(AFTER_START_EVENT, this); } catch (Exception x) { log.error("Unable to start cluster.", x); throw new LifecycleException(x); } + + setState(LifecycleState.STARTING); } protected void checkDefaults() { @@ -750,25 +702,18 @@ } } + /** - * Gracefully terminate the active cluster component.
- * This will disconnect the cluster communication channel, stop the - * listener and deregister the valves from host or engine.

- * Note:
The sub elements receiver, sender, membership, - * listener or valves are not removed. You can easily start the cluster again. - * - * @exception IllegalStateException - * if this component has not been started - * @exception LifecycleException - * if this component detects a fatal error that needs to be - * reported + * Stop Cluster and implement the requirements + * of {@link LifecycleBase#startInternal()}. + * + * @exception LifecycleException if this component detects a fatal error + * that prevents this component from being used */ - public void stop() throws LifecycleException { + @Override + protected void stopInternal() throws LifecycleException { - if (!started) - throw new IllegalStateException(sm.getString("cluster.notStarted")); - // Notify our interested LifecycleListeners - lifecycle.fireLifecycleEvent(BEFORE_STOP_EVENT, this); + setState(LifecycleState.STOPPING); if (clusterDeployer != null) clusterDeployer.stop(); this.managers.clear(); @@ -784,13 +729,25 @@ } catch (Exception x) { log.error("Unable to stop cluster valve.", x); } - started = false; - // Notify our interested LifecycleListeners - lifecycle.fireLifecycleEvent(AFTER_STOP_EVENT, this); - } + } - + /** + * Return a String rendering of this object. + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(this.getClass().getName()); + sb.append('['); + if (container == null) { + sb.append("Container is null"); + } else { + sb.append(container.getName()); + } + sb.append(']'); + return sb.toString(); + } + /** * send message to all cluster members @@ -850,9 +807,9 @@ hasMembers = channel.hasMembers(); if (log.isInfoEnabled()) log.info("Replication member added:" + member); // Notify our interested LifecycleListeners - lifecycle.fireLifecycleEvent(BEFORE_MEMBERREGISTER_EVENT, member); + fireLifecycleEvent(BEFORE_MEMBERREGISTER_EVENT, member); // Notify our interested LifecycleListeners - lifecycle.fireLifecycleEvent(AFTER_MEMBERREGISTER_EVENT, member); + fireLifecycleEvent(AFTER_MEMBERREGISTER_EVENT, member); } catch (Exception x) { log.error("Unable to connect to replication system.", x); } @@ -869,9 +826,9 @@ hasMembers = channel.hasMembers(); if (log.isInfoEnabled()) log.info("Received member disappeared:" + member); // Notify our interested LifecycleListeners - lifecycle.fireLifecycleEvent(BEFORE_MEMBERUNREGISTER_EVENT, member); + fireLifecycleEvent(BEFORE_MEMBERUNREGISTER_EVENT, member); // Notify our interested LifecycleListeners - lifecycle.fireLifecycleEvent(AFTER_MEMBERUNREGISTER_EVENT, member); + fireLifecycleEvent(AFTER_MEMBERUNREGISTER_EVENT, member); } catch (Exception x) { log.error("Unable remove cluster node from replication system.", x); } @@ -921,7 +878,7 @@ if (notifyLifecycleListenerOnFailure) { Member dest = message.getAddress(); // Notify our interested LifecycleListeners - lifecycle.fireLifecycleEvent(RECEIVE_MESSAGE_FAILURE_EVENT, + fireLifecycleEvent(RECEIVE_MESSAGE_FAILURE_EVENT, new SendMessageData(message, dest, null)); } log.debug("Message " + message.toString() + " from type " --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org