@Override public void clear() { clear(true); }
public Object remove(Object key, boolean notify) { MapEntry entry = (MapEntry)super.remove(key); try { if (getMapMembers().length > 0 && notify) { MapMessage msg = new MapMessage(getMapContextName(), MapMessage.MSG_REMOVE, false, (Serializable) key, null, null, null,null); getChannel().send(getMapMembers(), msg, getChannelSendOptions()); } } catch ( ChannelException x ) { log.error("Unable to replicate out data for a LazyReplicatedMap.remove operation",x); } return entry!=null?entry.getValue():null; }
public Member getNextBackupNode() { Member[] members = getMapMembers(); int node = getNextBackupIndex(); if ( members.length == 0 || node==-1) return null; if ( node >= members.length ) node = 0; return members[node]; }
backup = publishEntryInfo(key, entry.getValue()); } else if ( entry.isProxy() ) { msg = new MapMessage(getMapContextName(), MapMessage.MSG_RETRIEVE_BACKUP, false, (Serializable) key, null, null, null,null); Response[] resp = getRpcChannel().send(entry.getBackupNodes(),msg, RpcChannel.FIRST_REPLY, getChannelSendOptions(), getRpcTimeout()); if (resp == null || resp.length == 0 || resp[0].getMessage() == null) { msg.deserialize(getExternalLoaders()); backup = entry.getBackupNodes(); if ( msg.getValue()!=null ) entry.setValue((V) msg.getValue()); msg = new MapMessage(getMapContextName(), MapMessage.MSG_NOTIFY_MAPMEMBER,false, (Serializable)entry.getKey(), null, null, channel.getLocalMember(false), backup); if ( backup != null && backup.length > 0) { getChannel().send(backup, msg, getChannelSendOptions()); msg = new MapMessage(getMapContextName(),MapMessage.MSG_PROXY,false,(Serializable)key,null,null,channel.getLocalMember(false),backup); Member[] dest = getMapMembersExcl(backup); if ( dest!=null && dest.length >0) { getChannel().send(dest, msg, getChannelSendOptions()); val.setOwner(getMapOwner()); backup = getMapMembers(); if (backup.length > 0) { msg = new MapMessage(getMapContextName(), MapMessage.MSG_NOTIFY_MAPMEMBER,false, (Serializable)key,null,null,channel.getLocalMember(false),backup); getChannel().send(backup, msg, getChannelSendOptions());
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 } } else { log.warn("Transfer state, 0 replies, probably a timeout."); } } } catch (ChannelException x) { log.error("Unable to transfer LazyReplicatedMap state.", x); } catch (IOException x) { log.error("Unable to transfer LazyReplicatedMap state.", x); } catch (ClassNotFoundException x) { log.error("Unable to transfer LazyReplicatedMap state.", x); } stateTransferred = true; }
mapmsg.deserialize(getExternalLoaders()); } catch (IOException x) { log.error("Unable to deserialize MapMessage.", x); log.trace("Map message received from:"+sender.getName()+" msg:"+mapmsg); if (mapmsg.getMsgType() == MapMessage.MSG_START) { mapMemberAdded(mapmsg.getPrimary()); memberDisappeared(mapmsg.getPrimary()); entry.setPrimary(mapmsg.getPrimary()); if (mapmsg.getValue()!=null && mapmsg.getValue() instanceof ReplicatedMapEntry ) { ((ReplicatedMapEntry)mapmsg.getValue()).setOwner(getMapOwner()); ((ReplicatedMapEntry)entry.getValue()).setOwner(getMapOwner()); re.setOwner(getMapOwner()); entry.setValue(re); } else {
public V put(K key, V value, boolean notify) { MapEntry<K,V> entry = new MapEntry<>(key, value); entry.setBackup(false); entry.setProxy(false); entry.setPrimary(channel.getLocalMember(false)); V old = null; //make sure that any old values get removed if ( containsKey(key) ) old = remove(key); try { if ( notify ) { Member[] backup = publishEntryInfo(key, value); entry.setBackupNodes(backup); } } catch (ChannelException x) { log.error("Unable to replicate out data for a LazyReplicatedMap.put operation", x); } innerMap.put(key,entry); return old; }
/** * If the reply has already been sent to the requesting thread, * the rpc callback can handle any data that comes in after the fact. * @param msg Serializable * @param sender Member */ public void leftOver(Serializable msg, Member sender) { //left over membership messages if (! (msg instanceof MapMessage))return; MapMessage mapmsg = (MapMessage) msg; try { mapmsg.deserialize(getExternalLoaders()); if (mapmsg.getMsgType() == MapMessage.MSG_START) { mapMemberAdded(mapmsg.getPrimary()); } else if (mapmsg.getMsgType() == MapMessage.MSG_INIT) { memberAlive(mapmsg.getPrimary()); } } catch (IOException x ) { log.error("Unable to deserialize MapMessage.",x); } catch (ClassNotFoundException x ) { log.error("Unable to deserialize MapMessage.",x); } }
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) { memberDisappeared(faultyMember.getMember()); if ( (now - access) > timeout ) { log.warn(sm.getString("abstractReplicatedMap.ping.timeout", member, mapname)); memberDisappeared(member);
public void mapMemberAdded(Member member) { if ( member.equals(getChannel().getLocalMember(false)) ) return; boolean memberAdded = false; 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));
broadcast(MapMessage.MSG_INIT, true); transferState(); broadcast(MapMessage.MSG_START, true); } catch (ChannelException x) { log.warn("Unable to send map start message."); if (terminate) { breakdown(); throw new RuntimeException("Unable to start replicated map.",x);
public Member[] getMapMembers() { return getMapMembers(this.mapMembers); }
broadcast(MapMessage.MSG_INIT, true); transferState(); broadcast(MapMessage.MSG_START, true); } catch (ChannelException x) { log.warn("Unable to send map start message.");
public void breakdown() { this.state = State.DESTROYED; if (this.rpcChannel != null) { this.rpcChannel.breakdown(); } if (this.channel != null) { try {broadcast(MapMessage.MSG_STOP,false); }catch ( Exception ignore){} //cleanup this.channel.removeChannelListener(this); this.channel.removeMembershipListener(this); } this.rpcChannel = null; this.channel = null; this.mapMembers.clear(); innerMap.clear(); this.stateTransferred = false; this.externalLoaders = null; }
if ( !entry.isBackup() ) { msg = new MapMessage(getMapContextName(), MapMessage.MSG_RETRIEVE_BACKUP, false, (Serializable) key, null, null, null,null); Response[] resp = getRpcChannel().send(entry.getBackupNodes(),msg, this.getRpcChannel().FIRST_REPLY, Channel.SEND_OPTIONS_DEFAULT, getRpcTimeout()); if (resp == null || resp.length == 0) { msg.deserialize(getExternalLoaders()); backup = entry.getBackupNodes(); if ( entry.getValue() instanceof ReplicatedMapEntry ) { ReplicatedMapEntry val = (ReplicatedMapEntry)entry.getValue(); val.setOwner(getMapOwner()); backup = publishEntryInfo(key, entry.getValue()); } else if ( entry.isProxy() ) { msg = new MapMessage(getMapContextName(),MapMessage.MSG_PROXY,false,(Serializable)key,null,null,channel.getLocalMember(false),backup); Member[] dest = getMapMembersExcl(backup); if ( dest!=null && dest.length >0) { getChannel().send(dest, msg, getChannelSendOptions()); val.setOwner(getMapOwner()); entry.setBackup(false); entry.setProxy(false); if ( getMapOwner()!=null ) getMapOwner().objectMadePrimay(key, entry.getValue());
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 } } else { log.warn("Transfer state, 0 replies, probably a timeout."); } } } catch (ChannelException x) { log.error("Unable to transfer LazyReplicatedMap state.", x); } catch (IOException x) { log.error("Unable to transfer LazyReplicatedMap state.", x); } catch (ClassNotFoundException x) { log.error("Unable to transfer LazyReplicatedMap state.", x); } stateTransferred = true; }
mapmsg.deserialize(getExternalLoaders()); } catch (IOException x) { log.error("Unable to deserialize MapMessage.", x); log.trace("Map message received from:"+sender.getName()+" msg:"+mapmsg); if (mapmsg.getMsgType() == MapMessage.MSG_START) { mapMemberAdded(mapmsg.getPrimary()); memberDisappeared(mapmsg.getPrimary()); entry.setPrimary(mapmsg.getPrimary()); if (mapmsg.getValue()!=null && mapmsg.getValue() instanceof ReplicatedMapEntry ) { ((ReplicatedMapEntry)mapmsg.getValue()).setOwner(getMapOwner()); ((ReplicatedMapEntry)entry.getValue()).setOwner(getMapOwner()); re.setOwner(getMapOwner()); entry.setValue((V) re); } else {
public Object put(Object key, Object value, boolean notify) { MapEntry entry = new MapEntry(key,value); entry.setBackup(false); entry.setProxy(false); entry.setPrimary(channel.getLocalMember(false)); Object old = null; //make sure that any old values get removed if ( containsKey(key) ) old = remove(key); try { if ( notify ) { Member[] backup = publishEntryInfo(key, value); entry.setBackupNodes(backup); } } catch (ChannelException x) { log.error("Unable to replicate out data for a LazyReplicatedMap.put operation", x); } super.put(key,entry); return old; }
/** * If the reply has already been sent to the requesting thread, * the rpc callback can handle any data that comes in after the fact. * @param msg Serializable * @param sender Member */ @Override public void leftOver(Serializable msg, Member sender) { //left over membership messages if (! (msg instanceof MapMessage))return; MapMessage mapmsg = (MapMessage) msg; try { mapmsg.deserialize(getExternalLoaders()); if (mapmsg.getMsgType() == MapMessage.MSG_START) { mapMemberAdded(mapmsg.getPrimary()); } else if (mapmsg.getMsgType() == MapMessage.MSG_INIT) { memberAlive(mapmsg.getPrimary()); } } catch (IOException x ) { log.error("Unable to deserialize MapMessage.",x); } catch (ClassNotFoundException x ) { log.error("Unable to deserialize MapMessage.",x); } }
public Member getNextBackupNode() { Member[] members = getMapMembers(); int node = getNextBackupIndex(); if ( members.length == 0 || node==-1) return null; if ( node >= members.length ) node = 0; return members[node]; }