ACTIVATION PASSIVATION IN STATEFUL SESSION BEANS
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   jvishal1_jain
Posted On:   Wednesday, June 5, 2002 05:32 AM

I have the following code with me which i/c remote, home interfaces, bean class and deployment descriptor, client code. The client side o/p is also included. Can some body help me why I m getting the exception? //Bean class code. package count; import java.rmi.*; import javax.ejb.*; public class CountBean implements SessionBean { private int val; public void ejbCreate(int val) { this.val = val; System.out.println("Inside EJB Create"); } public void ejbRemove() { System.out.println("Inside EJB Remove"); } public void ejbPassivate() { System.out.println("Inside EJB Passivate&qu   More>>

I have the following code with me which i/c remote, home interfaces, bean class and deployment descriptor, client code. The client side o/p is also included. Can some body help me why I m getting the exception?

//Bean class code.
package count;

import java.rmi.*;
import javax.ejb.*;

public class CountBean implements SessionBean
{
private int val;
public void ejbCreate(int val)
{
this.val = val;
System.out.println("Inside EJB Create");
}
public void ejbRemove()
{
System.out.println("Inside EJB Remove");
}
public void ejbPassivate()
{
System.out.println("Inside EJB Passivate");
}
public void ejbActivate()
{
System.out.println("Inside EJB Activate");
}
public void setSessionContext(SessionContext ctxt)
{
System.out.println("Inside SetSession
Context");
}
public int count()
{
System.out.println("Inside Count");
return ++val;
}
}

//Remote interface code.
package count;

import javax.ejb.*;
import java.rmi.*;

public interface Count extends EJBObject
{
public int count()throws RemoteException;
}

//Home interface code.
package count;

import java.rmi.*;
import javax.ejb.*;

public interface CountHome extends EJBHome
{
Count create(int val)throws CreateException,RemoteException;
}

//Deployment descriptors
//EJB-JAR.xml
<?xml version="1.0"?>


'-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN'
'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>




CountBean
count.CountHome
count.Count
count.CountBean
class>
Stateful
type>

type>Container
type>





CountBean
*

Required




//weblogic-ejb-jar.xml
<?xml version="1.0"?>


'-//BEA Systems, Inc.//DTD WebLogic 6.0.0 EJB//EN'
'http://www.bea.com/servers/wls600/dtd/weblogic-ejb-jar.dtd'>



CountBean


2
1


count



//Client code
package count;

import java.util.Hashtable;
import javax.ejb.*;
import java.rmi.*;
import javax.naming.*;

public class CountClient
{
public static void main(String args[])
{
try
{
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://localhost:7001");
Context ctxt = new InitialContext(ht);
CountHome home = (CountHome)ctxt.lookup("count");
Count [] count = new Count[100];
System.out.println("Instantiating beans ..........................");
int countVal = 0;
for(int i = 0; i < 100; i++)
{
count[i] = home.create(countVal);
countVal = count[i].count();
System.out.println(countVal);
Thread.sleep(500);
}

System.out.println("Calling count on beans ..........................");

for(int i = 0; i < 3; i++)
{
countVal = count[i].count();
System.out.println(countVal);
Thread.sleep(500);
}

System.out.println("Removing beans ..........................");

}catch(Exception e){e.printStackTrace();}
}
}

//Client side output.

Instantiating beans ..........................
1
2
3
4
5
................
upto 100 is printed
Calling count on beans ..........................
java.rmi.NoSuchObjectException: Bean has been deleted.
at weblogic.rmi.internal.BasicOutboundRequest.sendReceive(BasicOutboundRequest.java:85)
at weblogic.rmi.internal.BasicRemoteRef.invoke(BasicRemoteRef.java:133)
at weblogic.rmi.internal.ProxyStub.invoke(ProxyStub.java:35)
at $Proxy2.count(Unknown Source)
at count.CountClient.main(CountClient.java:34)

Please tell me why I m getting the above exception

   <<Less
About | Sitemap | Contact