Return-Path: Delivered-To: apmail-tomcat-dev-archive@www.apache.org Received: (qmail 57658 invoked from network); 23 Feb 2006 19:56:37 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 23 Feb 2006 19:56:37 -0000 Received: (qmail 59278 invoked by uid 500); 23 Feb 2006 19:56:24 -0000 Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org Received: (qmail 59061 invoked by uid 500); 23 Feb 2006 19:56:23 -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 59050 invoked by uid 500); 23 Feb 2006 19:56:23 -0000 Delivered-To: apmail-jakarta-tomcat-dev@jakarta.apache.org Received: (qmail 59047 invoked by uid 99); 23 Feb 2006 19:56:23 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Feb 2006 11:56:23 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 23 Feb 2006 11:56:15 -0800 Received: (qmail 57359 invoked by uid 65534); 23 Feb 2006 19:55:54 -0000 Message-ID: <20060223195554.57358.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r380209 [1/12] - in /tomcat/container/tc5.5.x/modules: groupcom/ groupcom/etc/ groupcom/src/ groupcom/src/share/ groupcom/src/share/org/ groupcom/src/share/org/apache/ groupcom/src/share/org/apache/catalina/ groupcom/src/share/org/apache/ca... Date: Thu, 23 Feb 2006 19:55:25 -0000 To: tomcat-dev@jakarta.apache.org From: fhanik@apache.org X-Mailer: svnmailer-1.0.7 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: fhanik Date: Thu Feb 23 11:55:14 2006 New Revision: 380209 URL: http://svn.apache.org/viewcvs?rev=380209&view=rev Log: Skeleton for two new modules where tomcat replication logic is separated from the messaging logic Added: tomcat/container/tc5.5.x/modules/groupcom/ tomcat/container/tc5.5.x/modules/groupcom/build.xml tomcat/container/tc5.5.x/modules/groupcom/etc/ tomcat/container/tc5.5.x/modules/groupcom/etc/cluster-server.xml tomcat/container/tc5.5.x/modules/groupcom/src/ tomcat/container/tc5.5.x/modules/groupcom/src/share/ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ChannelException.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ClusterChannel.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ClusterMessage.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ClusterReceiver.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ClusterSender.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ClusterSession.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/Constants.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/LocalStrings.properties tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/Member.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/MembershipListener.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/MembershipService.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/MessageListener.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/demos/ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/demos/Draw.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/group/ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/group/ChannelCoordinator.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/group/ChannelInterceptorBase.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/group/GroupChannel.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/io/ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/io/ListenCallback.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/io/ObjectReader.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/io/ReplicationStream.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/io/SocketObjectReader.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/io/XByteBuffer.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/mbeans-descriptors.xml tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/mcast/ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/mcast/Constants.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/mcast/LocalStrings.properties tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/mcast/McastMember.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/mcast/McastMembership.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/mcast/McastService.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/mcast/McastServiceImpl.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/mcast/mbeans-descriptors.xml tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/package.html tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/tcp/ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/tcp/AsyncSocketSender.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/tcp/ClusterData.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/tcp/Constants.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/tcp/DataSender.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/tcp/DataSenders.properties tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/tcp/FastAsyncSocketSender.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/tcp/IDataSender.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/tcp/IDataSenderFactory.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/tcp/LocalStrings.properties tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/tcp/PooledSocketSender.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/tcp/ReplicationListener.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/tcp/ReplicationListener.jbx tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/tcp/ReplicationTransmitter.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/tcp/SendMessageData.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/tcp/SenderState.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/tcp/SocketSender.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/tcp/TcpReplicationThread.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/tcp/ThreadPool.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/tcp/WorkerThread.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/tcp/mbeans-descriptors.xml tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/util/ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/util/FastQueue.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/util/IDynamicProperty.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/util/IQueue.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/util/LinkObject.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/util/SingleRemoveSynchronizedAddLock.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/util/SmartQueue.java tomcat/container/tc5.5.x/modules/groupcom/test/ tomcat/container/tc5.5.x/modules/ha/ tomcat/container/tc5.5.x/modules/ha/build.xml tomcat/container/tc5.5.x/modules/ha/etc/ tomcat/container/tc5.5.x/modules/ha/src/ tomcat/container/tc5.5.x/modules/ha/src/share/ tomcat/container/tc5.5.x/modules/ha/src/share/org/ tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/ tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/ tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/CatalinaCluster.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/ClusterDeployer.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/ClusterListener.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/ClusterManager.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/ClusterReceiver.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/ClusterSender.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/ClusterSession.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/ClusterValve.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/Constants.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/LocalStrings.properties tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/Member.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/MembershipListener.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/MembershipService.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/MessageListener.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/deploy/ tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/deploy/FarmWarDeployer.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/deploy/FileChangeListener.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/deploy/FileMessage.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/deploy/FileMessageFactory.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/deploy/UndeployMessage.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/deploy/WarWatcher.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/mbeans-descriptors.xml tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/package.html tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/session/ tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/session/ClusterSessionListener.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/session/Constants.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/session/DeltaManager.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/session/DeltaRequest.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/session/DeltaSession.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/session/DeltaSessionFacade.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/session/JvmRouteBinderValve.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/session/JvmRouteSessionIDBinderLifecycleListener.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/session/JvmRouteSessionIDBinderListener.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/session/LocalStrings.properties tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/session/ReplicatedSession.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/session/ReplicationStream.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/session/SerializablePrincipal.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/session/SessionIDMessage.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/session/SessionMessage.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/session/SessionMessageImpl.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/session/SimpleTcpReplicationManager.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/session/mbeans-descriptors.xml tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/tcp/ tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/tcp/ClusterReceiverBase.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/tcp/Constants.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/tcp/LocalStrings.properties tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/tcp/ReplicationValve.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/tcp/SendMessageData.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/tcp/SimpleTcpCluster.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/tcp/SocketReplicationListener.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/tcp/SocketReplicationThread.java tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/cluster/tcp/mbeans-descriptors.xml tomcat/container/tc5.5.x/modules/ha/test/ Added: tomcat/container/tc5.5.x/modules/groupcom/build.xml URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/groupcom/build.xml?rev=380209&view=auto ============================================================================== --- tomcat/container/tc5.5.x/modules/groupcom/build.xml (added) +++ tomcat/container/tc5.5.x/modules/groupcom/build.xml Thu Feb 23 11:55:14 2006 @@ -0,0 +1,153 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Added: tomcat/container/tc5.5.x/modules/groupcom/etc/cluster-server.xml URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/groupcom/etc/cluster-server.xml?rev=380209&view=auto ============================================================================== --- tomcat/container/tc5.5.x/modules/groupcom/etc/cluster-server.xml (added) +++ tomcat/container/tc5.5.x/modules/groupcom/etc/cluster-server.xml Thu Feb 23 11:55:14 2006 @@ -0,0 +1,368 @@ + + + + + + + + + + + + + + + + + + + + + + + + + factory + org.apache.catalina.users.MemoryUserDatabaseFactory + + + pathname + conf/tomcat-users.xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Added: tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ChannelException.java URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ChannelException.java?rev=380209&view=auto ============================================================================== --- tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ChannelException.java (added) +++ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ChannelException.java Thu Feb 23 11:55:14 2006 @@ -0,0 +1,42 @@ +/* + * Copyright 1999,2004-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.cluster; + +/** + * Channel Exception + * @author Filip Hanik + * @version $Revision: 304032 $, $Date: 2005-07-27 10:11:55 -0500 (Wed, 27 Jul 2005) $ + */ + +public class ChannelException + extends Exception { + public ChannelException() { + super(); + } + + public ChannelException(String message) { + super(message); + } + + public ChannelException(String message, Throwable cause) { + super(message, cause); + } + + public ChannelException(Throwable cause) { + super(cause); + } + +} Added: tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ClusterChannel.java URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ClusterChannel.java?rev=380209&view=auto ============================================================================== --- tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ClusterChannel.java (added) +++ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ClusterChannel.java Thu Feb 23 11:55:14 2006 @@ -0,0 +1,76 @@ +/* + * Copyright 1999,2004-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.cluster; + +/** + * Channel interface + * A channel is an object that manages a group of members. + * It manages a complete cluster group, both membership and replication. + * @author Filip Hanik + * @version $Revision: 304032 $, $Date: 2005-07-27 10:11:55 -0500 (Wed, 27 Jul 2005) $ + */ +public interface ClusterChannel { + + /** + * Start and stop sequences can be controlled by these constants + */ + public static final int DEFAULT = 15; + public static final int MBR_RX_SEQ = 1; + public static final int SND_TX_SEQ = 2; + public static final int SND_RX_SEQ = 4; + public static final int MBR_TX_SEQ = 8; + + /** + * Starts up the channel. This can be called multiple times for individual services to start + * The svc parameter can be the logical or value of any constants + * @param svc int value of
+ * DEFAULT - will start all services
+ * MBR_RX_SEQ - starts the membership receiver
+ * MBR_TX_SEQ - starts the membership broadcaster
+ * SND_TX_SEQ - starts the replication transmitter
+ * SND_RX_SEQ - starts the replication receiver
+ * @throws ChannelException if a startup error occurs or the service is already started. + */ + public void start(int svc) throws ChannelException; + + /** + * Shuts down the channel. This can be called multiple times for individual services to shutdown + * The svc parameter can be the logical or value of any constants + * @param svc int value of
+ * DEFAULT - will shutdown all services
+ * MBR_RX_SEQ - stops the membership receiver
+ * MBR_TX_SEQ - stops the membership broadcaster
+ * SND_TX_SEQ - stops the replication transmitter
+ * SND_RX_SEQ - stops the replication receiver
+ * @throws ChannelException if a startup error occurs or the service is already started. + */ + public void stop(int svc) throws ChannelException; + + /** + * Send a message to one or more members in the cluster + * @param destination Member[] - the destinations, null or zero length means all + * @param msg ClusterMessage - the message to send + * @param options int - sender options, see class documentation + * @return ClusterMessage[] - the replies from the members, if any. + */ + public ClusterMessage[] send(Member[] destination, ClusterMessage msg, int options) throws ChannelException; + + + public void setClusterSender(ClusterSender sender); + public void setClusterReceiver(ClusterReceiver receiver); + public void setMembershipService(MembershipService service); + +} Added: tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ClusterMessage.java URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ClusterMessage.java?rev=380209&view=auto ============================================================================== --- tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ClusterMessage.java (added) +++ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ClusterMessage.java Thu Feb 23 11:55:14 2006 @@ -0,0 +1,100 @@ +/* + * Copyright 1999,2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.cluster; + +import java.io.Serializable; + +/** + * @author Filip Hanik + * @author Peter Rossbach + * + */ +public interface ClusterMessage extends Serializable { + + public final static int FLAG_FORBIDDEN = 0 ; + public final static int FLAG_ALLOWED = 1 ; + public final static int FLAG_DEFAULT = 2 ; + + /** + * Get the address that this message originated from. This would be set + * if the message was being relayed from a host other than the one + * that originally sent it. + */ + public Member getAddress(); + + /** + * Called by the cluster before sending it to the other + * nodes. + * + * @param member Member + */ + public void setAddress(Member member); + + /** + * Timestamp message. + * + * @return long + */ + public long getTimestamp(); + + /** + * Called by the cluster before sending out + * the message. + * + * @param timestamp The timestamp + */ + public void setTimestamp(long timestamp); + + /** + * Each message must have a unique ID, in case of using async replication, + * and a smart queue, this id is used to replace messages not yet sent. + * + * @return String + */ + public String getUniqueId(); + + /** + * Each message can made the desicion that resend is allowed or not or handle by default. + * @return 0 Forbidden, 1 allowed, 2 default + * @since 5.5.10 + */ + public int getResend(); + + /** + * set desicion that resend is allowed or not or handle by default. + * + * @param resend 0 Forbidden, 1 allowed, 2 default + * @since 5.5.10 + */ + public void setResend(int resend) ; + + /** + * Each message can made the desicion that compress is allowed or not or handle by default. + * + * @return 0 Forbidden, 1 allowed, 2 default + * @since 5.5.10 + */ + public int getCompress(); + + /** + * set desicion that compress is allowed or not or handle by default. + * + * @param compress 0 Forbidden, 1 allowed, 2 default + * @since 5.5.10 + */ + public void setCompress(int compress) ; + +} Added: tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ClusterReceiver.java URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ClusterReceiver.java?rev=380209&view=auto ============================================================================== --- tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ClusterReceiver.java (added) +++ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ClusterReceiver.java Thu Feb 23 11:55:14 2006 @@ -0,0 +1,66 @@ +/* + * Copyright 1999,2004-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.catalina.cluster; + + +/** + * Cluster Receiver Interface + * @author Filip Hanik + * @author Peter Rossbach + * @version $Revision: 379904 $, $Date: 2006-02-22 15:16:25 -0600 (Wed, 22 Feb 2006) $ + */ +public interface ClusterReceiver { + /** + * Start message listing + * @throws java.io.IOException + */ + public void start() throws java.io.IOException; + + /** + * Stop message listing + */ + public void stop(); + + + public boolean isSendAck(); + + /** + * set ack mode + * @param isSendAck + */ + public void setSendAck(boolean isSendAck); + + public boolean isCompress() ; + public void setCompress(boolean compress); + + /** + * get the listing ip interface + * @return The host + */ + public String getHost(); + + + /** + * get the listing ip port + * @return The port + */ + public int getPort(); + + public void setMessageListener(MessageListener listener); + public MessageListener getMessageListener(); + +} Added: tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ClusterSender.java URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ClusterSender.java?rev=380209&view=auto ============================================================================== --- tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ClusterSender.java (added) +++ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ClusterSender.java Thu Feb 23 11:55:14 2006 @@ -0,0 +1,50 @@ +/* + * Copyright 1999,2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.catalina.cluster; + +/** + * + * @author Filip Hanik + * @version $Revision: 303950 $, $Date: 2005-06-09 15:38:30 -0500 (Thu, 09 Jun 2005) $ + * + */ +public interface ClusterSender +{ + + public void add(Member member); + + public void remove(Member member); + + public void start() throws java.io.IOException; + + public void stop(); + + public void backgroundProcess() ; + + public void sendMessage(ClusterMessage message, Member member) throws java.io.IOException; + + public void sendMessage(ClusterMessage message) throws java.io.IOException; + + public void sendMessageClusterDomain(ClusterMessage message) throws java.io.IOException; + + public boolean isWaitForAck(); + public void setWaitForAck(boolean isWaitForAck); + + public boolean isCompress() ; + public void setCompress(boolean compress); + +} Added: tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ClusterSession.java URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ClusterSession.java?rev=380209&view=auto ============================================================================== --- tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ClusterSession.java (added) +++ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/ClusterSession.java Thu Feb 23 11:55:14 2006 @@ -0,0 +1,37 @@ +/* + * Copyright 1999,2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package org.apache.catalina.cluster; + +import org.apache.catalina.Session; +import javax.servlet.http.HttpSession; + +public interface ClusterSession extends Session, HttpSession { + /** + * returns true if this session is the primary session, if that is the + * case, the manager can expire it upon timeout. + * @return True if this session is primary + */ + public boolean isPrimarySession(); + + /** + * Sets whether this is the primary session or not. + * @param primarySession Flag value + */ + public void setPrimarySession(boolean primarySession); + +} Added: tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/Constants.java URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/Constants.java?rev=380209&view=auto ============================================================================== --- tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/Constants.java (added) +++ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/Constants.java Thu Feb 23 11:55:14 2006 @@ -0,0 +1,30 @@ +/* + * Copyright 1999,2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package org.apache.catalina.cluster; + +/** + * Manifest constants for the org.apache.catalina.cluster + * package. + * + * @author Bip Thelin + * @version $Revision: 302726 $, $Date: 2004-02-27 08:59:07 -0600 (Fri, 27 Feb 2004) $ + */ + +public final class Constants { + public static final String Package = "org.apache.catalina.cluster"; +} Added: tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/LocalStrings.properties URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/LocalStrings.properties?rev=380209&view=auto ============================================================================== --- tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/LocalStrings.properties (added) +++ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/LocalStrings.properties Thu Feb 23 11:55:14 2006 @@ -0,0 +1 @@ +cluster.mbean.register.already=MBean {0} already registered! Added: tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/Member.java URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/Member.java?rev=380209&view=auto ============================================================================== --- tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/Member.java (added) +++ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/Member.java Thu Feb 23 11:55:14 2006 @@ -0,0 +1,65 @@ +/* + * Copyright 1999,2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.catalina.cluster; + +/** + * The Member interface, defines a member in the Cluster. + * A member is a Tomcat process that participates in session replication.
+ * Each member can carry a set of properties, defined by the actual implementation.
+ * For TCP replication has been targeted for the first release, the hostname and listen port + * of the member is defined as hardcoded stuff.
+ * The Member interface together with MembershipListener, MembershipService are interfaces used to + * switch out the service used to establish membership in between the cluster nodes. + * + * @author Filip Hanik + * @version $Revision: 303950 $, $Date: 2005-06-09 15:38:30 -0500 (Thu, 09 Jun 2005) $ + */ + + +public interface Member { + /** + * Return implementation specific properties about this cluster node. + */ + public java.util.HashMap getMemberProperties(); + /** + * Returns the name of this node, should be unique within the cluster. + */ + public String getName(); + + /** + * Returns the name of the cluster domain from this node + */ + public String getDomain(); + + /** + * Returns the TCP listen host for the TCP implementation + */ + public String getHost(); + /** + * Returns the TCP listen portfor the TCP implementation + */ + public int getPort(); + + /** + * Contains information on how long this member has been online. + * The result is the number of milli seconds this member has been + * broadcasting its membership to the cluster. + * @return nr of milliseconds since this member started. + */ + public long getMemberAliveTime(); + +} Added: tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/MembershipListener.java URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/MembershipListener.java?rev=380209&view=auto ============================================================================== --- tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/MembershipListener.java (added) +++ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/MembershipListener.java Thu Feb 23 11:55:14 2006 @@ -0,0 +1,33 @@ +/* + * Copyright 1999,2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.catalina.cluster; + +/** + * The MembershipListener interface is used as a callback to the + * membership service. It has two methods that will notify the listener + * when a member has joined the cluster and when a member has disappeared (crashed) + * + * @author Filip Hanik + * @version $Revision: 302726 $, $Date: 2004-02-27 08:59:07 -0600 (Fri, 27 Feb 2004) $ + */ + + +public interface MembershipListener { + public void memberAdded(Member member); + public void memberDisappeared(Member member); + +} \ No newline at end of file Added: tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/MembershipService.java URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/MembershipService.java?rev=380209&view=auto ============================================================================== --- tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/MembershipService.java (added) +++ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/MembershipService.java Thu Feb 23 11:55:14 2006 @@ -0,0 +1,110 @@ +/* + * Copyright 1999,2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.catalina.cluster; + + +/** + * The membership service helps the cluster determine the membership + * logic in the cluster. + * @author Filip Hanik + * @version $Revision: 378093 $, $Date: 2006-02-15 15:13:45 -0600 (Wed, 15 Feb 2006) $ + */ + + +public interface MembershipService { + + public static final int MBR_RX = 1; + public static final int MBR_TX = 2; + + /** + * Sets the properties for the membership service. This must be called before + * the start() method is called. + * The properties are implementation specific. + * @param properties - to be used to configure the membership service. + */ + public void setProperties(java.util.Properties properties); + /** + * Returns the properties for the configuration used. + */ + public java.util.Properties getProperties(); + /** + * Starts the membership service. If a membership listeners is added + * the listener will start to receive membership events. + * Performs a start level 1 and 2 + * @throws java.lang.Exception if the service fails to start. + */ + public void start() throws java.lang.Exception; + + /** + * Starts the membership service. If a membership listeners is added + * the listener will start to receive membership events. + * @param level - level 1 starts listening for members, level 2 + * starts broad casting the server + * @throws java.lang.Exception if the service fails to start. + */ + public void start(int level) throws java.lang.Exception; + + + /** + * Stops the membership service + */ + public void stop(); + + /** + * Returns that cluster has members. + */ + public boolean hasMembers(); + + /** + * Returns a list of all the members in the cluster. + */ + + public Member[] getMembers(); + + /** + * Returns the member object that defines this member + */ + public Member getLocalMember(); + + /** + * Return all members by name + */ + public String[] getMembersByName() ; + + /** + * Return the member by name + */ + public Member findMemberByName(String name) ; + + /** + * Sets the local member properties for broadcasting + */ + public void setLocalMemberProperties(String listenHost, int listenPort); + + /** + * Sets the membership listener, only one listener can be added. + * If you call this method twice, the last listener will be used. + * @param listener The listener + */ + public void setMembershipListener(MembershipListener listener); + + /** + * removes the membership listener. + */ + public void removeMembershipListener(); + +} Added: tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/MessageListener.java URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/MessageListener.java?rev=380209&view=auto ============================================================================== --- tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/MessageListener.java (added) +++ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/MessageListener.java Thu Feb 23 11:55:14 2006 @@ -0,0 +1,28 @@ +/* + * Copyright 1999,2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.cluster; + +public interface MessageListener { + + public void messageReceived(ClusterMessage msg); + + public boolean accept(ClusterMessage msg); + + public boolean equals(Object listener); + + public int hashCode(); + +} Added: tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/demos/Draw.java URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/demos/Draw.java?rev=380209&view=auto ============================================================================== --- tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/demos/Draw.java (added) +++ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/cluster/demos/Draw.java Thu Feb 23 11:55:14 2006 @@ -0,0 +1,484 @@ +package org.apache.catalina.cluster.demos; + +import java.io.ByteArrayOutputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.util.Random; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.Image; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.awt.event.MouseEvent; +import java.awt.event.MouseMotionListener; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JPanel; + +import org.apache.catalina.cluster.ClusterMessage; +import org.apache.catalina.cluster.Member; +import org.apache.catalina.cluster.group.ChannelInterceptorBase; +import org.apache.catalina.cluster.group.GroupChannel; +import org.apache.catalina.cluster.mcast.McastService; +import org.apache.catalina.cluster.tcp.ReplicationListener; +import org.apache.catalina.cluster.tcp.ReplicationTransmitter; +import org.apache.commons.logging.impl.LogFactoryImpl; +/** + * Shared whiteboard, each new instance joins the same group. Each instance chooses a random color, + * mouse moves are broadcast to all group members, which then apply them to their canvas

+ * @author Bela Ban, Oct 17 2001 + */ +public class Draw extends ChannelInterceptorBase implements ActionListener { + static LogFactoryImpl dependencyhack = new LogFactoryImpl(); + static org.apache.commons.logging.impl.SimpleLog depHack2 = new org.apache.commons.logging.impl.SimpleLog("test"); + + private final ByteArrayOutputStream out = new ByteArrayOutputStream(); + String groupname = "DrawGroupDemo"; + private GroupChannel channel = null; + private int member_size = 1; + final boolean first = true; + final boolean cummulative = true; + private JFrame mainFrame = null; + private JPanel sub_panel = null; + private DrawPanel panel = null; + private JButton clear_button, leave_button; + private final Random random = new Random(System.currentTimeMillis()); + private final Font default_font = new Font("Helvetica", Font.PLAIN, 12); + private final Color draw_color = selectColor(); + private final Color background_color = Color.white; + boolean no_channel = false; + boolean jmx; + + public Draw(int port, boolean debug, boolean cummulative, boolean no_channel, boolean jmx) throws Exception { + this.no_channel = no_channel; + this.jmx = jmx; + if (no_channel) + return; + + ReplicationListener rl = new ReplicationListener(); + rl.setTcpListenAddress("auto"); + rl.setTcpListenPort(port); + rl.setTcpSelectorTimeout(100); + rl.setTcpThreadCount(4); + rl.getBind(); + + ReplicationTransmitter ps = new ReplicationTransmitter(); + ps.setReplicationMode("pooled"); + ps.setAckTimeout(15000); + ps.setAutoConnect(true); + ps.setCompress(false); + + McastService service = new McastService(); + service.setMcastAddr("228.0.0.5"); + service.setMcastFrequency(500); + service.setMcastDropTime(5000); + service.setMcastPort(45565); + service.setLocalMemberProperties(rl.getHost(),port); + + channel = new GroupChannel(); + channel.setClusterReceiver(rl); + channel.setClusterSender(ps); + channel.setMembershipService(service); + channel.start(channel.DEFAULT); + + channel.addInterceptor(this); + + if (debug) { + } + } + + public String getGroupName() { + return groupname; + } + + public void setGroupName(String groupname) { + if (groupname != null) + this.groupname = groupname; + } + + public static void main(String[] args) { + Draw draw = null; + int port = 4000; + boolean debug = false; + boolean cummulative = false; + boolean no_channel = false; + boolean jmx = false; + String group_name = null; + + for (int i = 0; i < args.length; i++) { + if ("-help".equals(args[i])) { + help(); + return; + } + if ("-debug".equals(args[i])) { + debug = true; + continue; + } + if ("-cummulative".equals(args[i])) { + cummulative = true; + continue; + } + if ("-port".equals(args[i])) { + port = Integer.parseInt(args[++i]); + continue; + } + if ("-no_channel".equals(args[i])) { + no_channel = true; + continue; + } + if ("-jmx".equals(args[i])) { + jmx = true; + continue; + } + if ("-groupname".equals(args[i])) { + group_name = args[++i]; + continue; + } + + help(); + return; + } + + try { + draw = new Draw(port, debug, cummulative, no_channel, jmx); + if (group_name != null) + draw.setGroupName(group_name); + draw.go(); + } catch (Throwable e) { + e.printStackTrace(); + System.exit(0); + } + } + + static void help() { + System.out.println("\nDraw [-help] [-debug] [-cummulative] [-no_channel] [-props ]" + + " [-groupname ]"); + System.out.println("-debug: brings up a visual debugger"); + System.out.println("-no_channel: doesn't use JGroups at all, any drawing will be relected on the " + + "whiteboard directly"); + System.out.println("-props: argument can be an old-style protocol stack specification, or it can be " + + "a URL. In the latter case, the protocol specification will be read from the URL\n"); + } + + private Color selectColor() { + int red = (Math.abs(random.nextInt()) % 255); + int green = (Math.abs(random.nextInt()) % 255); + int blue = (Math.abs(random.nextInt()) % 255); + return new Color(red, green, blue); + } + + public void go() throws Exception { + mainFrame = new JFrame(); + mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + panel = new DrawPanel(this); + panel.setBackground(background_color); + sub_panel = new JPanel(); + mainFrame.getContentPane().add("Center", panel); + clear_button = new JButton("Clear"); + clear_button.setFont(default_font); + clear_button.addActionListener(this); + leave_button = new JButton("Leave & Exit"); + leave_button.setFont(default_font); + leave_button.addActionListener(this); + sub_panel.add("South", clear_button); + sub_panel.add("South", leave_button); + mainFrame.getContentPane().add("South", sub_panel); + mainFrame.setBackground(background_color); + clear_button.setForeground(Color.blue); + leave_button.setForeground(Color.blue); + setTitle(); + mainFrame.pack(); + mainFrame.setLocation(15, 25); + mainFrame.setBounds(new Rectangle(250, 250)); + mainFrame.setVisible(true); + + } + + void setTitle(String title) { + String tmp = ""; + if (no_channel) { + mainFrame.setTitle(" Draw Demo "); + return; + } + if (title != null) { + mainFrame.setTitle(title); + } else { + if (channel.getMembershipService().getLocalMember() != null) + tmp += channel.getMembershipService().getLocalMember().getName(); + tmp += " (" + channel.getMembershipService().getMembers().length + ")"; + mainFrame.setTitle(tmp); + } + } + + void setTitle() { + setTitle(null); + } + + + + /* --------------- Callbacks --------------- */ + + + + public void clearPanel() { + if (panel != null) + panel.clear(); + } + + public DrawMessage getEmptyMessage() { + DrawMessage msg = new DrawMessage(); + msg.setAddress(channel.getMembershipService().getLocalMember()); + msg.setTimestamp(System.currentTimeMillis()); + msg.setCompress(0); + return msg; + } + + public void sendClearPanelMsg() { + int tmp[] = new int[1]; + tmp[0] = 0; + DrawCommand comm = new DrawCommand(DrawCommand.CLEAR); + ObjectOutputStream os; + + try { + out.reset(); + os = new ObjectOutputStream(out); + os.writeObject(comm); + os.flush(); + DrawMessage msg = this.getEmptyMessage(); + msg.setDrawCommand(comm); + channel.send(null,msg,0); + //draw on the local picture + messageReceived(msg); + } catch (Exception ex) { + System.err.println(ex); + } + } + + public void actionPerformed(ActionEvent e) { + String command = e.getActionCommand(); + if ("Clear".equals(command)) { + if (no_channel) { + clearPanel(); + return; + } + sendClearPanelMsg(); + } else if ("Leave & Exit".equals(command)) { + if (!no_channel) { + try { + channel.stop(channel.DEFAULT); + } catch (Exception ex) { + System.err.println(ex); + } + } + mainFrame.setVisible(false); + mainFrame.dispose(); + System.exit(0); + } else + System.out.println("Unknown action"); + } + + /* ------------------------------ ChannelListener interface -------------------------- */ + + + + public void memberAdded(Member addr) { + setTitle(); + } + + public void memberDisappeared(Member addr) { + setTitle(); + } + + public void messageReceived(ClusterMessage msg) { + if ( msg instanceof DrawMessage ) { + DrawMessage dmsg = (DrawMessage)msg; + DrawCommand comm = dmsg.getDrawCommand(); + switch (comm.mode) { + case DrawCommand.DRAW: + if (panel != null) + panel.drawPoint(comm); + break; + case DrawCommand.CLEAR: + clearPanel(); + break; + default: + System.err.println("***** Draw.run(): received invalid draw command " + comm.mode); + break; + } + } else { + System.out.println("Invalid message="+msg); + } + } + + + public static class DrawMessage implements ClusterMessage { + private Member address; + private long timestamp; + private String id; + private int resend; + private int compress; + private DrawCommand comm; + public Member getAddress() { return address;} + public void setAddress(Member member) { address = member;} + public long getTimestamp() { return timestamp;} + public void setTimestamp(long timestamp) {this.timestamp = timestamp;} + public String getUniqueId() {return id;} + public int getResend() { return resend;} + public void setResend(int resend) {this.resend = resend;} + public int getCompress() {return compress;} + public void setCompress(int compress) {this.compress = compress;} + public DrawCommand getDrawCommand(){return comm;} + public void setDrawCommand(DrawCommand command) {this.comm = command;} + + } + /* --------------------------- End of ChannelListener interface ---------------------- */ + + + + private class DrawPanel + extends JPanel implements MouseMotionListener { + final Dimension preferred_size = new Dimension(235, 170); + Image img = null; // for drawing pixels + Dimension d, imgsize; + Graphics gr = null; + Draw parent; + public DrawPanel(Draw parent) { + this.parent = parent; + createOffscreenImage(); + addMouseMotionListener(this); + addComponentListener(new ComponentAdapter() { + public void componentResized(ComponentEvent e) { + if (getWidth() <= 0 || getHeight() <= 0)return; + createOffscreenImage(); + } + }); + } + + void createOffscreenImage() { + d = getSize(); + if (img == null || imgsize == null || imgsize.width != d.width || imgsize.height != d.height) { + img = createImage(d.width, d.height); + if (img != null) + gr = img.getGraphics(); + imgsize = d; + } + } + + /* ---------------------- MouseMotionListener interface------------------------- */ + + public void mouseMoved(MouseEvent e) {} + + public void mouseDragged(MouseEvent e) { + ObjectOutputStream os; + int x = e.getX(), y = e.getY(); + DrawCommand comm = new DrawCommand(DrawCommand.DRAW, x, y, + draw_color.getRed(), draw_color.getGreen(), draw_color.getBlue()); + + if (no_channel) { + drawPoint(comm); + return; + } + + try { + out.reset(); + os = new ObjectOutputStream(out); + os.writeObject(comm); + os.flush(); + DrawMessage msg = parent.getEmptyMessage(); + msg.setDrawCommand(comm); + channel.send(null,msg,0); + parent.messageReceived(msg); + Thread.yield(); // gives the repainter some breath + } catch (Exception ex) { + System.err.println(ex); + } + } + + /* ------------------- End of MouseMotionListener interface --------------------- */ + + + /** + * Adds pixel to queue and calls repaint() whenever we have MAX_ITEMS pixels in the queue + * or when MAX_TIME msecs have elapsed (whichever comes first). The advantage compared to just calling + * repaint() after adding a pixel to the queue is that repaint() can most often draw multiple points + * at the same time. + */ + public void drawPoint(DrawCommand c) { + if (c == null || gr == null)return; + gr.setColor(new Color(c.r, c.g, c.b)); + gr.fillOval(c.x, c.y, 10, 10); + repaint(); + } + + public void clear() { + if (gr == null)return; + gr.clearRect(0, 0, getSize().width, getSize().height); + repaint(); + } + + public Dimension getPreferredSize() { + return preferred_size; + } + + public void paintComponent(Graphics g) { + super.paintComponent(g); + if (img != null) { + g.drawImage(img, 0, 0, null); + } + } + + } + + public static class DrawCommand + implements Serializable { + static final int DRAW = 1; + static final int CLEAR = 2; + final int mode; + int x = 0; + int y = 0; + int r = 0; + int g = 0; + int b = 0; + + DrawCommand(int mode) { + this.mode = mode; + } + + DrawCommand(int mode, int x, int y, int r, int g, int b) { + this.mode = mode; + this.x = x; + this.y = y; + this.r = r; + this.g = g; + this.b = b; + } + + DrawCommand Copy() { + return new DrawCommand(mode, x, y, r, g, b); + } + + public String toString() { + StringBuffer ret = new StringBuffer(); + switch (mode) { + case DRAW: + ret.append("DRAW(" + x + ", " + y + ") [" + r + '|' + g + '|' + b + ']'); + break; + case CLEAR: + ret.append("CLEAR"); + break; + default: + return ""; + } + return ret.toString(); + } + + } + +} + --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org