From c3eb53bc966e3c440d0fe7ba2fa4a80bd2488ea4 Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Wed, 15 Mar 2017 15:57:38 +1100 Subject: [PATCH 1/2] Tie session creation to the naming provider as well --- src/main/java/org/jboss/ejb/client/EJBClient.java | 15 ++++++++++++++- .../org/jboss/ejb/client/EJBClientContext.java | 6 +++--- .../java/org/jboss/ejb/client/EJBReceiver.java | 5 ++++- .../java/org/jboss/ejb/client/EJBRootContext.java | 2 +- .../ejb/protocol/remote/RemoteEJBReceiver.java | 4 ++-- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/jboss/ejb/client/EJBClient.java b/src/main/java/org/jboss/ejb/client/EJBClient.java index 52472012b..605c70e11 100644 --- a/src/main/java/org/jboss/ejb/client/EJBClient.java +++ b/src/main/java/org/jboss/ejb/client/EJBClient.java @@ -267,9 +267,22 @@ public static StatefulEJBLocator createSession(final URI uri, final Class */ public static StatefulEJBLocator createSession(StatelessEJBLocator statelessLocator) throws Exception { final EJBClientContext clientContext = EJBClientContext.getCurrent(); - return clientContext.createSession(statelessLocator); + return clientContext.createSession(statelessLocator, null); } + /** + * Create a new EJB session. + * + * @param statelessLocator the stateless locator identifying the stateful EJB + * @param namingProvider The naming provider that initiated the session creation + * @param the view type + * @return the new EJB locator + * @throws CreateException if an error occurs + */ + public static StatefulEJBLocator createSession(StatelessEJBLocator statelessLocator, NamingProvider namingProvider) throws Exception { + final EJBClientContext clientContext = EJBClientContext.getCurrent(); + return clientContext.createSession(statelessLocator, namingProvider); + } /** * Perform a one-way asynchronous invocation by method locator on a proxy. Any return value is ignored. * diff --git a/src/main/java/org/jboss/ejb/client/EJBClientContext.java b/src/main/java/org/jboss/ejb/client/EJBClientContext.java index 499ad3ad9..f21a02cbf 100644 --- a/src/main/java/org/jboss/ejb/client/EJBClientContext.java +++ b/src/main/java/org/jboss/ejb/client/EJBClientContext.java @@ -62,6 +62,7 @@ import org.wildfly.discovery.ServiceType; import org.wildfly.discovery.ServiceURL; import org.wildfly.discovery.ServicesQueue; +import org.wildfly.naming.client.NamingProvider; /** * The public API for an EJB client context. An EJB client context may be associated with (and used by) one or more threads concurrently. @@ -664,12 +665,11 @@ public static EJBClientContext requireCurrent() { return getCurrent(); } - StatefulEJBLocator createSession(final StatelessEJBLocator statelessLocator) throws Exception { + StatefulEJBLocator createSession(final StatelessEJBLocator statelessLocator, NamingProvider namingProvider) throws Exception { final LocatedAction, StatelessEJBLocator, T> action = - (receiver, originalLocator, newAffinity) -> receiver.createSession(originalLocator.withNewAffinity(newAffinity)); + (receiver, originalLocator, newAffinity) -> receiver.createSession(originalLocator.withNewAffinity(newAffinity), namingProvider); return performLocatedAction(statelessLocator, action); } - interface LocatedAction, T> { R execute(EJBReceiver receiver, L originalLocator, Affinity newAffinity) throws Exception; } diff --git a/src/main/java/org/jboss/ejb/client/EJBReceiver.java b/src/main/java/org/jboss/ejb/client/EJBReceiver.java index e825018b6..fca60773d 100644 --- a/src/main/java/org/jboss/ejb/client/EJBReceiver.java +++ b/src/main/java/org/jboss/ejb/client/EJBReceiver.java @@ -25,6 +25,8 @@ import java.net.SocketAddress; import java.net.URI; +import org.wildfly.naming.client.NamingProvider; + /** * A receiver for EJB invocations. Receivers can be associated with one or more client contexts. This interface is * implemented by providers for EJB invocation services. @@ -68,12 +70,13 @@ protected boolean cancelInvocation(EJBReceiverInvocationContext receiverContext, * and bean name combination. Returns a {@link StatefulEJBLocator} representing the newly created session. * * @param statelessLocator the stateless locator + * @param namingProvider the naming provider, may be null * @param the view type * @return the EJB locator for the newly opened session * @throws IllegalArgumentException if the session creation request is made for a bean which is not a stateful * session bean */ - protected abstract StatefulEJBLocator createSession(final StatelessEJBLocator statelessLocator) throws Exception; + protected abstract StatefulEJBLocator createSession(final StatelessEJBLocator statelessLocator, NamingProvider namingProvider) throws Exception; /** * Query the expected or actual source IP address configured for the given target URI. diff --git a/src/main/java/org/jboss/ejb/client/EJBRootContext.java b/src/main/java/org/jboss/ejb/client/EJBRootContext.java index 1da13120e..c094c69c2 100644 --- a/src/main/java/org/jboss/ejb/client/EJBRootContext.java +++ b/src/main/java/org/jboss/ejb/client/EJBRootContext.java @@ -138,7 +138,7 @@ protected Object lookupNative(final Name name) throws NamingException { final EJBIdentifier identifier = new EJBIdentifier(appName, moduleName, beanName, distinctName); if (stateful) { try { - locator = EJBClient.createSession(StatelessEJBLocator.create(view, identifier, affinity)); + locator = EJBClient.createSession(StatelessEJBLocator.create(view, identifier, affinity), namingProvider); } catch (Exception e) { throw Logs.MAIN.lookupFailed(name, name, e); } diff --git a/src/main/java/org/jboss/ejb/protocol/remote/RemoteEJBReceiver.java b/src/main/java/org/jboss/ejb/protocol/remote/RemoteEJBReceiver.java index 003284aeb..3c82b83a4 100644 --- a/src/main/java/org/jboss/ejb/protocol/remote/RemoteEJBReceiver.java +++ b/src/main/java/org/jboss/ejb/protocol/remote/RemoteEJBReceiver.java @@ -137,9 +137,9 @@ protected boolean cancelInvocation(final EJBReceiverInvocationContext receiverCo } } - protected StatefulEJBLocator createSession(final StatelessEJBLocator statelessLocator) throws Exception { + protected StatefulEJBLocator createSession(final StatelessEJBLocator statelessLocator, NamingProvider namingProvider) throws Exception { try { - IoFuture futureConnection = getConnection(statelessLocator, null); + IoFuture futureConnection = getConnection(statelessLocator, namingProvider); final EJBClientChannel ejbClientChannel = getClientChannel(futureConnection.getInterruptibly()); return ejbClientChannel.openSession(statelessLocator); } catch (IOException e) { From d708c2161b213d8b908d6e8901200817cba49f00 Mon Sep 17 00:00:00 2001 From: "David M. Lloyd" Date: Wed, 15 Mar 2017 00:11:53 -0500 Subject: [PATCH 2/2] Update EJBClient.java --- src/main/java/org/jboss/ejb/client/EJBClient.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jboss/ejb/client/EJBClient.java b/src/main/java/org/jboss/ejb/client/EJBClient.java index 605c70e11..f057816cf 100644 --- a/src/main/java/org/jboss/ejb/client/EJBClient.java +++ b/src/main/java/org/jboss/ejb/client/EJBClient.java @@ -279,10 +279,11 @@ public static StatefulEJBLocator createSession(StatelessEJBLocator sta * @return the new EJB locator * @throws CreateException if an error occurs */ - public static StatefulEJBLocator createSession(StatelessEJBLocator statelessLocator, NamingProvider namingProvider) throws Exception { + static StatefulEJBLocator createSession(StatelessEJBLocator statelessLocator, NamingProvider namingProvider) throws Exception { final EJBClientContext clientContext = EJBClientContext.getCurrent(); return clientContext.createSession(statelessLocator, namingProvider); } + /** * Perform a one-way asynchronous invocation by method locator on a proxy. Any return value is ignored. *