[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openejb-cvs
Subject:    [openejb-scm] openejb/modules/core/src/java/org/openejb/cluster/sfsb ClusteredSFInstanceContext.java
From:       gdamour () codehaus ! org
Date:       2005-12-21 14:21:53
Message-ID: 20051221142153.17217.qmail () codehaus ! org
[Download RAW message or body]

gdamour     2005/12/21 09:21:53

  Added:       modules/core/src/java/org/openejb/cluster/sfsb
                        ClusteredSFInstanceContext.java
                        ClusteredSFInstanceContextFactory.java
                        SFInstanceContextRecreator.java
  Log:

  GERONIMO-1397 Clustering of SFSB
  
  First step of many others to add the clustering of SFSB.
  
  This check-in adds the following features:
  * definition of an EJBClusterManager, which abstracts an EJB Cluster node;
  * this EJB cluster node is a standard GBean (the default or
  WADI implementation is DefaultEJBClusterManager);
  * in an openejb-jar.xml DD, a SFSB can declare a reference to this node via
  the ejb-cluster-reference element;
  * when the SFSB container is started, the EJB cluster node notifies
  the cluster that it is running a specific SFSB container;
  * when a clustered SFSB InstanceContext is created, an array of nodes running
  the container of this SFSB is associated to the InstanceContext. Note that
  this array of nodes is updated upon start-up of a clustered SFSB container or
  upon node failure;
  * this array of nodes capable of running the created SFSB is propagated to
  clients. Actually, this array is propagated at each EJB invocation.
  
  Revision  Changes    Path
  1.1                  \
openejb/modules/core/src/java/org/openejb/cluster/sfsb/ClusteredSFInstanceContext.java
  
  Index: ClusteredSFInstanceContext.java
  ===================================================================
  /**
   * Redistribution and use of this software and associated documentation
   * ("Software"), with or without modification, are permitted provided
   * that the following conditions are met:
   *
   * 1. Redistributions of source code must retain copyright
   *    statements and notices.  Redistributions must also contain a
   *    copy of this document.
   *
   * 2. Redistributions in binary form must reproduce the
   *    above copyright notice, this list of conditions and the
   *    following disclaimer in the documentation and/or other
   *    materials provided with the distribution.
   *
   * 3. The name "OpenEJB" must not be used to endorse or promote
   *    products derived from this Software without prior written
   *    permission of The OpenEJB Group.  For written permission,
   *    please contact info@openejb.org.
   *
   * 4. Products derived from this Software may not be called "OpenEJB"
   *    nor may "OpenEJB" appear in their names without prior written
   *    permission of The OpenEJB Group. OpenEJB is a registered
   *    trademark of The OpenEJB Group.
   *
   * 5. Due credit should be given to the OpenEJB Project
   *    (http://openejb.org/).
   *
   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
   * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * Copyright 2005 (C) The OpenEJB Group. All Rights Reserved.
   *
   * $Id: ClusteredSFInstanceContext.java,v 1.1 2005/12/21 14:21:52 gdamour Exp $
   */
  package org.openejb.cluster.sfsb;
  
  import java.util.Set;
  
  import javax.ejb.SessionBean;
  
  import org.apache.geronimo.core.service.Interceptor;
  import org.apache.geronimo.transaction.context.TransactionContextManager;
  import org.apache.geronimo.transaction.context.UserTransactionImpl;
  import org.openejb.client.ServerMetaData;
  import org.openejb.cluster.server.ClusteredEJBInstanceContext;
  import org.openejb.cluster.server.ServerMetaDataArrayHolder;
  import org.openejb.dispatch.SystemMethodIndices;
  import org.openejb.proxy.EJBProxyFactory;
  import org.openejb.sfsb.StatefulInstanceContext;
  
  /**
   * 
   * @version $Revision: 1.1 $ $Date: 2005/12/21 14:21:52 $
   */
  public class ClusteredSFInstanceContext extends StatefulInstanceContext implements \
ClusteredEJBInstanceContext {  private ServerMetaDataArrayHolder serversHolder;
      
      public ClusteredSFInstanceContext(Object containerId,
              EJBProxyFactory proxyFactory,
              SessionBean instance,
              Object id,
              TransactionContextManager transactionContextManager,
              UserTransactionImpl userTransaction,
              SystemMethodIndices systemMethodIndices,
              Interceptor systemChain,
              Set unshareableResources,
              Set applicationManagedSecurityResources,
              ServerMetaDataArrayHolder serversHolder) {
          super(containerId, proxyFactory, instance, id, transactionContextManager,
                  userTransaction, systemMethodIndices, systemChain,
                  unshareableResources, applicationManagedSecurityResources);
          this.serversHolder = serversHolder;
      }
  
      public ServerMetaData[] getServers() {
          return serversHolder.getServers();
      }
      
      public void flush() throws Throwable {
          super.flush();
          
          // TODO hook replication.
      }
  }
  
  
  
  1.1                  \
openejb/modules/core/src/java/org/openejb/cluster/sfsb/ClusteredSFInstanceContextFactory.java
  
  Index: ClusteredSFInstanceContextFactory.java
  ===================================================================
  /**
   * Redistribution and use of this software and associated documentation
   * ("Software"), with or without modification, are permitted provided
   * that the following conditions are met:
   *
   * 1. Redistributions of source code must retain copyright
   *    statements and notices.  Redistributions must also contain a
   *    copy of this document.
   *
   * 2. Redistributions in binary form must reproduce the
   *    above copyright notice, this list of conditions and the
   *    following disclaimer in the documentation and/or other
   *    materials provided with the distribution.
   *
   * 3. The name "OpenEJB" must not be used to endorse or promote
   *    products derived from this Software without prior written
   *    permission of The OpenEJB Group.  For written permission,
   *    please contact info@openejb.org.
   *
   * 4. Products derived from this Software may not be called "OpenEJB"
   *    nor may "OpenEJB" appear in their names without prior written
   *    permission of The OpenEJB Group. OpenEJB is a registered
   *    trademark of The OpenEJB Group.
   *
   * 5. Due credit should be given to the OpenEJB Project
   *    (http://openejb.org/).
   *
   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
   * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * Copyright 2005 (C) The OpenEJB Group. All Rights Reserved.
   *
   * $Id: ClusteredSFInstanceContextFactory.java,v 1.1 2005/12/21 14:21:52 gdamour \
                Exp $
   */
  package org.openejb.cluster.sfsb;
  
  import java.io.Serializable;
  import java.util.Set;
  
  import javax.ejb.EnterpriseBean;
  import javax.ejb.SessionBean;
  
  import org.apache.geronimo.transaction.InstanceContext;
  import org.apache.geronimo.transaction.context.UserTransactionImpl;
  import org.openejb.EJBInstanceContext;
  import org.openejb.cluster.server.ClusteredInstanceContextFactory;
  import org.openejb.cluster.server.EJBClusterManager;
  import org.openejb.cluster.server.EJBInstanceContextRecreator;
  import org.openejb.cluster.server.ServerMetaDataArrayHolder;
  import org.openejb.sfsb.StatefulInstanceContextFactory;
  
  /**
   * 
   * @version $Revision: 1.1 $ $Date: 2005/12/21 14:21:52 $
   */
  public class ClusteredSFInstanceContextFactory extends \
StatefulInstanceContextFactory  implements ClusteredInstanceContextFactory {
      private transient EJBClusterManager clusterManager;
      private final SFInstanceContextRecreator recreator;
      private transient ServerMetaDataArrayHolder serversHolder;
  
      public ClusteredSFInstanceContextFactory(Object containerId,
              Class beanClass,
              UserTransactionImpl userTransaction,
              Set unshareableResources,
              Set applicationManagedSecurityResources) {
          super(containerId,
                  beanClass,
                  userTransaction,
                  unshareableResources,
                  applicationManagedSecurityResources);
          
          recreator = new SFInstanceContextRecreator(); 
      }
      
      public void setEJBClusterManager(EJBClusterManager clusterManager) {
          this.clusterManager = clusterManager;
      }
  
      public void setServersHolder(ServerMetaDataArrayHolder serversHolder) {
          this.serversHolder = serversHolder;
      }
  
      public EJBInstanceContextRecreator getInstanceContextRecreator() {
          return recreator;
      }
      
      public InstanceContext newInstance() throws Exception {
          if (proxyFactory == null) {
              throw new IllegalStateException("ProxyFacory has not been set");
          }
  
          if (null == clusterManager) {
              return super.newInstance();
          }
  
          SessionBean bean = createInstance();
          String id = clusterManager.addInstance(bean, containerId);
  
          return newInstanceContext(id, bean);
      }
  
      private EJBInstanceContext newInstanceContext(String id, EnterpriseBean bean) {
          if (false == bean instanceof SessionBean) {
              throw new IllegalArgumentException("bean must be a " +
                  SessionBean.class + ". Was :" + bean.getClass());
          }
          
          return new ClusteredSFInstanceContext(
                  containerId,
                  proxyFactory,
                  (SessionBean) bean,
                  id,
                  transactionContextManager, userTransaction,
                  systemMethodIndices, systemChain, unshareableResources,
                  applicationManagedSecurityResources,
                  serversHolder);
      }
      
      private class SFInstanceContextRecreator implements \
EJBInstanceContextRecreator, Serializable {  
          public EJBInstanceContext recreate(Object id, EnterpriseBean bean) {
              if (false == id instanceof String) {
                  throw new IllegalArgumentException("Id should be a String.");
              }
              return newInstanceContext((String) id , bean);
          }
  
      }
  }
  
  
  
  1.1                  \
openejb/modules/core/src/java/org/openejb/cluster/sfsb/SFInstanceContextRecreator.java
  
  Index: SFInstanceContextRecreator.java
  ===================================================================
  /**
   * Redistribution and use of this software and associated documentation
   * ("Software"), with or without modification, are permitted provided
   * that the following conditions are met:
   *
   * 1. Redistributions of source code must retain copyright
   *    statements and notices.  Redistributions must also contain a
   *    copy of this document.
   *
   * 2. Redistributions in binary form must reproduce the
   *    above copyright notice, this list of conditions and the
   *    following disclaimer in the documentation and/or other
   *    materials provided with the distribution.
   *
   * 3. The name "OpenEJB" must not be used to endorse or promote
   *    products derived from this Software without prior written
   *    permission of The OpenEJB Group.  For written permission,
   *    please contact info@openejb.org.
   *
   * 4. Products derived from this Software may not be called "OpenEJB"
   *    nor may "OpenEJB" appear in their names without prior written
   *    permission of The OpenEJB Group. OpenEJB is a registered
   *    trademark of The OpenEJB Group.
   *
   * 5. Due credit should be given to the OpenEJB Project
   *    (http://openejb.org/).
   *
   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
   * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * Copyright 2005 (C) The OpenEJB Group. All Rights Reserved.
   *
   * $Id: SFInstanceContextRecreator.java,v 1.1 2005/12/21 14:21:52 gdamour Exp $
   */
  package org.openejb.cluster.sfsb;
  
  import java.util.Set;
  
  import javax.ejb.EnterpriseBean;
  import javax.ejb.SessionBean;
  
  import org.apache.geronimo.core.service.Interceptor;
  import org.apache.geronimo.transaction.context.TransactionContextManager;
  import org.apache.geronimo.transaction.context.UserTransactionImpl;
  import org.openejb.EJBInstanceContext;
  import org.openejb.cluster.server.EJBInstanceContextRecreator;
  import org.openejb.dispatch.SystemMethodIndices;
  import org.openejb.proxy.EJBProxyFactory;
  import org.openejb.sfsb.StatefulInstanceContext;
  
  /**
   * 
   * @version $Revision: 1.1 $ $Date: 2005/12/21 14:21:52 $
   */
  class SFInstanceContextRecreator implements EJBInstanceContextRecreator {
      private final Object containerId;
      private final UserTransactionImpl userTransaction;
      private final Set unshareableResources;
      private final Set applicationManagedSecurityResources;
      private transient EJBProxyFactory proxyFactory;
      private transient Interceptor systemChain;
      private transient SystemMethodIndices systemMethodIndices;
      private transient TransactionContextManager transactionContextManager;
      
      public SFInstanceContextRecreator(Object containerId,
              UserTransactionImpl userTransaction,
              Set unshareableResources,
              Set applicationManagedSecurityResources,
              EJBProxyFactory proxyFactory,
              Interceptor systemChain,
              SystemMethodIndices systemMethodIndices,
              TransactionContextManager transactionContextManager) {
          this.containerId = containerId;
          this.userTransaction = userTransaction;
          this.unshareableResources = unshareableResources;
          this.applicationManagedSecurityResources = \
applicationManagedSecurityResources;  this.proxyFactory = proxyFactory;
          this.systemChain = systemChain;
          this.systemMethodIndices = systemMethodIndices;
          this.transactionContextManager = transactionContextManager;
      }
  
      public EJBInstanceContext recreate(Object id, EnterpriseBean bean) {
          if (false == bean instanceof SessionBean) {
              throw new IllegalArgumentException("bean must be a " + 
                      SessionBean.class + ". Was :" + bean.getClass());
          }
  
          return new StatefulInstanceContext(
                  containerId,
                  proxyFactory,
                  (SessionBean) bean,
                  id,
                  transactionContextManager,
                  userTransaction,
                  systemMethodIndices,
                  systemChain,
                  unshareableResources,
                  applicationManagedSecurityResources);
      }
  }
  
  


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic