Java Code Examples for org.apache.catalina.tribes.Channel#SEND_OPTIONS_SYNCHRONIZED_ACK

The following examples show how to use org.apache.catalina.tribes.Channel#SEND_OPTIONS_SYNCHRONIZED_ACK . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleTcpCluster.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * send a cluster message to one member
 *
 * @param msg message to transfer
 * @param dest Receiver member
 * @see org.apache.catalina.ha.CatalinaCluster#send(org.apache.catalina.ha.ClusterMessage,
 *      org.apache.catalina.tribes.Member)
 */
@Override
public void send(ClusterMessage msg, Member dest) {
    try {
        msg.setAddress(getLocalMember());
        int sendOptions = channelSendOptions;
        if (msg instanceof SessionMessage
                && ((SessionMessage)msg).getEventType() == SessionMessage.EVT_ALL_SESSION_DATA) {
            sendOptions = Channel.SEND_OPTIONS_SYNCHRONIZED_ACK|Channel.SEND_OPTIONS_USE_ACK;
        }
        if (dest != null) {
            if (!getLocalMember().equals(dest)) {
                channel.send(new Member[] {dest}, msg, sendOptions);
            } else
                log.error(sm.getString("simpleTcpCluster.unableSend.localMember", msg));
        } else {
            Member[] destmembers = channel.getMembers();
            if (destmembers.length>0)
                channel.send(destmembers,msg, sendOptions);
            else if (log.isDebugEnabled())
                log.debug("No members in cluster, ignoring message:"+msg);
        }
    } catch (Exception x) {
        log.error(sm.getString("simpleTcpCluster.sendFailed"), x);
    }
}
 
Example 2
Source File: SimpleTcpCluster.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * send a cluster message to one member
 * 
 * @param msg message to transfer
 * @param dest Receiver member
 * @see org.apache.catalina.ha.CatalinaCluster#send(org.apache.catalina.ha.ClusterMessage,
 *      org.apache.catalina.tribes.Member)
 */
@Override
public void send(ClusterMessage msg, Member dest) {
    try {
        msg.setAddress(getLocalMember());
        int sendOptions = channelSendOptions;
        if (msg instanceof SessionMessage
                && ((SessionMessage)msg).getEventType() == SessionMessage.EVT_ALL_SESSION_DATA) {
            sendOptions = Channel.SEND_OPTIONS_SYNCHRONIZED_ACK|Channel.SEND_OPTIONS_USE_ACK;
        }
        if (dest != null) {
            if (!getLocalMember().equals(dest)) {
                channel.send(new Member[] {dest}, msg, sendOptions);
            } else
                log.error("Unable to send message to local member " + msg);
        } else {
            Member[] destmembers = channel.getMembers();
            if (destmembers.length>0)
                channel.send(destmembers,msg, sendOptions);
            else if (log.isDebugEnabled()) 
                log.debug("No members in cluster, ignoring message:"+msg);
        }
    } catch (Exception x) {
        log.error("Unable to send message through cluster sender.", x);
    }
}
 
Example 3
Source File: SimpleTcpCluster.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * send a cluster message to one member
 * 
 * @param msg message to transfer
 * @param dest Receiver member
 * @see org.apache.catalina.ha.CatalinaCluster#send(org.apache.catalina.ha.ClusterMessage,
 *      org.apache.catalina.tribes.Member)
 */
@Override
public void send(ClusterMessage msg, Member dest) {
    try {
        msg.setAddress(getLocalMember());
        int sendOptions = channelSendOptions;
        if (msg instanceof SessionMessage
                && ((SessionMessage)msg).getEventType() == SessionMessage.EVT_ALL_SESSION_DATA) {
            sendOptions = Channel.SEND_OPTIONS_SYNCHRONIZED_ACK|Channel.SEND_OPTIONS_USE_ACK;
        }
        if (dest != null) {
            if (!getLocalMember().equals(dest)) {
                channel.send(new Member[] {dest}, msg, sendOptions);
            } else
                log.error("Unable to send message to local member " + msg);
        } else {
            Member[] destmembers = channel.getMembers();
            if (destmembers.length>0)
                channel.send(destmembers,msg, sendOptions);
            else if (log.isDebugEnabled()) 
                log.debug("No members in cluster, ignoring message:"+msg);
        }
    } catch (Exception x) {
        log.error("Unable to send message through cluster sender.", x);
    }
}
 
Example 4
Source File: ChannelCoordinator.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public ChannelCoordinator(ChannelReceiver receiver,
                          ChannelSender sender,
                          MembershipService service) {

    this.optionFlag = Channel.SEND_OPTIONS_BYTE_MESSAGE |
            Channel.SEND_OPTIONS_USE_ACK |
            Channel.SEND_OPTIONS_SYNCHRONIZED_ACK;

    this.setClusterReceiver(receiver);
    this.setClusterSender(sender);
    this.setMembershipService(service);
}
 
Example 5
Source File: RpcChannel.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Send a message and wait for the response.
 * @param destination Member[] - the destination for the message, and the members you request a reply from
 * @param message Serializable - the message you are sending out
 * @param rpcOptions int - FIRST_REPLY, MAJORITY_REPLY or ALL_REPLY
 * @param channelOptions channel sender options
 * @param timeout long - timeout in milliseconds, if no reply is received within this time null is returned
 * @return Response[] - an array of response objects.
 * @throws ChannelException Error sending message
 */
public Response[] send(Member[] destination,
                       Serializable message,
                       int rpcOptions,
                       int channelOptions,
                       long timeout) throws ChannelException {

    if ( destination==null || destination.length == 0 ) return new Response[0];

    //avoid dead lock
    int sendOptions =
        channelOptions & ~Channel.SEND_OPTIONS_SYNCHRONIZED_ACK;

    RpcCollectorKey key = new RpcCollectorKey(UUIDGenerator.randomUUID(false));
    RpcCollector collector = new RpcCollector(key,rpcOptions,destination.length);
    try {
        synchronized (collector) {
            if ( rpcOptions != NO_REPLY ) responseMap.put(key, collector);
            RpcMessage rmsg = new RpcMessage(rpcId, key.id, message);
            channel.send(destination, rmsg, sendOptions);
            if ( rpcOptions != NO_REPLY ) collector.wait(timeout);
        }
    } catch ( InterruptedException ix ) {
        Thread.currentThread().interrupt();
    } finally {
        responseMap.remove(key);
    }
    return collector.getResponses();
}
 
Example 6
Source File: RpcChannel.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Send a message and wait for the response.
 * @param destination Member[] - the destination for the message, and the members you request a reply from
 * @param message Serializable - the message you are sending out
 * @param rpcOptions int - FIRST_REPLY, MAJORITY_REPLY or ALL_REPLY
 * @param channelOptions channel sender options
 * @param timeout long - timeout in milliseconds, if no reply is received within this time null is returned
 * @return Response[] - an array of response objects.
 * @throws ChannelException
 */
public Response[] send(Member[] destination, 
                       Serializable message,
                       int rpcOptions, 
                       int channelOptions,
                       long timeout) throws ChannelException {
    
    if ( destination==null || destination.length == 0 ) return new Response[0];
    
    //avoid dead lock
    int sendOptions =
        channelOptions & ~Channel.SEND_OPTIONS_SYNCHRONIZED_ACK;
    
    RpcCollectorKey key = new RpcCollectorKey(UUIDGenerator.randomUUID(false));
    RpcCollector collector = new RpcCollector(key,rpcOptions,destination.length);
    try {
        synchronized (collector) {
            if ( rpcOptions != NO_REPLY ) responseMap.put(key, collector);
            RpcMessage rmsg = new RpcMessage(rpcId, key.id, message);
            channel.send(destination, rmsg, sendOptions);
            if ( rpcOptions != NO_REPLY ) collector.wait(timeout);
        }
    } catch ( InterruptedException ix ) {
        Thread.currentThread().interrupt();
    }finally {
        responseMap.remove(key);
    }
    return collector.getResponses();
}
 
Example 7
Source File: RpcChannel.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Send a message and wait for the response.
 * @param destination Member[] - the destination for the message, and the members you request a reply from
 * @param message Serializable - the message you are sending out
 * @param rpcOptions int - FIRST_REPLY, MAJORITY_REPLY or ALL_REPLY
 * @param channelOptions channel sender options
 * @param timeout long - timeout in milliseconds, if no reply is received within this time null is returned
 * @return Response[] - an array of response objects.
 * @throws ChannelException
 */
public Response[] send(Member[] destination, 
                       Serializable message,
                       int rpcOptions, 
                       int channelOptions,
                       long timeout) throws ChannelException {
    
    if ( destination==null || destination.length == 0 ) return new Response[0];
    
    //avoid dead lock
    int sendOptions =
        channelOptions & ~Channel.SEND_OPTIONS_SYNCHRONIZED_ACK;
    
    RpcCollectorKey key = new RpcCollectorKey(UUIDGenerator.randomUUID(false));
    RpcCollector collector = new RpcCollector(key,rpcOptions,destination.length);
    try {
        synchronized (collector) {
            if ( rpcOptions != NO_REPLY ) responseMap.put(key, collector);
            RpcMessage rmsg = new RpcMessage(rpcId, key.id, message);
            channel.send(destination, rmsg, sendOptions);
            if ( rpcOptions != NO_REPLY ) collector.wait(timeout);
        }
    } catch ( InterruptedException ix ) {
        Thread.currentThread().interrupt();
    } finally {
        responseMap.remove(key);
    }
    return collector.getResponses();
}
 
Example 8
Source File: ChannelCoordinator.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
public ChannelCoordinator() {
    // Override default
    this.optionFlag = Channel.SEND_OPTIONS_BYTE_MESSAGE |
            Channel.SEND_OPTIONS_USE_ACK |
            Channel.SEND_OPTIONS_SYNCHRONIZED_ACK;
}
 
Example 9
Source File: ChannelCoordinator.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
public ChannelCoordinator() {
    // Override default
    this.optionFlag = Channel.SEND_OPTIONS_BYTE_MESSAGE |
            Channel.SEND_OPTIONS_USE_ACK |
            Channel.SEND_OPTIONS_SYNCHRONIZED_ACK;
}
 
Example 10
Source File: ChannelData.java    From Tomcat8-Source-Read with MIT License 2 votes vote down vote up
/**
 * Utility method, returns true if the options flag indicates that an ack
 * is to be sent after the message has been received and processed
 * @param options int - the options for the message
 * @return boolean
 * @see org.apache.catalina.tribes.Channel#SEND_OPTIONS_USE_ACK
 * @see org.apache.catalina.tribes.Channel#SEND_OPTIONS_SYNCHRONIZED_ACK
 */
public static boolean sendAckSync(int options) {
    return ( (Channel.SEND_OPTIONS_USE_ACK & options) == Channel.SEND_OPTIONS_USE_ACK) &&
        ( (Channel.SEND_OPTIONS_SYNCHRONIZED_ACK & options) == Channel.SEND_OPTIONS_SYNCHRONIZED_ACK);
}
 
Example 11
Source File: ChannelData.java    From Tomcat8-Source-Read with MIT License 2 votes vote down vote up
/**
 * Utility method, returns true if the options flag indicates that an ack
 * is to be sent after the message has been received but not yet processed
 * @param options int - the options for the message
 * @return boolean
 * @see org.apache.catalina.tribes.Channel#SEND_OPTIONS_USE_ACK
 * @see org.apache.catalina.tribes.Channel#SEND_OPTIONS_SYNCHRONIZED_ACK
 */
public static boolean sendAckAsync(int options) {
    return ( (Channel.SEND_OPTIONS_USE_ACK & options) == Channel.SEND_OPTIONS_USE_ACK) &&
        ( (Channel.SEND_OPTIONS_SYNCHRONIZED_ACK & options) != Channel.SEND_OPTIONS_SYNCHRONIZED_ACK);
}
 
Example 12
Source File: ChannelData.java    From Tomcat7.0.67 with Apache License 2.0 2 votes vote down vote up
/**
 * Utility method, returns true if the options flag indicates that an ack
 * is to be sent after the message has been received and processed
 * @param options int - the options for the message
 * @return boolean 
 * @see org.apache.catalina.tribes.Channel#SEND_OPTIONS_USE_ACK
 * @see org.apache.catalina.tribes.Channel#SEND_OPTIONS_SYNCHRONIZED_ACK
 */
public static boolean sendAckSync(int options) {
    return ( (Channel.SEND_OPTIONS_USE_ACK & options) == Channel.SEND_OPTIONS_USE_ACK) &&
        ( (Channel.SEND_OPTIONS_SYNCHRONIZED_ACK & options) == Channel.SEND_OPTIONS_SYNCHRONIZED_ACK);
}
 
Example 13
Source File: ChannelData.java    From Tomcat7.0.67 with Apache License 2.0 2 votes vote down vote up
/**
 * Utility method, returns true if the options flag indicates that an ack
 * is to be sent after the message has been received but not yet processed
 * @param options int - the options for the message
 * @return boolean 
 * @see org.apache.catalina.tribes.Channel#SEND_OPTIONS_USE_ACK
 * @see org.apache.catalina.tribes.Channel#SEND_OPTIONS_SYNCHRONIZED_ACK
 */
public static boolean sendAckAsync(int options) {
    return ( (Channel.SEND_OPTIONS_USE_ACK & options) == Channel.SEND_OPTIONS_USE_ACK) &&
        ( (Channel.SEND_OPTIONS_SYNCHRONIZED_ACK & options) != Channel.SEND_OPTIONS_SYNCHRONIZED_ACK);
}
 
Example 14
Source File: ChannelData.java    From tomcatsrc with Apache License 2.0 2 votes vote down vote up
/**
 * Utility method, returns true if the options flag indicates that an ack
 * is to be sent after the message has been received and processed
 * @param options int - the options for the message
 * @return boolean 
 * @see org.apache.catalina.tribes.Channel#SEND_OPTIONS_USE_ACK
 * @see org.apache.catalina.tribes.Channel#SEND_OPTIONS_SYNCHRONIZED_ACK
 */
public static boolean sendAckSync(int options) {
    return ( (Channel.SEND_OPTIONS_USE_ACK & options) == Channel.SEND_OPTIONS_USE_ACK) &&
        ( (Channel.SEND_OPTIONS_SYNCHRONIZED_ACK & options) == Channel.SEND_OPTIONS_SYNCHRONIZED_ACK);
}
 
Example 15
Source File: ChannelData.java    From tomcatsrc with Apache License 2.0 2 votes vote down vote up
/**
 * Utility method, returns true if the options flag indicates that an ack
 * is to be sent after the message has been received but not yet processed
 * @param options int - the options for the message
 * @return boolean 
 * @see org.apache.catalina.tribes.Channel#SEND_OPTIONS_USE_ACK
 * @see org.apache.catalina.tribes.Channel#SEND_OPTIONS_SYNCHRONIZED_ACK
 */
public static boolean sendAckAsync(int options) {
    return ( (Channel.SEND_OPTIONS_USE_ACK & options) == Channel.SEND_OPTIONS_USE_ACK) &&
        ( (Channel.SEND_OPTIONS_SYNCHRONIZED_ACK & options) != Channel.SEND_OPTIONS_SYNCHRONIZED_ACK);
}