001: /*******************************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: *******************************************************************************/package org.ofbiz.service.rmi;
019:
020: import java.rmi.RemoteException;
021: import java.rmi.server.RMIClientSocketFactory;
022: import java.rmi.server.RMIServerSocketFactory;
023: import java.rmi.server.UnicastRemoteObject;
024: import java.util.Map;
025:
026: import org.ofbiz.service.GenericRequester;
027: import org.ofbiz.service.GenericResultWaiter;
028: import org.ofbiz.service.GenericServiceException;
029: import org.ofbiz.service.LocalDispatcher;
030: import org.ofbiz.service.ModelService;
031:
032: /**
033: * Generic Services Remote Dispatcher Implementation
034: */
035: public class RemoteDispatcherImpl extends UnicastRemoteObject implements
036: RemoteDispatcher {
037:
038: public static final String module = RemoteDispatcherImpl.class
039: .getName();
040: private static final boolean exportAll = false;
041:
042: protected LocalDispatcher dispatcher = null;
043:
044: public RemoteDispatcherImpl(LocalDispatcher dispatcher,
045: RMIClientSocketFactory csf, RMIServerSocketFactory ssf)
046: throws RemoteException {
047: super (0, csf, ssf);
048: this .dispatcher = dispatcher;
049: }
050:
051: // RemoteDispatcher methods
052:
053: public Map runSync(String serviceName, Map context)
054: throws GenericServiceException, RemoteException {
055: this .checkExportFlag(serviceName);
056: return dispatcher.runSync(serviceName, context);
057: }
058:
059: public Map runSync(String serviceName, Map context,
060: int transactionTimeout, boolean requireNewTransaction)
061: throws GenericServiceException, RemoteException {
062: this .checkExportFlag(serviceName);
063: return dispatcher.runSync(serviceName, context,
064: transactionTimeout, requireNewTransaction);
065: }
066:
067: public void runSyncIgnore(String serviceName, Map context)
068: throws GenericServiceException, RemoteException {
069: this .checkExportFlag(serviceName);
070: dispatcher.runSyncIgnore(serviceName, context);
071: }
072:
073: public void runSyncIgnore(String serviceName, Map context,
074: int transactionTimeout, boolean requireNewTransaction)
075: throws GenericServiceException, RemoteException {
076: this .checkExportFlag(serviceName);
077: dispatcher.runSyncIgnore(serviceName, context,
078: transactionTimeout, requireNewTransaction);
079: }
080:
081: public void runAsync(String serviceName, Map context,
082: GenericRequester requester, boolean persist,
083: int transactionTimeout, boolean requireNewTransaction)
084: throws GenericServiceException, RemoteException {
085: this .checkExportFlag(serviceName);
086: dispatcher.runAsync(serviceName, context, requester, persist,
087: transactionTimeout, requireNewTransaction);
088: }
089:
090: public void runAsync(String serviceName, Map context,
091: GenericRequester requester, boolean persist)
092: throws GenericServiceException, RemoteException {
093: this .checkExportFlag(serviceName);
094: dispatcher.runAsync(serviceName, context, requester, persist);
095: }
096:
097: public void runAsync(String serviceName, Map context,
098: GenericRequester requester) throws GenericServiceException,
099: RemoteException {
100: this .checkExportFlag(serviceName);
101: dispatcher.runAsync(serviceName, context, requester);
102: }
103:
104: public void runAsync(String serviceName, Map context,
105: boolean persist) throws GenericServiceException,
106: RemoteException {
107: this .checkExportFlag(serviceName);
108: dispatcher.runAsync(serviceName, context, persist);
109: }
110:
111: public void runAsync(String serviceName, Map context)
112: throws GenericServiceException, RemoteException {
113: this .checkExportFlag(serviceName);
114: dispatcher.runAsync(serviceName, context);
115: }
116:
117: public GenericResultWaiter runAsyncWait(String serviceName,
118: Map context, boolean persist)
119: throws GenericServiceException, RemoteException {
120: this .checkExportFlag(serviceName);
121: return dispatcher.runAsyncWait(serviceName, context, persist);
122: }
123:
124: public GenericResultWaiter runAsyncWait(String serviceName,
125: Map context) throws GenericServiceException,
126: RemoteException {
127: this .checkExportFlag(serviceName);
128: return dispatcher.runAsyncWait(serviceName, context);
129: }
130:
131: public void schedule(String serviceName, Map context,
132: long startTime, int frequency, int interval, int count,
133: long endTime) throws GenericServiceException,
134: RemoteException {
135: this .checkExportFlag(serviceName);
136: dispatcher.schedule(serviceName, context, startTime, frequency,
137: interval, count, endTime);
138: }
139:
140: public void schedule(String serviceName, Map context,
141: long startTime, int frequency, int interval, int count)
142: throws GenericServiceException, RemoteException {
143: this .checkExportFlag(serviceName);
144: dispatcher.schedule(serviceName, context, startTime, frequency,
145: interval, count);
146: }
147:
148: public void schedule(String serviceName, Map context,
149: long startTime, int frequency, int interval, long endTime)
150: throws GenericServiceException, RemoteException {
151: this .checkExportFlag(serviceName);
152: dispatcher.schedule(serviceName, context, startTime, frequency,
153: interval, endTime);
154: }
155:
156: public void schedule(String serviceName, Map context, long startTime)
157: throws GenericServiceException, RemoteException {
158: this .checkExportFlag(serviceName);
159: dispatcher.schedule(serviceName, context, startTime);
160: }
161:
162: public void deregister() {
163: dispatcher.deregister();
164: }
165:
166: protected void checkExportFlag(String serviceName)
167: throws GenericServiceException {
168: ModelService model = dispatcher.getDispatchContext()
169: .getModelService(serviceName);
170: if (!model.export && !exportAll) {
171: // TODO: make this log on the server rather than the client
172: //Debug.logWarning("Attempt to invoke a non-exported service: " + serviceName, module);
173: throw new GenericServiceException(
174: "Cannot find requested service");
175: }
176: }
177:
178: }
|