001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.catalina.ha.session;
019:
020: import java.util.Map;
021:
022: import org.apache.catalina.ha.ClusterManager;
023: import org.apache.catalina.ha.ClusterMessage;
024: import org.apache.catalina.ha.*;
025:
026: /**
027: * Receive replicated SessionMessage form other cluster node.
028: * @author Filip Hanik
029: * @author Peter Rossbach
030: * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
031: */
032: public class ClusterSessionListener extends ClusterListener {
033:
034: /**
035: * The descriptive information about this implementation.
036: */
037: protected static final String info = "org.apache.catalina.session.ClusterSessionListener/1.1";
038:
039: //--Constructor---------------------------------------------
040:
041: public ClusterSessionListener() {
042: }
043:
044: //--Logic---------------------------------------------------
045:
046: /**
047: * Return descriptive information about this implementation.
048: */
049: public String getInfo() {
050:
051: return (info);
052:
053: }
054:
055: /**
056: * Callback from the cluster, when a message is received, The cluster will
057: * broadcast it invoking the messageReceived on the receiver.
058: *
059: * @param myobj
060: * ClusterMessage - the message received from the cluster
061: */
062: public void messageReceived(ClusterMessage myobj) {
063: if (myobj != null && myobj instanceof SessionMessage) {
064: SessionMessage msg = (SessionMessage) myobj;
065: String ctxname = msg.getContextName();
066: //check if the message is a EVT_GET_ALL_SESSIONS,
067: //if so, wait until we are fully started up
068: Map managers = cluster.getManagers();
069: if (ctxname == null) {
070: java.util.Iterator i = managers.keySet().iterator();
071: while (i.hasNext()) {
072: String key = (String) i.next();
073: ClusterManager mgr = (ClusterManager) managers
074: .get(key);
075: if (mgr != null)
076: mgr.messageDataReceived(msg);
077: else {
078: //this happens a lot before the system has started
079: // up
080: if (log.isDebugEnabled())
081: log.debug("Context manager doesn't exist:"
082: + key);
083: }
084: }
085: } else {
086: ClusterManager mgr = (ClusterManager) managers
087: .get(ctxname);
088: if (mgr != null)
089: mgr.messageDataReceived(msg);
090: else if (log.isWarnEnabled())
091: log
092: .warn("Context manager doesn't exist:"
093: + ctxname);
094: }
095: }
096: return;
097: }
098:
099: /**
100: * Accept only SessionMessage
101: *
102: * @param msg
103: * ClusterMessage
104: * @return boolean - returns true to indicate that messageReceived should be
105: * invoked. If false is returned, the messageReceived method will
106: * not be invoked.
107: */
108: public boolean accept(ClusterMessage msg) {
109: return (msg instanceof SessionMessage);
110: }
111: }
|