public void addToCache( final String componentName, final String memberTokenId, final Serializable key, final Serializable state) throws GMSException { if (logger.isLoggable(Level.FINER)) { logger.log(Level.FINER, "Adding to DSC by local Member:" + memberTokenId + ",Component:" + componentName + ",key:" + key + ",State:" + state); } final GMSCacheable cKey = createCompositeKey(componentName, memberTokenId, key); addToLocalCache(cKey, state); addToRemoteCache(cKey, state); }
private void printDSCContents() { if (logger.isLoggable(FINER)) { logger.log(FINER, getGMSContext().getServerIdentityToken() + ":DSC now contains ---------\n" + getDSCContents()); } }
public void removeAllForMember(final String memberToken) { final Set<GMSCacheable> keys = getFromCache(memberToken).keySet(); for (final GMSCacheable key : keys) { removeFromLocalCache(key); } } }
public void addToLocalCache(final String componentName, final String memberTokenId, final Serializable key, final byte[] state) { final GMSCacheable cKey = createCompositeKey(componentName, memberTokenId, key); addToLocalCache(cKey, state); }
public void removeFromCache(final String componentName, final String memberTokenId, final Serializable key) throws GMSException { final GMSCacheable cKey = createCompositeKey(componentName, memberTokenId, key); removeFromLocalCache(cKey); removeFromRemoteCache(cKey); }
retval.putAll(getEntryFromCacheForPattern(componentName, memberToken)); final String thisMember = getGMSContext().getServerIdentityToken(); String remoteDSCMemberToken = memberToken; List<String> currentMembers = getGMSContext().getGroupHandle().getAllCurrentMembers(); remoteDSCMemberToken = getOldestCurrentMember(thisMember); if (logger.isLoggable(Level.FINE)) { logger.log(Level.FINE, "getFromCacheForPattern componentName:" + componentName + " memberToken:" + memberToken + if (!getGMSContext().isShuttingDown()) { ConcurrentHashMap<GMSCacheable, Object> temp = new ConcurrentHashMap<GMSCacheable, Object>(cache); DSCMessage msg = new DSCMessage(temp, DSCMessage.OPERATION.ADDALLLOCAL.toString(), true); try { boolean sent = sendMessage( remoteDSCMemberToken, msg); if (sent) { final long MAX_WAIT = 6000; while (retval.isEmpty() && System.currentTimeMillis() < stopTime) { waitForCacheUpdate(WAIT_INTERVAL); retval.putAll(getEntryFromCacheForPattern(componentName, memberToken)); "getFromCacheForPattern(" + componentName + "," + memberToken + ")" + ": returning empty map. " + "reason: isShuttingDown()=" + getGMSContext().isShuttingDown() + " isCurrentMember=" + getGMSContext().getGroupHandle().getAllCurrentMembers().contains(memberToken));
DSCLogger.log(Level.FINE, "Adding Message: " + dMsg.getKey() + ":" + dMsg.getValue()); dsc.addToLocalCache(dMsg.getKey(), dMsg.getValue()); } else if (ops.equals(DSCMessage.OPERATION.REMOVE.toString())) { if (DSCLogger.isLoggable(Level.FINE)) { DSCLogger.log(Level.FINE, "Removing Values with Key: " + dMsg.getKey()); dsc.removeFromLocalCache(dMsg.getKey()); } else if (ops.equals(DSCMessage.OPERATION.ADDALLLOCAL.toString())) { if (dMsg.isCoordinator()) { try { DSCLogger.log(Level.FINE, "Syncing local cache with group ..."); dsc.addAllToRemoteCache(); DSCLogger.log(Level.FINE, "done with local to group sync..."); } catch (GMSException e) { DSCLogger.log(Level.FINE, "adding group cache state to local cache.."); dsc.addAllToLocalCache(dMsg.getCache()); dsc.addAllToLocalCache(dMsg.getCache()); if (DSCLogger.isLoggable(Level.FINE)) { DSCLogger.log(Level.FINE, "Add All Remote from member:" + token + " dsc=" + dsc);
void syncCache(final String memberToken, final boolean isCoordinator) throws GMSException { final ConcurrentHashMap<GMSCacheable, Object> temp; temp = new ConcurrentHashMap<GMSCacheable, Object>(cache); final DSCMessage msg = new DSCMessage(temp, DSCMessage.OPERATION.ADDALLLOCAL.toString(), isCoordinator); if (!memberToken.equals(getGMSContext().getServerIdentityToken())) { if (logger.isLoggable(Level.FINER)) { logger.log(Level.FINER, "Sending sync message from DistributedStateCache to member " + memberToken); } sendMessage(memberToken, msg); } if (isCoordinator) { indicateFirstSyncDone(); } }
public Object getFromCache(final String componentName, final String memberTokenId, final Serializable key) throws GMSException { if (key != null && componentName != null && memberTokenId != null) { GMSCacheable cKey = createCompositeKey(componentName, memberTokenId, key); cKey = getTrueKey(cKey); return cache.get(cKey); } else { //TODO: Localize throw new GMSException( new StringBuffer().append( "DistributedStateCache: ") .append("componentName, memberTokenId and key ") .append("are required parameters and cannot be null") .toString()); } }
void syncCache(final PeerID peerID, final boolean isCoordinator) throws GMSException { final ConcurrentHashMap<GMSCacheable, Object> temp; temp = new ConcurrentHashMap<GMSCacheable, Object>(cache); final DSCMessage msg = new DSCMessage(temp, DSCMessage.OPERATION.ADDALLLOCAL.toString(), isCoordinator); if (!peerID.getInstanceName().equals(getGMSContext().getServerIdentityToken())) { if (logger.isLoggable(Level.FINER)) { logger.log(Level.FINER, "Sending sync message from DistributedStateCache to member " + peerID); } boolean result = ((GroupCommunicationProviderImpl)this.ctxRef.get().getGroupCommunicationProvider()).sendMessage(peerID, msg); if (logger.isLoggable(Level.FINE)) { logger.log(Level.FINE, "synch cache sent result:" + result + " with member:" + peerID.getInstanceName() + " id:" + peerID); } } if (isCoordinator) { indicateFirstSyncDone(); } }
/** * Send <code>msg</code> to <code>member</code>. * * @param member if null, send <code>msg</code> to all members of the group * @param msg * @return boolean <code>true</code> if the message has been sent otherwise * <code>false</code>. <code>false</code>. is commonly returned for * non-error related congestion, meaning that you should be able to send * the message after waiting some amount of time. * @throws com.sun.enterprise.ee.cms.core.GMSException * */ private boolean sendMessage(final String member, final DSCMessage msg) throws GMSException { boolean sent = false; try { getGMSContext().getGroupCommunicationProvider().sendMessage(member, msg, true); sent = true; } catch (MemberNotInViewException e) { if (logger.isLoggable(Level.FINE)){ logger.log(Level.FINE, "Member " + member + " is not in the view anymore. Hence not performing sendMessage operation", e); } } catch (GMSException ge) { logger.log(Level.WARNING, "dsc.send.failed", new Object[]{member, msg}); } return sent; }
@Override public String toString() { return getDSCContents(); }
static DistributedStateCache getInstance(final String groupName) { // NOTE: assumes, that constructing an DistributedStateCacheImpl instance is light weight // and does not introduce any other dependencies (like registering itself somewhere, etc) // is there another instance already with that name? DistributedStateCacheImpl instance = ctxCache.get(groupName); if (instance == null) { // no, there is no one, create a new one then instance = new DistributedStateCacheImpl(groupName); if (logger.isLoggable(Level.FINE)) { logger.log(Level.FINE, "created a DistributedStateCache for group:" + groupName); } // put the new instance to the map, unless another thread won the race and has put its own instance already. // if there is another instance already, use that one instead and discard ours DistributedStateCacheImpl otherInstance = ctxCache.putIfAbsent(groupName, instance); if (otherInstance != null) { instance = otherInstance; } } return instance; }
retval.putAll(getEntryFromCacheForPattern(componentName, memberToken)); final String thisMember = getGMSContext().getServerIdentityToken(); String remoteDSCMemberToken = memberToken; List<String> currentMembers = getGMSContext().getGroupHandle().getAllCurrentMembers(); remoteDSCMemberToken = getOldestCurrentMember(thisMember); if (logger.isLoggable(Level.FINE)) { logger.log(Level.FINE, "getFromCacheForPattern componentName:" + componentName + " memberToken:" + memberToken + if (!getGMSContext().isShuttingDown()) { ConcurrentHashMap<GMSCacheable, Object> temp = new ConcurrentHashMap<GMSCacheable, Object>(cache); DSCMessage msg = new DSCMessage(temp, DSCMessage.OPERATION.ADDALLLOCAL.toString(), true); try { boolean sent = sendMessage( remoteDSCMemberToken, msg); if (sent) { final long MAX_WAIT = 6000; while (retval.isEmpty() && System.currentTimeMillis() < stopTime) { waitForCacheUpdate(WAIT_INTERVAL); retval.putAll(getEntryFromCacheForPattern(componentName, memberToken)); "getFromCacheForPattern(" + componentName + "," + memberToken + ")" + ": returning empty map. " + "reason: isShuttingDown()=" + getGMSContext().isShuttingDown() + " isCurrentMember=" + getGMSContext().getGroupHandle().getAllCurrentMembers().contains(memberToken));
DSCLogger.log(Level.FINE, "Adding Message: " + dMsg.getKey() + ":" + dMsg.getValue()); dsc.addToLocalCache(dMsg.getKey(), dMsg.getValue()); } else if (ops.equals(DSCMessage.OPERATION.REMOVE.toString())) { if (DSCLogger.isLoggable(Level.FINE)) { DSCLogger.log(Level.FINE, "Removing Values with Key: " + dMsg.getKey()); dsc.removeFromLocalCache(dMsg.getKey()); } else if (ops.equals(DSCMessage.OPERATION.ADDALLLOCAL.toString())) { if (dMsg.isCoordinator()) { try { DSCLogger.log(Level.FINE, "Syncing local cache with group ..."); dsc.addAllToRemoteCache(); DSCLogger.log(Level.FINE, "done with local to group sync..."); } catch (GMSException e) { DSCLogger.log(Level.FINE, "adding group cache state to local cache.."); dsc.addAllToLocalCache(dMsg.getCache()); dsc.addAllToLocalCache(dMsg.getCache()); if (DSCLogger.isLoggable(Level.FINE)) { DSCLogger.log(Level.FINE, "Add All Remote from member:" + token + " dsc=" + dsc);
public void removeFromCache(final String componentName, final String memberTokenId, final Serializable key) throws GMSException { final GMSCacheable cKey = createCompositeKey(componentName, memberTokenId, key); removeFromLocalCache(cKey); removeFromRemoteCache(cKey); }
void syncCache(final String memberToken, final boolean isCoordinator) throws GMSException { final ConcurrentHashMap<GMSCacheable, Object> temp; temp = new ConcurrentHashMap<GMSCacheable, Object>(cache); final DSCMessage msg = new DSCMessage(temp, DSCMessage.OPERATION.ADDALLLOCAL.toString(), isCoordinator); if (!memberToken.equals(getGMSContext().getServerIdentityToken())) { if (logger.isLoggable(Level.FINER)) { logger.log(Level.FINER, "Sending sync message from DistributedStateCache to member " + memberToken); } sendMessage(memberToken, msg); } if (isCoordinator) { indicateFirstSyncDone(); } }
public void addToLocalCache(final String componentName, final String memberTokenId, final Serializable key, final Serializable state) { final GMSCacheable cKey = createCompositeKey(componentName, memberTokenId, key); addToLocalCache(cKey, state); }
public Object getFromCache(final String componentName, final String memberTokenId, final Serializable key) throws GMSException { if (key != null && componentName != null && memberTokenId != null) { GMSCacheable cKey = createCompositeKey(componentName, memberTokenId, key); cKey = getTrueKey(cKey); return cache.get(cKey); } else { //TODO: Localize throw new GMSException( new StringBuffer().append( "DistributedStateCache: ") .append("componentName, memberTokenId and key ") .append("are required parameters and cannot be null") .toString()); } }
void syncCache(final PeerID peerID, final boolean isCoordinator) throws GMSException { final ConcurrentHashMap<GMSCacheable, Object> temp; temp = new ConcurrentHashMap<GMSCacheable, Object>(cache); final DSCMessage msg = new DSCMessage(temp, DSCMessage.OPERATION.ADDALLLOCAL.toString(), isCoordinator); if (!peerID.getInstanceName().equals(getGMSContext().getServerIdentityToken())) { if (logger.isLoggable(Level.FINER)) { logger.log(Level.FINER, "Sending sync message from DistributedStateCache to member " + peerID); } boolean result = ((GroupCommunicationProviderImpl)this.ctxRef.get().getGroupCommunicationProvider()).sendMessage(peerID, msg); if (logger.isLoggable(Level.FINE)) { logger.log(Level.FINE, "synch cache sent result:" + result + " with member:" + peerID.getInstanceName() + " id:" + peerID); } } if (isCoordinator) { indicateFirstSyncDone(); } }