Search in sources :

Example 1 with Response

use of org.apache.catalina.tribes.group.Response in project tomcat70 by apache.

the class AbstractReplicatedMap method ping.

/**
 * Sends a ping out to all the members in the cluster, not just map members
 * that this map is alive.
 * @param timeout long
 * @throws ChannelException
 */
protected void ping(long timeout) throws ChannelException {
    MapMessage msg = new MapMessage(this.mapContextName, MapMessage.MSG_PING, false, null, null, null, channel.getLocalMember(false), null);
    if (channel.getMembers().length > 0) {
        try {
            // send a ping, wait for all nodes to reply
            Response[] resp = rpcChannel.send(channel.getMembers(), msg, RpcChannel.ALL_REPLY, (channelSendOptions), (int) accessTimeout);
            for (int i = 0; i < resp.length; i++) {
                MapMessage mapMsg = (MapMessage) resp[i].getMessage();
                try {
                    mapMsg.deserialize(getExternalLoaders());
                    Member member = resp[i].getSource();
                    State state = (State) mapMsg.getValue();
                    if (state.isAvailable()) {
                        memberAlive(member);
                    } else if (state == State.STATETRANSFERRED) {
                        synchronized (mapMembers) {
                            if (log.isInfoEnabled())
                                log.info("Member[" + member + "] is state transferred but not available yet.");
                            if (mapMembers.containsKey(member)) {
                                mapMembers.put(member, Long.valueOf(System.currentTimeMillis()));
                            }
                        }
                    } else {
                        if (log.isInfoEnabled())
                            log.info("Member[" + member + "] is not available yet.");
                    }
                } catch (IOException x) {
                    log.error("Unable to deserialize MapMessage.", x);
                    return;
                } catch (ClassNotFoundException x) {
                    log.error("Unable to deserialize MapMessage.", x);
                    return;
                }
            }
        } catch (ChannelException ce) {
            // Handle known failed members
            FaultyMember[] faultyMembers = ce.getFaultyMembers();
            for (FaultyMember faultyMember : faultyMembers) {
                memberDisappeared(faultyMember.getMember());
            }
            throw ce;
        }
    }
    // update our map of members, expire some if we didn't receive a ping back
    synchronized (mapMembers) {
        Member[] members = mapMembers.keySet().toArray(new Member[mapMembers.size()]);
        long now = System.currentTimeMillis();
        for (Member member : members) {
            long access = mapMembers.get(member).longValue();
            if ((now - access) > timeout) {
                log.warn("Member[" + member + "] in the Map[" + mapname + "] has timed-out in the ping processing.");
                memberDisappeared(member);
            }
        }
    }
// synch
}
Also used : Response(org.apache.catalina.tribes.group.Response) IOException(java.io.IOException) FaultyMember(org.apache.catalina.tribes.ChannelException.FaultyMember) Member(org.apache.catalina.tribes.Member) FaultyMember(org.apache.catalina.tribes.ChannelException.FaultyMember) ChannelException(org.apache.catalina.tribes.ChannelException)

Example 2 with Response

use of org.apache.catalina.tribes.group.Response in project tomcat by apache.

the class EchoRpcTest method run.

@Override
public void run() {
    long counter = 0;
    while (counter < count) {
        String msg = message + " cnt=" + (++counter);
        try {
            System.out.println("Sending [" + msg + "]");
            long start = System.currentTimeMillis();
            Response[] resp = rpc.send(channel.getMembers(), msg, options, Channel.SEND_OPTIONS_DEFAULT, timeout);
            System.out.println("Send of [" + msg + "] completed. Nr of responses=" + resp.length + " Time:" + (System.currentTimeMillis() - start) + " ms.");
            for (Response response : resp) {
                System.out.println("Received a response message from [" + response.getSource().getName() + "] with data [" + response.getMessage() + "]");
            }
            Thread.sleep(pause);
        } catch (Exception x) {
        // Ignore
        }
    }
}
Also used : Response(org.apache.catalina.tribes.group.Response)

Example 3 with Response

use of org.apache.catalina.tribes.group.Response in project tomcat by apache.

the class AbstractReplicatedMap method transferState.

public void transferState() {
    try {
        Member[] members = getMapMembers();
        Member backup = members.length > 0 ? members[0] : null;
        if (backup != null) {
            MapMessage msg = new MapMessage(mapContextName, getStateMessageType(), false, null, null, null, null, null);
            Response[] resp = rpcChannel.send(new Member[] { backup }, msg, RpcChannel.FIRST_REPLY, channelSendOptions, rpcTimeout);
            if (resp.length > 0) {
                synchronized (stateMutex) {
                    msg = (MapMessage) resp[0].getMessage();
                    msg.deserialize(getExternalLoaders());
                    ArrayList<?> list = (ArrayList<?>) msg.getValue();
                    for (Object o : list) {
                        messageReceived((Serializable) o, resp[0].getSource());
                    }
                // for
                }
                stateTransferred = true;
            } else {
                log.warn(sm.getString("abstractReplicatedMap.transferState.noReplies"));
            }
        }
    } catch (ChannelException | ClassNotFoundException | IOException x) {
        log.error(sm.getString("abstractReplicatedMap.unable.transferState"), x);
    }
    this.state = State.STATETRANSFERRED;
}
Also used : Response(org.apache.catalina.tribes.group.Response) ArrayList(java.util.ArrayList) IOException(java.io.IOException) FaultyMember(org.apache.catalina.tribes.ChannelException.FaultyMember) Member(org.apache.catalina.tribes.Member) ChannelException(org.apache.catalina.tribes.ChannelException)

Example 4 with Response

use of org.apache.catalina.tribes.group.Response in project tomcat by apache.

the class StaticMembershipProvider method ping.

protected void ping() throws ChannelException {
    // send ping
    Member[] members = getAliveMembers(staticMembers.toArray(new Member[0]));
    if (members.length > 0) {
        try {
            MemberMessage msg = new MemberMessage(membershipId, MemberMessage.MSG_PING, service.getLocalMember(true));
            Response[] resp = rpcChannel.send(members, msg, RpcChannel.ALL_REPLY, sendOptions, rpcTimeout);
            for (Response response : resp) {
                messageReceived(response.getMessage(), response.getSource());
            }
        } catch (ChannelException ce) {
            // Handle known failed members
            FaultyMember[] faultyMembers = ce.getFaultyMembers();
            for (FaultyMember faultyMember : faultyMembers) {
                memberDisappeared(faultyMember.getMember());
            }
            throw ce;
        }
    }
    // expire
    checkExpired();
}
Also used : Response(org.apache.catalina.tribes.group.Response) FaultyMember(org.apache.catalina.tribes.ChannelException.FaultyMember) Member(org.apache.catalina.tribes.Member) FaultyMember(org.apache.catalina.tribes.ChannelException.FaultyMember) ChannelException(org.apache.catalina.tribes.ChannelException)

Example 5 with Response

use of org.apache.catalina.tribes.group.Response in project tomcat by apache.

the class StaticMembershipProvider method startMembership.

protected void startMembership(Member[] members) throws ChannelException {
    if (members.length == 0) {
        return;
    }
    MemberMessage msg = new MemberMessage(membershipId, MemberMessage.MSG_START, service.getLocalMember(true));
    Response[] resp = rpcChannel.send(members, msg, RpcChannel.ALL_REPLY, sendOptions, rpcTimeout);
    if (resp.length > 0) {
        for (Response response : resp) {
            messageReceived(response.getMessage(), response.getSource());
        }
    } else {
        log.warn(sm.getString("staticMembershipProvider.startMembership.noReplies"));
    }
}
Also used : Response(org.apache.catalina.tribes.group.Response)

Aggregations

Response (org.apache.catalina.tribes.group.Response)8 FaultyMember (org.apache.catalina.tribes.ChannelException.FaultyMember)6 Member (org.apache.catalina.tribes.Member)6 ChannelException (org.apache.catalina.tribes.ChannelException)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)2