01: /*
02: * $Id: RmiServiceEngine.java,v 1.1 2003/12/02 16:49:03 ajzeneski Exp $
03: *
04: * Copyright (c) 2003 The Open For Business Project - www.ofbiz.org
05: *
06: * Permission is hereby granted, free of charge, to any person obtaining a
07: * copy of this software and associated documentation files (the "Software"),
08: * to deal in the Software without restriction, including without limitation
09: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10: * and/or sell copies of the Software, and to permit persons to whom the
11: * Software is furnished to do so, subject to the following conditions:
12: *
13: * The above copyright notice and this permission notice shall be included
14: * in all copies or substantial portions of the Software.
15: *
16: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23: */
24: package org.ofbiz.service.rmi;
25:
26: import org.ofbiz.service.engine.GenericAsyncEngine;
27: import org.ofbiz.service.ModelService;
28: import org.ofbiz.service.GenericServiceException;
29: import org.ofbiz.service.ServiceDispatcher;
30:
31: import java.util.Map;
32: import java.rmi.Naming;
33: import java.rmi.NotBoundException;
34: import java.rmi.RemoteException;
35:
36: /**
37: * RmiServiceEngine.java
38: *
39: * @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
40: * @version $Revision: 1.1 $
41: * @since 3.0
42: */
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,
50: Map context) throws GenericServiceException {
51: return run(modelService, context);
52: }
53:
54: public void runSyncIgnore(String localName,
55: ModelService modelService, Map context)
56: throws GenericServiceException {
57: run(modelService, context);
58: }
59:
60: protected Map run(ModelService service, Map context)
61: throws GenericServiceException {
62: // locate the remote dispatcher
63: RemoteDispatcher rd = null;
64: try {
65: rd = (RemoteDispatcher) Naming.lookup(service.location);
66: } catch (NotBoundException e) {
67: throw new GenericServiceException(
68: "RemoteDispatcher not bound to : "
69: + service.location, e);
70: } catch (java.net.MalformedURLException e) {
71: throw new GenericServiceException(
72: "Invalid format for location");
73: } catch (RemoteException e) {
74: throw new GenericServiceException("RMI Error", e);
75: }
76:
77: Map result = null;
78: if (rd != null) {
79: try {
80: result = rd.runSync(service.invoke, context);
81: } catch (RemoteException e) {
82: throw new GenericServiceException(
83: "RMI Invocation Error", e);
84: }
85: } else {
86: throw new GenericServiceException(
87: "RemoteDispatcher came back as null");
88: }
89:
90: if (result == null) {
91: throw new GenericServiceException("Null result returned");
92: }
93:
94: return result;
95: }
96: }
|