1 24 package org.ofbiz.service.rmi; 25 26 import java.rmi.Naming ; 27 import java.rmi.NotBoundException ; 28 import java.rmi.RemoteException ; 29 import java.util.Map ; 30 31 import org.ofbiz.service.GenericServiceException; 32 import org.ofbiz.service.ModelService; 33 import org.ofbiz.service.ServiceDispatcher; 34 import org.ofbiz.service.engine.GenericAsyncEngine; 35 36 43 public class RmiServiceEngine extends GenericAsyncEngine { 44 45 public RmiServiceEngine(ServiceDispatcher dispatcher) { 46 super(dispatcher); 47 } 48 49 public Map runSync(String localName, ModelService modelService, Map context) throws GenericServiceException { 50 return run(modelService, context); 51 } 52 53 public void runSyncIgnore(String localName, ModelService modelService, Map context) throws GenericServiceException { 54 run(modelService, context); 55 } 56 57 protected Map run(ModelService service, Map context) throws GenericServiceException { 58 RemoteDispatcher rd = null; 60 try { 61 rd = (RemoteDispatcher) Naming.lookup(this.getLocation(service)); 62 } catch (NotBoundException e) { 63 throw new GenericServiceException("RemoteDispatcher not bound to : " + service.location, e); 64 } catch (java.net.MalformedURLException e) { 65 throw new GenericServiceException("Invalid format for location"); 66 } catch (RemoteException e) { 67 throw new GenericServiceException("RMI Error", e); 68 } 69 70 Map result = null; 71 if (rd != null) { 72 try { 73 result = rd.runSync(service.invoke, context); 74 } catch (RemoteException e) { 75 throw new GenericServiceException("RMI Invocation Error", e); 76 } 77 } else { 78 throw new GenericServiceException("RemoteDispatcher came back as null"); 79 } 80 81 if (result == null) { 82 throw new GenericServiceException("Null result returned"); 83 } 84 85 return result; 86 } 87 } 88 | Popular Tags |