001: /*
002: * $Id: RemoteDispatcherImpl.java,v 1.4 2003/12/08 20:13:42 ajzeneski Exp $
003: *
004: * Copyright (c) 2003 The Open For Business Project - www.ofbiz.org
005: *
006: * Permission is hereby granted, free of charge, to any person obtaining a
007: * copy of this software and associated documentation files (the "Software"),
008: * to deal in the Software without restriction, including without limitation
009: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
010: * and/or sell copies of the Software, and to permit persons to whom the
011: * Software is furnished to do so, subject to the following conditions:
012: *
013: * The above copyright notice and this permission notice shall be included
014: * in all copies or substantial portions of the Software.
015: *
016: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023: *
024: */
025: package org.ofbiz.service.rmi;
026:
027: import org.ofbiz.service.*;
028: import org.ofbiz.base.util.Debug;
029:
030: import java.rmi.server.UnicastRemoteObject;
031: import java.rmi.server.RMIClientSocketFactory;
032: import java.rmi.server.RMIServerSocketFactory;
033: import java.rmi.RemoteException;
034: import java.util.Map;
035:
036: /**
037: * Generic Services Remote Dispatcher Implementation
038: *
039: * @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
040: * @version $Revision: 1.4 $
041: * @since 3.0
042: */
043: public class RemoteDispatcherImpl extends UnicastRemoteObject implements
044: RemoteDispatcher {
045:
046: public static final String module = RemoteDispatcherImpl.class
047: .getName();
048: private static final boolean exportAll = false;
049:
050: protected LocalDispatcher dispatcher = null;
051:
052: RemoteDispatcherImpl(LocalDispatcher dispatcher,
053: RMIClientSocketFactory csf, RMIServerSocketFactory ssf)
054: throws RemoteException {
055: super (0, csf, ssf);
056: this .dispatcher = dispatcher;
057: }
058:
059: // RemoteDispatcher methods
060:
061: public Map runSync(String serviceName, Map context)
062: throws GenericServiceException, RemoteException {
063: this .checkExportFlag(serviceName);
064: return dispatcher.runSync(serviceName, context);
065: }
066:
067: public Map runSync(String serviceName, Map context,
068: int transactionTimeout, boolean requireNewTransaction)
069: throws GenericServiceException {
070: this .checkExportFlag(serviceName);
071: return dispatcher.runSync(serviceName, context,
072: transactionTimeout, requireNewTransaction);
073: }
074:
075: public void runSyncIgnore(String serviceName, Map context)
076: throws GenericServiceException, RemoteException {
077: this .checkExportFlag(serviceName);
078: dispatcher.runSyncIgnore(serviceName, context);
079: }
080:
081: public void runSyncIgnore(String serviceName, Map context,
082: int transactionTimeout, boolean requireNewTransaction)
083: throws GenericServiceException, RemoteException {
084: this .checkExportFlag(serviceName);
085: dispatcher.runSyncIgnore(serviceName, context,
086: transactionTimeout, requireNewTransaction);
087: }
088:
089: public void runAsync(String serviceName, Map context,
090: GenericRequester requester, boolean persist,
091: int transactionTimeout, boolean requireNewTransaction)
092: throws GenericServiceException, RemoteException {
093: this .checkExportFlag(serviceName);
094: dispatcher.runAsync(serviceName, context, requester, persist,
095: transactionTimeout, requireNewTransaction);
096: }
097:
098: public void runAsync(String serviceName, Map context,
099: GenericRequester requester, boolean persist)
100: throws GenericServiceException, RemoteException {
101: this .checkExportFlag(serviceName);
102: dispatcher.runAsync(serviceName, context, requester, persist);
103: }
104:
105: public void runAsync(String serviceName, Map context,
106: GenericRequester requester) throws GenericServiceException,
107: RemoteException {
108: this .checkExportFlag(serviceName);
109: dispatcher.runAsync(serviceName, context, requester);
110: }
111:
112: public void runAsync(String serviceName, Map context,
113: boolean persist) throws GenericServiceException,
114: RemoteException {
115: this .checkExportFlag(serviceName);
116: dispatcher.runAsync(serviceName, context, persist);
117: }
118:
119: public void runAsync(String serviceName, Map context)
120: throws GenericServiceException, RemoteException {
121: this .checkExportFlag(serviceName);
122: dispatcher.runAsync(serviceName, context);
123: }
124:
125: public GenericResultWaiter runAsyncWait(String serviceName,
126: Map context, boolean persist)
127: throws GenericServiceException, RemoteException {
128: this .checkExportFlag(serviceName);
129: return dispatcher.runAsyncWait(serviceName, context, persist);
130: }
131:
132: public GenericResultWaiter runAsyncWait(String serviceName,
133: Map context) throws GenericServiceException,
134: RemoteException {
135: this .checkExportFlag(serviceName);
136: return dispatcher.runAsyncWait(serviceName, context);
137: }
138:
139: public void schedule(String serviceName, Map context,
140: long startTime, int frequency, int interval, int count,
141: long endTime) throws GenericServiceException,
142: RemoteException {
143: this .checkExportFlag(serviceName);
144: dispatcher.schedule(serviceName, context, startTime, frequency,
145: interval, count, endTime);
146: }
147:
148: public void schedule(String serviceName, Map context,
149: long startTime, int frequency, int interval, int count)
150: throws GenericServiceException, RemoteException {
151: this .checkExportFlag(serviceName);
152: dispatcher.schedule(serviceName, context, startTime, frequency,
153: interval, count);
154: }
155:
156: public void schedule(String serviceName, Map context,
157: long startTime, int frequency, int interval, long endTime)
158: throws GenericServiceException, RemoteException {
159: this .checkExportFlag(serviceName);
160: dispatcher.schedule(serviceName, context, startTime, frequency,
161: interval, endTime);
162: }
163:
164: public void schedule(String serviceName, Map context, long startTime)
165: throws GenericServiceException, RemoteException {
166: this .checkExportFlag(serviceName);
167: dispatcher.schedule(serviceName, context, startTime);
168: }
169:
170: public void deregister() {
171: dispatcher.deregister();
172: }
173:
174: protected void checkExportFlag(String serviceName)
175: throws GenericServiceException {
176: ModelService model = dispatcher.getDispatchContext()
177: .getModelService(serviceName);
178: if (!model.export && !exportAll) {
179: Debug.logWarning(
180: "Attempt to invoke a non-exported service: "
181: + serviceName, module);
182: throw new GenericServiceException(
183: "Cannot find requested service");
184: }
185: }
186:
187: }
|