Modified: tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/deploy/UndeployMessage.java URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/deploy/UndeployMessage.java?view=diff&rev=466608&r1=466607&r2=466608 ============================================================================== --- tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/deploy/UndeployMessage.java (original) +++ tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/deploy/UndeployMessage.java Sat Oct 21 16:10:15 2006 @@ -1,113 +1,114 @@ -/* - * Copyright 1999,2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.catalina.ha.deploy; - -import org.apache.catalina.ha.ClusterMessage; -import org.apache.catalina.tribes.Member; -import java.io.Serializable; -public class UndeployMessage implements ClusterMessage,Serializable { - private Member address; - private long timestamp; - private String uniqueId; - private String contextPath; - private boolean undeploy; - private int resend = 0; - private int compress = 0; - - public UndeployMessage() {} //for serialization - public UndeployMessage(Member address, - long timestamp, - String uniqueId, - String contextPath, - boolean undeploy) { - this.address = address; - this.timestamp= timestamp; - this.undeploy = undeploy; - this.uniqueId = uniqueId; - this.undeploy = undeploy; - this.contextPath = contextPath; - } - - public Member getAddress() { - return address; - } - - public void setAddress(Member address) { - this.address = address; - } - - public long getTimestamp() { - return timestamp; - } - - public void setTimestamp(long timestamp) { - this.timestamp = timestamp; - } - - public String getUniqueId() { - return uniqueId; - } - - public void setUniqueId(String uniqueId) { - this.uniqueId = uniqueId; - } - - public String getContextPath() { - return contextPath; - } - - public void setContextPath(String contextPath) { - this.contextPath = contextPath; - } - - public boolean getUndeploy() { - return undeploy; - } - - public void setUndeploy(boolean undeploy) { - this.undeploy = undeploy; - } - /** - * @return Returns the compress. - * @since 5.5.10 - */ - public int getCompress() { - return compress; - } - /** - * @param compress The compress to set. - * @since 5.5.10 - */ - public void setCompress(int compress) { - this.compress = compress; - } - /** - * @return Returns the resend. - * @since 5.5.10 - */ - public int getResend() { - return resend; - } - /** - * @param resend The resend to set. - * @since 5.5.10 - */ - public void setResend(int resend) { - this.resend = resend; - } - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.catalina.ha.deploy; + +import org.apache.catalina.ha.ClusterMessage; +import org.apache.catalina.tribes.Member; +import java.io.Serializable; +public class UndeployMessage implements ClusterMessage,Serializable { + private Member address; + private long timestamp; + private String uniqueId; + private String contextPath; + private boolean undeploy; + private int resend = 0; + private int compress = 0; + + public UndeployMessage() {} //for serialization + public UndeployMessage(Member address, + long timestamp, + String uniqueId, + String contextPath, + boolean undeploy) { + this.address = address; + this.timestamp= timestamp; + this.undeploy = undeploy; + this.uniqueId = uniqueId; + this.undeploy = undeploy; + this.contextPath = contextPath; + } + + public Member getAddress() { + return address; + } + + public void setAddress(Member address) { + this.address = address; + } + + public long getTimestamp() { + return timestamp; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + + public String getUniqueId() { + return uniqueId; + } + + public void setUniqueId(String uniqueId) { + this.uniqueId = uniqueId; + } + + public String getContextPath() { + return contextPath; + } + + public void setContextPath(String contextPath) { + this.contextPath = contextPath; + } + + public boolean getUndeploy() { + return undeploy; + } + + public void setUndeploy(boolean undeploy) { + this.undeploy = undeploy; + } + /** + * @return Returns the compress. + * @since 5.5.10 + */ + public int getCompress() { + return compress; + } + /** + * @param compress The compress to set. + * @since 5.5.10 + */ + public void setCompress(int compress) { + this.compress = compress; + } + /** + * @return Returns the resend. + * @since 5.5.10 + */ + public int getResend() { + return resend; + } + /** + * @param resend The resend to set. + * @since 5.5.10 + */ + public void setResend(int resend) { + this.resend = resend; + } + +}
Modified: tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/deploy/WarWatcher.java URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/deploy/WarWatcher.java?view=diff&rev=466608&r1=466607&r2=466608 ============================================================================== --- tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/deploy/WarWatcher.java (original) +++ tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/deploy/WarWatcher.java Sat Oct 21 16:10:15 2006 @@ -1,238 +1,239 @@ -/* - * Copyright 1999,2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.catalina.ha.deploy; - -import java.io.File; -import java.util.HashMap; -import java.util.Map; -import java.util.Iterator; - -/** - * <p> - * The <b>WarWatcher </b> watches the deployDir for changes made to the - * directory (adding new WAR files->deploy or remove WAR files->undeploy) And - * notifies a listener of the changes made - * </p> - * - * @author Filip Hanik - * @author Peter Rossbach - * @version 1.1 - */ - -public class WarWatcher { - - /*--Static Variables----------------------------------------*/ - public static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory - .getLog(WarWatcher.class); - - /*--Instance Variables--------------------------------------*/ - /** - * Directory to watch for war files - */ - protected File watchDir = null; - - /** - * Parent to be notified of changes - */ - protected FileChangeListener listener = null; - - /** - * Currently deployed files - */ - protected Map currentStatus = new HashMap(); - - /*--Constructor---------------------------------------------*/ - - public WarWatcher() { - } - - public WarWatcher(FileChangeListener listener, File watchDir) { - this.listener = listener; - this.watchDir = watchDir; - } - - /*--Logic---------------------------------------------------*/ - - /** - * check for modification and send notifcation to listener - */ - public void check() { - if (log.isInfoEnabled()) - log.info("check cluster wars at " + watchDir); - File[] list = watchDir.listFiles(new WarFilter()); - if (list == null) - list = new File[0]; - //first make sure all the files are listed in our current status - for (int i = 0; i < list.length; i++) { - addWarInfo(list[i]); - } - - //check all the status codes and update the FarmDeployer - for (Iterator i = currentStatus.entrySet().iterator(); i.hasNext();) { - Map.Entry entry = (Map.Entry) i.next(); - WarInfo info = (WarInfo) entry.getValue(); - int check = info.check(); - if (check == 1) { - listener.fileModified(info.getWar()); - } else if (check == -1) { - listener.fileRemoved(info.getWar()); - //no need to keep in memory - currentStatus.remove(info.getWar()); - } - } - - } - - /** - * add cluster war to the watcher state - * @param warfile - */ - protected void addWarInfo(File warfile) { - WarInfo info = (WarInfo) currentStatus.get(warfile.getAbsolutePath()); - if (info == null) { - info = new WarInfo(warfile); - info.setLastState(-1); //assume file is non existent - currentStatus.put(warfile.getAbsolutePath(), info); - } - } - - /** - * clear watcher state - */ - public void clear() { - currentStatus.clear(); - } - - /** - * @return Returns the watchDir. - */ - public File getWatchDir() { - return watchDir; - } - - /** - * @param watchDir - * The watchDir to set. - */ - public void setWatchDir(File watchDir) { - this.watchDir = watchDir; - } - - /** - * @return Returns the listener. - */ - public FileChangeListener getListener() { - return listener; - } - - /** - * @param listener - * The listener to set. - */ - public void setListener(FileChangeListener listener) { - this.listener = listener; - } - - /*--Inner classes-------------------------------------------*/ - - /** - * File name filter for war files - */ - protected class WarFilter implements java.io.FilenameFilter { - public boolean accept(File path, String name) { - if (name == null) - return false; - return name.endsWith(".war"); - } - } - - /** - * File information on existing WAR files - */ - protected class WarInfo { - protected File war = null; - - protected long lastChecked = 0; - - protected long lastState = 0; - - public WarInfo(File war) { - this.war = war; - this.lastChecked = war.lastModified(); - if (!war.exists()) - lastState = -1; - } - - public boolean modified() { - return war.exists() && war.lastModified() > lastChecked; - } - - public boolean exists() { - return war.exists(); - } - - /** - * Returns 1 if the file has been added/modified, 0 if the file is - * unchanged and -1 if the file has been removed - * - * @return int 1=file added; 0=unchanged; -1=file removed - */ - public int check() { - //file unchanged by default - int result = 0; - - if (modified()) { - //file has changed - timestamp - result = 1; - lastState = result; - } else if ((!exists()) && (!(lastState == -1))) { - //file was removed - result = -1; - lastState = result; - } else if ((lastState == -1) && exists()) { - //file was added - result = 1; - lastState = result; - } - this.lastChecked = System.currentTimeMillis(); - return result; - } - - public File getWar() { - return war; - } - - public int hashCode() { - return war.getAbsolutePath().hashCode(); - } - - public boolean equals(Object other) { - if (other instanceof WarInfo) { - WarInfo wo = (WarInfo) other; - return wo.getWar().equals(getWar()); - } else { - return false; - } - } - - protected void setLastState(int lastState) { - this.lastState = lastState; - } - - } - +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.catalina.ha.deploy; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; +import java.util.Iterator; + +/** + * <p> + * The <b>WarWatcher </b> watches the deployDir for changes made to the + * directory (adding new WAR files->deploy or remove WAR files->undeploy) And + * notifies a listener of the changes made + * </p> + * + * @author Filip Hanik + * @author Peter Rossbach + * @version 1.1 + */ + +public class WarWatcher { + + /*--Static Variables----------------------------------------*/ + public static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory + .getLog(WarWatcher.class); + + /*--Instance Variables--------------------------------------*/ + /** + * Directory to watch for war files + */ + protected File watchDir = null; + + /** + * Parent to be notified of changes + */ + protected FileChangeListener listener = null; + + /** + * Currently deployed files + */ + protected Map currentStatus = new HashMap(); + + /*--Constructor---------------------------------------------*/ + + public WarWatcher() { + } + + public WarWatcher(FileChangeListener listener, File watchDir) { + this.listener = listener; + this.watchDir = watchDir; + } + + /*--Logic---------------------------------------------------*/ + + /** + * check for modification and send notifcation to listener + */ + public void check() { + if (log.isInfoEnabled()) + log.info("check cluster wars at " + watchDir); + File[] list = watchDir.listFiles(new WarFilter()); + if (list == null) + list = new File[0]; + //first make sure all the files are listed in our current status + for (int i = 0; i < list.length; i++) { + addWarInfo(list[i]); + } + + //check all the status codes and update the FarmDeployer + for (Iterator i = currentStatus.entrySet().iterator(); i.hasNext();) { + Map.Entry entry = (Map.Entry) i.next(); + WarInfo info = (WarInfo) entry.getValue(); + int check = info.check(); + if (check == 1) { + listener.fileModified(info.getWar()); + } else if (check == -1) { + listener.fileRemoved(info.getWar()); + //no need to keep in memory + currentStatus.remove(info.getWar()); + } + } + + } + + /** + * add cluster war to the watcher state + * @param warfile + */ + protected void addWarInfo(File warfile) { + WarInfo info = (WarInfo) currentStatus.get(warfile.getAbsolutePath()); + if (info == null) { + info = new WarInfo(warfile); + info.setLastState(-1); //assume file is non existent + currentStatus.put(warfile.getAbsolutePath(), info); + } + } + + /** + * clear watcher state + */ + public void clear() { + currentStatus.clear(); + } + + /** + * @return Returns the watchDir. + */ + public File getWatchDir() { + return watchDir; + } + + /** + * @param watchDir + * The watchDir to set. + */ + public void setWatchDir(File watchDir) { + this.watchDir = watchDir; + } + + /** + * @return Returns the listener. + */ + public FileChangeListener getListener() { + return listener; + } + + /** + * @param listener + * The listener to set. + */ + public void setListener(FileChangeListener listener) { + this.listener = listener; + } + + /*--Inner classes-------------------------------------------*/ + + /** + * File name filter for war files + */ + protected class WarFilter implements java.io.FilenameFilter { + public boolean accept(File path, String name) { + if (name == null) + return false; + return name.endsWith(".war"); + } + } + + /** + * File information on existing WAR files + */ + protected class WarInfo { + protected File war = null; + + protected long lastChecked = 0; + + protected long lastState = 0; + + public WarInfo(File war) { + this.war = war; + this.lastChecked = war.lastModified(); + if (!war.exists()) + lastState = -1; + } + + public boolean modified() { + return war.exists() && war.lastModified() > lastChecked; + } + + public boolean exists() { + return war.exists(); + } + + /** + * Returns 1 if the file has been added/modified, 0 if the file is + * unchanged and -1 if the file has been removed + * + * @return int 1=file added; 0=unchanged; -1=file removed + */ + public int check() { + //file unchanged by default + int result = 0; + + if (modified()) { + //file has changed - timestamp + result = 1; + lastState = result; + } else if ((!exists()) && (!(lastState == -1))) { + //file was removed + result = -1; + lastState = result; + } else if ((lastState == -1) && exists()) { + //file was added + result = 1; + lastState = result; + } + this.lastChecked = System.currentTimeMillis(); + return result; + } + + public File getWar() { + return war; + } + + public int hashCode() { + return war.getAbsolutePath().hashCode(); + } + + public boolean equals(Object other) { + if (other instanceof WarInfo) { + WarInfo wo = (WarInfo) other; + return wo.getWar().equals(getWar()); + } else { + return false; + } + } + + protected void setLastState(int lastState) { + this.lastState = lastState; + } + + } + } Modified: tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/BackupManager.java URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/BackupManager.java?view=diff&rev=466608&r1=466607&r2=466608 ============================================================================== --- tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/BackupManager.java (original) +++ tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/BackupManager.java Sat Oct 21 16:10:15 2006 @@ -1,271 +1,272 @@ -/* - * Copyright 1999,2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.catalina.ha.session; - -import java.io.ByteArrayInputStream; -import java.io.IOException; - -import org.apache.catalina.LifecycleException; -import org.apache.catalina.Loader; -import org.apache.catalina.Session; -import org.apache.catalina.ha.CatalinaCluster; -import org.apache.catalina.ha.ClusterManager; -import org.apache.catalina.ha.ClusterMessage; -import org.apache.catalina.session.StandardManager; -import org.apache.catalina.tribes.Member; -import org.apache.catalina.tribes.io.ReplicationStream; -import org.apache.catalina.tribes.tipis.LazyReplicatedMap; -import org.apache.catalina.tribes.Channel; - -/** - [EMAIL PROTECTED] Filip Hanik - [EMAIL PROTECTED] 1.0 - */ -public class BackupManager extends StandardManager implements ClusterManager -{ - public static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog( BackupManager.class ); - - protected static long DEFAULT_REPL_TIMEOUT = 15000;//15 seconds - - /** Set to true if we don't want the sessions to expire on shutdown */ - protected boolean mExpireSessionsOnShutdown = true; - - /** - * The name of this manager - */ - protected String name; - - /** - * A reference to the cluster - */ - protected CatalinaCluster cluster; - - /** - * Should listeners be notified? - */ - private boolean notifyListenersOnReplication; - /** - * - */ - private int mapSendOptions = Channel.SEND_OPTIONS_SYNCHRONIZED_ACK|Channel.SEND_OPTIONS_USE_ACK; - - /** - * Constructor, just calls super() - * - */ - public BackupManager() { - super(); - } - - -//******************************************************************************/ -// ClusterManager Interface -//******************************************************************************/ - - public void messageDataReceived(ClusterMessage msg) { - } - - public boolean isSendClusterDomainOnly() { - return false; - } - - /** - * @param sendClusterDomainOnly The sendClusterDomainOnly to set. - */ - public void setSendClusterDomainOnly(boolean sendClusterDomainOnly) { - } - - /** - * @return Returns the defaultMode. - */ - public boolean isDefaultMode() { - return false; - } - /** - * @param defaultMode The defaultMode to set. - */ - public void setDefaultMode(boolean defaultMode) { - } - - public void setExpireSessionsOnShutdown(boolean expireSessionsOnShutdown) - { - mExpireSessionsOnShutdown = expireSessionsOnShutdown; - } - - public void setCluster(CatalinaCluster cluster) { - if(log.isDebugEnabled()) - log.debug("Cluster associated with SimpleTcpReplicationManager"); - this.cluster = cluster; - } - - public boolean getExpireSessionsOnShutdown() - { - return mExpireSessionsOnShutdown; - } - - - /** - * Override persistence since they don't go hand in hand with replication for now. - */ - public void unload() throws IOException { - } - - public ClusterMessage requestCompleted(String sessionId) { - if ( !this.started ) return null; - LazyReplicatedMap map = (LazyReplicatedMap)sessions; - map.replicate(sessionId,false); - return null; - } - - -//========================================================================= -// OVERRIDE THESE METHODS TO IMPLEMENT THE REPLICATION -//========================================================================= - - public Session createEmptySession() { - return new DeltaSession(this); - } - - public ClassLoader[] getClassLoaders() { - return ClusterManagerBase.getClassLoaders(this.container); - } - - /** - * Open Stream and use correct ClassLoader (Container) Switch - * ThreadClassLoader - * - * @param data - * @return The object input stream - * @throws IOException - */ - public ReplicationStream getReplicationStream(byte[] data) throws IOException { - return getReplicationStream(data,0,data.length); - } - - public ReplicationStream getReplicationStream(byte[] data, int offset, int length) throws IOException { - ByteArrayInputStream fis = new ByteArrayInputStream(data, offset, length); - return new ReplicationStream(fis, getClassLoaders()); - } - - - - - public String getName() { - return this.name; - } - /** - * Prepare for the beginning of active use of the public methods of this - * component. This method should be called after <code>configure()</code>, - * and before any of the public methods of the component are utilized.<BR> - * Starts the cluster communication channel, this will connect with the other nodes - * in the cluster, and request the current session state to be transferred to this node. - * @exception IllegalStateException if this component has already been - * started - * @exception LifecycleException if this component detects a fatal error - * that prevents this component from being used - */ - public void start() throws LifecycleException { - if ( this.started ) return; - try { - CatalinaCluster catclust = (CatalinaCluster)cluster; - catclust.addManager(getName(), this); - LazyReplicatedMap map = new LazyReplicatedMap(this, - catclust.getChannel(), - DEFAULT_REPL_TIMEOUT, - getMapName(), - getClassLoaders()); - map.setChannelSendOptions(mapSendOptions); - this.sessions = map; - super.start(); - } catch ( Exception x ) { - log.error("Unable to start BackupManager",x); - throw new LifecycleException("Failed to start BackupManager",x); - } - } - - public String getMapName() { - CatalinaCluster catclust = (CatalinaCluster)cluster; - String name = catclust.getManagerName(getName(),this)+"-"+""; - if ( log.isDebugEnabled() ) log.debug("Backup manager, Setting map name to:"+name); - return name; - } - - /** - * Gracefully terminate the active use of the public methods of this - * component. This method should be the last one called on a given - * instance of this component.<BR> - * This will disconnect the cluster communication channel and stop the listener thread. - * @exception IllegalStateException if this component has not been started - * @exception LifecycleException if this component detects a fatal error - * that needs to be reported - */ - public void stop() throws LifecycleException - { - - LazyReplicatedMap map = (LazyReplicatedMap)sessions; - if ( map!=null ) { - map.breakdown(); - } - if ( !this.started ) return; - try { - } catch ( Exception x ){ - log.error("Unable to stop BackupManager",x); - throw new LifecycleException("Failed to stop BackupManager",x); - } finally { - super.stop(); - } - cluster.removeManager(getName(),this); - - } - - public void setDistributable(boolean dist) { - this.distributable = dist; - } - - public boolean getDistributable() { - return distributable; - } - - public void setName(String name) { - this.name = name; - } - public boolean isNotifyListenersOnReplication() { - return notifyListenersOnReplication; - } - public void setNotifyListenersOnReplication(boolean notifyListenersOnReplication) { - this.notifyListenersOnReplication = notifyListenersOnReplication; - } - - public void setMapSendOptions(int mapSendOptions) { - this.mapSendOptions = mapSendOptions; - } - - /* - * @see org.apache.catalina.ha.ClusterManager#getCluster() - */ - public CatalinaCluster getCluster() { - return cluster; - } - - public int getMapSendOptions() { - return mapSendOptions; - } - - public String[] getInvalidatedSessions() { - return new String[0]; - } - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.ha.session; + +import java.io.ByteArrayInputStream; +import java.io.IOException; + +import org.apache.catalina.LifecycleException; +import org.apache.catalina.Loader; +import org.apache.catalina.Session; +import org.apache.catalina.ha.CatalinaCluster; +import org.apache.catalina.ha.ClusterManager; +import org.apache.catalina.ha.ClusterMessage; +import org.apache.catalina.session.StandardManager; +import org.apache.catalina.tribes.Member; +import org.apache.catalina.tribes.io.ReplicationStream; +import org.apache.catalina.tribes.tipis.LazyReplicatedMap; +import org.apache.catalina.tribes.Channel; + +/** + [EMAIL PROTECTED] Filip Hanik + [EMAIL PROTECTED] 1.0 + */ +public class BackupManager extends StandardManager implements ClusterManager +{ + public static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog( BackupManager.class ); + + protected static long DEFAULT_REPL_TIMEOUT = 15000;//15 seconds + + /** Set to true if we don't want the sessions to expire on shutdown */ + protected boolean mExpireSessionsOnShutdown = true; + + /** + * The name of this manager + */ + protected String name; + + /** + * A reference to the cluster + */ + protected CatalinaCluster cluster; + + /** + * Should listeners be notified? + */ + private boolean notifyListenersOnReplication; + /** + * + */ + private int mapSendOptions = Channel.SEND_OPTIONS_SYNCHRONIZED_ACK|Channel.SEND_OPTIONS_USE_ACK; + + /** + * Constructor, just calls super() + * + */ + public BackupManager() { + super(); + } + + +//******************************************************************************/ +// ClusterManager Interface +//******************************************************************************/ + + public void messageDataReceived(ClusterMessage msg) { + } + + public boolean isSendClusterDomainOnly() { + return false; + } + + /** + * @param sendClusterDomainOnly The sendClusterDomainOnly to set. + */ + public void setSendClusterDomainOnly(boolean sendClusterDomainOnly) { + } + + /** + * @return Returns the defaultMode. + */ + public boolean isDefaultMode() { + return false; + } + /** + * @param defaultMode The defaultMode to set. + */ + public void setDefaultMode(boolean defaultMode) { + } + + public void setExpireSessionsOnShutdown(boolean expireSessionsOnShutdown) + { + mExpireSessionsOnShutdown = expireSessionsOnShutdown; + } + + public void setCluster(CatalinaCluster cluster) { + if(log.isDebugEnabled()) + log.debug("Cluster associated with SimpleTcpReplicationManager"); + this.cluster = cluster; + } + + public boolean getExpireSessionsOnShutdown() + { + return mExpireSessionsOnShutdown; + } + + + /** + * Override persistence since they don't go hand in hand with replication for now. + */ + public void unload() throws IOException { + } + + public ClusterMessage requestCompleted(String sessionId) { + if ( !this.started ) return null; + LazyReplicatedMap map = (LazyReplicatedMap)sessions; + map.replicate(sessionId,false); + return null; + } + + +//========================================================================= +// OVERRIDE THESE METHODS TO IMPLEMENT THE REPLICATION +//========================================================================= + + public Session createEmptySession() { + return new DeltaSession(this); + } + + public ClassLoader[] getClassLoaders() { + return ClusterManagerBase.getClassLoaders(this.container); + } + + /** + * Open Stream and use correct ClassLoader (Container) Switch + * ThreadClassLoader + * + * @param data + * @return The object input stream + * @throws IOException + */ + public ReplicationStream getReplicationStream(byte[] data) throws IOException { + return getReplicationStream(data,0,data.length); + } + + public ReplicationStream getReplicationStream(byte[] data, int offset, int length) throws IOException { + ByteArrayInputStream fis = new ByteArrayInputStream(data, offset, length); + return new ReplicationStream(fis, getClassLoaders()); + } + + + + + public String getName() { + return this.name; + } + /** + * Prepare for the beginning of active use of the public methods of this + * component. This method should be called after <code>configure()</code>, + * and before any of the public methods of the component are utilized.<BR> + * Starts the cluster communication channel, this will connect with the other nodes + * in the cluster, and request the current session state to be transferred to this node. + * @exception IllegalStateException if this component has already been + * started + * @exception LifecycleException if this component detects a fatal error + * that prevents this component from being used + */ + public void start() throws LifecycleException { + if ( this.started ) return; + try { + CatalinaCluster catclust = (CatalinaCluster)cluster; + catclust.addManager(getName(), this); + LazyReplicatedMap map = new LazyReplicatedMap(this, + catclust.getChannel(), + DEFAULT_REPL_TIMEOUT, + getMapName(), + getClassLoaders()); + map.setChannelSendOptions(mapSendOptions); + this.sessions = map; + super.start(); + } catch ( Exception x ) { + log.error("Unable to start BackupManager",x); + throw new LifecycleException("Failed to start BackupManager",x); + } + } + + public String getMapName() { + CatalinaCluster catclust = (CatalinaCluster)cluster; + String name = catclust.getManagerName(getName(),this)+"-"+""; + if ( log.isDebugEnabled() ) log.debug("Backup manager, Setting map name to:"+name); + return name; + } + + /** + * Gracefully terminate the active use of the public methods of this + * component. This method should be the last one called on a given + * instance of this component.<BR> + * This will disconnect the cluster communication channel and stop the listener thread. + * @exception IllegalStateException if this component has not been started + * @exception LifecycleException if this component detects a fatal error + * that needs to be reported + */ + public void stop() throws LifecycleException + { + + LazyReplicatedMap map = (LazyReplicatedMap)sessions; + if ( map!=null ) { + map.breakdown(); + } + if ( !this.started ) return; + try { + } catch ( Exception x ){ + log.error("Unable to stop BackupManager",x); + throw new LifecycleException("Failed to stop BackupManager",x); + } finally { + super.stop(); + } + cluster.removeManager(getName(),this); + + } + + public void setDistributable(boolean dist) { + this.distributable = dist; + } + + public boolean getDistributable() { + return distributable; + } + + public void setName(String name) { + this.name = name; + } + public boolean isNotifyListenersOnReplication() { + return notifyListenersOnReplication; + } + public void setNotifyListenersOnReplication(boolean notifyListenersOnReplication) { + this.notifyListenersOnReplication = notifyListenersOnReplication; + } + + public void setMapSendOptions(int mapSendOptions) { + this.mapSendOptions = mapSendOptions; + } + + /* + * @see org.apache.catalina.ha.ClusterManager#getCluster() + */ + public CatalinaCluster getCluster() { + return cluster; + } + + public int getMapSendOptions() { + return mapSendOptions; + } + + public String[] getInvalidatedSessions() { + return new String[0]; + } + +} Modified: tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/ClusterManagerBase.java URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/ClusterManagerBase.java?view=diff&rev=466608&r1=466607&r2=466608 ============================================================================== --- tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/ClusterManagerBase.java (original) +++ tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/ClusterManagerBase.java Sat Oct 21 16:10:15 2006 @@ -1,74 +1,75 @@ -/* - * Copyright 1999,2004-2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.catalina.ha.session; - -import org.apache.catalina.ha.ClusterManager; -import java.beans.PropertyChangeListener; -import org.apache.catalina.Lifecycle; -import org.apache.catalina.session.ManagerBase; -import org.apache.catalina.Loader; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import org.apache.catalina.tribes.io.ReplicationStream; -import org.apache.catalina.Container; - -/** - * - * @author Filip Hanik - * @version $Revision: 380100 $ $Date: 2006-02-23 06:08:14 -0600 (Thu, 23 Feb 2006) $ - */ - -public abstract class ClusterManagerBase extends ManagerBase implements Lifecycle, PropertyChangeListener, ClusterManager{ - - - public static ClassLoader[] getClassLoaders(Container container) { - Loader loader = null; - ClassLoader classLoader = null; - if (container != null) loader = container.getLoader(); - if (loader != null) classLoader = loader.getClassLoader(); - else classLoader = Thread.currentThread().getContextClassLoader(); - if ( classLoader == Thread.currentThread().getContextClassLoader() ) { - return new ClassLoader[] {classLoader}; - } else { - return new ClassLoader[] {classLoader,Thread.currentThread().getContextClassLoader()}; - } - } - - - public ClassLoader[] getClassLoaders() { - return getClassLoaders(container); - } - - /** - * Open Stream and use correct ClassLoader (Container) Switch - * ThreadClassLoader - * - * @param data - * @return The object input stream - * @throws IOException - */ - public ReplicationStream getReplicationStream(byte[] data) throws IOException { - return getReplicationStream(data,0,data.length); - } - - public ReplicationStream getReplicationStream(byte[] data, int offset, int length) throws IOException { - ByteArrayInputStream fis = new ByteArrayInputStream(data, offset, length); - return new ReplicationStream(fis, getClassLoaders()); - } - - +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.catalina.ha.session; + +import org.apache.catalina.ha.ClusterManager; +import java.beans.PropertyChangeListener; +import org.apache.catalina.Lifecycle; +import org.apache.catalina.session.ManagerBase; +import org.apache.catalina.Loader; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import org.apache.catalina.tribes.io.ReplicationStream; +import org.apache.catalina.Container; + +/** + * + * @author Filip Hanik + * @version $Revision: 380100 $ $Date: 2006-02-23 06:08:14 -0600 (Thu, 23 Feb 2006) $ + */ + +public abstract class ClusterManagerBase extends ManagerBase implements Lifecycle, PropertyChangeListener, ClusterManager{ + + + public static ClassLoader[] getClassLoaders(Container container) { + Loader loader = null; + ClassLoader classLoader = null; + if (container != null) loader = container.getLoader(); + if (loader != null) classLoader = loader.getClassLoader(); + else classLoader = Thread.currentThread().getContextClassLoader(); + if ( classLoader == Thread.currentThread().getContextClassLoader() ) { + return new ClassLoader[] {classLoader}; + } else { + return new ClassLoader[] {classLoader,Thread.currentThread().getContextClassLoader()}; + } + } + + + public ClassLoader[] getClassLoaders() { + return getClassLoaders(container); + } + + /** + * Open Stream and use correct ClassLoader (Container) Switch + * ThreadClassLoader + * + * @param data + * @return The object input stream + * @throws IOException + */ + public ReplicationStream getReplicationStream(byte[] data) throws IOException { + return getReplicationStream(data,0,data.length); + } + + public ReplicationStream getReplicationStream(byte[] data, int offset, int length) throws IOException { + ByteArrayInputStream fis = new ByteArrayInputStream(data, offset, length); + return new ReplicationStream(fis, getClassLoaders()); + } + + } Modified: tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/ClusterSessionListener.java URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/ClusterSessionListener.java?view=diff&rev=466608&r1=466607&r2=466608 ============================================================================== --- tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/ClusterSessionListener.java (original) +++ tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/ClusterSessionListener.java Sat Oct 21 16:10:15 2006 @@ -1,107 +1,108 @@ -/* - * Copyright 1999,2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.catalina.ha.session; - -import java.util.Map; - -import org.apache.catalina.ha.ClusterManager; -import org.apache.catalina.ha.ClusterMessage; -import org.apache.catalina.ha.*; - -/** - * Receive replicated SessionMessage form other cluster node. - * @author Filip Hanik - * @author Peter Rossbach - * @version $Revision: 378258 $ $Date: 2006-02-16 08:42:35 -0600 (Thu, 16 Feb 2006) $ - */ -public class ClusterSessionListener extends ClusterListener { - - /** - * The descriptive information about this implementation. - */ - protected static final String info = "org.apache.catalina.session.ClusterSessionListener/1.1"; - - //--Constructor--------------------------------------------- - - public ClusterSessionListener() { - } - - //--Logic--------------------------------------------------- - - /** - * Return descriptive information about this implementation. - */ - public String getInfo() { - - return (info); - - } - - /** - * 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 - */ - 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 managers = cluster.getManagers() ; - if (ctxname == null) { - java.util.Iterator i = managers.keySet().iterator(); - while (i.hasNext()) { - String key = (String) i.next(); - ClusterManager mgr = (ClusterManager) managers.get(key); - if (mgr != null) - mgr.messageDataReceived(msg); - else { - //this happens a lot before the system has started - // up - if (log.isDebugEnabled()) - log.debug("Context manager doesn't exist:" - + key); - } - } - } else { - ClusterManager mgr = (ClusterManager) managers.get(ctxname); - if (mgr != null) - mgr.messageDataReceived(msg); - else if (log.isWarnEnabled()) - log.warn("Context manager doesn't exist:" + ctxname); - } - } - return; - } - - /** - * Accept only SessionMessage - * - * @param msg - * ClusterMessage - * @return boolean - returns true to indicate that messageReceived should be - * invoked. If false is returned, the messageReceived method will - * not be invoked. - */ - public boolean accept(ClusterMessage msg) { - return (msg instanceof SessionMessage); - } -} - +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.catalina.ha.session; + +import java.util.Map; + +import org.apache.catalina.ha.ClusterManager; +import org.apache.catalina.ha.ClusterMessage; +import org.apache.catalina.ha.*; + +/** + * Receive replicated SessionMessage form other cluster node. + * @author Filip Hanik + * @author Peter Rossbach + * @version $Revision: 378258 $ $Date: 2006-02-16 08:42:35 -0600 (Thu, 16 Feb 2006) $ + */ +public class ClusterSessionListener extends ClusterListener { + + /** + * The descriptive information about this implementation. + */ + protected static final String info = "org.apache.catalina.session.ClusterSessionListener/1.1"; + + //--Constructor--------------------------------------------- + + public ClusterSessionListener() { + } + + //--Logic--------------------------------------------------- + + /** + * Return descriptive information about this implementation. + */ + public String getInfo() { + + return (info); + + } + + /** + * 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 + */ + 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 managers = cluster.getManagers() ; + if (ctxname == null) { + java.util.Iterator i = managers.keySet().iterator(); + while (i.hasNext()) { + String key = (String) i.next(); + ClusterManager mgr = (ClusterManager) managers.get(key); + if (mgr != null) + mgr.messageDataReceived(msg); + else { + //this happens a lot before the system has started + // up + if (log.isDebugEnabled()) + log.debug("Context manager doesn't exist:" + + key); + } + } + } else { + ClusterManager mgr = (ClusterManager) managers.get(ctxname); + if (mgr != null) + mgr.messageDataReceived(msg); + else if (log.isWarnEnabled()) + log.warn("Context manager doesn't exist:" + ctxname); + } + } + return; + } + + /** + * Accept only SessionMessage + * + * @param msg + * ClusterMessage + * @return boolean - returns true to indicate that messageReceived should be + * invoked. If false is returned, the messageReceived method will + * not be invoked. + */ + public boolean accept(ClusterMessage msg) { + return (msg instanceof SessionMessage); + } +} + Modified: tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/Constants.java URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/Constants.java?view=diff&rev=466608&r1=466607&r2=466608 ============================================================================== --- tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/Constants.java (original) +++ tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/Constants.java Sat Oct 21 16:10:15 2006 @@ -1,31 +1,32 @@ -/* - * Copyright 1999,2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -package org.apache.catalina.ha.session; - -/** - * Manifest constants for the <code>org.apache.catalina.ha.session</code> - * package. - * - * @author Peter Rossbach Pero - */ - -public class Constants { - - public static final String Package = "org.apache.catalina.ha.session"; - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package org.apache.catalina.ha.session; + +/** + * Manifest constants for the <code>org.apache.catalina.ha.session</code> + * package. + * + * @author Peter Rossbach Pero + */ + +public class Constants { + + public static final String Package = "org.apache.catalina.ha.session"; + +} --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]