Search in sources :

Example 1 with ErrorHandler

use of org.apache.catalina.tribes.ErrorHandler in project tomcat by apache.

the class RpcChannel method messageReceived.

@Override
public void messageReceived(Serializable msg, Member sender) {
    RpcMessage rmsg = (RpcMessage) msg;
    RpcCollectorKey key = new RpcCollectorKey(rmsg.uuid);
    if (rmsg.reply) {
        RpcCollector collector = responseMap.get(key);
        if (collector == null) {
            if (!(rmsg instanceof RpcMessage.NoRpcChannelReply))
                callback.leftOver(rmsg.message, sender);
        } else {
            synchronized (collector) {
                //make sure it hasn't been removed
                if (responseMap.containsKey(key)) {
                    if ((rmsg instanceof RpcMessage.NoRpcChannelReply))
                        collector.destcnt--;
                    else
                        collector.addResponse(rmsg.message, sender);
                    if (collector.isComplete())
                        collector.notifyAll();
                } else {
                    if (!(rmsg instanceof RpcMessage.NoRpcChannelReply))
                        callback.leftOver(rmsg.message, sender);
                }
            }
        //synchronized
        }
    //end if
    } else {
        boolean finished = false;
        final ExtendedRpcCallback excallback = (callback instanceof ExtendedRpcCallback) ? ((ExtendedRpcCallback) callback) : null;
        boolean asyncReply = ((replyMessageOptions & Channel.SEND_OPTIONS_ASYNCHRONOUS) == Channel.SEND_OPTIONS_ASYNCHRONOUS);
        Serializable reply = callback.replyRequest(rmsg.message, sender);
        ErrorHandler handler = null;
        final Serializable request = msg;
        final Serializable response = reply;
        final Member fsender = sender;
        if (excallback != null && asyncReply) {
            handler = new ErrorHandler() {

                @Override
                public void handleError(ChannelException x, UniqueId id) {
                    excallback.replyFailed(request, response, fsender, x);
                }

                @Override
                public void handleCompletion(UniqueId id) {
                    excallback.replySucceeded(request, response, fsender);
                }
            };
        }
        rmsg.reply = true;
        rmsg.message = reply;
        try {
            if (handler != null) {
                channel.send(new Member[] { sender }, rmsg, replyMessageOptions & ~Channel.SEND_OPTIONS_SYNCHRONIZED_ACK, handler);
            } else {
                channel.send(new Member[] { sender }, rmsg, replyMessageOptions & ~Channel.SEND_OPTIONS_SYNCHRONIZED_ACK);
            }
            finished = true;
        } catch (Exception x) {
            if (excallback != null && !asyncReply) {
                excallback.replyFailed(rmsg.message, reply, sender, x);
            } else {
                log.error(sm.getString("rpcChannel.replyFailed"), x);
            }
        }
        if (finished && excallback != null && !asyncReply) {
            excallback.replySucceeded(rmsg.message, reply, sender);
        }
    }
//end if
}
Also used : ErrorHandler(org.apache.catalina.tribes.ErrorHandler) UniqueId(org.apache.catalina.tribes.UniqueId) Serializable(java.io.Serializable) ChannelException(org.apache.catalina.tribes.ChannelException) Member(org.apache.catalina.tribes.Member) ChannelException(org.apache.catalina.tribes.ChannelException)

Aggregations

Serializable (java.io.Serializable)1 ChannelException (org.apache.catalina.tribes.ChannelException)1 ErrorHandler (org.apache.catalina.tribes.ErrorHandler)1 Member (org.apache.catalina.tribes.Member)1 UniqueId (org.apache.catalina.tribes.UniqueId)1