1 25 26 package org.objectweb.easybeans.rpc.rmi.server; 27 28 import java.rmi.RemoteException ; 29 30 import javax.rmi.PortableRemoteObject ; 31 32 import org.objectweb.easybeans.api.EZBContainer; 33 import org.objectweb.easybeans.api.Factory; 34 import org.objectweb.easybeans.rpc.api.EJBRequest; 35 import org.objectweb.easybeans.rpc.api.EJBResponse; 36 import org.objectweb.easybeans.server.Embedded; 37 38 42 public class RMIServerRPCImpl extends PortableRemoteObject implements RMIServerRPC { 43 44 47 private Embedded ejb3server; 48 49 50 53 private static final int WAIT_TIME = 1000; 54 55 60 public RMIServerRPCImpl(final Embedded ejb3server) throws RemoteException { 61 super(); 62 this.ejb3server = ejb3server; 63 } 64 65 72 public EJBResponse getEJBResponse(final EJBRequest request) throws RemoteException { 73 74 String id = request.getContainerId(); 75 if (id == null) { 76 throw new RemoteException ("No valid container id"); 77 } 78 EZBContainer container = ejb3server.getContainer(id); 80 if (container == null) { 81 throw new RemoteException ("Cannot find the container with id '" + id + "'."); 82 } 83 84 String factoryName = request.getFactory(); 86 87 88 while (!container.isAvailable()) { 90 try { 92 Thread.sleep(WAIT_TIME); 93 } catch (InterruptedException e) { 94 e.printStackTrace(); 95 } 96 } 97 98 Factory factory = container.getFactory(factoryName); 100 if (factory == null) { 101 throw new RemoteException ("Cannot find the factory with name '" + factoryName + "'."); 102 } 103 104 return factory.rpcInvoke(request); 106 } 108 109 } 110 | Popular Tags |