0

I have deployed applications like below in the domain mode

MyWebApp.war ---> which has web tier
MyEjb.jar --> which has all ejbs
service.jar --> from where ejb is invoked

Both are deployed in the domain mode.

and while invoking the same I use

java:global/MyEjb/...

This works but I want to know the performance impact as it is deployed on the same server. And also what needs to be changed if I want to access it as local.

As If I access it with java:app/MyEjb/.. It is not able to find the bean.

And also, If i am invoking the ejb from same server and using below code

Hashtable Props = new Hashtable();
Props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.as.naming.InitialContextFactory");
Props.put(Context.PROVIDER_URL, "remote://localhost:4447");
Props.put("jboss.naming.client.ejb.context", Boolean.valueOf(true));

Why to use "remote" in this case? Is there any other way to call locally?

My objective is to invoke the ejb locally since everything is running on the same JVM.

happy
  • 2,550
  • 17
  • 64
  • 109

1 Answers1

1

You are doing a JNDI lookup for local and remote access. The string you are passing to the Context defines whether this is a remote ore local lookup (together with the properties passed to the Context).

For a remote lookup your name will start with ejb:... (as explained for example here). Additionally you are creating an instance of Context by passing properties like "org.jboss.ejb.client.naming" which denotes the Java package in which the context factory resides:

Properties contextProperties = new Properties();
contextPropertiesL.put( Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
Context context = new InitialContext(contextProperties);

If your name starts with java:... then it is looked up locally. Locally means within the same JVM and therefore no serialization/deserialization of the objects has to be done. Local stubs are therefore more efficient in terms of runtime as the invocation of an EJB is just like the invocation of any other object's methods in your JVM.

The properties you are passing to the Context are only necessary in case you want to do a remote lookup.

siom
  • 1,610
  • 1
  • 14
  • 21
  • That means I am using java:global/MyEjb/ means i am accessing locally ?? and also if I don't pass any properties in Context then It say name not found – happy Aug 21 '17 at 09:38
  • Also how then this is differentiated java:global/...,java:module and java:app – happy Aug 21 '17 at 10:01
  • If you add contextPropertiesL.put( Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); to the properties passed to the context, then it will use the ejb client context factory and therewith the URL prefix ejb:/. – siom Aug 21 '17 at 12:00
  • global, module and app are different naming contexts, i.e. global is for the complete JVM, module only for the JEE module and app only for the jar. – siom Aug 21 '17 at 12:01
  • Now For local invoking I have removed all properties from Context and using java:global/MyEjb/ its working fine. – happy Aug 21 '17 at 12:29
  • how can i verify that it is invoking locally? – happy Aug 21 '17 at 12:56
  • A simple method is to invoke the toString() method on the proxy you have. For remote it says something like "Proxy for remote EJB ..." – siom Aug 21 '17 at 13:12
  • If i add properties in context or remove it both time i am getting "Proxy for view class:" from toString() – happy Aug 24 '17 at 06:31