package org.jfox.ejb.invoker.jrmp;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import javax.ejb.EJBException;
import org.jfox.ejb.Invocation;
import org.jfox.ejb.meta.Protocol;
import org.jfox.ejb.invoker.ContainerRemote;
import org.jfox.ejb.invoker.ContainerServiceSupport;
public class JRMPContainerService extends ContainerServiceSupport implements ContainerRemote {
private Remote stub = null;
private String protocol = Protocol.JRMP;
protected void doInit() throws Exception {
super.doInit();
try {
UnicastRemoteObject.unexportObject(this,true);
}
catch(Exception e){
}
}
protected void doStart() throws Exception {
stub = UnicastRemoteObject.exportObject(this);
INITIAL_CONTEXT.rebind(INVOKER_JNDI_PREFIX + "/" + protocol.toUpperCase(),stub);
Thread pingThread = new Thread(this,getClass().getName());
pingThread.setPriority(Thread.MIN_PRIORITY);
pingThread.start();
}
protected void doStop() throws Exception {
INITIAL_CONTEXT.unbind(INVOKER_JNDI_PREFIX + "/" + protocol.toUpperCase());
UnicastRemoteObject.unexportObject(this,true);
}
protected synchronized void doDestroy() throws Exception {
stub = null;
}
public Object invoke(Invocation invocation) throws RemoteException {
logger.debug("invoke " + invocation.toString());
try {
return container.invoke(invocation);
}
catch(RemoteException e){
logger.error(e.getMessage(),e);
throw e;
}
catch(Exception e){
logger.error(e.getMessage(),e);
throw new EJBException(e);
}
}
public static void main(String[] args) throws Exception{
}
}