This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit eed64ff5806705ae5779e225d8242be35a1812c5 Author: Mark Thomas <ma...@apache.org> AuthorDate: Wed Oct 2 11:00:34 2024 +0100 Code clean-up - formatting. No functional change. --- .DS_Store | Bin 0 -> 6148 bytes java/org/apache/catalina/tribes/ByteMessage.java | 31 +- java/org/apache/catalina/tribes/Channel.java | 311 ++++++++++++--------- .../apache/catalina/tribes/ChannelException.java | 59 ++-- .../apache/catalina/tribes/ChannelInterceptor.java | 130 +++++---- .../apache/catalina/tribes/ChannelListener.java | 15 +- .../org/apache/catalina/tribes/ChannelMessage.java | 32 ++- .../apache/catalina/tribes/ChannelReceiver.java | 20 +- java/org/apache/catalina/tribes/ChannelSender.java | 31 +- java/org/apache/catalina/tribes/ErrorHandler.java | 11 +- java/org/apache/catalina/tribes/Heartbeat.java | 4 +- java/org/apache/catalina/tribes/JmxChannel.java | 6 + .../org/apache/catalina/tribes/ManagedChannel.java | 18 +- java/org/apache/catalina/tribes/Member.java | 66 +++-- .../apache/catalina/tribes/MembershipListener.java | 8 +- .../apache/catalina/tribes/MembershipProvider.java | 32 ++- .../apache/catalina/tribes/MembershipService.java | 63 +++-- .../apache/catalina/tribes/MessageListener.java | 6 +- .../catalina/tribes/RemoteProcessException.java | 4 +- java/org/apache/catalina/tribes/UniqueId.java | 20 +- 20 files changed, 525 insertions(+), 342 deletions(-) diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000..1b83a3bed8 Binary files /dev/null and b/.DS_Store differ diff --git a/java/org/apache/catalina/tribes/ByteMessage.java b/java/org/apache/catalina/tribes/ByteMessage.java index bf3c4269a3..5afa7da900 100644 --- a/java/org/apache/catalina/tribes/ByteMessage.java +++ b/java/org/apache/catalina/tribes/ByteMessage.java @@ -22,21 +22,17 @@ import java.io.ObjectInput; import java.io.ObjectOutput; /** - * A byte message is not serialized and deserialized by the channel - * instead it is sent as a byte array. + * A byte message is not serialized and deserialized by the channel instead it is sent as a byte array. * <p> - * By default Tribes uses java serialization when it receives an object - * to be sent over the wire. Java serialization is not the most - * efficient of serializing data, and Tribes might not even - * have access to the correct class loaders to deserialize the object properly. + * By default Tribes uses java serialization when it receives an object to be sent over the wire. Java serialization is + * not the most efficient of serializing data, and Tribes might not even have access to the correct class loaders to + * deserialize the object properly. * <p> - * The ByteMessage class is a class where the channel when it receives it will - * not attempt to perform serialization, instead it will simply stream the <code>getMessage()</code> - * bytes. + * The ByteMessage class is a class where the channel when it receives it will not attempt to perform serialization, + * instead it will simply stream the <code>getMessage()</code> bytes. * <p> - * If you are using multiple applications on top of Tribes you should add some sort of header - * so that you can decide with the <code>ChannelListener.accept()</code> whether this message was intended - * for you. + * If you are using multiple applications on top of Tribes you should add some sort of header so that you can decide + * with the <code>ChannelListener.accept()</code> whether this message was intended for you. */ public class ByteMessage implements Externalizable { /** @@ -55,6 +51,7 @@ public class ByteMessage implements Externalizable { /** * Creates a byte message with + * * @param data byte[] - the message contents */ public ByteMessage(byte[] data) { @@ -63,6 +60,7 @@ public class ByteMessage implements Externalizable { /** * Returns the message contents of this byte message + * * @return byte[] - message contents, can be null */ public byte[] getMessage() { @@ -71,6 +69,7 @@ public class ByteMessage implements Externalizable { /** * Sets the message contents of this byte message + * * @param message byte[] */ public void setMessage(byte[] message) { @@ -78,7 +77,7 @@ public class ByteMessage implements Externalizable { } @Override - public void readExternal(ObjectInput in ) throws IOException { + public void readExternal(ObjectInput in) throws IOException { int length = in.readInt(); message = new byte[length]; in.readFully(message); @@ -86,9 +85,9 @@ public class ByteMessage implements Externalizable { @Override public void writeExternal(ObjectOutput out) throws IOException { - out.writeInt(message!=null?message.length:0); - if ( message!=null ) { - out.write(message,0,message.length); + out.writeInt(message != null ? message.length : 0); + if (message != null) { + out.write(message, 0, message.length); } } } diff --git a/java/org/apache/catalina/tribes/Channel.java b/java/org/apache/catalina/tribes/Channel.java index 52d4c398db..f92958a150 100644 --- a/java/org/apache/catalina/tribes/Channel.java +++ b/java/org/apache/catalina/tribes/Channel.java @@ -25,17 +25,16 @@ import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; /** - * A channel is a representation of a group of nodes all participating in some sort of - * communication with each other. + * A channel is a representation of a group of nodes all participating in some sort of communication with each other. * <p> - * The channel is the main API class for Tribes, this is essentially the only class - * that an application needs to be aware of. Through the channel the application can: + * The channel is the main API class for Tribes, this is essentially the only class that an application needs to be + * aware of. Through the channel the application can: * <ul> * <li>send messages</li> * <li>receive message (by registering a <code>ChannelListener</code></li> * <li>get all members of the group <code>getMembers()</code></li> - * <li>receive notifications of members added and members disappeared by - * registering a <code>MembershipListener</code></li> + * <li>receive notifications of members added and members disappeared by registering a + * <code>MembershipListener</code></li> * </ul> * The channel has 5 major components: * <ul> @@ -46,7 +45,9 @@ import org.apache.juli.logging.LogFactory; * <li>Channel interceptors, the ability to manipulate messages as they are sent or arrive</li> * </ul> * The channel layout is: - * <pre><code> + * + * <pre> + * <code> * ChannelListener_1..ChannelListener_N MembershipListener_1..MembershipListener_N [Application Layer] * \ \ / / * \ \ / / @@ -71,76 +72,80 @@ import org.apache.juli.logging.LogFactory; * / | \ * / | \ * MembershipService ChannelSender ChannelReceiver [IO layer] - * </code></pre> + * </code> + * </pre> * * @see org.apache.catalina.tribes.group.GroupChannel example usage */ public interface Channel { /** - * Start and stop sequences can be controlled by these constants. - * This allows you to start separate components of the channel. + * Start and stop sequences can be controlled by these constants. This allows you to start separate components of + * the channel. * <p> * DEFAULT - starts or stops all components in the channel + * * @see #start(int) * @see #stop(int) */ int DEFAULT = 15; /** - * Start and stop sequences can be controlled by these constants. - * This allows you to start separate components of the channel. + * Start and stop sequences can be controlled by these constants. This allows you to start separate components of + * the channel. * <p> - * SND_RX_SEQ - starts or stops the data receiver. Start means opening a server socket - * in case of a TCP implementation + * SND_RX_SEQ - starts or stops the data receiver. Start means opening a server socket in case of a TCP + * implementation + * * @see #start(int) * @see #stop(int) */ int SND_RX_SEQ = 1; /** - * Start and stop sequences can be controlled by these constants. - * This allows you to start separate components of the channel. + * Start and stop sequences can be controlled by these constants. This allows you to start separate components of + * the channel. * <p> - * SND_TX_SEQ - starts or stops the data sender. This should not open any sockets, - * as sockets are opened on demand when a message is being sent + * SND_TX_SEQ - starts or stops the data sender. This should not open any sockets, as sockets are opened on demand + * when a message is being sent + * * @see #start(int) * @see #stop(int) */ int SND_TX_SEQ = 2; /** - * Start and stop sequences can be controlled by these constants. - * This allows you to start separate components of the channel. + * Start and stop sequences can be controlled by these constants. This allows you to start separate components of + * the channel. * <p> - * MBR_RX_SEQ - starts or stops the membership listener. In a multicast implementation - * this will open a datagram socket and join a group and listen for membership messages - * members joining + * MBR_RX_SEQ - starts or stops the membership listener. In a multicast implementation this will open a datagram + * socket and join a group and listen for membership messages members joining + * * @see #start(int) * @see #stop(int) */ int MBR_RX_SEQ = 4; /** - * Start and stop sequences can be controlled by these constants. - * This allows you to start separate components of the channel. + * Start and stop sequences can be controlled by these constants. This allows you to start separate components of + * the channel. * <p> - * MBR_TX_SEQ - starts or stops the membership broadcaster. In a multicast implementation - * this will open a datagram socket and join a group and broadcast the local member information + * MBR_TX_SEQ - starts or stops the membership broadcaster. In a multicast implementation this will open a datagram + * socket and join a group and broadcast the local member information + * * @see #start(int) * @see #stop(int) */ int MBR_TX_SEQ = 8; /** - * Send options, when a message is sent, it can have an option flag - * to trigger certain behavior. Most flags are used to trigger channel interceptors - * as the message passes through the channel stack. + * Send options, when a message is sent, it can have an option flag to trigger certain behavior. Most flags are used + * to trigger channel interceptors as the message passes through the channel stack. * <p> * However, there are five default flags that every channel implementation must implement. * <p> - * SEND_OPTIONS_BYTE_MESSAGE - The message is a pure byte message and no marshaling or unmarshaling will - * be performed. + * SEND_OPTIONS_BYTE_MESSAGE - The message is a pure byte message and no marshaling or unmarshaling will be + * performed. * * @see #send(Member[], Serializable , int) * @see #send(Member[], Serializable, int, ErrorHandler) @@ -148,86 +153,86 @@ public interface Channel { int SEND_OPTIONS_BYTE_MESSAGE = 0x0001; /** - * Send options, when a message is sent, it can have an option flag - * to trigger certain behavior. Most flags are used to trigger channel interceptors - * as the message passes through the channel stack. + * Send options, when a message is sent, it can have an option flag to trigger certain behavior. Most flags are used + * to trigger channel interceptors as the message passes through the channel stack. * <p> * However, there are five default flags that every channel implementation must implement * <p> - * SEND_OPTIONS_USE_ACK - Message is sent and an ACK is received when the message has been received by the recipient. - * If no ack is received, the message is not considered successful. + * SEND_OPTIONS_USE_ACK - Message is sent and an ACK is received when the message has been received by the + * recipient. If no ack is received, the message is not considered successful. + * * @see #send(Member[], Serializable , int) * @see #send(Member[], Serializable, int, ErrorHandler) */ int SEND_OPTIONS_USE_ACK = 0x0002; /** - * Send options, when a message is sent, it can have an option flag - * to trigger certain behavior. Most flags are used to trigger channel interceptors - * as the message passes through the channel stack. + * Send options, when a message is sent, it can have an option flag to trigger certain behavior. Most flags are used + * to trigger channel interceptors as the message passes through the channel stack. * <p> * However, there are five default flags that every channel implementation must implement * <p> * SEND_OPTIONS_SYNCHRONIZED_ACK - Message is sent and an ACK is received when the message has been received and - * processed by the recipient. - * If no ack is received, the message is not considered successful + * processed by the recipient. If no ack is received, the message is not considered successful + * * @see #send(Member[], Serializable , int) * @see #send(Member[], Serializable, int, ErrorHandler) */ int SEND_OPTIONS_SYNCHRONIZED_ACK = 0x0004; /** - * Send options, when a message is sent, it can have an option flag - * to trigger certain behavior. Most flags are used to trigger channel interceptors - * as the message passes through the channel stack. + * Send options, when a message is sent, it can have an option flag to trigger certain behavior. Most flags are used + * to trigger channel interceptors as the message passes through the channel stack. * <p> * However, there are five default flags that every channel implementation must implement * <p> - * SEND_OPTIONS_ASYNCHRONOUS - Message will be placed on a queue and sent by a separate thread. - * If the queue is full, behaviour depends on {@link MessageDispatchInterceptor#isAlwaysSend()} + * SEND_OPTIONS_ASYNCHRONOUS - Message will be placed on a queue and sent by a separate thread. If the queue is + * full, behaviour depends on {@link MessageDispatchInterceptor#isAlwaysSend()} + * * @see #send(Member[], Serializable , int) * @see #send(Member[], Serializable, int, ErrorHandler) */ int SEND_OPTIONS_ASYNCHRONOUS = 0x0008; /** - * Send options, when a message is sent, it can have an option flag - * to trigger certain behavior. Most flags are used to trigger channel interceptors - * as the message passes through the channel stack. + * Send options, when a message is sent, it can have an option flag to trigger certain behavior. Most flags are used + * to trigger channel interceptors as the message passes through the channel stack. * <p> * However, there are five default flags that every channel implementation must implement * <p> * SEND_OPTIONS_SECURE - Message is sent over an encrypted channel + * * @see #send(Member[], Serializable , int) * @see #send(Member[], Serializable, int, ErrorHandler) */ int SEND_OPTIONS_SECURE = 0x0010; /** - * Send options. When a message is sent with this flag on - * the system sends the message using UDP instead of TCP. + * Send options. When a message is sent with this flag on the system sends the message using UDP instead of TCP. + * * @see #send(Member[], Serializable , int) * @see #send(Member[], Serializable, int, ErrorHandler) */ - int SEND_OPTIONS_UDP = 0x0020; + int SEND_OPTIONS_UDP = 0x0020; /** - * Send options. When a message is sent with this flag on - * the system sends a UDP message on the Multicast address instead of UDP or TCP to individual addresses. + * Send options. When a message is sent with this flag on the system sends a UDP message on the Multicast address + * instead of UDP or TCP to individual addresses. + * * @see #send(Member[], Serializable , int) * @see #send(Member[], Serializable, int, ErrorHandler) */ - int SEND_OPTIONS_MULTICAST = 0x0040; + int SEND_OPTIONS_MULTICAST = 0x0040; /** - * Send options, when a message is sent, it can have an option flag - * to trigger certain behavior. Most flags are used to trigger channel interceptors - * as the message passes through the channel stack. + * Send options, when a message is sent, it can have an option flag to trigger certain behavior. Most flags are used + * to trigger channel interceptors as the message passes through the channel stack. * <p> * However, there are five default flags that every channel implementation must implement * <p> - * SEND_OPTIONS_DEFAULT - the default sending options, just a helper variable. - * The default is <code>SEND_OPTIONS_USE_ACK</code> + * SEND_OPTIONS_DEFAULT - the default sending options, just a helper variable. The default is + * <code>SEND_OPTIONS_USE_ACK</code> + * * @see #SEND_OPTIONS_USE_ACK * @see #send(Member[], Serializable , int) * @see #send(Member[], Serializable, int, ErrorHandler) @@ -236,64 +241,75 @@ public interface Channel { /** - * Adds an interceptor to the stack for message processing. - * Interceptors are ordered in the way they are added. - * <pre><code> + * Adds an interceptor to the stack for message processing. Interceptors are ordered in the way they are added. + * + * <pre> + * <code> * channel.addInterceptor(A); * channel.addInterceptor(C); * channel.addInterceptor(B); - * </code></pre> - * Will result in an interceptor stack like this: - * <code>A -> C -> B</code> + * </code> + * </pre> + * + * Will result in an interceptor stack like this: <code>A -> C -> B</code> * <p> - * The complete stack will look like this: - * <code>Channel -> A -> C -> B -> ChannelCoordinator</code> + * The complete stack will look like this: <code>Channel -> A -> C -> B -> ChannelCoordinator</code> + * * @param interceptor ChannelInterceptorBase */ void addInterceptor(ChannelInterceptor interceptor); /** - * 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. + * 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 one of: - * <ul> - * <li>DEFAULT - will start all services</li> - * <li>MBR_RX_SEQ - starts the membership receiver</li> - * <li>MBR_TX_SEQ - starts the membership broadcaster</li> - * <li>SND_TX_SEQ - starts the replication transmitter</li> - * <li>SND_RX_SEQ - starts the replication receiver</li> - * </ul> - * <b>Note:</b> In order for the membership broadcaster to - * transmit the correct information, it has to be started after the replication receiver. + * <ul> + * <li>DEFAULT - will start all services</li> + * <li>MBR_RX_SEQ - starts the membership receiver</li> + * <li>MBR_TX_SEQ - starts the membership broadcaster</li> + * <li>SND_TX_SEQ - starts the replication transmitter</li> + * <li>SND_RX_SEQ - starts the replication receiver</li> + * </ul> + * <b>Note:</b> In order for the membership broadcaster to transmit the correct information, it has + * to be started after the replication receiver. + * * @throws ChannelException if a startup error occurs or the service is already started or an error occurs. */ 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 + * 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 one of: - * <ul> - * <li>DEFAULT - will shutdown all services</li> - * <li>MBR_RX_SEQ - stops the membership receiver</li> - * <li>MBR_TX_SEQ - stops the membership broadcaster</li> - * <li>SND_TX_SEQ - stops the replication transmitter</li> - * <li>SND_RX_SEQ - stops the replication receiver</li> - * </ul> + * <ul> + * <li>DEFAULT - will shutdown all services</li> + * <li>MBR_RX_SEQ - stops the membership receiver</li> + * <li>MBR_TX_SEQ - stops the membership broadcaster</li> + * <li>SND_TX_SEQ - stops the replication transmitter</li> + * <li>SND_RX_SEQ - stops the replication receiver</li> + * </ul> + * * @throws ChannelException if a startup error occurs or the service is already stopped or an error occurs. */ void stop(int svc) throws ChannelException; /** * Send a message to one or more members in the cluster - * @param destination Member[] - the destinations, cannot be null or zero length, the reason for that - * is that a membership change can occur and at that time the application is uncertain what group the message - * actually got sent to. - * @param msg Serializable - the message to send, has to be serializable, or a <code>ByteMessage</code> to - * send a pure byte array - * @param options int - sender options, see class documentation for each interceptor that is configured in order to trigger interceptors + * + * @param destination Member[] - the destinations, cannot be null or zero length, the reason for that is that a + * membership change can occur and at that time the application is uncertain what group the + * message actually got sent to. + * @param msg Serializable - the message to send, has to be serializable, or a <code>ByteMessage</code> to + * send a pure byte array + * @param options int - sender options, see class documentation for each interceptor that is configured in order + * to trigger interceptors + * * @return a unique Id that identifies the message that is sent + * * @throws ChannelException if a serialization error happens. + * * @see ByteMessage * @see #SEND_OPTIONS_USE_ACK * @see #SEND_OPTIONS_ASYNCHRONOUS @@ -303,30 +319,34 @@ public interface Channel { /** * 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 - * @param handler ErrorHandler - handle errors through a callback, rather than throw it + * @param msg ClusterMessage - the message to send + * @param options int - sender options, see class documentation + * @param handler ErrorHandler - handle errors through a callback, rather than throw it + * * @return a unique Id that identifies the message that is sent + * * @exception ChannelException - if a serialization error happens. */ UniqueId send(Member[] destination, Serializable msg, int options, ErrorHandler handler) throws ChannelException; /** - * Sends a heart beat through the interceptor stacks. - * Use this method to alert interceptors and other components to + * Sends a heart beat through the interceptor stacks. Use this method to alert interceptors and other components to * clean up garbage, timed out messages etc. * <p> - * If you application has a background thread, then you can save one thread, - * by configuring your channel to not use an internal heartbeat thread - * and invoking this method. + * If you application has a background thread, then you can save one thread, by configuring your channel to not use + * an internal heartbeat thread and invoking this method. + * * @see #setHeartbeat(boolean) */ void heartbeat(); /** * Enables or disables internal heartbeat. + * * @param enable boolean - default value is implementation specific + * * @see #heartbeat() */ void setHeartbeat(boolean enable); @@ -334,9 +354,11 @@ public interface Channel { /** * Add a membership listener, will get notified when a new member joins, leaves or crashes. * <p> - * If the membership listener implements the Heartbeat interface - * the <code>heartbeat()</code> method will be invoked when the heartbeat runs on the channel + * If the membership listener implements the Heartbeat interface the <code>heartbeat()</code> method will be invoked + * when the heartbeat runs on the channel + * * @param listener MembershipListener + * * @see MembershipListener */ void addMembershipListener(MembershipListener listener); @@ -344,9 +366,11 @@ public interface Channel { /** * Add a channel listener, this is a callback object when messages are received. * <p> - * If the channel listener implements the Heartbeat interface - * the <code>heartbeat()</code> method will be invoked when the heartbeat runs on the channel + * If the channel listener implements the Heartbeat interface the <code>heartbeat()</code> method will be invoked + * when the heartbeat runs on the channel + * * @param listener ChannelListener + * * @see ChannelListener * @see Heartbeat */ @@ -355,86 +379,100 @@ public interface Channel { /** * Remove a membership listener, listeners are removed based on {@link Object#hashCode()} and * {@link Object#equals(Object)}. + * * @param listener MembershipListener + * * @see MembershipListener */ void removeMembershipListener(MembershipListener listener); + /** * Remove a channel listener, listeners are removed based on {@link Object#hashCode()} and * {@link Object#equals(Object)}. + * * @param listener ChannelListener + * * @see ChannelListener */ void removeChannelListener(ChannelListener listener); /** - * Returns true if there are any members in the group. - * This call is the same as <code>getMembers().length > 0</code> + * Returns true if there are any members in the group. This call is the same as + * <code>getMembers().length > 0</code> + * * @return boolean - true if there are any members automatically discovered */ - boolean hasMembers() ; + boolean hasMembers(); /** * Get all current group members. + * * @return all members or empty array, never null */ - Member[] getMembers() ; + Member[] getMembers(); /** - * Return the member that represents this node. This is also the data - * that gets broadcasted through the membership broadcaster component - * @param incAlive - optimization, true if you want it to calculate alive time - * since the membership service started. + * Return the member that represents this node. This is also the data that gets broadcasted through the membership + * broadcaster component + * + * @param incAlive - optimization, true if you want it to calculate alive time since the membership service started. + * * @return Member */ Member getLocalMember(boolean incAlive); /** - * Returns the member from the membership service with complete and - * recent data. Some implementations might serialize and send - * membership information along with a message, and instead of sending - * complete membership details, only send the primary identifier for the member - * but not the payload or other information. When such message is received - * the application can retrieve the cached member through this call. - * In most cases, this is not necessary. + * Returns the member from the membership service with complete and recent data. Some implementations might + * serialize and send membership information along with a message, and instead of sending complete membership + * details, only send the primary identifier for the member but not the payload or other information. When such + * message is received the application can retrieve the cached member through this call. In most cases, this is not + * necessary. + * * @param mbr Member + * * @return Member */ Member getMember(Member mbr); /** * Return the name of this channel. + * * @return channel name */ String getName(); /** * Set the name of this channel + * * @param name The new channel name */ void setName(String name); /** * Return executor that can be used for utility tasks. + * * @return the executor */ ScheduledExecutorService getUtilityExecutor(); /** * Set the executor that can be used for utility tasks. + * * @param utilityExecutor the executor */ void setUtilityExecutor(ScheduledExecutorService utilityExecutor); /** - * Translates the name of an option to its integer value. Valid option names are "asynchronous" (alias "async"), + * Translates the name of an option to its integer value. Valid option names are "asynchronous" (alias "async"), * "byte_message" (alias "byte"), "multicast", "secure", "synchronized_ack" (alias "sync"), "udp", "use_ack" + * * @param opt The name of the option + * * @return the int value of the passed option name */ - static int getSendOptionValue(String opt){ + static int getSendOptionValue(String opt) { - switch (opt){ + switch (opt) { case "asynchronous": case "async": @@ -466,16 +504,19 @@ public interface Channel { /** * Translates a comma separated list of option names to their bitwise-ORd value + * * @param input A comma separated list of options, e.g. "async, multicast" + * * @return a bitwise ORd value of the passed option names */ - static int parseSendOptions(String input){ + static int parseSendOptions(String input) { try { return Integer.parseInt(input); - } catch (NumberFormatException nfe){ + } catch (NumberFormatException nfe) { final Log log = LogFactory.getLog(Channel.class); - log.trace(String.format("Failed to parse [%s] as integer, channelSendOptions possibly set by name(s)", input)); + log.trace(String.format("Failed to parse [%s] as integer, channelSendOptions possibly set by name(s)", + input)); } String[] options = input.split("\\s*,\\s*"); @@ -489,20 +530,24 @@ public interface Channel { } /** - * Translates an integer value of SendOptions to its human-friendly comma separated value list for use in JMX and such. + * Translates an integer value of SendOptions to its human-friendly comma separated value list for use in JMX and + * such. + * * @param input the int value of SendOptions + * * @return the human-friendly string representation in a reverse order (i.e. the last option will be shown first) */ - static String getSendOptionsAsString(int input){ + static String getSendOptionsAsString(int input) { // allOptionNames must be in order of the bits of the available options - final String[] allOptionNames = new String[]{ "byte", "use_ack", "sync", "async", "secure", "udp", "multicast" }; + final String[] allOptionNames = + new String[] { "byte", "use_ack", "sync", "async", "secure", "udp", "multicast" }; StringJoiner names = new StringJoiner(", "); - for (int bit=allOptionNames.length - 1; bit >= 0; bit--){ + for (int bit = allOptionNames.length - 1; bit >= 0; bit--) { // if the bit is set then add the name to the result - if (((1 << bit) & input) > 0){ + if (((1 << bit) & input) > 0) { names.add(allOptionNames[bit]); } } diff --git a/java/org/apache/catalina/tribes/ChannelException.java b/java/org/apache/catalina/tribes/ChannelException.java index 789a9338c0..0f2f69738b 100644 --- a/java/org/apache/catalina/tribes/ChannelException.java +++ b/java/org/apache/catalina/tribes/ChannelException.java @@ -19,14 +19,13 @@ package org.apache.catalina.tribes; import java.util.ArrayList; /** - * A channel exception is thrown when an internal error happens - * somewhere in the channel. + * A channel exception is thrown when an internal error happens somewhere in the channel. * <p> * When a global error happens, the cause can be retrieved using <code>getCause()</code>. * <p> - * If an application is sending a message and some of the recipients fail to receive it, - * the application can retrieve what recipients failed by using the <code>getFaultyMembers()</code> - * method. This way, an application will always know if a message was delivered successfully or not. + * If an application is sending a message and some of the recipients fail to receive it, the application can retrieve + * what recipients failed by using the <code>getFaultyMembers()</code> method. This way, an application will always know + * if a message was delivered successfully or not. */ public class ChannelException extends Exception { private static final long serialVersionUID = 1L; @@ -37,10 +36,11 @@ public class ChannelException extends Exception { /** * Holds a list of faulty members */ - private ArrayList<FaultyMember> faultyMembers=null; + private ArrayList<FaultyMember> faultyMembers = null; /** * Constructor, creates a ChannelException + * * @see java.lang.Exception#Exception() */ public ChannelException() { @@ -49,7 +49,9 @@ public class ChannelException extends Exception { /** * Constructor, creates a ChannelException with an error message + * * @param message The error message + * * @see java.lang.Exception#Exception(String) */ public ChannelException(String message) { @@ -58,8 +60,10 @@ public class ChannelException extends Exception { /** * Constructor, creates a ChannelException with an error message and a cause + * * @param message The error message - * @param cause Throwable + * @param cause Throwable + * * @see java.lang.Exception#Exception(String,Throwable) */ public ChannelException(String message, Throwable cause) { @@ -68,7 +72,9 @@ public class ChannelException extends Exception { /** * Constructor, creates a ChannelException with a cause + * * @param cause Throwable + * * @see java.lang.Exception#Exception(Throwable) */ public ChannelException(Throwable cause) { @@ -77,13 +83,15 @@ public class ChannelException extends Exception { /** * Returns the message for this exception + * * @return the error message + * * @see java.lang.Exception#getMessage() */ @Override public String getMessage() { StringBuilder buf = new StringBuilder(super.getMessage()); - if (faultyMembers==null || faultyMembers.size() == 0 ) { + if (faultyMembers == null || faultyMembers.size() == 0) { buf.append("; No faulty members identified."); } else { buf.append("; Faulty members:"); @@ -97,23 +105,27 @@ public class ChannelException extends Exception { /** * Adds a faulty member, and the reason the member failed. + * * @param mbr Member - * @param x Exception + * @param x Exception + * * @return <code>true</code> if the member was added */ - public boolean addFaultyMember(Member mbr, Exception x ) { - return addFaultyMember(new FaultyMember(mbr,x)); + public boolean addFaultyMember(Member mbr, Exception x) { + return addFaultyMember(new FaultyMember(mbr, x)); } /** * Adds a list of faulty members + * * @param mbrs FaultyMember[] + * * @return the number of members added */ public int addFaultyMember(FaultyMember[] mbrs) { int result = 0; - for (int i=0; mbrs!=null && i<mbrs.length; i++ ) { - if ( addFaultyMember(mbrs[i]) ) { + for (int i = 0; mbrs != null && i < mbrs.length; i++) { + if (addFaultyMember(mbrs[i])) { result++; } } @@ -122,14 +134,16 @@ public class ChannelException extends Exception { /** * Adds a faulty member + * * @param mbr FaultyMember + * * @return <code>true</code> if the member was added */ public boolean addFaultyMember(FaultyMember mbr) { - if ( this.faultyMembers==null ) { + if (this.faultyMembers == null) { this.faultyMembers = new ArrayList<>(); } - if ( !faultyMembers.contains(mbr) ) { + if (!faultyMembers.contains(mbr)) { return faultyMembers.add(mbr); } else { return false; @@ -138,22 +152,23 @@ public class ChannelException extends Exception { /** * Returns an array of members that failed and the reason they failed. + * * @return FaultyMember[] */ public FaultyMember[] getFaultyMembers() { - if ( this.faultyMembers==null ) { + if (this.faultyMembers == null) { return EMPTY_LIST; } return faultyMembers.toArray(new FaultyMember[0]); } /** - * Represent a failure to a specific member when a message was sent to more - * than one member + * Represent a failure to a specific member when a message was sent to more than one member */ public static class FaultyMember { protected final Exception cause; protected final Member member; + public FaultyMember(Member mbr, Exception x) { this.member = mbr; this.cause = x; @@ -169,20 +184,20 @@ public class ChannelException extends Exception { @Override public String toString() { - return "FaultyMember:"+member.toString(); + return "FaultyMember:" + member.toString(); } @Override public int hashCode() { - return (member!=null)?member.hashCode():0; + return (member != null) ? member.hashCode() : 0; } @Override public boolean equals(Object o) { - if (member==null || (!(o instanceof FaultyMember)) || (((FaultyMember)o).member==null)) { + if (member == null || (!(o instanceof FaultyMember)) || (((FaultyMember) o).member == null)) { return false; } - return member.equals(((FaultyMember)o).member); + return member.equals(((FaultyMember) o).member); } } diff --git a/java/org/apache/catalina/tribes/ChannelInterceptor.java b/java/org/apache/catalina/tribes/ChannelInterceptor.java index 3152016f0b..30d513c732 100644 --- a/java/org/apache/catalina/tribes/ChannelInterceptor.java +++ b/java/org/apache/catalina/tribes/ChannelInterceptor.java @@ -19,185 +19,213 @@ package org.apache.catalina.tribes; import org.apache.catalina.tribes.group.InterceptorPayload; /** - * A ChannelInterceptor is an interceptor that intercepts - * messages and membership messages in the channel stack. - * This allows interceptors to modify the message or perform - * other actions when a message is sent or received. + * A ChannelInterceptor is an interceptor that intercepts messages and membership messages in the channel stack. This + * allows interceptors to modify the message or perform other actions when a message is sent or received. * <p> * Interceptors are tied together in a linked list. + * * @see org.apache.catalina.tribes.group.ChannelInterceptorBase */ public interface ChannelInterceptor extends MembershipListener, Heartbeat { /** - * An interceptor can react to a message based on a set bit on the - * message options. - * When a message is sent, the options can be retrieved from ChannelMessage.getOptions() - * and if the bit is set, this interceptor will react to it. + * An interceptor can react to a message based on a set bit on the message options. When a message is sent, the + * options can be retrieved from ChannelMessage.getOptions() and if the bit is set, this interceptor will react to + * it. * <p> - * A simple evaluation if an interceptor should react to the message would be: - * <br> - * <code>boolean react = (getOptionFlag() == (getOptionFlag() & ChannelMessage.getOptions()));</code> - * <br> - * The default option is 0, meaning there is no way for the application to trigger the - * interceptor. The interceptor itself will decide. + * A simple evaluation if an interceptor should react to the message would be: <br> + * <code>boolean react = (getOptionFlag() == (getOptionFlag() & ChannelMessage.getOptions()));</code> <br> + * The default option is 0, meaning there is no way for the application to trigger the interceptor. The interceptor + * itself will decide. + * * @return int + * * @see ChannelMessage#getOptions() */ int getOptionFlag(); /** * Sets the option flag + * * @param flag int + * * @see #getOptionFlag() */ void setOptionFlag(int flag); /** * Set the next interceptor in the list of interceptors + * * @param next ChannelInterceptor */ - void setNext(ChannelInterceptor next) ; + void setNext(ChannelInterceptor next); /** * Retrieve the next interceptor in the list + * * @return ChannelInterceptor - returns the next interceptor in the list or null if no more interceptors exist */ ChannelInterceptor getNext(); /** * Set the previous interceptor in the list + * * @param previous ChannelInterceptor */ void setPrevious(ChannelInterceptor previous); /** * Retrieve the previous interceptor in the list + * * @return ChannelInterceptor - returns the previous interceptor in the list or null if no more interceptors exist */ ChannelInterceptor getPrevious(); /** - * The <code>sendMessage</code> method is called when a message is being sent to one more destinations. - * The interceptor can modify any of the parameters and then pass on the message down the stack by - * invoking <code>getNext().sendMessage(destination,msg,payload)</code>. + * The <code>sendMessage</code> method is called when a message is being sent to one more destinations. The + * interceptor can modify any of the parameters and then pass on the message down the stack by invoking + * <code>getNext().sendMessage(destination,msg,payload)</code>. * <p> * Alternatively the interceptor can stop the message from being sent by not invoking * <code>getNext().sendMessage(destination,msg,payload)</code>. * <p> - * If the message is to be sent asynchronous the application can be notified of completion and - * errors by passing in an error handler attached to a payload object. + * If the message is to be sent asynchronous the application can be notified of completion and errors by passing in + * an error handler attached to a payload object. * <p> - * The ChannelMessage.getAddress contains Channel.getLocalMember, and can be overwritten - * to simulate a message sent from another node. + * The ChannelMessage.getAddress contains Channel.getLocalMember, and can be overwritten to simulate a message sent + * from another node. + * * @param destination Member[] - the destination for this message - * @param msg ChannelMessage - the message to be sent - * @param payload InterceptorPayload - the payload, carrying an error handler and future useful data, can be null + * @param msg ChannelMessage - the message to be sent + * @param payload InterceptorPayload - the payload, carrying an error handler and future useful data, can be + * null + * * @throws ChannelException if a serialization error happens. + * * @see ErrorHandler * @see InterceptorPayload */ void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException; /** - * The <code>messageReceived</code> is invoked when a message is received. - * <code>ChannelMessage.getAddress()</code> is the sender, or the reply-to address - * if it has been overwritten. + * The <code>messageReceived</code> is invoked when a message is received. <code>ChannelMessage.getAddress()</code> + * is the sender, or the reply-to address if it has been overwritten. + * * @param data ChannelMessage */ void messageReceived(ChannelMessage data); /** - * The <code>heartbeat()</code> method gets invoked periodically - * to allow interceptors to clean up resources, time out object and - * perform actions that are unrelated to sending/receiving data. + * The <code>heartbeat()</code> method gets invoked periodically to allow interceptors to clean up resources, time + * out object and perform actions that are unrelated to sending/receiving data. */ @Override void heartbeat(); /** * Intercepts the <code>Channel.hasMembers()</code> method + * * @return boolean - if the channel has members in its membership group + * * @see Channel#hasMembers() */ - boolean hasMembers() ; + boolean hasMembers(); /** * Intercepts the <code>Channel.getMembers()</code> method + * * @return the members + * * @see Channel#getMembers() */ - Member[] getMembers() ; + Member[] getMembers(); /** * Intercepts the <code>Channel.getLocalMember(boolean)</code> method + * * @param incAliveTime boolean + * * @return the member that represents this node + * * @see Channel#getLocalMember(boolean) */ - Member getLocalMember(boolean incAliveTime) ; + Member getLocalMember(boolean incAliveTime); /** * Intercepts the <code>Channel.getMember(Member)</code> method + * * @param mbr Member + * * @return Member - the actual member information, including stay alive + * * @see Channel#getMember(Member) */ Member getMember(Member mbr); /** - * 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 + * 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 one of: - * <ul> - * <li>Channel.DEFAULT - will start all services</li> - * <li>Channel.MBR_RX_SEQ - starts the membership receiver</li> - * <li>Channel.MBR_TX_SEQ - starts the membership broadcaster</li> - * <li>Channel.SND_TX_SEQ - starts the replication transmitter</li> - * <li>Channel.SND_RX_SEQ - starts the replication receiver</li> - * </ul> + * <ul> + * <li>Channel.DEFAULT - will start all services</li> + * <li>Channel.MBR_RX_SEQ - starts the membership receiver</li> + * <li>Channel.MBR_TX_SEQ - starts the membership broadcaster</li> + * <li>Channel.SND_TX_SEQ - starts the replication transmitter</li> + * <li>Channel.SND_RX_SEQ - starts the replication receiver</li> + * </ul> + * * @throws ChannelException if a startup error occurs or the service is already started. + * * @see Channel */ 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 + * 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 one of: - * <ul> - * <li>Channel.DEFAULT - will shutdown all services</li> - * <li>Channel.MBR_RX_SEQ - stops the membership receiver</li> - * <li>Channel.MBR_TX_SEQ - stops the membership broadcaster</li> - * <li>Channel.SND_TX_SEQ - stops the replication transmitter</li> - * <li>Channel.SND_RX_SEQ - stops the replication receiver</li> - * </ul> + * <ul> + * <li>Channel.DEFAULT - will shutdown all services</li> + * <li>Channel.MBR_RX_SEQ - stops the membership receiver</li> + * <li>Channel.MBR_TX_SEQ - stops the membership broadcaster</li> + * <li>Channel.SND_TX_SEQ - stops the replication transmitter</li> + * <li>Channel.SND_RX_SEQ - stops the replication receiver</li> + * </ul> + * * @throws ChannelException if a startup error occurs or the service is already started. + * * @see Channel */ void stop(int svc) throws ChannelException; /** * Fire an event. + * * @param event the event */ void fireInterceptorEvent(InterceptorEvent event); /** * Return the channel that is related to this interceptor + * * @return Channel */ Channel getChannel(); /** * Set the channel that is related to this interceptor + * * @param channel The channel */ void setChannel(Channel channel); interface InterceptorEvent { int getEventType(); + String getEventTypeDesc(); + ChannelInterceptor getInterceptor(); } } diff --git a/java/org/apache/catalina/tribes/ChannelListener.java b/java/org/apache/catalina/tribes/ChannelListener.java index e774a31aed..a314c9b711 100644 --- a/java/org/apache/catalina/tribes/ChannelListener.java +++ b/java/org/apache/catalina/tribes/ChannelListener.java @@ -17,30 +17,33 @@ package org.apache.catalina.tribes; import java.io.Serializable; + /** * An interface to listens to incoming messages from a channel. * <p> * When a message is received, the Channel will invoke the channel listener in a conditional sequence. * <code>if (listener.accept(msg,sender)) listener.messageReceived(msg,sender);</code> * <p> - * A ChannelListener implementation MUST NOT return true on <code>accept(Serializable, Member)</code> - * if it doesn't intend to process the message. The channel can this way track whether a message - * was processed by an above application or if it was just received and forgot about, a feature required - * to support message-response(RPC) calls + * A ChannelListener implementation MUST NOT return true on <code>accept(Serializable, Member)</code> if it doesn't + * intend to process the message. The channel can this way track whether a message was processed by an above application + * or if it was just received and forgot about, a feature required to support message-response(RPC) calls */ public interface ChannelListener { /** * Receive a message from the channel - * @param msg Serializable + * + * @param msg Serializable * @param sender - the source of the message */ void messageReceived(Serializable msg, Member sender); /** * Invoked by the channel to determine if the listener will process this message or not. - * @param msg Serializable + * + * @param msg Serializable * @param sender Member + * * @return boolean */ boolean accept(Serializable msg, Member sender); diff --git a/java/org/apache/catalina/tribes/ChannelMessage.java b/java/org/apache/catalina/tribes/ChannelMessage.java index 66a6f953f2..0a39e3df97 100644 --- a/java/org/apache/catalina/tribes/ChannelMessage.java +++ b/java/org/apache/catalina/tribes/ChannelMessage.java @@ -21,32 +21,31 @@ import java.io.Serializable; import org.apache.catalina.tribes.io.XByteBuffer; /** - * Message that is passed through the interceptor stack after the - * data serialized in the Channel object and then passed down to the - * interceptor and eventually down to the ChannelSender component. - * + * Message that is passed through the interceptor stack after the data serialized in the Channel object and then passed + * down to the interceptor and eventually down to the ChannelSender component. */ public interface ChannelMessage extends Serializable, Cloneable { /** - * Get the address that this message originated from. - * Almost always <code>Channel.getLocalMember(boolean)</code>. - * This would be set to a different address - * if the message was being relayed from a host other than the one - * that originally sent it. + * Get the address that this message originated from. Almost always <code>Channel.getLocalMember(boolean)</code>. + * This would be set to a different address if the message was being relayed from a host other than the one that + * originally sent it. + * * @return the source or reply-to address of this message */ Member getAddress(); /** * Sets the source or reply-to address of this message + * * @param member Member */ void setAddress(Member member); /** * Timestamp of when the message was created. + * * @return long timestamp in milliseconds */ long getTimestamp(); @@ -59,48 +58,55 @@ public interface ChannelMessage extends Serializable, Cloneable { void setTimestamp(long timestamp); /** - * Each message must have a globally unique Id. - * interceptors heavily depend on this id for message processing + * Each message must have a globally unique Id. interceptors heavily depend on this id for message processing + * * @return byte */ byte[] getUniqueId(); /** * The byte buffer that contains the actual message payload + * * @param buf XByteBuffer */ void setMessage(XByteBuffer buf); /** * returns the byte buffer that contains the actual message payload + * * @return XByteBuffer */ XByteBuffer getMessage(); /** - * The message options is a 32 bit flag set - * that triggers interceptors and message behavior. + * The message options is a 32 bit flag set that triggers interceptors and message behavior. + * * @see Channel#send(Member[], Serializable, int) * @see ChannelInterceptor#getOptionFlag + * * @return int - the option bits set for this message */ int getOptions(); /** * sets the option bits for this message + * * @param options int + * * @see #getOptions() */ void setOptions(int options); /** * Shallow clone, what gets cloned depends on the implementation + * * @return ChannelMessage */ Object clone(); /** * Deep clone, all fields MUST get cloned + * * @return ChannelMessage */ Object deepclone(); diff --git a/java/org/apache/catalina/tribes/ChannelReceiver.java b/java/org/apache/catalina/tribes/ChannelReceiver.java index c23c8ab05f..8a93c46d4b 100644 --- a/java/org/apache/catalina/tribes/ChannelReceiver.java +++ b/java/org/apache/catalina/tribes/ChannelReceiver.java @@ -19,15 +19,16 @@ package org.apache.catalina.tribes; import java.io.IOException; /** - * The <code>ChannelReceiver</code> interface is the data receiver component - * at the bottom layer, the IO layer (for layers see the {@link Channel} interface). - * This class may optionally implement a thread pool for parallel processing of incoming messages. + * The <code>ChannelReceiver</code> interface is the data receiver component at the bottom layer, the IO layer (for + * layers see the {@link Channel} interface). This class may optionally implement a thread pool for parallel processing + * of incoming messages. */ public interface ChannelReceiver extends Heartbeat { int MAX_UDP_SIZE = 65535; /** * Start listening for incoming messages on the host/port + * * @throws IOException Listen failed */ void start() throws IOException; @@ -38,8 +39,8 @@ public interface ChannelReceiver extends Heartbeat { void stop(); /** - * String representation of the IPv4 or IPv6 address that this host is listening - * to. + * String representation of the IPv4 or IPv6 address that this host is listening to. + * * @return the host that this receiver is listening to */ String getHost(); @@ -47,44 +48,53 @@ public interface ChannelReceiver extends Heartbeat { /** * Returns the listening port + * * @return port */ int getPort(); /** * Returns the secure listening port + * * @return port, -1 if a secure port is not activated */ int getSecurePort(); /** * Returns the UDP port + * * @return port, -1 if the UDP port is not activated. */ int getUdpPort(); /** * Sets the message listener to receive notification of incoming + * * @param listener MessageListener + * * @see MessageListener */ void setMessageListener(MessageListener listener); /** * Returns the message listener that is associated with this receiver + * * @return MessageListener + * * @see MessageListener */ MessageListener getMessageListener(); /** * Return the channel that is related to this ChannelReceiver + * * @return Channel */ Channel getChannel(); /** * Set the channel that is related to this ChannelReceiver + * * @param channel The channel */ void setChannel(Channel channel); diff --git a/java/org/apache/catalina/tribes/ChannelSender.java b/java/org/apache/catalina/tribes/ChannelSender.java index e271c23b16..85538f46bd 100644 --- a/java/org/apache/catalina/tribes/ChannelSender.java +++ b/java/org/apache/catalina/tribes/ChannelSender.java @@ -20,28 +20,29 @@ import java.io.IOException; /** - * The <code>ChannelSender</code> interface is the data sender component - * at the bottom layer, the IO layer (for layers see the {@link Channel} interface). - * The channel sender must support "silent" members, i.e., be able to send a message to a member - * that is not in the membership, but is part of the destination parameter + * The <code>ChannelSender</code> interface is the data sender component at the bottom layer, the IO layer (for layers + * see the {@link Channel} interface). The channel sender must support "silent" members, i.e., be able to send a message + * to a member that is not in the membership, but is part of the destination parameter */ -public interface ChannelSender extends Heartbeat -{ +public interface ChannelSender extends Heartbeat { /** * Notify the sender of a member being added to the group.<br> * Optional. This can be an empty implementation, that does nothing + * * @param member Member */ void add(Member member); + /** - * Notification that a member has been removed or crashed. - * Can be used to clean up open connections etc + * Notification that a member has been removed or crashed. Can be used to clean up open connections etc + * * @param member Member */ void remove(Member member); /** * Start the channel sender + * * @throws IOException if preprocessing takes place and an error happens */ void start() throws IOException; @@ -54,26 +55,32 @@ public interface ChannelSender extends Heartbeat /** * A channel heartbeat, use this method to clean up resources */ - @Override void heartbeat() ; + @Override + void heartbeat(); /** * Send a message to one or more recipients. - * @param message ChannelMessage - the message to be sent + * + * @param message ChannelMessage - the message to be sent * @param destination Member[] - the destinations - * @throws ChannelException - if an error happens, the ChannelSender MUST report - * individual send failures on a per member basis, using ChannelException.addFaultyMember + * + * @throws ChannelException - if an error happens, the ChannelSender MUST report individual send failures on a per + * member basis, using ChannelException.addFaultyMember + * * @see ChannelException#addFaultyMember(Member,java.lang.Exception) */ void sendMessage(ChannelMessage message, Member[] destination) throws ChannelException; /** * Return the channel that is related to this ChannelSender + * * @return Channel */ Channel getChannel(); /** * Set the channel that is related to this ChannelSender + * * @param channel The channel */ void setChannel(Channel channel); diff --git a/java/org/apache/catalina/tribes/ErrorHandler.java b/java/org/apache/catalina/tribes/ErrorHandler.java index f5d24f3fdd..55ff6c601a 100644 --- a/java/org/apache/catalina/tribes/ErrorHandler.java +++ b/java/org/apache/catalina/tribes/ErrorHandler.java @@ -17,23 +17,26 @@ package org.apache.catalina.tribes; /** - * The <code>ErrorHandler</code> class is used when sending messages - * that are sent asynchronously and the application still needs to get - * confirmation when the message was sent successfully or when a message errored out. + * The <code>ErrorHandler</code> class is used when sending messages that are sent asynchronously and the application + * still needs to get confirmation when the message was sent successfully or when a message errored out. */ public interface ErrorHandler { /** * Invoked if the message is dispatched async, and an error occurs - * @param x ChannelException - the error that happened + * + * @param x ChannelException - the error that happened * @param id - the unique id for the message + * * @see Channel#send(Member[], java.io.Serializable, int, ErrorHandler) */ void handleError(ChannelException x, UniqueId id); /** * Invoked when the message has been sent successfully. + * * @param id - the unique id for the message + * * @see Channel#send(Member[], java.io.Serializable, int, ErrorHandler) */ void handleCompletion(UniqueId id); diff --git a/java/org/apache/catalina/tribes/Heartbeat.java b/java/org/apache/catalina/tribes/Heartbeat.java index a3436516b5..2e1dd0fd3b 100644 --- a/java/org/apache/catalina/tribes/Heartbeat.java +++ b/java/org/apache/catalina/tribes/Heartbeat.java @@ -17,8 +17,8 @@ package org.apache.catalina.tribes; /** - * Can be implemented by the ChannelListener and Membership listeners to receive heartbeat - * notifications from the Channel + * Can be implemented by the ChannelListener and Membership listeners to receive heartbeat notifications from the + * Channel * * @see Channel * @see Channel#heartbeat() diff --git a/java/org/apache/catalina/tribes/JmxChannel.java b/java/org/apache/catalina/tribes/JmxChannel.java index 8dc822d5eb..e2b050734c 100644 --- a/java/org/apache/catalina/tribes/JmxChannel.java +++ b/java/org/apache/catalina/tribes/JmxChannel.java @@ -23,36 +23,42 @@ public interface JmxChannel extends MBeanRegistration { /** * If set to true, this channel is registered with jmx. + * * @return true if this channel will be registered with jmx. */ boolean isJmxEnabled(); /** * If set to true, this channel is registered with jmx. + * * @param jmxEnabled set to true if this channel should be registered with jmx. */ void setJmxEnabled(boolean jmxEnabled); /** * Return the jmx domain which this channel is registered. + * * @return jmxDomain */ String getJmxDomain(); /** * Set the jmx domain which this channel should be registered. + * * @param jmxDomain The jmx domain which this channel should be registered. */ void setJmxDomain(String jmxDomain); /** * Return the jmx prefix which will be used with channel ObjectName. + * * @return jmxPrefix */ String getJmxPrefix(); /** * Set the jmx prefix which will be used with channel ObjectName. + * * @param jmxPrefix The jmx prefix which will be used with channel ObjectName. */ void setJmxPrefix(String jmxPrefix); diff --git a/java/org/apache/catalina/tribes/ManagedChannel.java b/java/org/apache/catalina/tribes/ManagedChannel.java index 06121df2fc..fa4b9fca49 100644 --- a/java/org/apache/catalina/tribes/ManagedChannel.java +++ b/java/org/apache/catalina/tribes/ManagedChannel.java @@ -19,56 +19,70 @@ package org.apache.catalina.tribes; import java.util.Iterator; /** - * A managed channel interface gives you access to the components of the channels - * such as senders, receivers, interceptors etc for configurations purposes + * A managed channel interface gives you access to the components of the channels such as senders, receivers, + * interceptors etc for configurations purposes */ public interface ManagedChannel extends Channel { /** * Sets the channel sender + * * @param sender ChannelSender + * * @see ChannelSender */ void setChannelSender(ChannelSender sender); /** * Sets the channel receiver + * * @param receiver ChannelReceiver + * * @see ChannelReceiver */ void setChannelReceiver(ChannelReceiver receiver); /** * Sets the membership service + * * @param service MembershipService + * * @see MembershipService */ void setMembershipService(MembershipService service); /** * returns the channel sender + * * @return ChannelSender + * * @see ChannelSender */ ChannelSender getChannelSender(); /** * returns the channel receiver + * * @return ChannelReceiver + * * @see ChannelReceiver */ ChannelReceiver getChannelReceiver(); /** * Returns the membership service + * * @return MembershipService + * * @see MembershipService */ MembershipService getMembershipService(); /** * Returns the interceptor stack + * * @return Iterator + * * @see Channel#addInterceptor(ChannelInterceptor) */ Iterator<ChannelInterceptor> getInterceptors(); diff --git a/java/org/apache/catalina/tribes/Member.java b/java/org/apache/catalina/tribes/Member.java index a93485a116..3a62e7a7a7 100644 --- a/java/org/apache/catalina/tribes/Member.java +++ b/java/org/apache/catalina/tribes/Member.java @@ -19,25 +19,25 @@ package org.apache.catalina.tribes; import java.io.Serializable; /** - * The Member interface, defines a member in the group. - * Each member can carry a set of properties, defined by the actual implementation. + * The Member interface, defines a member in the group. Each member can carry a set of properties, defined by the actual + * implementation. * <p> * A member is identified by the host/ip/uniqueId. * <ul> * <li>The host is what interface the member is listening to, to receive data</li> * <li>The port is what port the member is listening to, to receive data</li> - * <li>The uniqueId defines the session id for the member. This is an important feature - * since a member that has crashed and the starts up again on the same port/host is - * not guaranteed to be the same member, so no state transfers will ever be confused.</li> + * <li>The uniqueId defines the session id for the member. This is an important feature since a member that has crashed + * and the starts up again on the same port/host is not guaranteed to be the same member, so no state transfers will + * ever be confused.</li> * </ul> */ public interface Member extends Serializable { /** - * When a member leaves the cluster, the payload of the memberDisappeared member - * will be the following bytes. This indicates a soft shutdown, and not a crash + * When a member leaves the cluster, the payload of the memberDisappeared member will be the following bytes. This + * indicates a soft shutdown, and not a crash */ - byte[] SHUTDOWN_PAYLOAD = new byte[] {66, 65, 66, 89, 45, 65, 76, 69, 88}; + byte[] SHUTDOWN_PAYLOAD = new byte[] { 66, 65, 66, 89, 45, 65, 76, 69, 88 }; /** * @return the name of this node, should be unique within the group. @@ -46,55 +46,65 @@ public interface Member extends Serializable { /** * Returns the listen host for the ChannelReceiver implementation + * * @return IPv4 or IPv6 representation of the host address this member listens to incoming data + * * @see ChannelReceiver */ byte[] getHost(); /** * Returns the listen port for the ChannelReceiver implementation + * * @return the listen port for this member, -1 if its not listening on an insecure port + * * @see ChannelReceiver */ int getPort(); /** - * Returns the secure listen port for the ChannelReceiver implementation. - * Returns -1 if its not listening to a secure port. + * Returns the secure listen port for the ChannelReceiver implementation. Returns -1 if its not listening to a + * secure port. + * * @return the listen port for this member, -1 if its not listening on a secure port + * * @see ChannelReceiver */ int getSecurePort(); /** * Returns the UDP port that this member is listening to for UDP messages. + * * @return the listen UDP port for this member, -1 if its not listening on a UDP port */ int getUdpPort(); /** - * 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 group. + * 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 group. + * * @return nr of milliseconds since this member started. */ long getMemberAliveTime(); /** * Set the alive time in ms. + * * @param memberAliveTime the value to set */ void setMemberAliveTime(long memberAliveTime); /** * The current state of the member. + * * @return {@code true} if the member is functioning correctly */ boolean isReady(); /** * The current state of the member. + * * @return {@code true} if the member is suspect, but the crash has not been confirmed */ boolean isSuspect(); @@ -105,8 +115,9 @@ public interface Member extends Serializable { boolean isFailing(); /** - * returns a UUID unique for this member over all sessions. - * If the member crashes and restarts, the uniqueId will be different. + * returns a UUID unique for this member over all sessions. If the member crashes and restarts, the uniqueId will be + * different. + * * @return byte[] */ byte[] getUniqueId(); @@ -118,6 +129,7 @@ public interface Member extends Serializable { /** * Set the payload associated with this member. + * * @param payload the payload */ void setPayload(byte[] payload); @@ -129,6 +141,7 @@ public interface Member extends Serializable { /** * Set the command associated with this member. + * * @param command the command */ void setCommand(byte[] command); @@ -139,25 +152,29 @@ public interface Member extends Serializable { byte[] getDomain(); /** - * Highly optimized version of serializing a member into a byte array - * Returns a cached byte[] reference, do not modify this data - * @param getalive calculate memberAlive time + * Highly optimized version of serializing a member into a byte array Returns a cached byte[] reference, do not + * modify this data + * + * @param getalive calculate memberAlive time + * * @return the data as a byte array */ byte[] getData(boolean getalive); /** - * Highly optimized version of serializing a member into a byte array - * Returns a cached byte[] reference, do not modify this data - * @param getalive calculate memberAlive time - * @param reset reset the cached data package, and create a new one + * Highly optimized version of serializing a member into a byte array Returns a cached byte[] reference, do not + * modify this data + * + * @param getalive calculate memberAlive time + * @param reset reset the cached data package, and create a new one + * * @return the data as a byte array */ byte[] getData(boolean getalive, boolean reset); /** - * Length of a message obtained by {@link #getData(boolean)} or - * {@link #getData(boolean, boolean)}. + * Length of a message obtained by {@link #getData(boolean)} or {@link #getData(boolean, boolean)}. + * * @return the data length */ int getDataLength(); @@ -169,6 +186,7 @@ public interface Member extends Serializable { /** * Set if the member is local. + * * @param local set to {@code true} if this is the local member */ void setLocal(boolean local); diff --git a/java/org/apache/catalina/tribes/MembershipListener.java b/java/org/apache/catalina/tribes/MembershipListener.java index fe0c00975f..f6d1fdfe15 100644 --- a/java/org/apache/catalina/tribes/MembershipListener.java +++ b/java/org/apache/catalina/tribes/MembershipListener.java @@ -17,13 +17,13 @@ package org.apache.catalina.tribes; /** - * 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 group and when a member has disappeared (crashed) + * 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 group and when a member has disappeared (crashed) */ public interface MembershipListener { /** * A member was added to the group + * * @param member Member - the member that was added */ void memberAdded(Member member); @@ -31,7 +31,9 @@ public interface MembershipListener { /** * A member was removed from the group<br> * If the member left voluntarily, the Member.getCommand will contain the Member.SHUTDOWN_PAYLOAD data + * * @param member Member + * * @see Member#SHUTDOWN_PAYLOAD */ void memberDisappeared(Member member); diff --git a/java/org/apache/catalina/tribes/MembershipProvider.java b/java/org/apache/catalina/tribes/MembershipProvider.java index 235a9b597f..975fb21a89 100644 --- a/java/org/apache/catalina/tribes/MembershipProvider.java +++ b/java/org/apache/catalina/tribes/MembershipProvider.java @@ -22,44 +22,53 @@ public interface MembershipProvider { /** * Initialize the membership provider with the specified configuration. + * * @param properties configuration + * * @throws Exception if an error occurs */ void init(Properties properties) throws Exception; /** * Start the membership provider. + * * @param level the readiness level - * <ul> - * <li>Channel.DEFAULT - will start all services</li> - * <li>Channel.MBR_RX_SEQ - starts the membership receiver</li> - * <li>Channel.MBR_TX_SEQ - starts the membership broadcaster</li> - * </ul> + * <ul> + * <li>Channel.DEFAULT - will start all services</li> + * <li>Channel.MBR_RX_SEQ - starts the membership receiver</li> + * <li>Channel.MBR_TX_SEQ - starts the membership broadcaster</li> + * </ul> + * * @throws Exception if an error occurs */ void start(int level) throws Exception; /** * Stop the membership provider. + * * @param level the readiness level - * <ul> - * <li>Channel.DEFAULT - will stop all services</li> - * <li>Channel.MBR_RX_SEQ - stops the membership receiver</li> - * <li>Channel.MBR_TX_SEQ - stops the membership broadcaster</li> - * </ul> + * <ul> + * <li>Channel.DEFAULT - will stop all services</li> + * <li>Channel.MBR_RX_SEQ - stops the membership receiver</li> + * <li>Channel.MBR_TX_SEQ - stops the membership broadcaster</li> + * </ul> + * * @return {@code true} if successful + * * @throws Exception if an error occurs */ boolean stop(int level) throws Exception; /** * Set the associated membership listener. + * * @param listener the listener */ void setMembershipListener(MembershipListener listener); /** * Set the associated membership service. + * * @param service the service */ void setMembershipService(MembershipService service); @@ -71,13 +80,16 @@ public interface MembershipProvider { /** * Get the specified member from the associated membership. + * * @param mbr the member + * * @return the member */ Member getMember(Member mbr); /** * Get the members from the associated membership. + * * @return the members */ Member[] getMembers(); diff --git a/java/org/apache/catalina/tribes/MembershipService.java b/java/org/apache/catalina/tribes/MembershipService.java index 22be1e56c4..5d9e6040de 100644 --- a/java/org/apache/catalina/tribes/MembershipService.java +++ b/java/org/apache/catalina/tribes/MembershipService.java @@ -17,10 +17,9 @@ package org.apache.catalina.tribes; - /** - * The <code>MembershipService</code> interface is the membership component - * at the bottom layer, the IO layer (for layers see the javadoc for the {@link Channel} interface). + * The <code>MembershipService</code> interface is the membership component at the bottom layer, the IO layer (for + * layers see the javadoc for the {@link Channel} interface). */ public interface MembershipService { @@ -28,9 +27,9 @@ public interface MembershipService { int MBR_TX = Channel.MBR_TX_SEQ; /** - * Sets the properties for the membership service. This must be called before - * the <code>start()</code> method is called. - * The properties are implementation specific. + * Sets the properties for the membership service. This must be called before the <code>start()</code> method is + * called. The properties are implementation specific. + * * @param properties - to be used to configure the membership service. */ void setProperties(java.util.Properties properties); @@ -41,29 +40,31 @@ public interface MembershipService { 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 + * 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 Exception if the service fails to start. */ void start() throws Exception; /** - * Starts the membership service. If a membership listeners is added - * the listener will start to receive membership events. - * @param level - level MBR_RX starts listening for members, level MBR_TX - * starts broad casting the server - * @throws Exception if the service fails to start. + * Starts the membership service. If a membership listeners is added the listener will start to receive membership + * events. + * + * @param level - level MBR_RX starts listening for members, level MBR_TX starts broad casting the server + * + * @throws Exception if the service fails to start. * @throws java.lang.IllegalArgumentException if the level is incorrect. */ void start(int level) throws Exception; /** - * Stops the membership service. If a membership listeners is added - * the listener will start to receive membership events. - * @param level - level MBR_RX stops listening for members, level MBR_TX - * stops broad casting the server + * Stops the membership service. If a membership listeners is added the listener will start to receive membership + * events. + * + * @param level - level MBR_RX stops listening for members, level MBR_TX stops broad casting the server + * * @throws java.lang.IllegalArgumentException if the level is incorrect. */ void stop(int level); @@ -75,7 +76,9 @@ public interface MembershipService { /** * Retrieve the specified member from the membership. + * * @param mbr The member to retrieve + * * @return the member */ Member getMember(Member mbr); @@ -87,9 +90,10 @@ public interface MembershipService { /** * Get the local member. + * * @return the member object that defines this member - * @param incAliveTime <code>true</code> to set the alive time - * on the local member + * + * @param incAliveTime <code>true</code> to set the alive time on the local member */ Member getLocalMember(boolean incAliveTime); @@ -100,7 +104,9 @@ public interface MembershipService { /** * Get a member. + * * @param name The member name + * * @return the member */ Member findMemberByName(String name); @@ -111,13 +117,14 @@ public interface MembershipService { * @param listenHost Listen to host * @param listenPort Listen to port * @param securePort Use a secure port - * @param udpPort Use UDP + * @param udpPort Use UDP */ void setLocalMemberProperties(String listenHost, int listenPort, int securePort, int udpPort); /** - * Sets the membership listener, only one listener can be added. - * If you call this method twice, the last listener will be used. + * 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 */ void setMembershipListener(MembershipListener listener); @@ -128,39 +135,45 @@ public interface MembershipService { void removeMembershipListener(); /** - * Set a payload to be broadcasted with each membership - * broadcast. + * Set a payload to be broadcasted with each membership broadcast. + * * @param payload byte[] */ void setPayload(byte[] payload); /** * Set the associated domain. + * * @param domain the domain */ void setDomain(byte[] domain); /** * Broadcasts a message to all members. + * * @param message The message to broadcast + * * @throws ChannelException Message broadcast failed */ void broadcast(ChannelMessage message) throws ChannelException; /** * Return the channel that is related to this MembershipService + * * @return Channel */ Channel getChannel(); /** * Set the channel that is related to this MembershipService + * * @param channel The channel */ void setChannel(Channel channel); /** * Get the MembershipProvider + * * @return MembershipProvider */ MembershipProvider getMembershipProvider(); diff --git a/java/org/apache/catalina/tribes/MessageListener.java b/java/org/apache/catalina/tribes/MessageListener.java index 7426368279..f413833b0b 100644 --- a/java/org/apache/catalina/tribes/MessageListener.java +++ b/java/org/apache/catalina/tribes/MessageListener.java @@ -17,20 +17,22 @@ package org.apache.catalina.tribes; /** - * The listener to be registered with the ChannelReceiver, internal Tribes - * component. + * The listener to be registered with the ChannelReceiver, internal Tribes component. */ public interface MessageListener { /** * Receive a message from the IO components in the Channel stack + * * @param msg the message */ void messageReceived(ChannelMessage msg); /** * Allows skipping processing of the specified message. + * * @param msg the message + * * @return {@code true} if the message will be processed */ boolean accept(ChannelMessage msg); diff --git a/java/org/apache/catalina/tribes/RemoteProcessException.java b/java/org/apache/catalina/tribes/RemoteProcessException.java index c72b55036e..01eac03690 100644 --- a/java/org/apache/catalina/tribes/RemoteProcessException.java +++ b/java/org/apache/catalina/tribes/RemoteProcessException.java @@ -19,8 +19,8 @@ package org.apache.catalina.tribes; /** * Message thrown by a sender when USE_SYNC_ACK receives a FAIL_ACK_COMMAND. * <p> - * This means that the message was received on the remote node but the processing of the message failed. - * This message will be embedded in a ChannelException.FaultyMember + * This means that the message was received on the remote node but the processing of the message failed. This message + * will be embedded in a ChannelException.FaultyMember * * @see ChannelException */ diff --git a/java/org/apache/catalina/tribes/UniqueId.java b/java/org/apache/catalina/tribes/UniqueId.java index e13001581d..0a2524da86 100644 --- a/java/org/apache/catalina/tribes/UniqueId.java +++ b/java/org/apache/catalina/tribes/UniqueId.java @@ -23,7 +23,7 @@ import org.apache.catalina.tribes.util.Arrays; /** * Represents a globally unique Id. */ -public final class UniqueId implements Serializable{ +public final class UniqueId implements Serializable { private static final long serialVersionUID = 1L; final byte[] id; @@ -38,12 +38,12 @@ public final class UniqueId implements Serializable{ public UniqueId(byte[] id, int offset, int length) { this.id = new byte[length]; - System.arraycopy(id,offset,this.id,0,length); + System.arraycopy(id, offset, this.id, 0, length); } @Override public int hashCode() { - if ( id == null ) { + if (id == null) { return 0; } return Arrays.hashCode(id); @@ -52,18 +52,18 @@ public final class UniqueId implements Serializable{ @Override public boolean equals(Object other) { boolean result = (other instanceof UniqueId); - if ( result ) { - UniqueId uid = (UniqueId)other; - if ( this.id == null && uid.id == null ) { + if (result) { + UniqueId uid = (UniqueId) other; + if (this.id == null && uid.id == null) { result = true; - } else if ( this.id == null && uid.id != null ) { + } else if (this.id == null && uid.id != null) { result = false; - } else if ( this.id != null && uid.id == null ) { + } else if (this.id != null && uid.id == null) { result = false; } else { - result = Arrays.equals(this.id,uid.id); + result = Arrays.equals(this.id, uid.id); } - }//end if + } // end if return result; } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org