Hello,

here are the important code parts of a sample, the complete code is
attached:

1. StatefulSession1Bean.java

public class StatefulSession1Bean implements SessionBean
{
    private SessionContext sessionContext;
    private Hashtable beanlist;
    private Hashtable handlelist;

<snip>

    public void initBeanrefByHandle() throws RemoteException
    {
        try
        {
            InitialContext iniContext = new InitialContext();
            Session2Home home = (Session2Home)
iniContext.lookup("StatefulSession2");
            System.out.println("Found StatefulSession2Home");
            Session2 bean = home.create();
            System.out.println("Created StatefulSession2");
            String key = new String("Session1");
            Handle handle = bean.getHandle();
            handlelist.put(key, handle);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

    public void accessBeanrefByHandle() throws RemoteException
    {
        try
        {
 
System.out.println("StatefulSession1Bean.accessBeanrefByHandle");
// here the ClassCastException occurs:
            Handle handle =  (Handle) handlelist.get("Session1");
            if (handle != null) {
              System.out.println("Classname: " +
handle.getClass().getName());
              Session2 bean = (Session2) handle.getEJBObject();
              System.out.println("call echo: " + bean.echo("hello"));
            }
            else {
              System.out.println("handle is null");
            }
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

<snip>

2. SessionClient

public class SessionClient
{
    public static void main(String args[]) throws Exception
    {

        try
        {
            System.setProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
            System.setProperty("java.naming.provider.url",
"localhost:1099");
      
            InitialContext iniContext = new InitialContext();
            Session1Home home = (Session1Home)
iniContext.lookup("StatefulSession1");
            System.out.println("Found StatefulSession1Home");
            Session1 bean = home.create();
            System.out.println("Created StatefulSession1");
            bean.initBeanrefByHandle();
            bean.accessBeanrefByHandle();
            bean.accessBeanrefByHandle();
            // wait until bean has beean passivated
            Thread.sleep(180000); // here 3 min
            bean.accessBeanrefByHandle();
            bean.remove();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }

    }
}

3. And the StackTrace server.log

[Default] StatefulSession1Bean.ejbCreate() called
[Default] Found StatefulSession2Home
[Default] StatefulSession2Bean.ejbCreate() called
[Default] Created StatefulSession2
[Default] StatefulSession1Bean.accessBeanrefByHandle
[Default] Classname:
org.jboss.ejb.plugins.jrmp.interfaces.StatefulHandleImpl
[Default] StatefulSession2Bean.echo, arg=hello
[Default] call echo: hello
[Default] StatefulSession1Bean.accessBeanrefByHandle
[Default] Classname:
org.jboss.ejb.plugins.jrmp.interfaces.StatefulHandleImpl
[Default] StatefulSession2Bean.echo, arg=hello
[Default] call echo: hello
[Bean Cache] Resized cache for bean StatefulSession1: old capacity = 1000,
new capacity = 50
[Bean Cache] Scheduling for passivation overaged bean StatefulSession2 with
id = 1011608325344 - Cache size = 1
[Bean Cache] Aging out from cache bean StatefulSession2with id =
1011608325344; cache size = 1
[Container factory] Scheduled passivation of bean StatefulSession2 with id =
1011608325344
[Default] StatefulSession2Bean.ejbPassivate() called
[Container factory] Passivated bean StatefulSession2 with id = 1011608325344
[Bean Cache] Scheduling for passivation overaged bean StatefulSession1 with
id = 1011608325343 - Cache size = 1
[Bean Cache] Aging out from cache bean StatefulSession1with id =
1011608325343; cache size = 1
[Container factory] Scheduled passivation of bean StatefulSession1 with id =
1011608325343
[Default] StatefulSession1Bean.ejbPassivate() called
[Container factory] Passivated bean StatefulSession1 with id = 1011608325343
[Default] StatefulSession1Bean.ejbActivate() called
[StatefulSession1] Activated bean StatefulSession1 with id = 1011608325343
[Default] StatefulSession1Bean.accessBeanrefByHandle
[Default] java.lang.ClassCastException: $Proxy39
[Default]       at
StatefulSession1Bean.accessBeanrefByHandle(StatefulSession1Bean.java:126)
[Default]       at java.lang.reflect.Method.invoke(Native Method)
[Default]       at
org.jboss.ejb.StatefulSessionContainer$ContainerInterceptor.invoke(StatefulS
essionContainer.java:650)
[Default]       at
org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:12
8)
[Default]       at
org.jboss.ejb.plugins.StatefulSessionInstanceInterceptor.invoke(StatefulSess
ionInstanceInterceptor.java:243)
[Default]       at
org.jboss.ejb.plugins.TxInterceptorCMT.invokeNext(TxInterceptorCMT.java:133)
[Default]       at
org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.
java:307)
[Default]       at
org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:99)
[Default]       at
org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:195)
[Default]       at
org.jboss.ejb.StatefulSessionContainer.invoke(StatefulSessionContainer.java:
341)
[Default]       at
org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invoke(JRMPContainerI
nvoker.java:395)
[Default]       at java.lang.reflect.Method.invoke(Native Method)
[Default]       at
sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:241)
[Default]       at sun.rmi.transport.Transport$1.run(Transport.java:142)
[Default]       at java.security.AccessController.doPrivileged(Native
Method)
[Default]       at
sun.rmi.transport.Transport.serviceCall(Transport.java:139)
[Default]       at
sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:443)
[Default]       at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:6
43)
[Default]       at java.lang.Thread.run(Thread.java:484)

Thanks in advance

Annegret

-----Urspr�ngliche Nachricht-----
Von: Paul Cody [mailto:[EMAIL PROTECTED]]
Gesendet: Donnerstag, 17. Januar 2002 22:59
An: [EMAIL PROTECTED]
Betreff: RE: [JBoss-user] Weird Hashtable contens after bean passivation
/ activation


The $ProxyX classes are probably JDK1.3 dynamic proxy classes.  Can you post
the code and stacktrace?

Paul

> -----Original Message-----
> From: Sternagel Annegret (PN-SYS/PE)
> [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, January 17, 2002 8:26 AM
> To: [EMAIL PROTECTED]
> Subject: [JBoss-user] Weird Hashtable contens after bean passivation /
> activation
> 
> 
> Hello,
> 
> I want to store references to stateful sessionbeans in a 
> Hashtable of a
> stateful sessionbean.
> I tried to store the beanhandle and got a weird behavior:
> The classname of the stored objects has been
> 'org.jboss.ejb.plugins.jrmp.interfaces.StatefulHandleImpl'.
> When I get the object from the Hashtable normally the 
> classname is correct,
> but when the bean has been passivated and activated the 
> classname has been
> something like '$Proxy3'
> and I get a ClassCastException on the cast to a Handle.
> 
> I know the classname of the bean references in jboss is 
> somthing like $Proxy
> (to see sometimes in Exception printStackTrace ...). It looks 
> like that
> through passivation / activation the handles have been restored to the
> remoteinterfaces of the beans ....
> 
> What's going on here ?
> How should I store bean references: as remoteinterface or handle ?
> 
> Annegret
> 
> 
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/jboss-user
> 

_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Attachment: StatfulSession.zip
Description: Binary data

Reply via email to