[jboss-cvs] JBossAS SVN: r64592 - branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Aug 14 20:33:50 EDT 2007
Author: bdecoste
Date: 2007-08-14 20:33:50 -0400 (Tue, 14 Aug 2007)
New Revision: 64592
Modified:
branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/BaseSessionContext.java
branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/Container.java
branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/EJB3Deployer.java
branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/EJB3Util.java
branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/EJBContainer.java
branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java
branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/Ejb3Registry.java
branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/InitialContextFactory.java
branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/LocalProxy.java
branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/SessionContainer.java
Log:
[EJBTHREE-1019] merged from Branch_4_2
Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/BaseSessionContext.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/BaseSessionContext.java 2007-08-15 00:33:04 UTC (rev 64591)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/BaseSessionContext.java 2007-08-15 00:33:50 UTC (rev 64592)
@@ -122,7 +122,7 @@
public void writeExternal(ObjectOutput out) throws IOException
{
- out.writeUTF(container.getObjectName().getCanonicalName());
+ out.writeUTF(Ejb3Registry.guid(container));
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/Container.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/Container.java 2007-08-15 00:33:04 UTC (rev 64591)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/Container.java 2007-08-15 00:33:50 UTC (rev 64592)
@@ -87,4 +87,6 @@
DependencyPolicy getDependencyPolicy();
InvocationStatistics getInvokeStats();
+
+ boolean isClustered();
}
Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/EJB3Deployer.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/EJB3Deployer.java 2007-08-15 00:33:04 UTC (rev 64591)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/EJB3Deployer.java 2007-08-15 00:33:50 UTC (rev 64592)
@@ -332,7 +332,7 @@
mainDeployer.addDeployer(thisProxy);
// todo remove when we merge older model of ENC
- InitialContext iniCtx = new InitialContext();
+ InitialContext iniCtx = InitialContextFactory.getInitialContext();
initializeJavaComp(iniCtx);
}
Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/EJB3Util.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/EJB3Util.java 2007-08-15 00:33:04 UTC (rev 64591)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/EJB3Util.java 2007-08-15 00:33:50 UTC (rev 64592)
@@ -85,18 +85,6 @@
return defaultContainerName;
}
-
- public static InitialContext getInitialContext(Hashtable props)
- throws NamingException
- {
- InitialContext ctx = null;
- if (props != null)
- {
- ctx = new InitialContext(props);
- }
- else ctx = new InitialContext();
- return ctx;
- }
}
Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/EJBContainer.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/EJBContainer.java 2007-08-15 00:33:04 UTC (rev 64591)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/EJBContainer.java 2007-08-15 00:33:50 UTC (rev 64592)
@@ -433,10 +433,8 @@
{
try
{
- if (initialContextProperties == null)
- return new InitialContext();
- else
- return new InitialContext(initialContextProperties);
+ InitialContext ctx = InitialContextFactory.getInitialContext(initialContextProperties);
+ return ctx;
}
catch (NamingException e)
{
@@ -498,6 +496,8 @@
*/
public String getPartitionName()
{
+ if (partitionName == null)
+ this.findPartitionName();
return partitionName;
}
@@ -1019,4 +1019,9 @@
}
return info;
}
+
+ public boolean isClustered()
+ {
+ return false;
+ }
}
Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java 2007-08-15 00:33:04 UTC (rev 64591)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java 2007-08-15 00:33:50 UTC (rev 64592)
@@ -111,7 +111,7 @@
this.deploymentScope = deploymentScope;
try
{
- initialContext = EJB3Util.getInitialContext(unit.getJndiProperties());
+ initialContext = InitialContextFactory.getInitialContext(unit.getJndiProperties());
}
catch (NamingException e)
{
Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/Ejb3Registry.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/Ejb3Registry.java 2007-08-15 00:33:04 UTC (rev 64591)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/Ejb3Registry.java 2007-08-15 00:33:50 UTC (rev 64592)
@@ -21,11 +21,14 @@
*/
package org.jboss.ejb3;
+import java.rmi.dgc.VMID;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import org.jboss.annotation.ejb.Clustered;
+
import org.jboss.logging.Logger;
/**
@@ -39,34 +42,65 @@
private static final Logger log = Logger.getLogger(Ejb3Registry.class);
private static Map<String, Container> containers = new HashMap<String, Container>();
+ private static Map<String, Container> clusterContainers = new HashMap<String, Container>();
+
+ private static final VMID vmid = new VMID();
/**
* Find a potential container.
*
- * @param oid the canonical object name of the container
+ * @param guid the GUID
* @return the container or null if not found
*/
- public static Container findContainer(String oid)
+ public static Container findContainer(String guid)
{
- return containers.get(oid);
+ return containers.get(guid);
}
+
+ public static VMID getVMID()
+ {
+ return vmid;
+ }
/**
* Reports the existance of a container.
*
- * @param oid the canonical object name of the container
+ * @param guid the GUID
* @return true if found, false otherwise
*/
- public static boolean hasContainer(String oid)
+ public static boolean hasContainer(String guid)
{
- return containers.containsKey(oid);
+ return containers.containsKey(guid);
}
- private static final String oid(Container container)
+ public static boolean hasClusterContainer(String oid)
{
+ return clusterContainers.containsKey(oid);
+ }
+
+ public static final String guid(Container container, VMID vmid)
+ {
+ return container.getObjectName().getCanonicalName() + ",VMID=" + vmid;
+ }
+
+ public static final String guid(Container container)
+ {
+ return guid(container, vmid);
+ }
+
+ public static final String clusterUid(Container container)
+ {
+ if (container.isClustered())
+ return container.getObjectName().getCanonicalName() + ",Partition=" + ((EJBContainer)container).getPartitionName();
+
return container.getObjectName().getCanonicalName();
}
+ public static final String clusterUid(String oid, String partitionName)
+ {
+ return oid + ",Partition=" + partitionName;
+ }
+
/**
* Registers a container.
*
@@ -75,10 +109,13 @@
*/
public static void register(Container container)
{
- String oid = oid(container);
- if(hasContainer(oid))
- throw new IllegalStateException("Container " + oid + " + is already registered");
- containers.put(oid, container);
+ String guid = guid(container);
+ if(hasContainer(guid))
+ throw new IllegalStateException("Container " + guid + " + is already registered");
+ containers.put(guid, container);
+
+ if (container.isClustered())
+ clusterContainers.put(clusterUid(container), container);
}
/**
@@ -89,13 +126,32 @@
*/
public static void unregister(Container container)
{
- String oid = oid(container);
- if(!hasContainer(oid))
- throw new IllegalStateException("Container " + oid + " + is not registered");
- containers.remove(oid);
+ String guid = guid(container);
+ if(!hasContainer(guid))
+ throw new IllegalStateException("Container " + guid + " + is not registered");
+ containers.remove(guid);
+
+ if (container.isClustered())
+ clusterContainers.remove(clusterUid(container));
}
/**
+ * Returns the container specified by the given GUID.
+ * Never returns null.
+ *
+ * @param guid the GUID
+ * @return the container
+ * @throws IllegalStateException if the container is not registered
+ */
+ public static Container getContainer(String guid)
+ {
+ if(!hasContainer(guid))
+ throw new IllegalStateException("Container " + guid + " is not registered");
+
+ return containers.get(guid);
+ }
+
+ /**
* Returns the container specified by the given canocical object name.
* Never returns null.
*
@@ -103,11 +159,13 @@
* @return the container
* @throws IllegalStateException if the container is not registered
*/
- public static Container getContainer(String oid)
+ public static Container getClusterContainer(String clusterUid)
{
- if(!hasContainer(oid))
- throw new IllegalStateException("Container " + oid + " is not registered");
- return containers.get(oid);
+ Container container = clusterContainers.get(clusterUid);
+ if(container == null)
+ throw new IllegalStateException("Container " + clusterUid + " is not registered " + clusterContainers);
+
+ return container;
}
/**
@@ -119,5 +177,4 @@
{
return Collections.unmodifiableCollection(containers.values());
}
-
}
Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/InitialContextFactory.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/InitialContextFactory.java 2007-08-15 00:33:04 UTC (rev 64591)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/InitialContextFactory.java 2007-08-15 00:33:50 UTC (rev 64592)
@@ -21,27 +21,54 @@
*/
package org.jboss.ejb3;
+import java.util.Hashtable;
import java.util.Properties;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
+import org.jboss.logging.Logger;
+
+import org.jboss.mx.util.MBeanServerLocator;
+
/**
* @version <tt>$Revision$</tt>
* @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
*/
public class InitialContextFactory
{
+private static final Logger log = Logger.getLogger(InitialContextFactory.class);
+
private static Properties props = null;
private static Properties securityProperties = null;
+ private static InitialContext baseInitialContext = null;
+ private static Context haContext = null;
+ private static Integer haJndiPort = null;
public static InitialContext getInitialContext() throws NamingException
{
InitialContext jndiContext;
-
+
if (props == null)
- jndiContext = new InitialContext();
+ {
+ if (baseInitialContext == null)
+ {
+ baseInitialContext = new InitialContext();
+ }
+ jndiContext = baseInitialContext;
+
+ try
+ {
+ jndiContext.getEnvironment();
+ }
+ catch (NamingException e)
+ {
+ jndiContext = baseInitialContext = new InitialContext();
+ }
+ }
else
{
if (securityProperties != null)
@@ -54,10 +81,62 @@
else
jndiContext = new InitialContext(props);
}
-
+
return jndiContext;
}
+ public static InitialContext getInitialContext(Hashtable props)
+ throws NamingException
+ {
+ InitialContext ctx = null;
+ if (props != null)
+ {
+ ctx = new InitialContext(props);
+ }
+ else
+ {
+ ctx = getInitialContext();
+ }
+ return ctx;
+ }
+
+ public static Context getHAContext(Context ctx)
+ throws NamingException
+ {
+ if (haContext == null)
+ {
+ Hashtable env = ctx.getEnvironment();
+ Object providerUrl = env.get(Context.PROVIDER_URL);
+ if (providerUrl == null)
+ {
+ try
+ {
+ env.put(Context.PROVIDER_URL, "localhost:" + getHaJndiPort());
+ InitialContext haCtx = new InitialContext(env);
+ haCtx.bind("HA_TEST", null);
+ haCtx.unbind("HA_TEST");
+ haContext = haCtx;
+ }
+ catch (Exception e)
+ {
+ log.debug("Unable to access HA JNDI: " + e);
+ }
+ }
+ }
+ return haContext;
+ }
+
+ private static Integer getHaJndiPort() throws Exception
+ {
+ if (haJndiPort == null)
+ {
+ MBeanServer server = MBeanServerLocator.locateJBoss();
+ ObjectName objectName = new ObjectName("jboss:service=HAJNDI");
+ haJndiPort = (Integer)server.getAttribute(objectName, "Port");
+ }
+ return haJndiPort;
+ }
+
public static void setProperties(Properties properties)
{
props = properties;
Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/LocalProxy.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/LocalProxy.java 2007-08-15 00:33:04 UTC (rev 64591)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/LocalProxy.java 2007-08-15 00:33:50 UTC (rev 64592)
@@ -40,9 +40,10 @@
{
private static Logger log = Logger.getLogger(LocalProxy.class);
- // FIXME: should be private
- protected transient Container container = null;
- private String containerId;
+ private transient Container container = null;
+ protected String containerClusterUid;
+ protected String containerGuid;
+ protected String proxyName;
protected LocalProxy()
{
@@ -51,28 +52,32 @@
protected LocalProxy(Container container)
{
this.container = container;
- this.containerId = container.getObjectName().getCanonicalName();
+ this.containerGuid = Ejb3Registry.guid(container);
+ this.containerClusterUid = Ejb3Registry.clusterUid(container);
+ proxyName = container.getEjbName();
}
protected Container getContainer()
{
if(container == null)
- container = Ejb3Registry.findContainer(containerId);
+ container = Ejb3Registry.findContainer(containerGuid);
if(container == null)
- log.warn("Container " + containerId + " is not yet available");
+ log.warn("Container " + containerGuid + " is not yet available");
return container;
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
{
- this.containerId = in.readUTF();
- // TODO: one container is private, this won't have to be done anymore
- this.container = Ejb3Registry.findContainer(containerId);
+ this.containerGuid = in.readUTF();
+ this.containerClusterUid = in.readUTF();
+ this.proxyName = in.readUTF();
}
public void writeExternal(ObjectOutput out) throws IOException
{
- out.writeUTF(containerId);
+ out.writeUTF(containerGuid);
+ out.writeUTF(containerClusterUid);
+ out.writeUTF(proxyName);
}
public abstract String toString();
Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/SessionContainer.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/SessionContainer.java 2007-08-15 00:33:04 UTC (rev 64591)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/SessionContainer.java 2007-08-15 00:33:50 UTC (rev 64592)
@@ -238,7 +238,7 @@
public static InvocationResponse marshallException(Invocation invocation, Throwable exception, Map responseContext) throws Throwable
{
- if (!invocation.getMetaData().hasTag(IsLocalInterceptor.IS_LOCAL)) throw exception;
+ if (invocation.getMetaData(IsLocalInterceptor.IS_LOCAL,IsLocalInterceptor.IS_LOCAL) == null) throw exception;
InvocationResponse response = new InvocationResponse();
response.setContextInfo(responseContext);
@@ -253,7 +253,7 @@
{
InvocationResponse response;
// marshall return value
- if (rtn != null && invocation.getMetaData().hasTag(IsLocalInterceptor.IS_LOCAL))
+ if (rtn != null && invocation.getMetaData(IsLocalInterceptor.IS_LOCAL, IsLocalInterceptor.IS_LOCAL) != null)
{
response = new InvocationResponse(new MarshalledObjectForLocalCalls(rtn));
}
More information about the jboss-cvs-commits
mailing list