KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > service > rmi > RmiServiceEngine


1 /*
2  * $Id: RmiServiceEngine.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2003 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * 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 java.rmi.Naming JavaDoc;
27 import java.rmi.NotBoundException JavaDoc;
28 import java.rmi.RemoteException JavaDoc;
29 import java.util.Map JavaDoc;
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 /**
37  * RmiServiceEngine.java
38  *
39  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
40  * @version $Rev: 5462 $
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 JavaDoc runSync(String JavaDoc localName, ModelService modelService, Map JavaDoc context) throws GenericServiceException {
50         return run(modelService, context);
51     }
52
53     public void runSyncIgnore(String JavaDoc localName, ModelService modelService, Map JavaDoc context) throws GenericServiceException {
54         run(modelService, context);
55     }
56
57     protected Map JavaDoc run(ModelService service, Map JavaDoc context) throws GenericServiceException {
58         // locate the remote dispatcher
59
RemoteDispatcher rd = null;
60         try {
61             rd = (RemoteDispatcher) Naming.lookup(this.getLocation(service));
62         } catch (NotBoundException JavaDoc e) {
63             throw new GenericServiceException("RemoteDispatcher not bound to : " + service.location, e);
64         } catch (java.net.MalformedURLException JavaDoc e) {
65             throw new GenericServiceException("Invalid format for location");
66         } catch (RemoteException JavaDoc e) {
67             throw new GenericServiceException("RMI Error", e);
68         }
69
70         Map JavaDoc result = null;
71         if (rd != null) {
72             try {
73                 result = rd.runSync(service.invoke, context);
74             } catch (RemoteException JavaDoc 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