org.apache.catalina.ha.CatalinaCluster Java Examples
The following examples show how to use
org.apache.catalina.ha.CatalinaCluster.
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: 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 #2
Source File: TomcatWebAppBuilder.java From tomee with Apache License 2.0 | 6 votes |
private void manageCluster(final Cluster cluster) { if (cluster == null || cluster instanceof SimpleTomEETcpCluster) { return; } Cluster current = cluster; if (cluster instanceof SimpleTcpCluster) { final Container container = cluster.getContainer(); current = new SimpleTomEETcpCluster((SimpleTcpCluster) cluster); container.setCluster(current); } if (current instanceof CatalinaCluster) { final CatalinaCluster haCluster = (CatalinaCluster) current; TomEEClusterListener listener = SystemInstance.get().getComponent(TomEEClusterListener.class); if (listener == null) { listener = new TomEEClusterListener(); SystemInstance.get().setComponent(TomEEClusterListener.class, listener); } haCluster.addClusterListener(listener); // better to be a singleton clusters.add(haCluster); } }
Example #3
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 #4
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 #5
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 #6
Source File: ReplicatedContext.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Start this component and implement the requirements * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}. * * @exception LifecycleException if this component detects a fatal error * that prevents this component from being used */ @Override protected synchronized void startInternal() throws LifecycleException { try { CatalinaCluster catclust = (CatalinaCluster)this.getCluster(); if (this.context == null) this.context = new ReplApplContext(this); if ( catclust != null ) { ReplicatedMap<String,Object> map = new ReplicatedMap<String,Object>(this, catclust.getChannel(),DEFAULT_REPL_TIMEOUT, getName(),getClassLoaders()); map.setChannelSendOptions(mapSendOptions); ((ReplApplContext)this.context).setAttributeMap(map); if (getAltDDName() != null) context.setAttribute(Globals.ALT_DD_ATTR, getAltDDName()); } super.startInternal(); } catch ( Exception x ) { log.error("Unable to start ReplicatedContext",x); throw new LifecycleException("Failed to start ReplicatedContext",x); } }
Example #7
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 #8
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 #9
Source File: ReplicatedContext.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Start this component and implement the requirements * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}. * * @exception LifecycleException if this component detects a fatal error * that prevents this component from being used */ @Override protected synchronized void startInternal() throws LifecycleException { try { CatalinaCluster catclust = (CatalinaCluster)this.getCluster(); if (this.context == null) this.context = new ReplApplContext(this); if ( catclust != null ) { ReplicatedMap<String,Object> map = new ReplicatedMap<String,Object>(this, catclust.getChannel(),DEFAULT_REPL_TIMEOUT, getName(),getClassLoaders()); map.setChannelSendOptions(mapSendOptions); ((ReplApplContext)this.context).setAttributeMap(map); if (getAltDDName() != null) context.setAttribute(Globals.ALT_DD_ATTR, getAltDDName()); } super.startInternal(); } catch ( Exception x ) { log.error("Unable to start ReplicatedContext",x); throw new LifecycleException("Failed to start ReplicatedContext",x); } }
Example #10
Source File: ReplicatedContext.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * Start this component and implement the requirements * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}. * * @exception LifecycleException if this component detects a fatal error * that prevents this component from being used */ @Override protected synchronized void startInternal() throws LifecycleException { super.startInternal(); try { CatalinaCluster catclust = (CatalinaCluster)this.getCluster(); if ( catclust != null ) { ReplicatedMap<String,Object> map = new ReplicatedMap<>( this, catclust.getChannel(),DEFAULT_REPL_TIMEOUT, getName(),getClassLoaders()); map.setChannelSendOptions(mapSendOptions); ((ReplApplContext)this.context).setAttributeMap(map); } } catch ( Exception x ) { log.error(sm.getString("replicatedContext.startUnable", getName()),x); throw new LifecycleException(sm.getString("replicatedContext.startFailed", getName()),x); } }
Example #11
Source File: JvmRouteBinderValve.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * Start this component and implement the requirements * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}. * * @exception LifecycleException if this component detects a fatal error * that prevents this component from being used */ @Override protected synchronized void startInternal() throws LifecycleException { if (cluster == null) { Cluster containerCluster = getContainer().getCluster(); if (containerCluster instanceof CatalinaCluster) { setCluster((CatalinaCluster)containerCluster); } } if (log.isInfoEnabled()) { log.info(sm.getString("jvmRoute.valve.started")); if (cluster == null) { log.info(sm.getString("jvmRoute.noCluster")); } } super.startInternal(); }
Example #12
Source File: ClusterManagerBase.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Override protected void startInternal() throws LifecycleException { super.startInternal(); if (getCluster() == null) { Cluster cluster = getContainer().getCluster(); if (cluster instanceof CatalinaCluster) { setCluster((CatalinaCluster)cluster); } } if (cluster != null) cluster.registerManager(this); }
Example #13
Source File: ClusterManagerBase.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override protected void startInternal() throws LifecycleException { super.startInternal(); if (getCluster() == null) { Cluster cluster = getContext().getCluster(); if (cluster instanceof CatalinaCluster) { setCluster((CatalinaCluster)cluster); } } if (cluster != null) cluster.registerManager(this); }
Example #14
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 #15
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 #16
Source File: ReplicationValve.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Start this component and implement the requirements * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}. * * @exception LifecycleException if this component detects a fatal error * that prevents this component from being used */ @Override protected synchronized void startInternal() throws LifecycleException { if (cluster == null) { Cluster containerCluster = getContainer().getCluster(); if (containerCluster instanceof CatalinaCluster) { setCluster((CatalinaCluster)containerCluster); } else { if (log.isWarnEnabled()) { log.warn(sm.getString("ReplicationValve.nocluster")); } } } super.startInternal(); }
Example #17
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 #18
Source File: ReplicationValve.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Start this component and implement the requirements * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}. * * @exception LifecycleException if this component detects a fatal error * that prevents this component from being used */ @Override protected synchronized void startInternal() throws LifecycleException { if (cluster == null) { Cluster containerCluster = getContainer().getCluster(); if (containerCluster instanceof CatalinaCluster) { setCluster((CatalinaCluster)containerCluster); } else { if (log.isWarnEnabled()) { log.warn(sm.getString("ReplicationValve.nocluster")); } } } super.startInternal(); }
Example #19
Source File: ClusterSingleSignOn.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Start this component and implement the requirements * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}. * * @exception LifecycleException if this component detects a fatal error * that prevents this component from being used */ @Override protected synchronized void startInternal() throws LifecycleException { // Load the cluster component, if any try { if(cluster == null) { Container host = getContainer(); if(host instanceof Host) { if(host.getCluster() instanceof CatalinaCluster) { setCluster((CatalinaCluster) host.getCluster()); } } } if (cluster == null) { throw new LifecycleException(sm.getString("clusterSingleSignOn.nocluster")); } ClassLoader[] cls = new ClassLoader[] { this.getClass().getClassLoader() }; ReplicatedMap<String,SingleSignOnEntry> cache = new ReplicatedMap<>( this, cluster.getChannel(), rpcTimeout, cluster.getClusterName() + "-SSO-cache", cls, terminateOnStartFailure); cache.setChannelSendOptions(mapSendOptions); cache.setAccessTimeout(accessTimeout); this.cache = cache; } catch (Throwable t) { ExceptionUtils.handleThrowable(t); throw new LifecycleException(sm.getString("clusterSingleSignOn.clusterLoad.fail"), t); } super.startInternal(); }
Example #20
Source File: ClusterSingleSignOn.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Start this component and implement the requirements * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}. * * @exception LifecycleException if this component detects a fatal error * that prevents this component from being used */ @Override protected synchronized void startInternal() throws LifecycleException { // Load the cluster component, if any try { if(cluster == null) { Container host = getContainer(); if(host instanceof Host) { if(host.getCluster() instanceof CatalinaCluster) { setCluster((CatalinaCluster) host.getCluster()); } } } if (cluster == null) { throw new LifecycleException( "There is no Cluster for ClusterSingleSignOn"); } ClassLoader[] cls = new ClassLoader[] { this.getClass().getClassLoader() }; ReplicatedMap<String,SingleSignOnEntry> cache = new ReplicatedMap<String,SingleSignOnEntry>( this, cluster.getChannel(), rpcTimeout, cluster.getClusterName() + "-SSO-cache", cls, terminateOnStartFailure); cache.setChannelSendOptions(mapSendOptions); this.cache = cache; } catch (Throwable t) { ExceptionUtils.handleThrowable(t); throw new LifecycleException( "ClusterSingleSignOn exception during clusterLoad " + t); } super.startInternal(); }
Example #21
Source File: ClusterSingleSignOn.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Start this component and implement the requirements * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}. * * @exception LifecycleException if this component detects a fatal error * that prevents this component from being used */ @Override protected synchronized void startInternal() throws LifecycleException { // Load the cluster component, if any try { if(cluster == null) { Container host = getContainer(); if(host instanceof Host) { if(host.getCluster() instanceof CatalinaCluster) { setCluster((CatalinaCluster) host.getCluster()); } } } if (cluster == null) { throw new LifecycleException( "There is no Cluster for ClusterSingleSignOn"); } ClassLoader[] cls = new ClassLoader[] { this.getClass().getClassLoader() }; ReplicatedMap<String,SingleSignOnEntry> cache = new ReplicatedMap<String,SingleSignOnEntry>( this, cluster.getChannel(), rpcTimeout, cluster.getClusterName() + "-SSO-cache", cls, terminateOnStartFailure); cache.setChannelSendOptions(mapSendOptions); this.cache = cache; } catch (Throwable t) { ExceptionUtils.handleThrowable(t); throw new LifecycleException( "ClusterSingleSignOn exception during clusterLoad " + t); } super.startInternal(); }
Example #22
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 #23
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 #24
Source File: JvmRouteBinderValve.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Send the changed Sessionid to all clusternodes. * * @see JvmRouteSessionIDBinderListener#messageReceived( * org.apache.catalina.ha.ClusterMessage) * @param sessionId * current failed sessionid * @param newSessionID * new session id, bind to the new cluster node */ protected void sendSessionIDClusterBackup(Request request, String sessionId, String newSessionID) { CatalinaCluster c = getCluster(); if (c != null && !(getManager(request) instanceof BackupManager)) { SessionIDMessage msg = new SessionIDMessage(); msg.setOrignalSessionID(sessionId); msg.setBackupSessionID(newSessionID); Context context = request.getContext(); msg.setContextName(context.getName()); msg.setHost(context.getParent().getName()); c.send(msg); } }
Example #25
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 #26
Source File: JvmRouteBinderValve.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Send the changed Sessionid to all clusternodes. * * @see JvmRouteSessionIDBinderListener#messageReceived( * org.apache.catalina.ha.ClusterMessage) * @param sessionId * current failed sessionid * @param newSessionID * new session id, bind to the new cluster node */ protected void sendSessionIDClusterBackup(Request request, String sessionId, String newSessionID) { CatalinaCluster c = getCluster(); if (c != null && !(getManager(request) instanceof BackupManager)) { SessionIDMessage msg = new SessionIDMessage(); msg.setOrignalSessionID(sessionId); msg.setBackupSessionID(newSessionID); Context context = request.getContext(); msg.setContextName(context.getName()); msg.setHost(context.getParent().getName()); c.send(msg); } }
Example #27
Source File: ReplicationValve.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Start this component and implement the requirements * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}. * * @exception LifecycleException if this component detects a fatal error * that prevents this component from being used */ @Override protected synchronized void startInternal() throws LifecycleException { if (cluster == null) { Cluster containerCluster = getContainer().getCluster(); if (containerCluster instanceof CatalinaCluster) { setCluster((CatalinaCluster)containerCluster); } else { if (log.isWarnEnabled()) { log.warn(sm.getString("ReplicationValve.nocluster")); } } } super.startInternal(); }
Example #28
Source File: ClusterObserver.java From tomee with Apache License 2.0 | 5 votes |
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); } } }
Example #29
Source File: ClusterManagerBase.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Override protected void startInternal() throws LifecycleException { super.startInternal(); if (getCluster() == null) { Cluster cluster = getContainer().getCluster(); if (cluster instanceof CatalinaCluster) { setCluster((CatalinaCluster)cluster); } } if (cluster != null) cluster.registerManager(this); }
Example #30
Source File: ClusterManagerBase.java From Tomcat8-Source-Read with MIT License | 4 votes |
@Override public CatalinaCluster getCluster() { return cluster; }