01: /*******************************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: *******************************************************************************/package org.ofbiz.service.rmi;
19:
20: import java.rmi.Naming;
21: import java.rmi.NotBoundException;
22: import java.rmi.RemoteException;
23: import java.util.Map;
24:
25: import org.ofbiz.service.GenericServiceException;
26: import org.ofbiz.service.ModelService;
27: import org.ofbiz.service.ServiceDispatcher;
28: import org.ofbiz.service.engine.GenericAsyncEngine;
29:
30: /**
31: * RmiServiceEngine.java
32: */
33: public class RmiServiceEngine extends GenericAsyncEngine {
34:
35: public RmiServiceEngine(ServiceDispatcher dispatcher) {
36: super (dispatcher);
37: }
38:
39: public Map runSync(String localName, ModelService modelService,
40: Map context) throws GenericServiceException {
41: return run(modelService, context);
42: }
43:
44: public void runSyncIgnore(String localName,
45: ModelService modelService, Map context)
46: throws GenericServiceException {
47: run(modelService, context);
48: }
49:
50: protected Map run(ModelService service, Map context)
51: throws GenericServiceException {
52: // locate the remote dispatcher
53: RemoteDispatcher rd = null;
54: try {
55: rd = (RemoteDispatcher) Naming.lookup(this
56: .getLocation(service));
57: } catch (NotBoundException e) {
58: throw new GenericServiceException(
59: "RemoteDispatcher not bound to : "
60: + service.location, e);
61: } catch (java.net.MalformedURLException e) {
62: throw new GenericServiceException(
63: "Invalid format for location");
64: } catch (RemoteException e) {
65: throw new GenericServiceException("RMI Error", e);
66: }
67:
68: Map result = null;
69: if (rd != null) {
70: try {
71: result = rd.runSync(service.invoke, context);
72: } catch (RemoteException e) {
73: throw new GenericServiceException(
74: "RMI Invocation Error", e);
75: }
76: } else {
77: throw new GenericServiceException(
78: "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: }
|