Author: doogie
Date: Wed Sep 9 06:15:08 2009 New Revision: 812783 URL: http://svn.apache.org/viewvc?rev=812783&view=rev Log: Service definitions are now wrapped with their filename and line number, for easier debugging. Added: ofbiz/trunk/framework/service/src/org/ofbiz/service/GenericInvoker.java Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java Added: ofbiz/trunk/framework/service/src/org/ofbiz/service/GenericInvoker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/GenericInvoker.java?rev=812783&view=auto ============================================================================== --- ofbiz/trunk/framework/service/src/org/ofbiz/service/GenericInvoker.java (added) +++ ofbiz/trunk/framework/service/src/org/ofbiz/service/GenericInvoker.java Wed Sep 9 06:15:08 2009 @@ -0,0 +1,90 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.service; + +import java.util.Map; + +import org.ofbiz.service.engine.GenericEngine; + +import org.webslinger.invoker.Invoker; + +/** + * Generic Invoker Interface + */ +public interface GenericInvoker extends Invoker { + + /** + * Run the service synchronously and return the result. + * + * @param localName Name of the LocalDispatcher. + * @param engine GenericEngine object. + * @param context Map of name, value pairs composing the context. + * @return Map of name, value pairs composing the result. + * @throws GenericServiceException + */ + public Map<String, Object> runSync(String localName, GenericEngine engine, Map<String, Object> context) throws GenericServiceException; + + /** + * Run the service synchronously and IGNORE the result. + * + * @param localName Name of the LocalDispatcher. + * @param engine GenericEngine object. + * @param context Map of name, value pairs composing the context. + * @throws GenericServiceException + */ + public void runSyncIgnore(String localName, GenericEngine engine, Map<String, Object> context) throws GenericServiceException; + + /** + * Run the service asynchronously, passing an instance of GenericRequester that will receive the result. + * + * @param localName Name of the LocalDispatcher. + * @param engine GenericEngine object. + * @param context Map of name, value pairs composing the context. + * @param requester Object implementing GenericRequester interface which will receive the result. + * @param persist True for store/run; False for run. + * @throws GenericServiceException + */ + public void runAsync(String localName, GenericEngine engine, Map<String, Object> context, GenericRequester requester, boolean persist) + throws GenericServiceException; + + /** + * Run the service asynchronously and IGNORE the result. + * + * @param localName Name of the LocalDispatcher. + * @param engine GenericEngine object. + * @param context Map of name, value pairs composing the context. + * @param persist True for store/run; False for run. + * @throws GenericServiceException + */ + public void runAsync(String localName, GenericEngine engine, Map<String, Object> context, boolean persist) throws GenericServiceException; + + /** + * Send the service callbacks + * @param engine GenericEngine object + * @param context Map of name, value pairs composing the context + * @param cbObj Object to return to callback (Throwable or Map) + * @param mode Service mode (sync or async) + * @throws GenericServiceException + */ + public void sendCallbacks(GenericEngine engine, Map<String, Object> context, int mode) throws GenericServiceException; + public void sendCallbacks(GenericEngine engine, Map<String, Object> context, Map<String, Object> result, int mode) throws GenericServiceException; + public void sendCallbacks(GenericEngine engine, Map<String, Object> context, Throwable t, int mode) throws GenericServiceException; + public GenericInvoker copy(ModelService modelService); +} + Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java?rev=812783&r1=812782&r2=812783&view=diff ============================================================================== --- ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java (original) +++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java Wed Sep 9 06:15:08 2009 @@ -197,6 +197,8 @@ /** Flag to say if we have pulled in our addition parameters from our implemented service(s) */ protected boolean inheritedParameters = false; + public GenericInvoker invoker; + public ModelService() {} public ModelService(ModelService model) { @@ -222,6 +224,7 @@ this.overrideParameters = model.overrideParameters; this.inheritedParameters = model.inheritedParameters(); this.internalGroup = model.internalGroup; + this.invoker = model.invoker.copy(this); List<ModelParam> modelParamList = model.getModelParamList(); for (ModelParam param: modelParamList) { Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java?rev=812783&r1=812782&r2=812783&view=diff ============================================================================== --- ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java (original) +++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java Wed Sep 9 06:15:08 2009 @@ -20,6 +20,8 @@ import java.io.IOException; import java.io.Serializable; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.net.URL; import java.util.Collection; import java.util.Iterator; @@ -44,6 +46,7 @@ import org.ofbiz.entity.model.ModelEntity; import org.ofbiz.entity.model.ModelField; import org.ofbiz.entity.model.ModelFieldType; +import org.ofbiz.service.engine.GenericEngine; import org.ofbiz.service.group.GroupModel; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -51,6 +54,8 @@ import org.w3c.dom.NodeList; import org.xml.sax.SAXException; +import org.webslinger.invoker.Wrap; + import freemarker.template.utility.StringUtil; /** @@ -258,6 +263,16 @@ ModelService service = new ModelService(); service.name = UtilXml.checkEmpty(serviceElement.getAttribute("name")).intern(); + Wrap<GenericInvoker> wrap = new Wrap<GenericInvoker>().fileName(resourceLocation + '#' + service.name).wrappedClass(GenericInvokerImpl.class); + for (Method method: GenericInvokerImpl.class.getDeclaredMethods()) { + wrap.wrap(method); + } + Object startLine = serviceElement.getUserData("startLine"); + if (startLine != null) { + wrap.lineNumber(((Integer) startLine).intValue()); + } + service.invoker = wrap.newInstance(new Class<?>[] {ModelService.class}, new Object[] {service}); + service.definitionLocation = resourceLocation; service.engineName = UtilXml.checkEmpty(serviceElement.getAttribute("engine")).intern(); service.location = UtilXml.checkEmpty(serviceElement.getAttribute("location")).intern(); @@ -741,7 +756,7 @@ Document document = null; try { - document = UtilXml.readXmlDocument(url, true); + document = UtilXml.readXmlDocument(url, true, true); } catch (SAXException sxe) { // Error generated during parsing) Exception x = sxe; @@ -758,4 +773,56 @@ return document; } + + public static class GenericInvokerImpl implements GenericInvoker { + private final ModelService modelService; + + public GenericInvokerImpl(ModelService modelService) { + this.modelService = modelService; + } + + public Map<String, Object> runSync(String localName, GenericEngine engine, Map<String, Object> context) throws GenericServiceException { + return engine.runSync(localName, modelService, context); + } + + public void runSyncIgnore(String localName, GenericEngine engine, Map<String, Object> context) throws GenericServiceException { + engine.runSyncIgnore(localName, modelService, context); + } + + public void runAsync(String localName, GenericEngine engine, Map<String, Object> context, GenericRequester requester, boolean persist) throws GenericServiceException { + engine.runAsync(localName, modelService, context, requester, persist); + } + + public void runAsync(String localName, GenericEngine engine, Map<String, Object> context, boolean persist) throws GenericServiceException { + engine.runAsync(localName, modelService, context, persist); + } + + public void sendCallbacks(GenericEngine engine, Map<String, Object> context, int mode) throws GenericServiceException { + engine.sendCallbacks(modelService, context, mode); + } + + public void sendCallbacks(GenericEngine engine, Map<String, Object> context, Map<String, Object> result, int mode) throws GenericServiceException { + engine.sendCallbacks(modelService, context, result, mode); + } + + public void sendCallbacks(GenericEngine engine, Map<String, Object> context, Throwable t, int mode) throws GenericServiceException { + engine.sendCallbacks(modelService, context, t, mode); + } + + public GenericInvokerImpl copy(ModelService modelService) { + try { + try { + return getClass().getConstructor(ModelService.class).newInstance(modelService); + } catch (InvocationTargetException e) { + throw e.getCause(); + } + } catch (RuntimeException e) { + throw e; + } catch (Error e) { + throw e; + } catch (Throwable e) { + throw (InternalError) new InternalError(e.getMessage()).initCause(e); + } + } + } } Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java?rev=812783&r1=812782&r2=812783&view=diff ============================================================================== --- ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java (original) +++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java Wed Sep 9 06:15:08 2009 @@ -389,8 +389,8 @@ // ===== invoke the service ===== if (!isError && !isFailure) { - Map<String, Object> invokeResult = engine.runSync(localName, modelService, context); - engine.sendCallbacks(modelService, context, invokeResult, GenericEngine.SYNC_MODE); + Map<String, Object> invokeResult = modelService.invoker.runSync(localName, engine, context); + modelService.invoker.sendCallbacks(engine, context, invokeResult, GenericEngine.SYNC_MODE); if (invokeResult != null) { result.putAll(invokeResult); } else { @@ -506,7 +506,7 @@ } String errMsg = "Service [" + modelService.name + "] threw an unexpected exception/error"; Debug.logError(t, errMsg, module); - engine.sendCallbacks(modelService, context, t, GenericEngine.SYNC_MODE); + modelService.invoker.sendCallbacks(engine, context, t, GenericEngine.SYNC_MODE); try { TransactionUtil.rollback(beganTrans, errMsg, t); } catch (GenericTransactionException te) { @@ -693,11 +693,11 @@ // run the service if (!isError && !isFailure) { if (requester != null) { - engine.runAsync(localName, service, context, requester, persist); + service.invoker.runAsync(localName, engine, context, requester, persist); } else { - engine.runAsync(localName, service, context, persist); + service.invoker.runAsync(localName, engine, context, persist); } - engine.sendCallbacks(service, context, GenericEngine.ASYNC_MODE); + service.invoker.sendCallbacks(engine, context, GenericEngine.ASYNC_MODE); } if (Debug.timingOn()) { @@ -710,7 +710,7 @@ } String errMsg = "Service [" + service.name + "] threw an unexpected exception/error"; Debug.logError(t, errMsg, module); - engine.sendCallbacks(service, context, t, GenericEngine.ASYNC_MODE); + service.invoker.sendCallbacks(engine, context, t, GenericEngine.ASYNC_MODE); try { TransactionUtil.rollback(beganTrans, errMsg, t); } catch (GenericTransactionException te) { |
Free forum by Nabble | Edit this page |