dain        2006/02/01 06:50:03

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

  Major refactor
  Split container into an object to represent a deployed ejb and a set of 
shared containers which process invocations
  Introduced interface between CMP container and CMP engine
  
  Revision  Changes    Path
  1.2       +90 -94    
openejb/modules/core/src/java/org/openejb/cluster/sfsb/ClusteredSFInstanceContext.java
  
  Index: ClusteredSFInstanceContext.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/cluster/sfsb/ClusteredSFInstanceContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ClusteredSFInstanceContext.java   21 Dec 2005 14:21:52 -0000      1.1
  +++ ClusteredSFInstanceContext.java   1 Feb 2006 11:50:03 -0000       1.2
  @@ -1,94 +1,90 @@
  -/**

  - * 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 [EMAIL PROTECTED]

  - *

  - * 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$

  - */

  -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$ $Date$

  - */

  -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.

  -    }

  -}

  +/**
  + * 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 [EMAIL PROTECTED]
  + *
  + * 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$
  + */
  +package org.openejb.cluster.sfsb;
  +
  +import java.util.Set;
  +import javax.ejb.SessionBean;
  +
  +import org.openejb.StatefulEjbDeployment;
  +import org.openejb.client.ServerMetaData;
  +import org.openejb.cluster.server.ClusteredEJBInstanceContext;
  +import org.openejb.cluster.server.ServerMetaDataArrayHolder;
  +import org.openejb.proxy.EJBProxyFactory;
  +import org.openejb.sfsb.StatefulInstanceContext;
  +import org.openejb.StatefulEjbContainer;
  +
  +/**
  + * @version $Revision$ $Date$
  + */
  +public class ClusteredSFInstanceContext extends StatefulInstanceContext 
implements ClusteredEJBInstanceContext {
  +    private ServerMetaDataArrayHolder serversHolder;
  +
  +    public ClusteredSFInstanceContext(StatefulEjbDeployment 
statefulEjbDeployment,
  +            StatefulEjbContainer statefulEjbContainer,
  +            SessionBean instance,
  +            Object id,
  +            EJBProxyFactory proxyFactory,
  +            Set unshareableResources,
  +            Set applicationManagedSecurityResources,
  +            ServerMetaDataArrayHolder serversHolder) {
  +        super(statefulEjbDeployment,
  +                statefulEjbContainer,
  +                instance,
  +                id,
  +                proxyFactory,
  +                unshareableResources,
  +                applicationManagedSecurityResources);
  +        this.serversHolder = serversHolder;
  +    }
  +
  +    public ServerMetaData[] getServers() {
  +        return serversHolder.getServers();
  +    }
  +
  +    public void flush() throws Throwable {
  +        super.flush();
  +        // TODO hook replication.
  +    }
  +}
  
  
  
  1.2       +125 -140  
openejb/modules/core/src/java/org/openejb/cluster/sfsb/ClusteredSFInstanceContextFactory.java
  
  Index: ClusteredSFInstanceContextFactory.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/cluster/sfsb/ClusteredSFInstanceContextFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ClusteredSFInstanceContextFactory.java    21 Dec 2005 14:21:52 -0000      
1.1
  +++ ClusteredSFInstanceContextFactory.java    1 Feb 2006 11:50:03 -0000       
1.2
  @@ -1,140 +1,125 @@
  -/**

  - * 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 [EMAIL PROTECTED]

  - *

  - * 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$

  - */

  -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$ $Date$

  - */

  -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);

  -        }

  -

  -    }

  -}

  +/**
  + * 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 [EMAIL PROTECTED]
  + *
  + * 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$
  + */
  +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.openejb.EJBInstanceContext;
  +import org.openejb.StatefulEjbDeployment;
  +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.proxy.EJBProxyFactory;
  +import org.openejb.sfsb.StatefulInstanceContextFactory;
  +import org.openejb.StatefulEjbContainer;
  +
  +/**
  + * @version $Revision$ $Date$
  + */
  +public class ClusteredSFInstanceContextFactory extends 
StatefulInstanceContextFactory
  +        implements ClusteredInstanceContextFactory {
  +    private transient EJBClusterManager clusterManager;
  +    private final SFInstanceContextRecreator recreator;
  +    private transient ServerMetaDataArrayHolder serversHolder;
  +
  +    public ClusteredSFInstanceContextFactory(StatefulEjbDeployment 
statefulEjbDeployment,
  +            StatefulEjbContainer statefulEjbContainer,
  +            EJBProxyFactory proxyFactory,
  +            Set unshareableResources,
  +            Set applicationManagedSecurityResources) {
  +        super(statefulEjbDeployment, statefulEjbContainer, proxyFactory, 
unshareableResources, applicationManagedSecurityResources);
  +        recreator = new SFInstanceContextRecreator();
  +    }
  +
  +    public void setClusterManager(EJBClusterManager clusterManager) {
  +        this.clusterManager = clusterManager;
  +    }
  +
  +    public void setServersHolder(ServerMetaDataArrayHolder serversHolder) {
  +        this.serversHolder = serversHolder;
  +    }
  +
  +    public EJBInstanceContextRecreator getInstanceContextRecreator() {
  +        return recreator;
  +    }
  +
  +    public InstanceContext newInstance() throws Exception {
  +        SessionBean bean = createInstance();
  +        String id = clusterManager.addInstance(bean, 
statefulEjbDeployment.getContainerId());
  +
  +        return newInstanceContext(id, bean);
  +    }
  +
  +    private EJBInstanceContext newInstanceContext(String id, SessionBean 
bean) {
  +        return new ClusteredSFInstanceContext(
  +                statefulEjbDeployment,
  +                statefulEjbContainer,
  +                bean,
  +                id,
  +                proxyFactory,
  +                unshareableResources,
  +                applicationManagedSecurityResources,
  +                serversHolder);
  +    }
  +
  +    private class SFInstanceContextRecreator implements 
EJBInstanceContextRecreator, Serializable {
  +        private static final long serialVersionUID = -3075688417789981035L;
  +
  +        public EJBInstanceContext recreate(Object id, EnterpriseBean bean) {
  +            if (!(id instanceof String)) {
  +                throw new IllegalArgumentException("id must be a String");
  +            }
  +            if (!(bean instanceof SessionBean)) {
  +                throw new IllegalArgumentException("bean must be a 
SessionBean");
  +            }
  +            return newInstanceContext((String) id, (SessionBean) bean);
  +        }
  +    }
  +}
  \ No newline at end of file
  
  
  

Reply via email to