Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.context » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements. See the NOTICE file distributed with this
    4    * work for additional information regarding copyright ownership. The ASF
    5    * licenses this file to You under the Apache License, Version 2.0 (the
    6    * "License"); you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
    9    * or agreed to in writing, software distributed under the License is
   10    * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   11    * KIND, either express or implied. See the License for the specific language
   12    * governing permissions and limitations under the License.
   13    */
   14   package org.apache.webbeans.context;
   15   
   16   import java.util.Iterator;
   17   import java.util.Map;
   18   import java.util.Set;
   19   import java.util.concurrent.ConcurrentHashMap;
   20   
   21   import org.apache.webbeans.config.WebBeansFinder;
   22   import org.apache.webbeans.util.Asserts;
   23   
   24   public class SessionContextManager
   25   {
   26       private Map<String, SessionContext> sessionContexts = null;
   27   
   28       public SessionContextManager()
   29       {
   30           sessionContexts = new ConcurrentHashMap<String, SessionContext>();        
   31       }
   32   
   33       public static SessionContextManager getInstance()
   34       {
   35           SessionContextManager sessionContextManager = (SessionContextManager)WebBeansFinder.getSingletonInstance(WebBeansFinder.SINGLETON_SESSION_CONTEXT_MANAGER);        
   36           
   37           return sessionContextManager;
   38       }
   39   
   40       public void addNewSessionContext(String sessionId, SessionContext context)
   41       {
   42           Asserts.assertNotNull(sessionId, "sessionId parameter can not be null");
   43           Asserts.assertNotNull(context, "context parameter can not be null");
   44   
   45           sessionContexts.put(sessionId, context);
   46       }
   47   
   48       public SessionContext getSessionContextWithSessionId(String sessionId)
   49       {
   50           Asserts.assertNotNull(sessionId, "sessionId parameter can not be null");
   51   
   52           return sessionContexts.get(sessionId);
   53       }
   54   
   55       public void destroySessionContextWithSessionId(String sessionId)
   56       {
   57           Set<String> keySet = sessionContexts.keySet();
   58           Iterator<String> it = keySet.iterator();
   59   
   60           while (it.hasNext())
   61           {
   62               String id = it.next();
   63               if (id.equals(sessionId))
   64               {
   65                   it.remove();
   66               }
   67           }
   68       }
   69   
   70       public void destroyAllSessions()
   71       {
   72           sessionContexts.clear();
   73       }
   74   }

Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.context » [javadoc | source]