org.apache.catalina.ha.ClusterManager Java Examples
The following examples show how to use
org.apache.catalina.ha.ClusterManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DeltaSession.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * Applies a diff to an existing object. * @param diff Serialized diff data * @param offset Array offset * @param length Array length * @throws IOException IO error deserializing */ @Override public void applyDiff(byte[] diff, int offset, int length) throws IOException, ClassNotFoundException { lockInternal(); try (ObjectInputStream stream = ((ClusterManager) getManager()).getReplicationStream(diff, offset, length)) { ClassLoader contextLoader = Thread.currentThread().getContextClassLoader(); try { ClassLoader[] loaders = getClassLoaders(); if (loaders != null && loaders.length > 0) Thread.currentThread().setContextClassLoader(loaders[0]); getDeltaRequest().readExternal(stream); getDeltaRequest().execute(this, ((ClusterManager)getManager()).isNotifyListenersOnReplication()); } finally { Thread.currentThread().setContextClassLoader(contextLoader); } } finally { unlockInternal(); } }
Example #2
Source File: ReplicationValve.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Send all changed cross context sessions to backups * @param containerCluster */ protected void sendCrossContextSession(CatalinaCluster containerCluster) { List<DeltaSession> sessions = crossContextSessions.get(); if(sessions != null && sessions.size() >0) { for(Iterator<DeltaSession> iter = sessions.iterator(); iter.hasNext() ;) { Session session = iter.next(); if(log.isDebugEnabled()) log.debug(sm.getString("ReplicationValve.crossContext.sendDelta", session.getManager().getContainer().getName() )); sendMessage(session,(ClusterManager)session.getManager(),containerCluster); if(doStatistics()) { nrOfCrossContextSendRequests++; } } } }
Example #3
Source File: ReplicationValve.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * @param request * @param totalstart * @param isCrossContext * @param clusterManager * @param containerCluster */ protected void sendReplicationMessage(Request request, long totalstart, boolean isCrossContext, ClusterManager clusterManager, CatalinaCluster containerCluster) { //this happens after the request long start = 0; if(doStatistics()) { start = System.currentTimeMillis(); } try { // send invalid sessions // DeltaManager returns String[0] if (!(clusterManager instanceof DeltaManager)) sendInvalidSessions(clusterManager, containerCluster); // send replication sendSessionReplicationMessage(request, clusterManager, containerCluster); if(isCrossContext) sendCrossContextSession(containerCluster); } catch (Exception x) { // FIXME we have a lot of sends, but the trouble with one node stops the correct replication to other nodes! log.error(sm.getString("ReplicationValve.send.failure"), x); } finally { // FIXME this stats update are not cheap!! if(doStatistics()) { updateStats(totalstart,start); } } }
Example #4
Source File: ReplicationValve.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Send Cluster Replication Request * @param request current request * @param manager session manager * @param cluster replication cluster */ protected void sendSessionReplicationMessage(Request request, ClusterManager manager, CatalinaCluster cluster) { Session session = request.getSessionInternal(false); if (session != null) { String uri = request.getDecodedRequestURI(); // request without session change if (!isRequestWithoutSessionChange(uri)) { if (log.isDebugEnabled()) log.debug(sm.getString("ReplicationValve.invoke.uri", uri)); sendMessage(session,manager,cluster); } else if(doStatistics()) nrOfFilterRequests++; } }
Example #5
Source File: JvmRouteBinderValve.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Detect possible the JVMRoute change at cluster backup node.. * * @param request * tomcat request being processed * @param response * tomcat response being processed * @exception IOException * if an input/output error has occurred * @exception ServletException * if a servlet error has occurred */ @Override public void invoke(Request request, Response response) throws IOException, ServletException { if (getEnabled() && request.getContext() != null && request.getContext().getDistributable() && !request.isAsyncDispatching()) { // valve cluster can access manager - other cluster handle turnover // at host level - hopefully! Manager manager = request.getContext().getManager(); if (manager != null && ( (manager instanceof ClusterManager && getCluster() != null && getCluster().getManager(((ClusterManager)manager).getName()) != null) || (manager instanceof PersistentManager))) handlePossibleTurnover(request); } // Pass this request on to the next valve in our pipeline getNext().invoke(request, response); }
Example #6
Source File: SimpleTcpCluster.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Create new Manager without add to cluster (comes with start the manager) * * @param name * Context Name of this manager * @see org.apache.catalina.Cluster#createManager(java.lang.String) * @see DeltaManager#start() */ @Override public synchronized Manager createManager(String name) { if (log.isDebugEnabled()) { log.debug("Creating ClusterManager for context " + name + " using class " + getManagerTemplate().getClass().getName()); } ClusterManager manager = null; try { manager = managerTemplate.cloneFromTemplate(); manager.setName(name); } catch (Exception x) { log.error("Unable to clone cluster manager, defaulting to org.apache.catalina.ha.session.DeltaManager", x); manager = new org.apache.catalina.ha.session.DeltaManager(); } finally { if ( manager != null) manager.setCluster(this); } return manager; }
Example #7
Source File: SimpleTcpCluster.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Override public void registerManager(Manager manager) { if (! (manager instanceof ClusterManager)) { log.warn("Manager [ " + manager + "] does not implement ClusterManager, addition to cluster has been aborted."); return; } ClusterManager cmanager = (ClusterManager) manager ; cmanager.setDistributable(true); // Notify our interested LifecycleListeners fireLifecycleEvent(BEFORE_MANAGERREGISTER_EVENT, manager); String clusterName = getManagerName(cmanager.getName(), manager); cmanager.setName(clusterName); cmanager.setCluster(this); managers.put(clusterName, cmanager); // Notify our interested LifecycleListeners fireLifecycleEvent(AFTER_MANAGERREGISTER_EVENT, manager); }
Example #8
Source File: DeltaSession.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Applies a diff to an existing object. * @param diff byte[] * @param offset int * @param length int * @throws IOException */ @Override public void applyDiff(byte[] diff, int offset, int length) throws IOException, ClassNotFoundException { try { lock(); ReplicationStream stream = ( (ClusterManager) getManager()).getReplicationStream(diff, offset, length); ClassLoader contextLoader = Thread.currentThread().getContextClassLoader(); try { ClassLoader[] loaders = getClassLoaders(); if (loaders != null && loaders.length > 0) Thread.currentThread().setContextClassLoader(loaders[0]); getDeltaRequest().readExternal(stream); getDeltaRequest().execute(this, ((ClusterManager)getManager()).isNotifyListenersOnReplication()); stream.close(); } finally { Thread.currentThread().setContextClassLoader(contextLoader); } }finally { unlock(); } }
Example #9
Source File: DeltaSession.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Applies a diff to an existing object. * @param diff byte[] * @param offset int * @param length int * @throws IOException */ @Override public void applyDiff(byte[] diff, int offset, int length) throws IOException, ClassNotFoundException { try { lock(); ReplicationStream stream = ( (ClusterManager) getManager()).getReplicationStream(diff, offset, length); ClassLoader contextLoader = Thread.currentThread().getContextClassLoader(); try { ClassLoader[] loaders = getClassLoaders(); if (loaders != null && loaders.length > 0) Thread.currentThread().setContextClassLoader(loaders[0]); getDeltaRequest().readExternal(stream); getDeltaRequest().execute(this, ((ClusterManager)getManager()).isNotifyListenersOnReplication()); stream.close(); } finally { Thread.currentThread().setContextClassLoader(contextLoader); } }finally { unlock(); } }
Example #10
Source File: SimpleTcpCluster.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override public void registerManager(Manager manager) { if (! (manager instanceof ClusterManager)) { log.warn(sm.getString("simpleTcpCluster.clustermanager.notImplement", manager)); return; } ClusterManager cmanager = (ClusterManager) manager; // Notify our interested LifecycleListeners fireLifecycleEvent(BEFORE_MANAGERREGISTER_EVENT, manager); String clusterName = getManagerName(cmanager.getName(), manager); cmanager.setName(clusterName); cmanager.setCluster(this); managers.put(clusterName, cmanager); // Notify our interested LifecycleListeners fireLifecycleEvent(AFTER_MANAGERREGISTER_EVENT, manager); }
Example #11
Source File: SimpleTcpCluster.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * Create new Manager without add to cluster (comes with start the manager) * * @param name * Context Name of this manager * @see org.apache.catalina.Cluster#createManager(java.lang.String) * @see DeltaManager#start() */ @Override public synchronized Manager createManager(String name) { if (log.isDebugEnabled()) { log.debug("Creating ClusterManager for context " + name + " using class " + getManagerTemplate().getClass().getName()); } ClusterManager manager = null; try { manager = managerTemplate.cloneFromTemplate(); manager.setName(name); } catch (Exception x) { log.error(sm.getString("simpleTcpCluster.clustermanager.cloneFailed"), x); manager = new org.apache.catalina.ha.session.DeltaManager(); } finally { if ( manager != null) manager.setCluster(this); } return manager; }
Example #12
Source File: JvmRouteBinderValve.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Detect possible the JVMRoute change at cluster backup node.. * * @param request * tomcat request being processed * @param response * tomcat response being processed * @exception IOException * if an input/output error has occurred * @exception ServletException * if a servlet error has occurred */ @Override public void invoke(Request request, Response response) throws IOException, ServletException { if (getEnabled() && request.getContext() != null && request.getContext().getDistributable() && !request.isAsyncDispatching()) { // valve cluster can access manager - other cluster handle turnover // at host level - hopefully! Manager manager = request.getContext().getManager(); if (manager != null && ( (manager instanceof ClusterManager && getCluster() != null && getCluster().getManager(((ClusterManager)manager).getName()) != null) || (manager instanceof PersistentManager))) handlePossibleTurnover(request); } // Pass this request on to the next valve in our pipeline getNext().invoke(request, response); }
Example #13
Source File: ReplicationValve.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Send all changed cross context sessions to backups * @param containerCluster */ protected void sendCrossContextSession(CatalinaCluster containerCluster) { List<DeltaSession> sessions = crossContextSessions.get(); if(sessions != null && sessions.size() >0) { for(Iterator<DeltaSession> iter = sessions.iterator(); iter.hasNext() ;) { Session session = iter.next(); if(log.isDebugEnabled()) log.debug(sm.getString("ReplicationValve.crossContext.sendDelta", session.getManager().getContainer().getName() )); sendMessage(session,(ClusterManager)session.getManager(),containerCluster); if(doStatistics()) { nrOfCrossContextSendRequests++; } } } }
Example #14
Source File: SimpleTcpCluster.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Override public void registerManager(Manager manager) { if (! (manager instanceof ClusterManager)) { log.warn("Manager [ " + manager + "] does not implement ClusterManager, addition to cluster has been aborted."); return; } ClusterManager cmanager = (ClusterManager) manager; // Notify our interested LifecycleListeners fireLifecycleEvent(BEFORE_MANAGERREGISTER_EVENT, manager); String clusterName = getManagerName(cmanager.getName(), manager); cmanager.setName(clusterName); cmanager.setCluster(this); managers.put(clusterName, cmanager); // Notify our interested LifecycleListeners fireLifecycleEvent(AFTER_MANAGERREGISTER_EVENT, manager); }
Example #15
Source File: SimpleTcpCluster.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Create new Manager without add to cluster (comes with start the manager) * * @param name * Context Name of this manager * @see org.apache.catalina.Cluster#createManager(java.lang.String) * @see DeltaManager#start() */ @Override public synchronized Manager createManager(String name) { if (log.isDebugEnabled()) { log.debug("Creating ClusterManager for context " + name + " using class " + getManagerTemplate().getClass().getName()); } ClusterManager manager = null; try { manager = managerTemplate.cloneFromTemplate(); manager.setName(name); } catch (Exception x) { log.error("Unable to clone cluster manager, defaulting to org.apache.catalina.ha.session.DeltaManager", x); manager = new org.apache.catalina.ha.session.DeltaManager(); } finally { if ( manager != null) manager.setCluster(this); } return manager; }
Example #16
Source File: ReplicationValve.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * Send Cluster Replication Request * @param request current request * @param manager session manager */ protected void sendSessionReplicationMessage(Request request, ClusterManager manager) { Session session = request.getSessionInternal(false); if (session != null) { String uri = request.getDecodedRequestURI(); // request without session change if (!isRequestWithoutSessionChange(uri)) { if (log.isDebugEnabled()) { log.debug(sm.getString("ReplicationValve.invoke.uri", uri)); } sendMessage(session,manager); } else if(doStatistics()) { nrOfFilterRequests++; } } }
Example #17
Source File: ReplicationValve.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * Send all changed cross context sessions to backups */ protected void sendCrossContextSession() { List<DeltaSession> sessions = crossContextSessions.get(); if(sessions != null && sessions.size() >0) { for (DeltaSession session : sessions) { if(log.isDebugEnabled()) { log.debug(sm.getString("ReplicationValve.crossContext.sendDelta", session.getManager().getContext().getName() )); } sendMessage(session,(ClusterManager)session.getManager()); if(doStatistics()) { nrOfCrossContextSendRequests++; } } } }
Example #18
Source File: ReplicationValve.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Send Cluster Replication Request * @param request current request * @param manager session manager * @param cluster replication cluster */ protected void sendSessionReplicationMessage(Request request, ClusterManager manager, CatalinaCluster cluster) { Session session = request.getSessionInternal(false); if (session != null) { String uri = request.getDecodedRequestURI(); // request without session change if (!isRequestWithoutSessionChange(uri)) { if (log.isDebugEnabled()) log.debug(sm.getString("ReplicationValve.invoke.uri", uri)); sendMessage(session,manager,cluster); } else if(doStatistics()) nrOfFilterRequests++; } }
Example #19
Source File: ReplicationValve.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * @param request * @param totalstart * @param isCrossContext * @param clusterManager * @param containerCluster */ protected void sendReplicationMessage(Request request, long totalstart, boolean isCrossContext, ClusterManager clusterManager, CatalinaCluster containerCluster) { //this happens after the request long start = 0; if(doStatistics()) { start = System.currentTimeMillis(); } try { // send invalid sessions // DeltaManager returns String[0] if (!(clusterManager instanceof DeltaManager)) sendInvalidSessions(clusterManager, containerCluster); // send replication sendSessionReplicationMessage(request, clusterManager, containerCluster); if(isCrossContext) sendCrossContextSession(containerCluster); } catch (Exception x) { // FIXME we have a lot of sends, but the trouble with one node stops the correct replication to other nodes! log.error(sm.getString("ReplicationValve.send.failure"), x); } finally { // FIXME this stats update are not cheap!! if(doStatistics()) { updateStats(totalstart,start); } } }
Example #20
Source File: JvmRouteBinderValve.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * Detect possible the JVMRoute change at cluster backup node.. * * @param request * tomcat request being processed * @param response * tomcat response being processed * @exception IOException * if an input/output error has occurred * @exception ServletException * if a servlet error has occurred */ @Override public void invoke(Request request, Response response) throws IOException, ServletException { if (getEnabled() && request.getContext() != null && request.getContext().getDistributable() && !request.isAsyncDispatching()) { // valve cluster can access manager - other cluster handle turnover // at host level - hopefully! Manager manager = request.getContext().getManager(); if (manager != null && ( (manager instanceof ClusterManager && getCluster() != null && getCluster().getManager(((ClusterManager)manager).getName()) != null) || (manager instanceof PersistentManager))) { handlePossibleTurnover(request); } } // Pass this request on to the next valve in our pipeline getNext().invoke(request, response); }
Example #21
Source File: ReplicationValve.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Send message delta message from request session * @param session current session * @param manager session manager * @param cluster replication cluster */ protected void sendMessage(Session session, ClusterManager manager, CatalinaCluster cluster) { String id = session.getIdInternal(); if (id != null) { send(manager, cluster, id); } }
Example #22
Source File: SimpleTcpCluster.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Remove an application from cluster replication bus. * * @see org.apache.catalina.Cluster#removeManager(Manager) */ @Override public void removeManager(Manager manager) { if (manager != null && manager instanceof ClusterManager ) { ClusterManager cmgr = (ClusterManager) manager; // Notify our interested LifecycleListeners fireLifecycleEvent(BEFORE_MANAGERUNREGISTER_EVENT,manager); managers.remove(getManagerName(cmgr.getName(),manager)); cmgr.setCluster(null); // Notify our interested LifecycleListeners fireLifecycleEvent(AFTER_MANAGERUNREGISTER_EVENT, manager); } }
Example #23
Source File: ReplicationValve.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Send message delta message from request session * @param session current session * @param manager session manager * @param cluster replication cluster */ protected void sendMessage(Session session, ClusterManager manager, CatalinaCluster cluster) { String id = session.getIdInternal(); if (id != null) { send(manager, cluster, id); } }
Example #24
Source File: ReplicationValve.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * 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++; } }
Example #25
Source File: ReplicationValve.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * check for session invalidations * @param manager * @param cluster */ protected void sendInvalidSessions(ClusterManager manager, CatalinaCluster cluster) { String[] invalidIds=manager.getInvalidatedSessions(); if ( invalidIds.length > 0 ) { for ( int i=0;i<invalidIds.length; i++ ) { try { send(manager,cluster,invalidIds[i]); } catch ( Exception x ) { log.error(sm.getString("ReplicationValve.send.invalid.failure",invalidIds[i]),x); } } } }
Example #26
Source File: ReplicationValve.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * check for session invalidations * @param manager * @param cluster */ protected void sendInvalidSessions(ClusterManager manager, CatalinaCluster cluster) { String[] invalidIds=manager.getInvalidatedSessions(); if ( invalidIds.length > 0 ) { for ( int i=0;i<invalidIds.length; i++ ) { try { send(manager,cluster,invalidIds[i]); } catch ( Exception x ) { log.error(sm.getString("ReplicationValve.send.invalid.failure",invalidIds[i]),x); } } } }
Example #27
Source File: ReplicationValve.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * 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++; } }
Example #28
Source File: SimpleTcpCluster.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Remove an application from cluster replication bus. * * @see org.apache.catalina.Cluster#removeManager(Manager) */ @Override public void removeManager(Manager manager) { if (manager != null && manager instanceof ClusterManager ) { ClusterManager cmgr = (ClusterManager) manager; // Notify our interested LifecycleListeners fireLifecycleEvent(BEFORE_MANAGERUNREGISTER_EVENT,manager); managers.remove(getManagerName(cmgr.getName(),manager)); cmgr.setCluster(null); // Notify our interested LifecycleListeners fireLifecycleEvent(AFTER_MANAGERUNREGISTER_EVENT, manager); } }
Example #29
Source File: DeltaSession.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Override public void setOwner(Object owner) { if ( owner instanceof ClusterManager && getManager()==null) { ClusterManager cm = (ClusterManager)owner; this.setManager(cm); this.setValid(true); this.setPrimarySession(false); this.access(); this.resetDeltaRequest(); this.endAccess(); } }
Example #30
Source File: BackupManager.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Override public ClusterManager cloneFromTemplate() { BackupManager result = new BackupManager(); clone(result); result.mExpireSessionsOnShutdown = mExpireSessionsOnShutdown; result.mapSendOptions = mapSendOptions; result.rpcTimeout = rpcTimeout; result.terminateOnStartFailure = terminateOnStartFailure; return result; }