use of org.apache.catalina.tribes.group.Response in project tomcat70 by apache.
the class AbstractReplicatedMap method transferState.
public void transferState() {
try {
Member[] members = getMapMembers();
Member backup = members.length > 0 ? (Member) 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 (int i = 0; i < list.size(); i++) {
messageReceived((Serializable) list.get(i), resp[0].getSource());
}
// for
}
stateTransferred = true;
} else {
log.warn("Transfer state, 0 replies, probably a timeout.");
}
}
} catch (ChannelException x) {
log.error("Unable to transfer AbstractReplicatedMap state.", x);
} catch (IOException x) {
log.error("Unable to transfer AbstractReplicatedMap state.", x);
} catch (ClassNotFoundException x) {
log.error("Unable to transfer AbstractReplicatedMap state.", x);
}
this.state = State.STATETRANSFERRED;
}
use of org.apache.catalina.tribes.group.Response in project tomcat by apache.
the class AbstractReplicatedMap method broadcast.
/**
* Helper method to broadcast a message to all members in a channel
* @param msgtype int
* @param rpc boolean
* @throws ChannelException Send error
*/
protected void broadcast(int msgtype, boolean rpc) throws ChannelException {
Member[] members = channel.getMembers();
// No destination.
if (members.length == 0) {
return;
}
// send out a map membership message, only wait for the first reply
MapMessage msg = new MapMessage(this.mapContextName, msgtype, false, null, null, null, channel.getLocalMember(false), null);
if (rpc) {
Response[] resp = rpcChannel.send(members, msg, RpcChannel.FIRST_REPLY, (channelSendOptions), rpcTimeout);
if (resp.length > 0) {
for (Response response : resp) {
mapMemberAdded(response.getSource());
messageReceived(response.getMessage(), response.getSource());
}
} else {
log.warn(sm.getString("abstractReplicatedMap.broadcast.noReplies"));
}
} else {
channel.send(channel.getMembers(), msg, channelSendOptions);
}
}
use of org.apache.catalina.tribes.group.Response in project tomcat 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 Send error
*/
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 (Response response : resp) {
MapMessage mapMsg = (MapMessage) response.getMessage();
try {
mapMsg.deserialize(getExternalLoaders());
Member member = response.getSource();
State state = (State) mapMsg.getValue();
if (state.isAvailable()) {
memberAlive(member);
} else if (state == State.STATETRANSFERRED) {
synchronized (mapMembers) {
if (log.isInfoEnabled()) {
log.info(sm.getString("abstractReplicatedMap.ping.stateTransferredMember", member));
}
if (mapMembers.containsKey(member)) {
mapMembers.put(member, Long.valueOf(System.currentTimeMillis()));
}
}
} else {
if (log.isInfoEnabled()) {
log.info(sm.getString("abstractReplicatedMap.mapMember.unavailable", member));
}
}
} catch (ClassNotFoundException | IOException e) {
log.error(sm.getString("abstractReplicatedMap.unable.deserialize.MapMessage"), e);
}
}
} 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[0]);
long now = System.currentTimeMillis();
for (Member member : members) {
long access = mapMembers.get(member).longValue();
if ((now - access) > timeout) {
log.warn(sm.getString("abstractReplicatedMap.ping.timeout", member, mapname));
memberDisappeared(member);
}
}
}
// synch
}
Aggregations