[jboss-svn-commits] JBL Code SVN: r9752 - in labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util: jbpm and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Feb 25 19:15:49 EST 2007


Author: estebanschifman
Date: 2007-02-25 19:15:49 -0500 (Sun, 25 Feb 2007)
New Revision: 9752

Added:
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/Invoker.java
Modified:
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/jbpm/CommandVehicle.java
Log:
Jbpm interface new class Invoker, and fix bugs/add operations in CommandVehicle

Added: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/Invoker.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/Invoker.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/Invoker.java	2007-02-26 00:15:49 UTC (rev 9752)
@@ -0,0 +1,127 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.util;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Collection;
+import java.util.UUID;
+
+import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.couriers.PickUpOnlyCourier;
+import org.jboss.soa.esb.addressing.Call;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.MalformedEPRException;
+import org.jboss.soa.esb.couriers.Courier;
+import org.jboss.soa.esb.couriers.CourierException;
+import org.jboss.soa.esb.couriers.CourierFactory;
+import org.jboss.soa.esb.couriers.CourierTimeoutException;
+import org.jboss.soa.esb.couriers.CourierUtil;
+import org.jboss.soa.esb.listeners.RegistryUtil;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.services.registry.RegistryException;
+
+
+/**
+ * 
+ * Utility class to hide implementation details for sending Command messages and optionally awaiting for a response. 
+ * 
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a> 
+ *
+ */
+
+public class Invoker {
+
+	/**
+	 * Encapsulate command in an ESB Message, and deliver.
+	 * 
+	 * @param command AbstractCommandMessage - Transform into an ESB Message, and send
+	 * @param category String - Service category name for Registry inquiry
+	 * @param name String - Service name for Registry inquiry
+	 * @throws RegistryException
+	 * @throws MalformedEPRException
+	 * @throws CourierException
+	 */
+	public static void invoke(AbstractCommandVehicle command, String category, String name)
+		throws RegistryException, MalformedEPRException, CourierException
+	{
+		try { invokeAndAwaitResponse(command,category,name,-1); }
+		catch (CourierTimeoutException e)
+		{
+			_logger.fatal("This should NEVER happen");
+		}
+	} //________________________________
+	
+	/**
+	 * Encapsulate command in an ESB Message, deliver it, and wait for a response Message.
+	 * 
+	 * @param command AbstractCommandMessage - Transform into an ESB Message, and send
+	 * @param category String - Service category name for Registry inquiry
+	 * @param name String - Service name for Registry inquiry
+	 * @param maxWaitMillis int - Maximum time to wait for a response
+	 * @return
+	 * @throws RegistryException
+	 * @throws MalformedEPRException
+	 * @throws CourierException
+	 * @throws CourierTimeoutException - If response was not received in specified time
+	 */
+	
+	public static Message invokeAndAwaitResponse(AbstractCommandVehicle command, String category, String name
+						,int maxWaitMillis)
+		throws RegistryException, MalformedEPRException, CourierException, CourierTimeoutException
+	{
+		Message outgoing = command.toCommandMessage();
+		Call call	= outgoing.getHeader().getCall();
+		URI	 uri	= null;
+		try  { uri = new URI(UUID.randomUUID().toString()); }
+		catch (URISyntaxException e)
+		{
+			_logger.fatal("This should NOT happen");
+			return null;
+		}
+		
+		call.setMessageID(uri);
+		Collection<EPR> eprs = RegistryUtil.getEprs(category, name);
+		EPR toEpr = (eprs.size()<1) ? null : eprs.iterator().next();
+		call.setTo(toEpr);
+
+		Courier sender = CourierFactory.getCourier(toEpr);
+		PickUpOnlyCourier receiver = null;
+		EPR replyToEpr = null;
+		boolean waitForResponse = (maxWaitMillis > 0);
+		if (waitForResponse)
+		{
+			replyToEpr	= CourierUtil.getTemporaryReplyToEpr(toEpr);
+			call.setReplyTo(replyToEpr);
+			call.setFaultTo(replyToEpr);
+			receiver	= CourierFactory.getPickupCourier(replyToEpr);
+		}
+
+		sender.deliver(outgoing);
+		return (waitForResponse)
+			? receiver.pickup(maxWaitMillis)
+			: null
+		;
+	}
+	
+	private static Logger _logger = Logger.getLogger(Invoker.class);
+}


Property changes on: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/Invoker.java
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/jbpm/CommandVehicle.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/jbpm/CommandVehicle.java	2007-02-26 00:07:19 UTC (rev 9751)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/jbpm/CommandVehicle.java	2007-02-26 00:15:49 UTC (rev 9752)
@@ -55,6 +55,7 @@
 	public static final String PROCESS_INSTANCE_ID			="instanceId";
 	public static final String TOKEN_ID						="tokenId";
 	public static final String TRANSITION_NAME				="transitionName";
+	public static final String CURRENT_NODE_NAME			="currentNodeName";
 	public static final String VARIABLE_NAMES_LIST			="variableNamesList";
 	public static final String VARIABLE_VALUES				="variableValuesMap";
 	public static final String USER_OBJECT					="userObject";
@@ -80,6 +81,7 @@
 		,setProcessInstanceVariables
 		,getTokenVariables
 		,setTokenVariables
+		,hasInstanceEnded
 		
 		// Operations originated in jBPM ActionHandlers
 		,responseToRequest
@@ -96,6 +98,7 @@
 	public long	  getInstanceId		() 			{ return (Long)		_values.get(PROCESS_INSTANCE_ID); }
 	public long   getTokenId		() 			{ return (Long)		_values.get(TOKEN_ID); }
 	public String getTransitionName	() 			{ return (String)	_values.get(TRANSITION_NAME); }
+	public String getCurrentNodeName() 			{ return (String)	_values.get(CURRENT_NODE_NAME); }
 	@SuppressWarnings("unchecked")
 	public Set<String> getVariableNames	()		{ return (Set<String>)_values.get(VARIABLE_NAMES_LIST); }
 	@SuppressWarnings("unchecked")
@@ -119,6 +122,7 @@
 	public void	setInstanceId		(long	obj){ super.setValue(PROCESS_INSTANCE_ID	,obj); }
 	public void	setTokenId			(long	obj){ super.setValue(TOKEN_ID				,obj); }
 	public void	setTransitionName 	(String	obj){ super.setValue(TRANSITION_NAME		,obj); }
+	public void	setCurrentNodeName 	(String	obj){ super.setValue(CURRENT_NODE_NAME		,obj); }
 	public void setVariableNames	(Set<String> obj){ super.setValue(VARIABLE_NAMES_LIST,obj); }
 	public void setVariableValues(Map<String,Object>obj)
 	{ 




More information about the jboss-svn-commits mailing list