package org.jboss.test.testbeancluster.bean;
import javax.ejb.*;
import java.rmi.RemoteException;
import java.rmi.dgc.VMID;
import org.jboss.test.testbeancluster.interfaces.NodeAnswer;
public class StatefulSessionBean extends org.jboss.test.testbean.bean.StatefulSessionBean
{
public transient VMID myId = null;
public void ejbCreate(String name) throws RemoteException, CreateException
{
super.ejbCreate(name);
this.myId = new VMID();
log.debug("My ID: " + this.myId);
}
public void ejbActivate() throws RemoteException
{
super.ejbActivate();
if (this.myId == null)
{
this.myId = new VMID();
}
log.debug("Activate. My ID: " + this.myId + " name: " + this.name);
}
public void ejbPassivate() throws RemoteException
{
super.ejbPassivate();
log.debug("Passivate. My ID: " + this.myId + " name: " + this.name);
}
public NodeAnswer getNodeState() throws RemoteException
{
NodeAnswer state = new NodeAnswer(this.myId, this.name);
log.debug("getNodeState, " + state);
return state;
}
public void setName(String name) throws RemoteException
{
this.name = name;
log.debug("Name set to " + name);
}
public void setNameOnlyOnNode(String name, VMID node) throws RemoteException
{
if (node.equals(this.myId))
this.setName(name);
else
throw new EJBException("Trying to assign value on node " + this.myId + " but this node expected: " + node);
}
}