openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yingw...@apache.org
Subject svn commit: r983032 - in /openwebbeans/trunk: webbeans-impl/src/main/java/org/apache/webbeans/context/ webbeans-impl/src/main/java/org/apache/webbeans/conversation/ webbeans-web/src/main/java/org/apache/webbeans/servlet/
Date Fri, 06 Aug 2010 15:54:14 GMT
Author: yingwang
Date: Fri Aug  6 15:54:13 2010
New Revision: 983032

URL: http://svn.apache.org/viewvc?rev=983032&view=rev
Log:
[OWB-385] commit failover part1

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ConversationContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/SessionContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationManager.java
    openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ConversationContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ConversationContext.java?rev=983032&r1=983031&r2=983032&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ConversationContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ConversationContext.java
Fri Aug  6 15:54:13 2010
@@ -18,17 +18,28 @@
  */
 package org.apache.webbeans.context;
 
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.NotSerializableException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.lang.annotation.Annotation;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
 import javax.enterprise.context.spi.Contextual;
 
+import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.context.creational.BeanInstanceBag;
 import org.apache.webbeans.context.type.ContextTypes;
+import org.apache.webbeans.util.WebBeansUtil;
 
 /**
  * Conversation context implementation. 
  */
-public class ConversationContext extends AbstractContext
+public class ConversationContext extends AbstractContext implements Externalizable
 {
     /*
      * Constructor
@@ -44,4 +55,46 @@ public class ConversationContext extends
         this.componentInstanceMap = new ConcurrentHashMap<Contextual<?>, BeanInstanceBag<?>>();
     }
 
+    public void readExternal(ObjectInput in) throws IOException,
+            ClassNotFoundException 
+    {
+        this.type = (ContextTypes) in.readObject();
+        this.scopeType = (Class<? extends Annotation>) in.readObject();
+        Map<String, BeanInstanceBag<?>> map = (Map<String, BeanInstanceBag<?>>)in.readObject();
+        setComponentInstanceMap();
+        Iterator<String> it = map.keySet().iterator();
+        Contextual<?> contextual = null;
+        while(it.hasNext()) 
+        {
+            String id = (String)it.next();
+            if (id != null)
+            {
+                contextual = (Contextual<?>) BeanManagerImpl.getManager().getPassivationCapableBean(id);
+            }
+            if (contextual != null) 
+            {
+                componentInstanceMap.put(contextual, map.get(id));
+            }
+        }
+    }
+
+    public void writeExternal(ObjectOutput out) throws IOException 
+    {
+            out.writeObject(this.type);
+            out.writeObject(this.scopeType);
+            Iterator<Contextual<?>> it = componentInstanceMap.keySet().iterator();
+            Map<String, BeanInstanceBag<?>> map = new HashMap<String, BeanInstanceBag<?>>();
+            while(it.hasNext()) 
+            {
+                Contextual<?>contextual = it.next();
+                String id = WebBeansUtil.isPassivationCapable(contextual);
+                if (id == null) 
+                {
+                    throw new NotSerializableException("cannot serialize " + contextual.toString());
+                }
+                map.put(id, componentInstanceMap.get(contextual));
+            }
+            out.writeObject(map);
+    }
+    
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/SessionContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/SessionContext.java?rev=983032&r1=983031&r2=983032&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/SessionContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/SessionContext.java
Fri Aug  6 15:54:13 2010
@@ -18,18 +18,29 @@
  */
 package org.apache.webbeans.context;
 
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.NotSerializableException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
 import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
 import javax.enterprise.context.spi.Contextual;
 
+import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.context.creational.BeanInstanceBag;
 import org.apache.webbeans.context.type.ContextTypes;
+import org.apache.webbeans.util.WebBeansUtil;
 
 /**
  * Session context implementation.
  */
-public class SessionContext extends AbstractContext implements Serializable
+public class SessionContext extends AbstractContext implements Serializable, Externalizable
 {
     private static final long serialVersionUID = 1L;
 
@@ -44,4 +55,46 @@ public class SessionContext extends Abst
         this.componentInstanceMap = new ConcurrentHashMap<Contextual<?>, BeanInstanceBag<?>>();
     }
 
+    public void readExternal(ObjectInput in) throws IOException,
+            ClassNotFoundException 
+    {
+        this.type = (ContextTypes) in.readObject();
+        this.scopeType = (Class<? extends Annotation>) in.readObject();
+        Map<String, BeanInstanceBag<?>> map = (Map<String, BeanInstanceBag<?>>)in.readObject();
+        setComponentInstanceMap();
+        Iterator<String> it = map.keySet().iterator();
+        Contextual<?> contextual = null;
+        while(it.hasNext()) 
+        {
+            String id = (String)it.next();
+            if (id != null)
+            {
+                contextual = (Contextual<?>) BeanManagerImpl.getManager().getPassivationCapableBean(id);
+            }
+            if (contextual != null) 
+            {
+                componentInstanceMap.put(contextual, map.get(id));
+            }
+        }
+    }
+
+    public void writeExternal(ObjectOutput out) throws IOException 
+    {
+        out.writeObject(this.type);
+        out.writeObject(this.scopeType);
+        Iterator<Contextual<?>> it = componentInstanceMap.keySet().iterator();
+        Map<String, BeanInstanceBag<?>> map = new HashMap<String, BeanInstanceBag<?>>();
+        while(it.hasNext()) 
+        {
+            Contextual<?>contextual = it.next();
+            String id = WebBeansUtil.isPassivationCapable(contextual);
+            if (id == null) 
+            {
+                throw new NotSerializableException("cannot serialize " + contextual.toString());
+            }
+            map.put(id, componentInstanceMap.get(contextual));
+        }
+        out.writeObject(map);
+    }
+    
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationImpl.java?rev=983032&r1=983031&r2=983032&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationImpl.java
Fri Aug  6 15:54:13 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.webbeans.conversation;
 
+import java.io.Serializable;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -35,8 +36,13 @@ import org.apache.webbeans.util.Asserts;
  * @version $Rev$ $Date$
  *
  */
-public class ConversationImpl implements Conversation
+public class ConversationImpl implements Conversation, Serializable
 {
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 8511063860333431722L;
+
     /**Logger instance*/
     private static final WebBeansLogger logger = WebBeansLogger.getLogger(ConversationImpl.class);
     

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationManager.java?rev=983032&r1=983031&r2=983032&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationManager.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationManager.java
Fri Aug  6 15:54:13 2010
@@ -19,7 +19,9 @@
 package org.apache.webbeans.conversation;
 
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -96,6 +98,31 @@ public class ConversationManager
         
         return false;
     }
+    
+    /**
+     * Return all conversation/context associated with sessionid.
+     * 
+     * @param sessionId
+     * @return
+     */
+    public Map<Conversation, ConversationContext> getConversationMapWithSessionId(String
sessionId) 
+    {
+        Asserts.assertNotNull(sessionId,"sessionId parameter can not be null");
+        Set<Conversation> set = conversations.keySet();
+        Iterator<Conversation> it = set.iterator();
+        ConversationImpl conv = null;
+        Map<Conversation, ConversationContext> map = new HashMap<Conversation, ConversationContext>();
+        while (it.hasNext())
+        {
+            conv = (ConversationImpl) it.next();
+            if (conv.getSessionId().equals(sessionId))
+            {
+                map.put(conv, conversations.get(conv));
+            }
+        }
+        return map;
+    }
+    
 
     /**
      * Remove given conversation.

Modified: openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java?rev=983032&r1=983031&r2=983032&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java
(original)
+++ openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java
Fri Aug  6 15:54:13 2010
@@ -33,10 +33,12 @@ import javax.servlet.http.HttpSessionLis
 import org.apache.webbeans.config.OWBLogConst;
 import org.apache.webbeans.config.OpenWebBeansConfiguration;
 import org.apache.webbeans.conversation.ConversationManager;
+import org.apache.webbeans.corespi.ServiceLoader;
 import org.apache.webbeans.el.ELContextStore;
 import org.apache.webbeans.lifecycle.LifecycleFactory;
 import org.apache.webbeans.logger.WebBeansLogger;
 import org.apache.webbeans.spi.ContainerLifecycle;
+import org.apache.webbeans.spi.FailOverService;
 import org.apache.webbeans.util.WebBeansUtil;
 
 /**
@@ -53,12 +55,15 @@ public class WebBeansConfigurationListen
     /**Manages the container lifecycle*/
     protected ContainerLifecycle lifeCycle = null;
     
+    protected FailOverService failoverService = null;
+    
     /**
      * Default constructor
      */
     public WebBeansConfigurationListener()
     {
-        
+        failoverService = (FailOverService)
+        ServiceLoader.getService(FailOverService.class);
     }
 
     /**
@@ -102,6 +107,21 @@ public class WebBeansConfigurationListen
         }
         this.lifeCycle.getContextService().endContext(RequestScoped.class, event);      
 
 
+        if (failoverService != null && 
+                failoverService.isSupportFailOver()) 
+        {
+            Object request = event.getServletRequest();
+            if(request instanceof HttpServletRequest)
+            {
+                HttpServletRequest httpRequest = (HttpServletRequest)request;
+                HttpSession session = httpRequest.getSession(false);
+                if (session != null) 
+                {
+                    failoverService.sessionIsIdle(session);
+                }
+            }
+        }
+        
         // clean up the EL caches after each request
         ELContextStore elStore = ELContextStore.getInstance(false);
         if (elStore != null)
@@ -141,7 +161,15 @@ public class WebBeansConfigurationListen
                     {
                         logger.error(OWBLogConst.ERROR_0013, e);
                     }
-                }
+                } 
+                else 
+                {
+                    if (failoverService != null && 
+                            failoverService.isSupportFailOver()) 
+                    {
+                        failoverService.sessionIsInUse(currentSession);
+                    }
+                }                
             }
 
         }
@@ -193,7 +221,6 @@ public class WebBeansConfigurationListen
     @Override
     public void sessionDidActivate(HttpSessionEvent event)
     {
-        //TODO activation
     }
 
     /**
@@ -202,7 +229,6 @@ public class WebBeansConfigurationListen
     @Override
     public void sessionWillPassivate(HttpSessionEvent event)
     {
-        //TODO Passivation
     }
 
 }



Mime
View raw message