/** * send a cluster message to one member * * @param msg message to transfer * @param dest Receiver member * @see org.apache.catalina.ha.CatalinaCluster#send(org.apache.catalina.ha.ClusterMessage, * org.apache.catalina.tribes.Member) */ @Override public void send(ClusterMessage msg, Member dest) { try { msg.setAddress(getLocalMember()); int sendOptions = channelSendOptions; if (msg instanceof SessionMessage && ((SessionMessage)msg).getEventType() == SessionMessage.EVT_ALL_SESSION_DATA) { sendOptions = Channel.SEND_OPTIONS_SYNCHRONIZED_ACK|Channel.SEND_OPTIONS_USE_ACK; } if (dest != null) { if (!getLocalMember().equals(dest)) { channel.send(new Member[] {dest}, msg, sendOptions); } else log.error("Unable to send message to local member " + msg); } else { Member[] destmembers = channel.getMembers(); if (destmembers.length>0) channel.send(destmembers,msg, sendOptions); else if (log.isDebugEnabled()) log.debug("No members in cluster, ignoring message:"+msg); } } catch (Exception x) { log.error("Unable to send message through cluster sender.", x); } }
/** * send a cluster message to one member * * @param msg * message to transfer * @param dest * Receiver member * @see org.apache.catalina.ha.CatalinaCluster#send(org.apache.catalina.ha.ClusterMessage, * org.apache.catalina.tribes.Member) */ @Override public void send(ClusterMessage msg, Member dest) { try { msg.setAddress(getLocalMember()); int sendOptions = channelSendOptions; if (msg instanceof SessionMessage && ((SessionMessage) msg).getEventType() == SessionMessage.EVT_ALL_SESSION_DATA) { sendOptions = Channel.SEND_OPTIONS_SYNCHRONIZED_ACK | Channel.SEND_OPTIONS_USE_ACK; } if (dest != null) { if (!getLocalMember().equals(dest)) { channel.send(new Member[] { dest }, msg, sendOptions); } else log.error("Unable to send message to local member " + msg); } else { Member[] destmembers = channel.getMembers(); if (destmembers.length > 0) channel.send(destmembers, msg, sendOptions); else if (log.isDebugEnabled()) log.debug("No members in cluster, ignoring message:" + msg); } } catch (Exception x) { log.error("Unable to send message through cluster sender.", x); } }
/** * send a cluster message to one member * * @param msg message to transfer * @param dest Receiver member * @see org.apache.catalina.ha.CatalinaCluster#send(org.apache.catalina.ha.ClusterMessage, * org.apache.catalina.tribes.Member) */ @Override public void send(ClusterMessage msg, Member dest) { try { msg.setAddress(getLocalMember()); if (dest != null) { if (!getLocalMember().equals(dest)) { channel.send(new Member[] {dest}, msg,channelSendOptions); } else log.error("Unable to send message to local member " + msg); } else { Member[] destmembers = channel.getMembers(); if (destmembers.length>0) channel.send(destmembers,msg,channelSendOptions); else if (log.isDebugEnabled()) log.debug("No members in cluster, ignoring message:"+msg); } } catch (Exception x) { log.error("Unable to send message through cluster sender.", x); } }
@Override public ClusterMessage requestCompleted(String sessionId) { if (!getState().isAvailable()) return null; LazyReplicatedMap<String,Session> map = (LazyReplicatedMap<String,Session>)sessions; map.replicate(sessionId,false); return null; }
/** * A message was received from another node, this is the callback method to * implement if you are interested in receiving replication messages. * * @param cmsg - * the message received. */ @Override public void messageDataReceived(ClusterMessage cmsg) { if (cmsg != null && cmsg instanceof SessionMessage) { SessionMessage msg = (SessionMessage) cmsg; switch (msg.getEventType()) { case SessionMessage.EVT_GET_ALL_SESSIONS: case SessionMessage.EVT_SESSION_CREATED: case SessionMessage.EVT_SESSION_EXPIRED: case SessionMessage.EVT_SESSION_ACCESSED: case SessionMessage.EVT_SESSION_DELTA: case SessionMessage.EVT_CHANGE_SESSION_ID: { synchronized(receivedMessageQueue) { if(receiverQueue) { receivedMessageQueue.add(msg); return ; } } break; } default: { //we didn't queue, do nothing break; } } //switch messageReceived(msg, msg.getAddress() != null ? (Member) msg.getAddress() : null); } }
/** * send manager requestCompleted message to cluster * @param manager SessionManager * @param cluster replication cluster * @param sessionId sessionid from the manager * @see DeltaManager#requestCompleted(String) * @see SimpleTcpCluster#send(ClusterMessage) */ protected void send(ClusterManager manager, CatalinaCluster cluster, String sessionId) { ClusterMessage msg = manager.requestCompleted(sessionId); if (msg != null) { cluster.send(msg); if(doStatistics()) nrOfSendRequests++; } }
public void messageReceived(ClusterMessage message) { if (log.isDebugEnabled() && message != null) log.debug("Assuming clocks are synched: Replication for " + message.getUniqueId() + " took=" + (System.currentTimeMillis() - (message).getTimestamp()) + " ms."); //invoke all the listeners boolean accepted = false; if (message != null) { for (Iterator<ClusterListener> iter = clusterListeners.iterator(); iter.hasNext();) { ClusterListener listener = iter.next(); if (listener.accept(message)) { accepted = true; listener.messageReceived(message); } } if (!accepted && notifyLifecycleListenerOnFailure) { Member dest = message.getAddress(); // Notify our interested LifecycleListeners fireLifecycleEvent(RECEIVE_MESSAGE_FAILURE_EVENT, new SendMessageData(message, dest, null)); if (log.isDebugEnabled()) { log.debug("Message " + message.toString() + " from type " + message.getClass().getName() + " transfered but no listener registered"); } } } return; }
@Override public ClusterMessage requestCompleted(String sessionId) { if (!getState().isAvailable()) return null; LazyReplicatedMap<String, Session> map = (LazyReplicatedMap<String, Session>) sessions; map.replicate(sessionId, false); return null; }
/** * A message was received from another node, this is the callback method to * implement if you are interested in receiving replication messages. * * @param cmsg * - the message received. */ @Override public void messageDataReceived(ClusterMessage cmsg) { if (cmsg != null && cmsg instanceof SessionMessage) { SessionMessage msg = (SessionMessage) cmsg; switch (msg.getEventType()) { case SessionMessage.EVT_GET_ALL_SESSIONS: case SessionMessage.EVT_SESSION_CREATED: case SessionMessage.EVT_SESSION_EXPIRED: case SessionMessage.EVT_SESSION_ACCESSED: case SessionMessage.EVT_SESSION_DELTA: case SessionMessage.EVT_CHANGE_SESSION_ID: { synchronized (receivedMessageQueue) { if (receiverQueue) { receivedMessageQueue.add(msg); return; } } break; } default: { // we didn't queue, do nothing break; } } // switch messageReceived(msg, msg.getAddress() != null ? (Member) msg.getAddress() : null); } }
/** * Callback from the cluster, when a message is received, The cluster will * broadcast it invoking the messageReceived on the receiver. * * @param msg * ClusterMessage - the message received from the cluster */ @Override public void messageReceived(ClusterMessage msg) { if (msg instanceof SessionIDMessage) { SessionIDMessage sessionmsg = (SessionIDMessage) msg; if (log.isDebugEnabled()) log.debug(sm.getString("jvmRoute.receiveMessage.sessionIDChanged", sessionmsg.getOrignalSessionID(), sessionmsg.getBackupSessionID(), sessionmsg.getContextName())); Container container = getCluster().getContainer(); Container host = null; if (container instanceof Engine) { host = container.findChild(sessionmsg.getHost()); } else { host = container; } if (host != null) { Context context = (Context) host.findChild(sessionmsg.getContextName()); if (context != null) { try { Session session = context.getManager().findSession(sessionmsg.getOrignalSessionID()); if (session != null) { session.setId(sessionmsg.getBackupSessionID()); } else if (log.isInfoEnabled()) log.info(sm.getString("jvmRoute.lostSession", sessionmsg.getOrignalSessionID(), sessionmsg.getContextName())); } catch (IOException e) { log.error(e); } } else if (log.isErrorEnabled()) log.error(sm.getString("jvmRoute.contextNotFound", sessionmsg.getContextName(), ((StandardEngine) host.getParent()).getJvmRoute())); } else if (log.isErrorEnabled()) log.error(sm.getString("jvmRoute.hostNotFound", sessionmsg.getContextName())); } return; }
public void messageReceived(ClusterMessage message) { if (log.isDebugEnabled() && message != null) log.debug("Assuming clocks are synched: Replication for " + message.getUniqueId() + " took=" + (System.currentTimeMillis() - (message).getTimestamp()) + " ms."); // invoke all the listeners boolean accepted = false; if (message != null) { for (Iterator<ClusterListener> iter = clusterListeners.iterator(); iter.hasNext();) { ClusterListener listener = iter.next(); if (listener.accept(message)) { accepted = true; listener.messageReceived(message); } } if (!accepted && notifyLifecycleListenerOnFailure) { Member dest = message.getAddress(); // Notify our interested LifecycleListeners fireLifecycleEvent(RECEIVE_MESSAGE_FAILURE_EVENT, new SendMessageData(message, dest, null)); if (log.isDebugEnabled()) { log.debug("Message " + message.toString() + " from type " + message.getClass().getName() + " transfered but no listener registered"); } } } return; }
@Override public ClusterMessage requestCompleted(String sessionId) { if (!getState().isAvailable()) return null; LazyReplicatedMap map = (LazyReplicatedMap)sessions; map.replicate(sessionId,false); return null; }
public void expire(boolean notify, boolean notifyCluster) { if (expiring) return; String expiredId = getIdInternal(); if(notifyCluster && expiredId != null && manager != null && manager instanceof DeltaManager) { DeltaManager dmanager = (DeltaManager)manager; CatalinaCluster cluster = dmanager.getCluster(); ClusterMessage msg = dmanager.requestCompleted(expiredId, true); if (msg != null) { cluster.send(msg); } } super.expire(notify); if (notifyCluster) { if (log.isDebugEnabled()) log.debug(sm.getString("deltaSession.notifying", ((ClusterManager)manager).getName(), Boolean.valueOf(isPrimarySession()), expiredId)); if ( manager instanceof DeltaManager ) { ( (DeltaManager) manager).sessionExpired(expiredId); } } }
/** * Callback from the cluster, when a message is received, The cluster will * broadcast it invoking the messageReceived on the receiver. * * @param myobj * ClusterMessage - the message received from the cluster */ @Override public void messageReceived(ClusterMessage myobj) { if (myobj != null && myobj instanceof SessionMessage) { SessionMessage msg = (SessionMessage) myobj; String ctxname = msg.getContextName(); //check if the message is a EVT_GET_ALL_SESSIONS, //if so, wait until we are fully started up Map<String,ClusterManager> managers = cluster.getManagers() ; if (ctxname == null) { for (Map.Entry<String, ClusterManager> entry : managers.entrySet()) { if (entry.getValue() != null) entry.getValue().messageDataReceived(msg); else { //this happens a lot before the system has started // up if (log.isDebugEnabled()) log.debug("Context manager doesn't exist:" + entry.getKey()); } } } else { ClusterManager mgr = managers.get(ctxname); if (mgr != null) mgr.messageDataReceived(msg); else if (log.isWarnEnabled()) log.warn("Context manager doesn't exist:" + ctxname); } } return; }
private void send(final ClusterMessage message, final AppInfo app) { for (final CatalinaCluster cluster : clusters) { final String path = app.path; if (new File(path).exists() && !app.autoDeploy) { cluster.send(message); } } }
public void expire(boolean notify, boolean notifyCluster) { // Check to see if session has already been invalidated. // Do not check expiring at this point as expire should not return until // isValid is false if (!isValid) return; synchronized (this) { // Check again, now we are inside the sync so this code only runs once // Double check locking - isValid needs to be volatile if (!isValid) return; if (manager == null) return; String expiredId = getIdInternal(); if(notifyCluster && expiredId != null && manager instanceof DeltaManager) { DeltaManager dmanager = (DeltaManager)manager; CatalinaCluster cluster = dmanager.getCluster(); ClusterMessage msg = dmanager.requestCompleted(expiredId, true); if (msg != null) { cluster.send(msg); } } super.expire(notify); if (notifyCluster) { if (log.isDebugEnabled()) log.debug(sm.getString("deltaSession.notifying", ((ClusterManager)manager).getName(), Boolean.valueOf(isPrimarySession()), expiredId)); if ( manager instanceof DeltaManager ) { ( (DeltaManager) manager).sessionExpired(expiredId); } } } }
@Override public void messageDataReceived(ClusterMessage msg) { }