Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
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.geronimo.clustering.wadi;
 
 import java.util.Map;
 import java.util.Set;
 
 import  org.codehaus.wadi.aop.replication.AOPStackContext;
 import  org.codehaus.wadi.core.assembler.StackContext;
 import  org.codehaus.wadi.core.manager.Manager;
 import  org.codehaus.wadi.core.manager.SessionMonitor;
 import  org.codehaus.wadi.group.Dispatcher;
 import  org.codehaus.wadi.group.Peer;
 import  org.codehaus.wadi.replication.strategy.BackingStrategyFactory;
 import  org.codehaus.wadi.servicespace.ServiceSpace;
 import  org.codehaus.wadi.servicespace.ServiceSpaceName;

Version:
$Rev$ $Date$
 
     private static final Log log = LogFactory.getLog(BasicWADISessionManager.class);
 
     private final ClassLoader cl;
     private final WADICluster cluster;
     private final WADISessionManagerConfigInfo configInfo;
     private final BackingStrategyFactory backingStrategyFactory;
     private final CopyOnWriteArrayList<SessionListenerlisteners;
 
     private Manager manager;
     private SessionMonitor sessionMonitor;
     private ServiceSpace serviceSpace;
 
 
     public BasicWADISessionManager(ClassLoader cl,
             WADISessionManagerConfigInfo configInfo,
             WADICluster cluster,
             BackingStrategyFactory backingStrategyFactory) {
         this. = cl;
         this. = configInfo;
         this. = cluster;
         this. = backingStrategyFactory;
 
          = new CopyOnWriteArrayList<SessionListener>();
     }
 
     public void doStart() throws Exception {
         Dispatcher underlyingDisp = .getCluster().getDispatcher();
         
         ServiceSpaceName serviceSpaceName = new ServiceSpaceName(.getServiceSpaceURI());
         StackContext stackContext;
         if (.isDeltaReplication()) {
             stackContext = new AOPStackContext(,
                 serviceSpaceName,
                 underlyingDisp,
                 .getSessionTimeoutSeconds(),
                 .getNumPartitions(),
                 .getSweepInterval(),
                 );
         } else {
             stackContext = new StackContext(,
                 serviceSpaceName,
                 underlyingDisp,
                 .getSessionTimeoutSeconds(),
                 .getNumPartitions(),
                 .getSweepInterval(),
                 );
         }
         stackContext.setDisableReplication(.isDisableReplication());
        stackContext.build();
         = stackContext.getServiceSpace();
         = stackContext.getManager();
         = stackContext.getSessionMonitor();
        .addSessionListener(new SessionListenerAdapter());
        
        .start();
    }
    public void doStop() throws Exception {
        .stop();
    }
    public void doFail() {
        try {
            .stop();
        } catch (Exception e) {
            .error(e);
        }
    }
    public Session createSession(String sessionIdthrows SessionAlreadyExistException {
        org.codehaus.wadi.core.session.Session session;
        try {
            session = .createWithName(sessionId);
        } catch (org.codehaus.wadi.core.manager.SessionAlreadyExistException e) {
            throw new SessionAlreadyExistException("Session " + sessionId + " already exists"e);
        }
        return new WADISessionAdaptor(session);
    }
    public Manager getManager() {
        return ;
    }
    public Node getNode() {
        return .getLocalNode();
    }
    public Set<NodegetRemoteNodes() {
        Map<Peer, RemoteNodepeerToRemoteNode = new HashMap<Peer, RemoteNode>();
        Set<NodeclusterNodes = .getRemoteNodes();
        for (Iterator<Nodeiterator = clusterNodes.iterator(); iterator.hasNext();) {
            RemoteNode remoteNode = (RemoteNodeiterator.next();
            peerToRemoteNode.put(remoteNode.getPeer(), remoteNode);
        }
        
        Set<Nodenodes = new HashSet<Node>();
        Set<Peer> peers = .getHostingPeers();
        for (Peer peer : peers) {
            RemoteNode remoteNode = peerToRemoteNode.get(peer);
            if (null == remoteNode) {
                throw new AssertionError("remoteNode is null");
            }
            nodes.add(remoteNode);
        }
        return nodes;
    }
    public void registerListener(SessionListener listener) {
        .add(listener);
    }
    public void unregisterListener(SessionListener listener) {
        .remove(listener);
    }
    private void notifyInboundSessionMigration(org.codehaus.wadi.core.session.Session session) {
        for (SessionListener listener : ) {
            listener.notifyInboundSessionMigration(new WADISessionAdaptor(session));
        }
    }
    private void notifyOutboundSessionMigration(org.codehaus.wadi.core.session.Session session) {
        for (SessionListener listener : ) {
            listener.notifyOutboundSessionMigration(new WADISessionAdaptor(session));
        }
    }
    private void notifySessionDestruction(org.codehaus.wadi.core.session.Session session) {
        for (SessionListener listener : ) {
            listener.notifySessionDestruction(new WADISessionAdaptor(session));
        }
    }
    private class SessionListenerAdapter implements org.codehaus.wadi.core.manager.SessionListener {
        public void onSessionCreation(org.codehaus.wadi.core.session.Session session) {
        }
        public void onSessionDestruction(org.codehaus.wadi.core.session.Session session) {
            notifySessionDestruction(session);
        }
        
        public void onInboundSessionMigration(org.codehaus.wadi.core.session.Session session) {
            notifyInboundSessionMigration(session);
        }
        
        public void onOutbountSessionMigration(org.codehaus.wadi.core.session.Session session) {
            notifyOutboundSessionMigration(session);
        }
        
    }
    public static final GBeanInfo GBEAN_INFO;
    public static final String GBEAN_ATTR_WADI_CONFIG_INFO = "wadiConfigInfo";
    public static final String GBEAN_REF_CLUSTER = "Cluster";
    public static final String GBEAN_REF_BACKING_STRATEGY_FACTORY = "BackingStrategyFactory";
    static {
        GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic("WADI Session Manager",
                BasicWADISessionManager.class.);
        infoBuilder.addAttribute("classLoader"ClassLoader.classfalse);
        infoBuilder.addAttribute(WADISessionManagerConfigInfo.classtrue);
        infoBuilder.addReference(, BackingStrategyFactory.class,
                .);
        infoBuilder.addInterface(SessionManager.class);
        infoBuilder.addInterface(WADISessionManager.class);
        infoBuilder.setConstructor(new String[] { "classLoader"
                ,
                
                 });
         = infoBuilder.getBeanInfo();
    }
    public static GBeanInfo getGBeanInfo() {
        return ;
    }
New to GrepCode? Check out our FAQ X