use of org.apache.catalina.tribes.ChannelException in project tomcat 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(sm.getString("abstractReplicatedMap.transferState.noReplies"));
}
}
} catch (ChannelException x) {
log.error(sm.getString("abstractReplicatedMap.unable.transferState"), x);
} catch (IOException x) {
log.error(sm.getString("abstractReplicatedMap.unable.transferState"), x);
} catch (ClassNotFoundException x) {
log.error(sm.getString("abstractReplicatedMap.unable.transferState"), x);
}
}
use of org.apache.catalina.tribes.ChannelException in project tomcat by apache.
the class AbstractReplicatedMap method mapMemberAdded.
public void mapMemberAdded(Member member) {
if (member.equals(getChannel().getLocalMember(false)))
return;
boolean memberAdded = false;
//select a backup node if we don't have one
Member mapMember = getChannel().getMember(member);
if (mapMember == null) {
log.warn(sm.getString("abstractReplicatedMap.mapMemberAdded.nullMember", member));
return;
}
synchronized (mapMembers) {
if (!mapMembers.containsKey(mapMember)) {
if (log.isInfoEnabled())
log.info(sm.getString("abstractReplicatedMap.mapMemberAdded.added", mapMember));
mapMembers.put(mapMember, Long.valueOf(System.currentTimeMillis()));
memberAdded = true;
}
}
if (memberAdded) {
synchronized (stateMutex) {
Iterator<Map.Entry<K, MapEntry<K, V>>> i = innerMap.entrySet().iterator();
while (i.hasNext()) {
Map.Entry<K, MapEntry<K, V>> e = i.next();
MapEntry<K, V> entry = innerMap.get(e.getKey());
if (entry == null)
continue;
if (entry.isPrimary() && (entry.getBackupNodes() == null || entry.getBackupNodes().length == 0)) {
try {
Member[] backup = publishEntryInfo(entry.getKey(), entry.getValue());
entry.setBackupNodes(backup);
entry.setPrimary(channel.getLocalMember(false));
} catch (ChannelException x) {
log.error(sm.getString("abstractReplicatedMap.unableSelect.backup"), x);
}
//catch
}
//end if
}
//while
}
//synchronized
}
//end if
}
use of org.apache.catalina.tribes.ChannelException in project tomcat by apache.
the class AbstractReplicatedMap method init.
/**
* Initializes the map by creating the RPC channel, registering itself as a channel listener
* This method is also responsible for initiating the state transfer
* @param owner Object
* @param channel Channel
* @param mapContextName String
* @param timeout long
* @param channelSendOptions int
* @param cls ClassLoader[]
* @param terminate - Flag for whether to terminate this map that failed to start.
*/
protected void init(MapOwner owner, Channel channel, String mapContextName, long timeout, int channelSendOptions, ClassLoader[] cls, boolean terminate) {
long start = System.currentTimeMillis();
if (log.isInfoEnabled())
log.info(sm.getString("abstractReplicatedMap.init.start", mapContextName));
this.mapOwner = owner;
this.externalLoaders = cls;
this.channelSendOptions = channelSendOptions;
this.channel = channel;
this.rpcTimeout = timeout;
this.mapname = mapContextName;
//unique context is more efficient if it is stored as bytes
this.mapContextName = mapContextName.getBytes(StandardCharsets.ISO_8859_1);
if (log.isTraceEnabled())
log.trace("Created Lazy Map with name:" + mapContextName + ", bytes:" + Arrays.toString(this.mapContextName));
//create an rpc channel and add the map as a listener
this.rpcChannel = new RpcChannel(this.mapContextName, channel, this);
//add this map as a message listener
this.channel.addChannelListener(this);
//listen for membership notifications
this.channel.addMembershipListener(this);
try {
//broadcast our map, this just notifies other members of our existence
broadcast(MapMessage.MSG_INIT, true);
//transfer state from another map
transferState();
//state is transferred, we are ready for messaging
broadcast(MapMessage.MSG_START, true);
} catch (ChannelException x) {
log.warn(sm.getString("abstractReplicatedMap.unableSend.startMessage"));
if (terminate) {
breakdown();
throw new RuntimeException(sm.getString("abstractReplicatedMap.unableStart"), x);
}
}
this.state = State.INITIALIZED;
long complete = System.currentTimeMillis() - start;
if (log.isInfoEnabled())
log.info(sm.getString("abstractReplicatedMap.init.completed", mapContextName, Long.toString(complete)));
}
use of org.apache.catalina.tribes.ChannelException in project tomcat by apache.
the class MultipointBioSender method sendMessage.
@Override
public synchronized void sendMessage(Member[] destination, ChannelMessage msg) throws ChannelException {
byte[] data = XByteBuffer.createDataPackage((ChannelData) msg);
BioSender[] senders = setupForSend(destination);
ChannelException cx = null;
for (int i = 0; i < senders.length; i++) {
try {
senders[i].sendMessage(data, (msg.getOptions() & Channel.SEND_OPTIONS_USE_ACK) == Channel.SEND_OPTIONS_USE_ACK);
} catch (Exception x) {
if (cx == null)
cx = new ChannelException(x);
cx.addFaultyMember(destination[i], x);
}
}
if (cx != null)
throw cx;
}
use of org.apache.catalina.tribes.ChannelException in project tomcat by apache.
the class MultipointBioSender method close.
private synchronized void close() throws ChannelException {
ChannelException x = null;
Object[] members = bioSenders.keySet().toArray();
for (int i = 0; i < members.length; i++) {
Member mbr = (Member) members[i];
try {
BioSender sender = bioSenders.get(mbr);
sender.disconnect();
} catch (Exception e) {
if (x == null)
x = new ChannelException(e);
x.addFaultyMember(mbr, e);
}
bioSenders.remove(mbr);
}
if (x != null)
throw x;
}
Aggregations