Skip to main content

GF v3: Singleton pass by reference problem

15 replies [Last post]
lft
Offline
Joined: 2010-04-07

Hi all.
I have one application that uses Singleton bean which declared with option pass-by-ref in sun-ejb-jar.xml. Another application uses Stateful beans that when "init" (business method) called trying to call "register" method of Singleton bean passing themself as a parameter. Singleton bean serves them with Hashtable so one bean can find another bean instance (same that provided to user) and call its methods. This construction works, but when I restart glassfish domain and call init method it gives me:

at com.sun.corba.ee.impl.logging.ORBUtilSystemException.couldNotFindClass(ORBUtilSystemException.java:10144)
at com.sun.corba.ee.impl.logging.ORBUtilSystemException.couldNotFindClass(ORBUtilSystemException.java:10159)
at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:1163)
at com.sun.corba.ee.impl.encoding.CDRInputObject.read_value(CDRInputObject.java:655)
at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl$14.read(DynamicMethodMarshallerImpl.java:383)
at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl.readArguments(DynamicMethodMarshallerImpl.java:453)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:174)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:682)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:216)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1841)
at com.sun.corba.ee.impl.protocol.SharedCDRClientRequestDispatcherImpl.marshalingComplete(SharedCDRClientRequestDispatcherImpl.java:119)
at com.sun.corba.ee.impl.protocol.CorbaClientDelegateImpl.invoke(CorbaClientDelegateImpl.java:235)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke(StubInvocationHandlerImpl.java:187)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(StubInvocationHandlerImpl.java:147)
at com.sun.corba.ee.impl.presentation.rmi.codegen.CodegenStubBase.invoke(CodegenStubBase.java:225)
at openbox.session.component.__ComponentManager_Remote_DynamicStub.registerComponent(openbox/session/component/__ComponentManager_Remote_DynamicStub.java)
at openbox.session.component._ComponentManager_Wrapper.registerComponent(openbox/session/component/_ComponentManager_Wrapper.java)
at openbox.tavern.TavernSlotMachineBean.init(TavernSlotMachineBean.java:95)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:4038)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5223)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5203)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:201)
at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjectInvocationHandlerDelegate.java:75)
at $Proxy197.init(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie.dispatchToMethod(ReflectiveTie.java:146)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:176)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:682)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:216)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1841)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1695)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:1078)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:221)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:797)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.dispatch(CorbaMessageMediatorImpl.java:561)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.doWork(CorbaMessageMediatorImpl.java:2558)
at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:492)
at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:528)

And after restarting of application with Singleton bean it works fine again. I tryed to use @Startup annotation for singleton bean and that did not resolve the problem.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
lft
Offline
Joined: 2010-04-07

Another exception I've got after restarting the server:
javax.ejb.EJBException: java.rmi.MarshalException: CORBA BAD_PARAM 1330446342 Maybe; nested exception is:
java.io.NotSerializableException:
at test._Manager_Wrapper.register(test/_Manager_Wrapper.java)
at test.EJB01Bean.init(EJB01Bean.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:4038)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5223)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5203)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:201)
at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjectInvocationHandlerDelegate.java:75)
at $Proxy117.init(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie.dispatchToMethod(ReflectiveTie.java:146)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:176)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:682)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:216)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1841)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1695)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:1078)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:221)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:797)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.dispatch(CorbaMessageMediatorImpl.java:561)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.doWork(CorbaMessageMediatorImpl.java:2558)
at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:492)
at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:528)
Caused by: java.rmi.MarshalException: CORBA BAD_PARAM 1330446342 Maybe; nested exception is:
java.io.NotSerializableException:
at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.mapSystemException(Util.java:311)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke(StubInvocationHandlerImpl.java:200)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(StubInvocationHandlerImpl.java:147)
at com.sun.corba.ee.impl.presentation.rmi.codegen.CodegenStubBase.invoke(CodegenStubBase.java:225)
at test.__Manager_Remote_DynamicStub.register(test/__Manager_Remote_DynamicStub.java)
... 31 more
Caused by: java.io.NotSerializableException:
at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.mapSystemException(Util.java:304)
... 35 more
Caused by: org.omg.CORBA.BAD_PARAM: vmcid: OMG minor code: 6 completed: Maybe
at com.sun.corba.ee.impl.logging.OMGSystemException.notSerializable(OMGSystemException.java:990)
at com.sun.corba.ee.impl.logging.OMGSystemException.notSerializable(OMGSystemException.java:1005)
at com.sun.corba.ee.impl.orbutil.ORBUtility.throwNotSerializableForCorba(ORBUtility.java:753)
at com.sun.corba.ee.impl.encoding.CDROutputStream_1_0.write_abstract_interface(CDROutputStream_1_0.java:765)
at com.sun.corba.ee.impl.encoding.CDROutputObject.write_abstract_interface(CDROutputObject.java:709)
at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.writeAbstractObject(Util.java:501)
at com.sun.corba.ee.impl.io.IIOPOutputStream.writeObjectField(IIOPOutputStream.java:883)
at com.sun.corba.ee.impl.io.IIOPOutputStream.outputClassFields(IIOPOutputStream.java:959)
at com.sun.corba.ee.impl.io.IIOPOutputStream.defaultWriteObjectDelegate(IIOPOutputStream.java:281)
at com.sun.corba.ee.impl.io.IIOPOutputStream.outputObject(IIOPOutputStream.java:718)
at com.sun.corba.ee.impl.io.IIOPOutputStream.simpleWriteObject(IIOPOutputStream.java:227)
at com.sun.corba.ee.impl.io.ValueHandlerImpl.writeValueInternal(ValueHandlerImpl.java:268)
at com.sun.corba.ee.impl.io.ValueHandlerImpl.writeValueWithVersion(ValueHandlerImpl.java:240)
at com.sun.corba.ee.impl.io.ValueHandlerImpl.writeValue(ValueHandlerImpl.java:193)
at com.sun.corba.ee.impl.encoding.CDROutputStream_1_0.callWriteValue(CDROutputStream_1_0.java:932)
at com.sun.corba.ee.impl.encoding.CDROutputStream_1_0.writeRMIIIOPValueType(CDROutputStream_1_0.java:917)
at com.sun.corba.ee.impl.encoding.CDROutputStream_1_0.write_value(CDROutputStream_1_0.java:1044)
at com.sun.corba.ee.impl.encoding.CDROutputStream_1_0.write_value(CDROutputStream_1_0.java:1012)
at com.sun.corba.ee.impl.encoding.CDROutputStream_1_0.write_value(CDROutputStream_1_0.java:1057)
at com.sun.corba.ee.impl.encoding.CDROutputObject.write_value(CDROutputObject.java:672)
at com.sun.corba.ee.impl.corba.TCUtility.marshalIn(TCUtility.java:151)
at com.sun.corba.ee.impl.corba.AnyImpl.write_value(AnyImpl.java:639)
at com.sun.corba.ee.impl.encoding.CDROutputStream_1_0.write_any(CDROutputStream_1_0.java:677)
at com.sun.corba.ee.impl.encoding.CDROutputObject.write_any(CDROutputObject.java:620)
at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.writeAny(Util.java:375)
at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl$10.write(DynamicMethodMarshallerImpl.java:300)
at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl.writeArguments(DynamicMethodMarshallerImpl.java:467)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke(StubInvocationHandlerImpl.java:185)
... 34 more
[b]EJB01Local and EJB01 are Serializable[/b]
After restarting or redeploying of manager application it works again.
[b]I think in all cases it is serialization problem.[/b]

ksak
Offline
Joined: 2005-05-20

It's hard to say whether this is explicitly causing the problem but the interfaces should not be defined to implement Serializable. Remote ejb reference objects are special container objects that can automatically be passed as parameters and return values. Marking an interface Serializable is not part of the ejb programming model. The only objects that are directly serializable from the application's perspective are the legacy EJB 2.x Remote handle objects, which don't apply here.

Also, these are all remote interfaces right? Local ejb references can not be passed outside of the application in which they are defined. Was this example executed with the interfaces still packaged in the app server lib directory? If so, please remove them and after making the other changes rerun the example. If things are still not working please file an issue.

lft
Offline
Joined: 2010-04-07

But when I try to use it like this:
------------------------------------------------
@Stateful
public class EJB01Bean implements EJB01, EJB01Local{
@EJB Manager manager;
@Resource SessionContext ctx;
public void init() {
EJB01Local obj=ctx.getBusinessObject(EJB01Local.class);
// /*or*/ EJB01 obj=ctx.getBusinessObject(EJB01.class);
if (obj ==null) Logger.getLogger(getClass().getName()).severe("obj is null");
else manager.register("EJB01", obj);
}
public void method1(int i) {
Logger.getLogger(getClass().getName()).severe("method1 i=="+i);
}
public void remoteMethod(){
Logger.getLogger(getClass().getName()).severe("RemoteMethod called.");
}
public void notRemoteMethod(){
Logger.getLogger(getClass().getName()).severe("notRemoteMethod called.");
}
}
_______________________________________________
Some times it works fine but some times it gives me:
[#|2010-04-14T13:03:09.154+0400|WARNING|glassfishv3.0|javax.enterprise.resource.corba.ee.S1AS-ORB.rpc.encoding|_ThreadID=30;_ThreadName=Thread-1;|"IOP0081021
1: (MARSHAL) Exception from readValue on ValueHandler in CDRInputStream"
org.omg.CORBA.MARSHAL: vmcid: SUN minor code: 211 completed: Maybe
at com.sun.corba.ee.impl.logging.ORBUtilSystemException.valuehandlerReadException(ORBUtilSystemException.java:8888)
at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.readRMIIIOPValueType(CDRInputStream_1_0.java:1076)
at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:1175)
at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:986)
at com.sun.corba.ee.impl.encoding.CDRInputObject.read_value(CDRInputObject.java:646)
at com.sun.corba.ee.impl.corba.TCUtility.unmarshalIn(TCUtility.java:286)
at com.sun.corba.ee.impl.corba.AnyImpl.read_value(AnyImpl.java:611)
at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_any(CDRInputStream_1_0.java:829)
at com.sun.corba.ee.impl.encoding.CDRInputObject.read_any(CDRInputObject.java:583)
at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.readAny(Util.java:461)
at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl$10.read(DynamicMethodMarshallerImpl.java:292)
at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl.readResult(DynamicMethodMarshallerImpl.java:484)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke(StubInvocationHandlerImpl.java:190)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(StubInvocationHandlerImpl.java:147)
at com.sun.corba.ee.impl.presentation.rmi.codegen.CodegenStubBase.invoke(CodegenStubBase.java:225)
at test.__Manager_Remote_DynamicStub.get(test/__Manager_Remote_DynamicStub.java)
at test._Manager_Wrapper.get(test/_Manager_Wrapper.java)
at test.EJB02Bean.method2(EJB02Bean.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:4038)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5223)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5203)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:201)
at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjectInvocationHandlerDelegate.java:75)
at $Proxy157.method2(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie.dispatchToMethod(ReflectiveTie.java:146)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:176)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:682)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:216)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1841)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1695)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:1078)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:221)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:797)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.dispatch(CorbaMessageMediatorImpl.java:561)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.doWork(CorbaMessageMediatorImpl.java:2558)
at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:492)
at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:528)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.sun.corba.ee.impl.io.ObjectStreamClass.readResolve(ObjectStreamClass.java:350)
at com.sun.corba.ee.impl.io.IIOPInputStream.simpleReadObject(IIOPInputStream.java:452)
at com.sun.corba.ee.impl.io.ValueHandlerImpl.readValueInternal(ValueHandlerImpl.java:364)
at com.sun.corba.ee.impl.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:320)
at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.readRMIIIOPValueType(CDRInputStream_1_0.java:1066)
... 45 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.corba.ee.impl.io.ObjectStreamClass.readResolve(ObjectStreamClass.java:348)
... 49 more
Caused by: java.lang.IllegalStateException: Can't overwrite cause
at java.lang.Throwable.initCause(Throwable.java:320)
at com.sun.ejb.containers.RemoteBusinessWrapperBase.readResolve(RemoteBusinessWrapperBase.java:139)
... 54 more
|#]

lft
Offline
Joined: 2010-04-07

Standalone client:

Code:
------------------------------------------------
package test;
import javax.naming.InitialContext;
public class Client {
public static void main(String[] args){
try{
InitialContext context = new InitialContext();
EJB01 ejb01=(EJB01)context.lookup("java:global/testEJBExceptions/EJB01Bean!test.EJB01");
ejb01.init();
ejb01.method1(123);
EJB02 ejb02=(EJB02)context.lookup("java:global/testEJBExceptions/EJB02Bean!test.EJB02");
ejb02.init();
ejb02.method2(345);
}catch (Exception ex){
ex.printStackTrace();
}
}
}
------------------------------------------------

lft
Offline
Joined: 2010-04-07

Running client produce following messages in the server.log:

[#|2010-04-13T13:17:04.317+0400|SEVERE|glassfishv3.0|test.EJB01Bean|_ThreadID=33;_ThreadName=Thread-1;|method1 i==123|#]

[#|2010-04-13T13:17:04.559+0400|SEVERE|glassfishv3.0|test.EJB02Bean|_ThreadID=33;_ThreadName=Thread-1;|method2 i==345|#]

[#|2010-04-13T13:17:04.560+0400|SEVERE|glassfishv3.0|test.EJB01Bean|_ThreadID=33;_ThreadName=Thread-1;|notRemoteMethod called.|#]

[b]But after restarting (asadmin restart-domain) :[/b]

org.omg.CORBA.MARSHAL: vmcid: SUN minor code: 257 completed: Maybe
...

Restarting application and it works again.

That's all. Sorry for my english.

ksak
Offline
Joined: 2005-05-20

Thanks for the detailed info. I can see two potential issues.

The first is the way the reference is registered :

public void init() {
manager.register("EJB01", this);
}

The "this" pointer should never be passed outside of a bean. Only the container should have access to the actual bean instance. If you need to pass a reference to a bean you need to pass an actual ejb reference object instead. In the case of a client, that's the object returned from a lookup. If a bean itself wants to pass its own ejb reference, it can acquire it via the SessionContext.getBusinessObject method. This should also allow you to remove the Registerable interface. It's not necessary since Remote ejb references can automatically be passed as parameters and return values.

Secondly, we don't recommend packaging application code and putting it in the server's lib directory. If more than one application shares the same interfaces they should be replicated in each application. Putting the code in the lib directory means there is no way to update it once it is loaded in the JVM. Replicating the classes is not ideal either but once we have well-defined application-level support for OSGI there will be a cleaner solution for sharing application classes.

lft
Offline
Joined: 2010-04-07

The goal as you may have guessed is to allow one bean instance to call another defined bean instance. jndi lookup will generate new one, but I need that is used by client. Client may have multiple instances but I need that one last registered with manager.

>it can acquire it via the SessionContext.getBusinessObject
I have created this construction cause GF v3 does not support SessionContext.getBusinessObject. It returns null.

>we don't recommend packaging application code and putting it in the server's lib directory
I tried to use --libraries deploy option, but there was some kind of issue (i don't remember), so I just placed it in the lib directory. The only way GF can see changed libs is to restart it - it's not useful, but I think to replicate interfaces into more than 15 application is less useful

ksak
Offline
Joined: 2005-05-20

What are you passing to getBusinessObject() ?

lft
Offline
Joined: 2010-04-07

Sorry I thought I tried getBusinessObject method, but it seems I didn't.

So I tried to use it and it works perfect!! Like this:
_____________________________________
@Stateful
public class EJB01Bean implements EJB01{//, EJB01Local{
@EJB Manager manager;
@Resource SessionContext ctx;
public void init() {
EJB01 obj=ctx.getBusinessObject(EJB01.class);
if (obj ==null) Logger.getLogger(getClass().getName()).severe("obj is null");
else manager.register("EJB01", obj);
}
public void method1(int i) {
Logger.getLogger(getClass().getName()).severe("method1 i=="+i);
}
public void remoteMethod(){
Logger.getLogger(getClass().getName()).severe("RemoteMethod called.");
}
}
_____________________________________
@Stateful
public class EJB02Bean implements EJB02{
@EJB Manager manager;
@Resource SessionContext ctx;
public void init() {
EJB02 obj=ctx.getBusinessObject(EJB02.class);
if (obj==null) Logger.getLogger(getClass().getName()).severe("obj is null");
else manager.register("EJB02", obj);
}
public void method2(int i) {
Logger.getLogger(getClass().getName()).severe("method2 i=="+i);
if (true){ // some kind of user independent clause
// get last registered by user (init()) EJB01
EJB01 ejb01=(EJB01)manager.get("EJB01");
//call method
ejb01.remoteMethod();
}
}
}
-----------------------------------------------------------
the output is:
[#|2010-04-14T13:04:17.869+0400|SEVERE|glassfishv3.0|test.EJB01Bean|_ThreadID=28;_ThreadName=Thread-1;|method1 i==123|#]

[#|2010-04-14T13:04:18.169+0400|SEVERE|glassfishv3.0|test.EJB02Bean|_ThreadID=28;_ThreadName=Thread-1;|method2 i==345|#]

[#|2010-04-14T13:04:18.171+0400|SEVERE|glassfishv3.0|test.EJB01Bean|_ThreadID=28;_ThreadName=Thread-1;|RemoteMethod called.|#]

lft
Offline
Joined: 2010-04-07

The third jar (EJBManager.jar) contains:
ManagerBean - imp[lementation of Manager - singleton bean that contains Hash table where registered beans last derived by client (client informs manager by calling init()). I now that it's not good practice to place pieces of the same applications in different jars (no ear). But there are a lot of jars like that contains EJB01Bean and EJB02Bean and when one of them is undeployed or replaced other should not be affected.

Code:
--------------------------------------------------
package test;
import java.util.Hashtable;
import javax.ejb.ConcurrencyManagement;
import javax.ejb.ConcurrencyManagementType;
import javax.ejb.Singleton;
@Singleton
@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
public class ManagerBean implements Manager{
private Hashtable ht;
public ManagerBean() {
ht=new Hashtable();
}
public void register(String name, Registerable obj) {
ht.put(name, obj);
}
public Registerable get(String name) {
return ht.get(name);
}
}
--------------------------------------------------

lft
Offline
Joined: 2010-04-07

second jar (TestEJB01.jar) contains:
EJB01Bean - implementation of EJB01;
EJB02Bean - implementation of EJB02;

Code:
--------------------------------------------------------
package test;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.ejb.Stateful;
@Stateful
public class EJB01Bean implements EJB01, Registerable{
@EJB Manager manager;
public void init() {
manager.register("EJB01", this);
}
public void method1(int i) {
Logger.getLogger(getClass().getName()).severe("method1 i=="+i);
}
public void notRemoteMethod(){
Logger.getLogger(getClass().getName()).severe("notRemoteMethod called.");
}
}
--------------------------------------------------------
package test;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.ejb.Stateful;
@Stateful
public class EJB02Bean implements EJB02, Registerable{
@EJB Manager manager;
public void init() {
manager.register("EJB02", this);
}
public void method2(int i) {
Logger.getLogger(getClass().getName()).severe("method2 i=="+i);
if (true){ // some kind of user independent clause
// get last registered by user (init()) EJB01
EJB01Bean ejb01=(EJB01Bean)manager.get("EJB01");
//call method
ejb01.notRemoteMethod();
}
}
}
--------------------------------------------------------

lft
Offline
Joined: 2010-04-07

first jar named for example EJBTestLIB contains:
EJB01.java - remote interface for stateful bean;
EJB02.java - remote interface for stateful bean;
Manager.java - remote interface for singleton bean;
Registerable.java - interface for objects that can be registered by Manager

Code:
-----------------------------------------------------
package test;
import javax.ejb.Remote;
@Remote
public interface EJB01{
public void init();
public void method1 (int i);
}
-----------------------------------------------------
package test;
import javax.ejb.Remote;
@Remote
public interface EJB02 {
public void init();
public void method2 (int i);
}
-----------------------------------------------------
package test;
import javax.ejb.Remote;
@Remote
public interface Manager {
public void register (String name, Registerable obj);
public Registerable get(String name);
}
-----------------------------------------------------
package test;
import java.io.Serializable;
public interface Registerable extends Serializable{}
-----------------------------------------------------
I placed this library to glassfishv3/glassfish/domains/domain1/lib/

ksak
Offline
Joined: 2005-05-20

The pass-by-ref shouldn't make any difference here. pass-by-ref only allows pass-by-reference semantics for code running within the same application. That means the hash table will still be deep copied when returned from the Singleton, which is not the behavior you want.

What exact object is registered with the Singleton? Please post the code that makes that call.

lft
Offline
Joined: 2010-04-07

Thanks ksak for you reply. I appreciate your attempt to help me.
I will try to reproduce my error on a simple piece of code.
it does mater where and how classes and interfaces are packaged. So I will provide this information too.

lft
Offline
Joined: 2010-04-07

So nobody has any suggestions. Bug?