You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2008/01/08 17:19:50 UTC

svn commit: r610045 [4/5] - in /incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima: aae/jms_adapter/ adapter/jms/activemq/ adapter/jms/client/ adapter/jms/service/ examples/ee/

Propchange: incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/JmsOutputChannel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/ModifiableListener.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/ModifiableListener.java?rev=610045&r1=610044&r2=610045&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/ModifiableListener.java (original)
+++ incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/ModifiableListener.java Tue Jan  8 08:19:46 2008
@@ -1,8 +1,8 @@
-package org.apache.uima.adapter.jms.activemq;
-import org.apache.uima.adapter.jms.activemq.UimaDefaultMessageListenerContainer;
-
-
-public interface ModifiableListener
-{
-	public void setListener( UimaDefaultMessageListenerContainer aContainer);
-}
+package org.apache.uima.adapter.jms.activemq;
+import org.apache.uima.adapter.jms.activemq.UimaDefaultMessageListenerContainer;
+
+
+public interface ModifiableListener
+{
+	public void setListener( UimaDefaultMessageListenerContainer aContainer);
+}

Propchange: incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/ModifiableListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/TempDestinationResolver.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/TempDestinationResolver.java?rev=610045&r1=610044&r2=610045&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/TempDestinationResolver.java (original)
+++ incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/TempDestinationResolver.java Tue Jan  8 08:19:46 2008
@@ -1,35 +1,35 @@
-package org.apache.uima.adapter.jms.activemq;
-
-import javax.jms.Destination;
-import javax.jms.JMSException;
-import javax.jms.Session;
-
-import org.apache.activemq.ActiveMQConnectionFactory;
-import org.springframework.jms.support.destination.DestinationResolver;
-
-
-public class TempDestinationResolver implements DestinationResolver
-{
-	private ActiveMQConnectionFactory factory = null;
-	private UimaDefaultMessageListenerContainer listener;
-	
-	public Destination resolveDestinationName(Session session, String destinationName, boolean pubSubDomain) throws JMSException
-	{
-		Destination destination = session.createTemporaryQueue();
-
-		if ( listener != null )
-		{
-			listener.setDestination(destination);
-		}
-		return destination;
-	}
-
-	public void setListener( UimaDefaultMessageListenerContainer aListener )
-	{
-		listener = aListener;
-	}
-	public void setConnectionFactory( ActiveMQConnectionFactory aFactory )
-	{
-		factory = aFactory;
-	}
-}
+package org.apache.uima.adapter.jms.activemq;
+
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Session;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.springframework.jms.support.destination.DestinationResolver;
+
+
+public class TempDestinationResolver implements DestinationResolver
+{
+	private ActiveMQConnectionFactory factory = null;
+	private UimaDefaultMessageListenerContainer listener;
+	
+	public Destination resolveDestinationName(Session session, String destinationName, boolean pubSubDomain) throws JMSException
+	{
+		Destination destination = session.createTemporaryQueue();
+
+		if ( listener != null )
+		{
+			listener.setDestination(destination);
+		}
+		return destination;
+	}
+
+	public void setListener( UimaDefaultMessageListenerContainer aListener )
+	{
+		listener = aListener;
+	}
+	public void setConnectionFactory( ActiveMQConnectionFactory aFactory )
+	{
+		factory = aFactory;
+	}
+}

Propchange: incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/TempDestinationResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/UimaDefaultMessageListenerContainer.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/UimaDefaultMessageListenerContainer.java?rev=610045&r1=610044&r2=610045&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/UimaDefaultMessageListenerContainer.java (original)
+++ incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/UimaDefaultMessageListenerContainer.java Tue Jan  8 08:19:46 2008
@@ -1,183 +1,183 @@
-package org.apache.uima.adapter.jms.activemq;
-
-import java.net.ConnectException;
-
-import javax.jms.Connection;
-import javax.jms.Destination;
-import javax.jms.ExceptionListener;
-import javax.jms.JMSException;
-
-import org.apache.activemq.ActiveMQConnectionFactory;
-import org.apache.activemq.command.ActiveMQDestination;
-import org.apache.activemq.command.ActiveMQQueue;
-import org.apache.uima.UIMAFramework;
-import org.apache.uima.aae.UIMAEE_Constants;
-import org.apache.uima.aae.controller.Endpoint;
-import org.apache.uima.aae.controller.Endpoint_impl;
-import org.apache.uima.adapter.jms.JmsConstants;
-import org.apache.uima.util.Level;
-import org.springframework.core.task.TaskExecutor;
-import org.springframework.jms.listener.AbstractJmsListeningContainer;
-import org.springframework.jms.listener.DefaultMessageListenerContainer;
-import org.springframework.jms.support.destination.DestinationResolver;
-import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
-
-public class UimaDefaultMessageListenerContainer extends DefaultMessageListenerContainer
-implements ExceptionListener
-{
-	private static final Class CLASS_NAME = UimaDefaultMessageListenerContainer.class;
-	private String destinationName="";
-	private Endpoint endpoint;
-	
-	public UimaDefaultMessageListenerContainer()
-	{
-		super();
-		setRecoveryInterval(60000);
-		setAcceptMessagesWhileStopping(false);
-		
-	}
-	private boolean disableListener( Throwable t)
-	{
-		
-		if ( t instanceof AbstractJmsListeningContainer.SharedConnectionNotInitializedException ||
-			 ( t instanceof JMSException && t.getCause() != null && t.getCause() instanceof ConnectException ) )
-			return true;
-		return false;
-	}
-	protected void handleListenerSetupFailure( Throwable t, boolean alreadyHandled )
-	{
-		if ( !(t instanceof javax.jms.IllegalStateException ) )
-		{
-			t.printStackTrace();
-			final String endpoint = ((ActiveMQQueue)getDestination()).getPhysicalName();
-			UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, this.getClass().getName(),
-	                "handleListenerSetupFailure", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_listener_exception__WARNING",
-	                new Object[] {  endpoint, getBrokerUrl() });
-
-			if ( disableListener(t) )
-			{
-				System.out.println("****** Unable To Connect Listener To Broker:"+getBrokerUrl());
-				System.out.println("****** Closing Listener on Queue:"+endpoint);
-				setRecoveryInterval(0);
-				
-				//	Spin a shutdown thread to terminate listener. The thread is needed due
-				//	to Spring. 
-				new Thread() {
-					public void run()
-					{
-						try
-						{
-							UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, this.getClass().getName(),
-					                "handleListenerSetupFailure", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_diable_listener__WARNING",
-					                new Object[] {  endpoint, getBrokerUrl() });
-							
-							shutdown();
-						}
-						catch( Exception e) { e.printStackTrace();}
-					}
-				}.start();
-			}
-			else
-			{
-				super.handleListenerSetupFailure(t, false);
-			}
-		}
-		
-		
-	}
-
-	protected void handleListenerException( Throwable t )
-	{
-			super.handleListenerException(t);
-		
-	}
-
-	public void afterPropertiesSet()
-	{
-		super.afterPropertiesSet();
-		try
-		{
-			System.setProperty("BrokerURI", ((ActiveMQConnectionFactory)super.getConnectionFactory()).getBrokerURL());
-
-			Destination destination = super.getDestination();
-			if (destination != null && destination instanceof ActiveMQDestination )
-			{
-				destinationName = ((ActiveMQDestination)destination).getPhysicalName();
-			}
-			if ( getMessageListener() instanceof JmsInputChannel )
-			{
-				((JmsInputChannel)getMessageListener()).setListenerContainer(this);
-			}
-			else if ( getMessageListener() instanceof ModifiableListener)
-			{
-				((ModifiableListener)getMessageListener()).setListener(this);
-			}
-		}
-		catch( Exception e)
-		{
-			e.printStackTrace();
-		}
-	}
-	
-	public String getDestinationName()
-	{
-		
-		return destinationName;
-	}
-	public String getEndpointName()
-	{
-		
-		return ((ActiveMQDestination)getDestination()).getPhysicalName();
-	}
-	public String getBrokerUrl()
-	{
-		return ((ActiveMQConnectionFactory)super.getConnectionFactory()).getBrokerURL();
-	}
-	
-	public void setDestinationResolver( DestinationResolver resolver )
-	{
-		((TempDestinationResolver)resolver).setListener(this);
-		super.setDestinationResolver(resolver);
-	}
-	public void closeConnection() throws Exception
-	{
-		try
-		{
-			setRecoveryInterval(0);
-			setAutoStartup(false);
-			getSharedConnection().close();
-		}
-		catch( Exception e)
-		{
-			UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, this.getClass().getName(),
-	                "closeConnection", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_exception__WARNING",
-	                new Object[] {Thread.currentThread().getId(), e});
-			
-		}
-	}
-	public void setDestination( Destination aDestination )
-	{
-		super.setDestination(aDestination);
-		if ( endpoint != null)
-		{
-			endpoint.setDestination(aDestination);
-			endpoint.setServerURI(getBrokerUrl());
-		}
-	}
-	public Destination getListenerEndpoint()
-	{
-		return getDestination(); 
-	}
-
-	public void onException(JMSException arg0)
-	{
-		System.out.println("Exception!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
-	}
-
-	public void setTargetEndpoint( Endpoint anEndpoint )
-	{
-		endpoint = anEndpoint;
-	}
-private static final String copyright = com.ibm.uima.copyright.Copyright.COPYRIGHT;
-
-}
+package org.apache.uima.adapter.jms.activemq;
+
+import java.net.ConnectException;
+
+import javax.jms.Connection;
+import javax.jms.Destination;
+import javax.jms.ExceptionListener;
+import javax.jms.JMSException;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.command.ActiveMQDestination;
+import org.apache.activemq.command.ActiveMQQueue;
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.aae.UIMAEE_Constants;
+import org.apache.uima.aae.controller.Endpoint;
+import org.apache.uima.aae.controller.Endpoint_impl;
+import org.apache.uima.adapter.jms.JmsConstants;
+import org.apache.uima.util.Level;
+import org.springframework.core.task.TaskExecutor;
+import org.springframework.jms.listener.AbstractJmsListeningContainer;
+import org.springframework.jms.listener.DefaultMessageListenerContainer;
+import org.springframework.jms.support.destination.DestinationResolver;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+public class UimaDefaultMessageListenerContainer extends DefaultMessageListenerContainer
+implements ExceptionListener
+{
+	private static final Class CLASS_NAME = UimaDefaultMessageListenerContainer.class;
+	private String destinationName="";
+	private Endpoint endpoint;
+	
+	public UimaDefaultMessageListenerContainer()
+	{
+		super();
+		setRecoveryInterval(60000);
+		setAcceptMessagesWhileStopping(false);
+		
+	}
+	private boolean disableListener( Throwable t)
+	{
+		
+		if ( t instanceof AbstractJmsListeningContainer.SharedConnectionNotInitializedException ||
+			 ( t instanceof JMSException && t.getCause() != null && t.getCause() instanceof ConnectException ) )
+			return true;
+		return false;
+	}
+	protected void handleListenerSetupFailure( Throwable t, boolean alreadyHandled )
+	{
+		if ( !(t instanceof javax.jms.IllegalStateException ) )
+		{
+			t.printStackTrace();
+			final String endpoint = ((ActiveMQQueue)getDestination()).getPhysicalName();
+			UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, this.getClass().getName(),
+	                "handleListenerSetupFailure", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_listener_exception__WARNING",
+	                new Object[] {  endpoint, getBrokerUrl() });
+
+			if ( disableListener(t) )
+			{
+				System.out.println("****** Unable To Connect Listener To Broker:"+getBrokerUrl());
+				System.out.println("****** Closing Listener on Queue:"+endpoint);
+				setRecoveryInterval(0);
+				
+				//	Spin a shutdown thread to terminate listener. The thread is needed due
+				//	to Spring. 
+				new Thread() {
+					public void run()
+					{
+						try
+						{
+							UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, this.getClass().getName(),
+					                "handleListenerSetupFailure", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_diable_listener__WARNING",
+					                new Object[] {  endpoint, getBrokerUrl() });
+							
+							shutdown();
+						}
+						catch( Exception e) { e.printStackTrace();}
+					}
+				}.start();
+			}
+			else
+			{
+				super.handleListenerSetupFailure(t, false);
+			}
+		}
+		
+		
+	}
+
+	protected void handleListenerException( Throwable t )
+	{
+			super.handleListenerException(t);
+		
+	}
+
+	public void afterPropertiesSet()
+	{
+		super.afterPropertiesSet();
+		try
+		{
+			System.setProperty("BrokerURI", ((ActiveMQConnectionFactory)super.getConnectionFactory()).getBrokerURL());
+
+			Destination destination = super.getDestination();
+			if (destination != null && destination instanceof ActiveMQDestination )
+			{
+				destinationName = ((ActiveMQDestination)destination).getPhysicalName();
+			}
+			if ( getMessageListener() instanceof JmsInputChannel )
+			{
+				((JmsInputChannel)getMessageListener()).setListenerContainer(this);
+			}
+			else if ( getMessageListener() instanceof ModifiableListener)
+			{
+				((ModifiableListener)getMessageListener()).setListener(this);
+			}
+		}
+		catch( Exception e)
+		{
+			e.printStackTrace();
+		}
+	}
+	
+	public String getDestinationName()
+	{
+		
+		return destinationName;
+	}
+	public String getEndpointName()
+	{
+		
+		return ((ActiveMQDestination)getDestination()).getPhysicalName();
+	}
+	public String getBrokerUrl()
+	{
+		return ((ActiveMQConnectionFactory)super.getConnectionFactory()).getBrokerURL();
+	}
+	
+	public void setDestinationResolver( DestinationResolver resolver )
+	{
+		((TempDestinationResolver)resolver).setListener(this);
+		super.setDestinationResolver(resolver);
+	}
+	public void closeConnection() throws Exception
+	{
+		try
+		{
+			setRecoveryInterval(0);
+			setAutoStartup(false);
+			getSharedConnection().close();
+		}
+		catch( Exception e)
+		{
+			UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, this.getClass().getName(),
+	                "closeConnection", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_exception__WARNING",
+	                new Object[] {Thread.currentThread().getId(), e});
+			
+		}
+	}
+	public void setDestination( Destination aDestination )
+	{
+		super.setDestination(aDestination);
+		if ( endpoint != null)
+		{
+			endpoint.setDestination(aDestination);
+			endpoint.setServerURI(getBrokerUrl());
+		}
+	}
+	public Destination getListenerEndpoint()
+	{
+		return getDestination(); 
+	}
+
+	public void onException(JMSException arg0)
+	{
+		System.out.println("Exception!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+	}
+
+	public void setTargetEndpoint( Endpoint anEndpoint )
+	{
+		endpoint = anEndpoint;
+	}
+private static final String copyright = com.ibm.uima.copyright.Copyright.COPYRIGHT;
+
+}

Propchange: incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/UimaDefaultMessageListenerContainer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/UimaEEAdminSpringContext.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/UimaEEAdminSpringContext.java?rev=610045&r1=610044&r2=610045&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/UimaEEAdminSpringContext.java (original)
+++ incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/UimaEEAdminSpringContext.java Tue Jan  8 08:19:46 2008
@@ -1,157 +1,157 @@
-package org.apache.uima.adapter.jms.activemq;
-
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.activemq.broker.BrokerService;
-import org.apache.uima.UIMAFramework;
-import org.apache.uima.aae.UimaEEAdminContext;
-import org.apache.uima.adapter.jms.JmsConstants;
-import org.apache.uima.util.Level;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationEvent;
-import org.springframework.context.ApplicationListener;
-import org.springframework.context.support.FileSystemXmlApplicationContext;
-
-public class UimaEEAdminSpringContext 
-implements UimaEEAdminContext, ApplicationListener
-{
-	private static final Class CLASS_NAME = UimaEEAdminSpringContext.class;
-
-	private FileSystemXmlApplicationContext springContainer = null;
-	private BrokerService service;
-	private boolean isShutdown;
-	private ConcurrentHashMap listenerMap = new ConcurrentHashMap();
-	
-	
-	public UimaEEAdminSpringContext( FileSystemXmlApplicationContext aSpringContainer )
-	{
-		springContainer = aSpringContainer;
-		String beanNames[] = springContainer.getBeanNamesForType(org.apache.uima.adapter.jms.activemq.UimaDefaultMessageListenerContainer.class);
-		for( int i=0; beanNames != null && i < beanNames.length; i++)
-		{
-			try
-			{
-				UimaDefaultMessageListenerContainer listenerContainer = 
-					((UimaDefaultMessageListenerContainer)springContainer.getBean(beanNames[i]));
-				ListenerEntry listenerEntry = new ListenerEntry();
-				listenerEntry.setListenerContainer(listenerContainer);
-				listenerMap.put(listenerContainer.getDestinationName(), listenerEntry);
-			}
-			catch( Exception e) {}
-		}
-	}
-	
-	public void setBroker( BrokerService aBrokerService )
-	{
-		service = aBrokerService;
-	}
-	
-	public ApplicationContext getSpringContainer()
-	{
-		return springContainer;
-	}
-	/**
-	 * Stops a listener thread on a given endpoint
-	 */
-	public synchronized void stopListener(String anEndpointName )
-	{
-		try
-		{
-			if ( anEndpointName != null && anEndpointName.trim().length() > 0 && springContainer.isActive() && listenerMap.containsKey(anEndpointName))
-			{
-				ListenerEntry listenerEntry = null;
-				
-				listenerEntry =((ListenerEntry)listenerMap.get(anEndpointName));
-				if ( listenerEntry != null && listenerEntry.isStopped() == false )
-				{
-					listenerEntry.setStopped(true);
-					UimaDefaultMessageListenerContainer listenerContainer = 
-						((ListenerEntry)listenerMap.get(anEndpointName)).getListenerContainer();
-					spinThreadForListenerShutdown(listenerContainer);
-				}
-			}				
-		}
-		catch( Exception e) {}
-	}
-	
-	private void spinThreadForListenerShutdown(final UimaDefaultMessageListenerContainer listenerContainer)
-	{
-		//	Spin a shutdown thread to terminate listener. The thread is needed due
-		//	to Spring. 
-		new Thread() {
-			public void run()
-			{
-				try
-				{
-					listenerContainer.setAutoStartup(false);
-					listenerContainer.setRecoveryInterval(0);
-					listenerContainer.shutdown();
-					listenerContainer.destroy();
-					UIMAFramework.getLogger(CLASS_NAME).logrb(Level.INFO, this.getClass().getName(),
-			                "spinThreadForListenerShutdown.run()", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_stop_listener__INFO",
-			                new Object[] {  listenerContainer.getEndpointName() });
-				}
-				catch( Exception e) { e.printStackTrace();}
-			}
-		}.start();
-	}
-	public void onApplicationEvent(ApplicationEvent anEvent)
-	{
-		shutdown();
-	}
-	/**
-	 *	Stops the Spring Container 
-	 */
-	public void shutdown()
-	{
-		if ( springContainer.isActive() )
-		{
-			isShutdown = true;
-			//	Spin a thread so that the Spring container can shut itself down
-			new Thread("Spring Container Shutdown Thread") {
-				public void run()
-				{
-					try
-					{
-						System.out.println("Destroying Spring Container");
-						springContainer.destroy();
-						springContainer = null;
-					}
-					catch( Exception e) { e.printStackTrace();}
-				}
-			}.start();
-		}
-		listenerMap.clear();
-	}
-	public boolean isShutdown()
-	{
-		return isShutdown;
-	}
-
-	protected class ListenerEntry
-	{
-		private boolean stopped = false;
-		private UimaDefaultMessageListenerContainer listenerContainer = null;
-		
-		protected UimaDefaultMessageListenerContainer getListenerContainer()
-		{
-			return listenerContainer;
-		}
-		protected void setListenerContainer(UimaDefaultMessageListenerContainer listenerContainer)
-		{
-			this.listenerContainer = listenerContainer;
-		}
-		protected boolean isStopped()
-		{
-			return stopped;
-		}
-		protected void setStopped(boolean stopped)
-		{
-			this.stopped = stopped;
-		}
-		
-	}
-	
-	private static final String copyright = com.ibm.uima.copyright.Copyright.COPYRIGHT;
-
-}
+package org.apache.uima.adapter.jms.activemq;
+
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.activemq.broker.BrokerService;
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.aae.UimaEEAdminContext;
+import org.apache.uima.adapter.jms.JmsConstants;
+import org.apache.uima.util.Level;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationEvent;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.support.FileSystemXmlApplicationContext;
+
+public class UimaEEAdminSpringContext 
+implements UimaEEAdminContext, ApplicationListener
+{
+	private static final Class CLASS_NAME = UimaEEAdminSpringContext.class;
+
+	private FileSystemXmlApplicationContext springContainer = null;
+	private BrokerService service;
+	private boolean isShutdown;
+	private ConcurrentHashMap listenerMap = new ConcurrentHashMap();
+	
+	
+	public UimaEEAdminSpringContext( FileSystemXmlApplicationContext aSpringContainer )
+	{
+		springContainer = aSpringContainer;
+		String beanNames[] = springContainer.getBeanNamesForType(org.apache.uima.adapter.jms.activemq.UimaDefaultMessageListenerContainer.class);
+		for( int i=0; beanNames != null && i < beanNames.length; i++)
+		{
+			try
+			{
+				UimaDefaultMessageListenerContainer listenerContainer = 
+					((UimaDefaultMessageListenerContainer)springContainer.getBean(beanNames[i]));
+				ListenerEntry listenerEntry = new ListenerEntry();
+				listenerEntry.setListenerContainer(listenerContainer);
+				listenerMap.put(listenerContainer.getDestinationName(), listenerEntry);
+			}
+			catch( Exception e) {}
+		}
+	}
+	
+	public void setBroker( BrokerService aBrokerService )
+	{
+		service = aBrokerService;
+	}
+	
+	public ApplicationContext getSpringContainer()
+	{
+		return springContainer;
+	}
+	/**
+	 * Stops a listener thread on a given endpoint
+	 */
+	public synchronized void stopListener(String anEndpointName )
+	{
+		try
+		{
+			if ( anEndpointName != null && anEndpointName.trim().length() > 0 && springContainer.isActive() && listenerMap.containsKey(anEndpointName))
+			{
+				ListenerEntry listenerEntry = null;
+				
+				listenerEntry =((ListenerEntry)listenerMap.get(anEndpointName));
+				if ( listenerEntry != null && listenerEntry.isStopped() == false )
+				{
+					listenerEntry.setStopped(true);
+					UimaDefaultMessageListenerContainer listenerContainer = 
+						((ListenerEntry)listenerMap.get(anEndpointName)).getListenerContainer();
+					spinThreadForListenerShutdown(listenerContainer);
+				}
+			}				
+		}
+		catch( Exception e) {}
+	}
+	
+	private void spinThreadForListenerShutdown(final UimaDefaultMessageListenerContainer listenerContainer)
+	{
+		//	Spin a shutdown thread to terminate listener. The thread is needed due
+		//	to Spring. 
+		new Thread() {
+			public void run()
+			{
+				try
+				{
+					listenerContainer.setAutoStartup(false);
+					listenerContainer.setRecoveryInterval(0);
+					listenerContainer.shutdown();
+					listenerContainer.destroy();
+					UIMAFramework.getLogger(CLASS_NAME).logrb(Level.INFO, this.getClass().getName(),
+			                "spinThreadForListenerShutdown.run()", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_stop_listener__INFO",
+			                new Object[] {  listenerContainer.getEndpointName() });
+				}
+				catch( Exception e) { e.printStackTrace();}
+			}
+		}.start();
+	}
+	public void onApplicationEvent(ApplicationEvent anEvent)
+	{
+		shutdown();
+	}
+	/**
+	 *	Stops the Spring Container 
+	 */
+	public void shutdown()
+	{
+		if ( springContainer.isActive() )
+		{
+			isShutdown = true;
+			//	Spin a thread so that the Spring container can shut itself down
+			new Thread("Spring Container Shutdown Thread") {
+				public void run()
+				{
+					try
+					{
+						System.out.println("Destroying Spring Container");
+						springContainer.destroy();
+						springContainer = null;
+					}
+					catch( Exception e) { e.printStackTrace();}
+				}
+			}.start();
+		}
+		listenerMap.clear();
+	}
+	public boolean isShutdown()
+	{
+		return isShutdown;
+	}
+
+	protected class ListenerEntry
+	{
+		private boolean stopped = false;
+		private UimaDefaultMessageListenerContainer listenerContainer = null;
+		
+		protected UimaDefaultMessageListenerContainer getListenerContainer()
+		{
+			return listenerContainer;
+		}
+		protected void setListenerContainer(UimaDefaultMessageListenerContainer listenerContainer)
+		{
+			this.listenerContainer = listenerContainer;
+		}
+		protected boolean isStopped()
+		{
+			return stopped;
+		}
+		protected void setStopped(boolean stopped)
+		{
+			this.stopped = stopped;
+		}
+		
+	}
+	
+	private static final String copyright = com.ibm.uima.copyright.Copyright.COPYRIGHT;
+
+}

Propchange: incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/UimaEEAdminSpringContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/UimaEEBrokerMemoryUsageListener.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/UimaEEBrokerMemoryUsageListener.java?rev=610045&r1=610044&r2=610045&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/UimaEEBrokerMemoryUsageListener.java (original)
+++ incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/UimaEEBrokerMemoryUsageListener.java Tue Jan  8 08:19:46 2008
@@ -1,29 +1,29 @@
-package org.apache.uima.adapter.jms.activemq;
-
-import org.apache.activemq.memory.UsageListener;
-import org.apache.activemq.memory.UsageManager;
-import org.apache.uima.UIMAFramework;
-import org.apache.uima.adapter.jms.JmsConstants;
-import org.apache.uima.util.Level;
-
-public class UimaEEBrokerMemoryUsageListener implements UsageListener
-{
-	private static final Class CLASS_NAME = UimaEEBrokerMemoryUsageListener.class;
-
-	public void onMemoryUseChanged(UsageManager aUsageManager, int oldPercentageUsage, int newPercentageUsage)
-	{
-		if ( aUsageManager.isFull() )
-		{
-			UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, CLASS_NAME.getName(),
-                    "onMemoryUseChanged", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_no_memory__WARNING",
-                    new Object[] { aUsageManager.getLimit(), aUsageManager.getPercentUsage()});
-		}
-		else if ( UIMAFramework.getLogger().isLoggable(Level.FINEST))
-		{
-			UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINEST, CLASS_NAME.getName(),
-                    "onMemoryUseChanged", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_broker_memory__FINEST",
-                    new Object[] { aUsageManager.getLimit(), oldPercentageUsage, newPercentageUsage});
-		}
-	}
-
-}
+package org.apache.uima.adapter.jms.activemq;
+
+import org.apache.activemq.memory.UsageListener;
+import org.apache.activemq.memory.UsageManager;
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.adapter.jms.JmsConstants;
+import org.apache.uima.util.Level;
+
+public class UimaEEBrokerMemoryUsageListener implements UsageListener
+{
+	private static final Class CLASS_NAME = UimaEEBrokerMemoryUsageListener.class;
+
+	public void onMemoryUseChanged(UsageManager aUsageManager, int oldPercentageUsage, int newPercentageUsage)
+	{
+		if ( aUsageManager.isFull() )
+		{
+			UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, CLASS_NAME.getName(),
+                    "onMemoryUseChanged", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_no_memory__WARNING",
+                    new Object[] { aUsageManager.getLimit(), aUsageManager.getPercentUsage()});
+		}
+		else if ( UIMAFramework.getLogger().isLoggable(Level.FINEST))
+		{
+			UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINEST, CLASS_NAME.getName(),
+                    "onMemoryUseChanged", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_broker_memory__FINEST",
+                    new Object[] { aUsageManager.getLimit(), oldPercentageUsage, newPercentageUsage});
+		}
+	}
+
+}

Propchange: incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/UimaEEBrokerMemoryUsageListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/UimaEeExceptionListener.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/UimaEeExceptionListener.java?rev=610045&r1=610044&r2=610045&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/UimaEeExceptionListener.java (original)
+++ incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/UimaEeExceptionListener.java Tue Jan  8 08:19:46 2008
@@ -1,56 +1,56 @@
-package org.apache.uima.adapter.jms.activemq;
-
-import javax.jms.ExceptionListener;
-import javax.jms.JMSException;
-
-import org.apache.uima.UIMAFramework;
-import org.apache.uima.aae.InProcessCache;
-import org.apache.uima.aae.UIMAEE_Constants;
-import org.apache.uima.aae.controller.AnalysisEngineController;
-import org.apache.uima.aae.message.UimaEEShutdownTriggerEvent;
-import org.apache.uima.util.Level;
-import org.springframework.context.ApplicationEvent;
-import org.springframework.context.ApplicationListener;
-import org.springframework.context.event.ContextClosedEvent;
-
-public class UimaEeExceptionListener implements ExceptionListener, ApplicationListener
-{
-
-	public void onException(JMSException arg0)
-	{
-		System.out.println("Exception");
-		arg0.printStackTrace();
-
-	}
-	public void onApplicationEvent(ApplicationEvent anEvent)
-	{
-		if ( anEvent instanceof UimaEEShutdownTriggerEvent)
-		{
-System.out.println("Reaper Received Shutdown Request");
-/*
-	AnalysisEngineController targetController =
-				((UimaEEShutdownTriggerEvent)anEvent).getTargetController();
-			
-			if ( targetController != null && targetController.isTopLevelComponent() )
-			{
-				targetController.terminate();
-				InProcessCache inProcessCache = targetController.getInProcessCache();
-				if ( !inProcessCache.isEmpty() )
-				{
-					inProcessCache.registerCallbackWhenCacheEmpty(targetController.getEventListener());
-				}
-				else
-				{
-					//	Callback to notify that the cache is empty
-					targetController.getEventListener().onCacheEmpty();
-				}
-			}
-*/			
-		}
-		else
-		{
-			System.out.println("=====> Initialize Event:"+anEvent.getClass().getName());
-		}
-	}
-
-}
+package org.apache.uima.adapter.jms.activemq;
+
+import javax.jms.ExceptionListener;
+import javax.jms.JMSException;
+
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.aae.InProcessCache;
+import org.apache.uima.aae.UIMAEE_Constants;
+import org.apache.uima.aae.controller.AnalysisEngineController;
+import org.apache.uima.aae.message.UimaEEShutdownTriggerEvent;
+import org.apache.uima.util.Level;
+import org.springframework.context.ApplicationEvent;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextClosedEvent;
+
+public class UimaEeExceptionListener implements ExceptionListener, ApplicationListener
+{
+
+	public void onException(JMSException arg0)
+	{
+		System.out.println("Exception");
+		arg0.printStackTrace();
+
+	}
+	public void onApplicationEvent(ApplicationEvent anEvent)
+	{
+		if ( anEvent instanceof UimaEEShutdownTriggerEvent)
+		{
+System.out.println("Reaper Received Shutdown Request");
+/*
+	AnalysisEngineController targetController =
+				((UimaEEShutdownTriggerEvent)anEvent).getTargetController();
+			
+			if ( targetController != null && targetController.isTopLevelComponent() )
+			{
+				targetController.terminate();
+				InProcessCache inProcessCache = targetController.getInProcessCache();
+				if ( !inProcessCache.isEmpty() )
+				{
+					inProcessCache.registerCallbackWhenCacheEmpty(targetController.getEventListener());
+				}
+				else
+				{
+					//	Callback to notify that the cache is empty
+					targetController.getEventListener().onCacheEmpty();
+				}
+			}
+*/			
+		}
+		else
+		{
+			System.out.println("=====> Initialize Event:"+anEvent.getClass().getName());
+		}
+	}
+
+}

Propchange: incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/UimaEeExceptionListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/client/BaseUIMAAsynchronousEngine_impl.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/client/BaseUIMAAsynchronousEngine_impl.java?rev=610045&r1=610044&r2=610045&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/client/BaseUIMAAsynchronousEngine_impl.java (original)
+++ incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/client/BaseUIMAAsynchronousEngine_impl.java Tue Jan  8 08:19:46 2008
@@ -1,629 +1,629 @@
-package org.apache.uima.adapter.jms.client;
-
-import java.io.File;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Properties;
-
-import javax.jms.MessageListener;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-
-import org.apache.uima.UIMAFramework;
-import org.apache.uima.UIMA_IllegalArgumentException;
-import org.apache.uima.aae.AsynchAECasManager_impl;
-import org.apache.uima.aae.client.UimaAsynchronousEngine;
-import org.apache.uima.aae.client.UimaEEStatusCallbackListener;
-import org.apache.uima.aae.controller.AnalysisEngineController;
-import org.apache.uima.aae.controller.ControllerLifecycle;
-import org.apache.uima.aae.message.AsynchAEMessage;
-import org.apache.uima.aae.message.UIMAMessage;
-import org.apache.uima.cas.CAS;
-import org.apache.uima.resource.Resource;
-import org.apache.uima.resource.ResourceConfigurationException;
-import org.apache.uima.resource.ResourceInitializationException;
-import org.apache.uima.resource.ResourceManager;
-import org.apache.uima.resource.ResourceProcessException;
-import org.apache.uima.util.Level;
-import org.apache.uima.adapter.jms.service.Dd2spring;
-import org.apache.uima.aae.UIDGenerator;
-
-import javax.jms.DeliveryMode;
-import javax.jms.Queue;
-
-import org.apache.activemq.ActiveMQConnectionFactory;
-import org.apache.activemq.command.ActiveMQDestination;
-import org.apache.activemq.command.ActiveMQTextMessage;
-import org.apache.uima.adapter.jms.JmsConstants;
-import org.apache.uima.adapter.jms.activemq.UimaEEAdminSpringContext;
-
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.support.FileSystemXmlApplicationContext;
-
-/**
- * Uima EE client code
- * 
- * 
- */
-public class BaseUIMAAsynchronousEngine_impl extends BaseUIMAAsynchronousEngineCommon_impl implements UimaAsynchronousEngine, MessageListener
-{
-	private static final Class CLASS_NAME = BaseUIMAAsynchronousEngine_impl.class;
-
-	/**
-	 * Helper method to create JMS Text Message
-	 */
-	protected TextMessage createTextMessage() throws ResourceInitializationException
-	{
-		return new ActiveMQTextMessage();
-	}
-
-	/**
-	 * Called at the end of collectionProcessingComplete - WAS closes receiving
-	 * thread here
-	 */
-	protected void cleanup() throws Exception
-	{
-	}
-
-	/**
-	 * Return a name of the queue to which the JMS Producer is connected to.
-	 */
-	public String getEndPointName() throws ResourceProcessException
-	{
-		try
-		{
-			return (((ActiveMQDestination) producer.getDestination()).getPhysicalName());
-		}
-		catch (Exception e)
-		{
-			throw new ResourceProcessException(e);
-		}
-	}
-	/**
-	 * Helper method to set common properties in the JMS Message
-	 * @param msg
-	 * @throws Exception
-	 */
-	private void setCommonProperties( TextMessage msg ) throws Exception
-	{
-		//	Identify this client's queue
-		msg.setStringProperty(AsynchAEMessage.MessageFrom, consumerDestination.getQueueName());
-		//	Identify client's broker 
-		msg.setStringProperty(UIMAMessage.ServerURI, brokerURI);
-		//	Indicate that this is Request message
-		msg.setIntProperty(AsynchAEMessage.MessageType, AsynchAEMessage.Request);
-		//	Indicate that this is GetMeta command
-		//	Set the Consumer destination. The service must reply to this destination
-		msg.setJMSReplyTo(consumerDestination);
-	}
-	/**
-	 * Initialize JMS Message with properties relevant to GetMeta request.
-	 */
-	protected void setMetaRequestMessage(TextMessage msg) throws Exception
-	{
-		setCommonProperties(msg);
-		msg.setIntProperty(AsynchAEMessage.Command, AsynchAEMessage.GetMeta);
-		//	Set carge to empty String. This is needed for non-tcp protocols.
-		((ActiveMQTextMessage) msg).setText("");
-	}
-
-	/**
-	 * Initialize JMS Message with properties relevant to Process CAS request.
-	 */
-	protected void setCASMessage(String casReferenceId, CAS aCAS, TextMessage msg) throws ResourceProcessException
-	{
-		try
-		{
-			setCommonProperties(msg);
-			msg.setIntProperty(AsynchAEMessage.Command, AsynchAEMessage.Process);
-			msg.setStringProperty(AsynchAEMessage.CasReference, casReferenceId);
-			msg.setIntProperty(AsynchAEMessage.Payload, AsynchAEMessage.XMIPayload);
-			msg.setText(serializeCAS(aCAS));
-		}
-		catch (Exception e)
-		{
-			throw new ResourceProcessException(e);
-		}
-	}
-	/**
-	 * Initialize JMS Message with properties relevant to CPC request.
-	 */
-	public void setCPCMessage(TextMessage msg) throws Exception
-	{
-		setCommonProperties(msg);
-		msg.setIntProperty(AsynchAEMessage.Command, AsynchAEMessage.CollectionProcessComplete);
-		msg.setIntProperty(AsynchAEMessage.Payload, AsynchAEMessage.None);
-		msg.setBooleanProperty(AsynchAEMessage.RemoveEndpoint, true);
-		msg.setText("");
-	}
-	
-	
-	/**
-	 * Force all threads to stop and than do cleanup of resources.
-	 * 
-	 */
-	public void stop()
-	{
-		UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINEST, CLASS_NAME.getName(), "stop", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_stopping_as_client_INFO", new Object[] {});
-
-		if (!running)
-		{
-			return;
-		}
-
-		running = false;
-
-		try
-		{
-			//	Close JMS 
-			producerSession.close();
-			consumerSession.close();
-			consumer.close();
-			session.close();
-			connection.close();
-			connection = null;
-
-			// Unblock threads
-			if (threadMonitorMap.size() > 0)
-			{
-				Iterator it = threadMonitorMap.keySet().iterator();
-				while (it.hasNext())
-				{
-					long key = ((Long) it.next()).longValue();
-					ThreadMonitor threadMonitor = (ThreadMonitor) threadMonitorMap.get(key);
-					synchronized (threadMonitor.getMonitor())
-					{
-						threadMonitor.setWasSignaled();
-						threadMonitor.getMonitor().notifyAll();
-					}
-				}
-			}
-
-			// Unlock all 3 gates
-			synchronized (cpcGate)
-			{
-				cpcGate.notifyAll();
-			}
-			synchronized (endOfCollectionMonitor)
-			{
-				receivedCpcReply = true;
-				endOfCollectionMonitor.notifyAll();
-			}
-			synchronized (metadataReplyMonitor)
-			{
-				receivedMetaReply = true;
-				metadataReplyMonitor.notifyAll();
-			}
-			UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINEST, CLASS_NAME.getName(), "stop", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_stopped_as_client_INFO", new Object[] {});
-			//	Undeploy all containers from the registry in case the services
-			//	are collocated with this client
-			for (Iterator i = springContainerRegistry.entrySet().iterator(); i.hasNext();)
-			{
-				Map.Entry entry = (Map.Entry) i.next();
-				Object key = entry.getKey();
-				undeploy((String) key);
-			}
-			asynchManager = null;
-			springContainerRegistry.clear();
-			listeners.clear();
-
-			// Cancel any timers
-			Iterator iter = clientCache.values().iterator();
-			while (iter.hasNext())
-			{
-				((ClientRequest) iter.next()).cancelTimer();
-			}
-			clientCache.clear();
-		}
-		catch (Exception e)
-		{
-			e.printStackTrace();
-		}
-		finally
-		{
-			synchronized (this)
-			{
-				try
-				{
-					wait(2000); // Let asynch shutdown threads to stop
-				}
-				catch (Exception e)
-				{
-				}
-			}
-
-		}
-	}
-
-	/**
-	 * Return a new session from an established connection. If the connection is
-	 * not established yet, it will be created.
-	 *
-	 * @param aBrokerURI - URL of the broker
-	 * @return - valid session object
-	 * @throws Exception -
-	 */
-	protected Session getSession(String aBrokerURI) throws Exception
-	{
-		if (connection == null)
-		{
-			ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(aBrokerURI);
-			connection = factory.createConnection();
-			connection.start();
-		}
-		session = connection.createSession(false, 0);
-		return session;
-	}
-	/**
-	 * Create a JMS producer that is connected to a given queue. 
-	 * 
-	 * @param aBrokerURI - broker managing a service queue
-	 * @param aQueueName - service queue to which connection is made
-	 * 
-	 * @throws Exception
-	 */
-	public void initializeProducer(String aBrokerURI, String aQueueName) throws Exception
-	{
-		UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINEST, CLASS_NAME.getName(), "initializeProducer", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_init_jms_producer_INFO", new Object[] { aBrokerURI, aQueueName });
-
-		brokerURI = aBrokerURI;
-		producerSession = getSession(aBrokerURI);
-		Queue producerDestination = producerSession.createQueue(aQueueName);
-		producer = producerSession.createProducer(producerDestination);
-		producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-		return;
-	}
-	/**
-	 * Create a JMS Consumer on a temporary queue. Service replies will be handled by 
-	 * this consumer. 
-	 * 
-	 * @param aBrokerURI 
-	 * @throws Exception
-	 */
-	public void initializeConsumer(String aBrokerURI) throws Exception
-	{
-		consumerSession = getSession(aBrokerURI);
-		consumerDestination = consumerSession.createTemporaryQueue();
-		UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINEST, CLASS_NAME.getName(), "initializeConsumer", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_init_jms_consumer_INFO", new Object[] { aBrokerURI, consumerDestination.getQueueName() });
-		consumer = consumerSession.createConsumer(consumerDestination);
-		consumer.setMessageListener(this);
-	}
-
-	public void initialize(String[] configFiles, Map anApplicationContext) throws ResourceInitializationException
-	{
-		reset();
-
-		if (anApplicationContext != null)
-		{
-			Properties p = new Properties();
-			p.put(UimaAsynchronousEngine.ApplicationContext, anApplicationContext);
-			System.setProperties(p);
-		}
-
-		try
-		{
-
-			deployEmbeddedBroker();
-			deploySpringContainer(configFiles);
-		}
-		catch (Exception e)
-		{
-			e.printStackTrace();
-			throw new ResourceInitializationException(e);
-		}
-		running = true;
-		initialized = true;
-	}
-
-	public void initialize(Map anApplicationContext) throws ResourceInitializationException
-	{
-		reset();
-		Properties performanceTuningSettings = null;
-
-		if (!anApplicationContext.containsKey(UimaAsynchronousEngine.ServerUri))
-		{
-			throw new ResourceInitializationException();
-		}
-		if (!anApplicationContext.containsKey(UimaAsynchronousEngine.Endpoint))
-		{
-			throw new ResourceInitializationException();
-		}
-		ResourceManager rm = null;
-		if (anApplicationContext.containsKey(Resource.PARAM_RESOURCE_MANAGER))
-		{
-			rm = (ResourceManager) anApplicationContext.get(Resource.PARAM_RESOURCE_MANAGER);
-		}
-		else
-		{
-			rm = UIMAFramework.newDefaultResourceManager();
-		}
-
-		if (anApplicationContext.containsKey(UIMAFramework.CAS_INITIAL_HEAP_SIZE))
-		{
-			String cas_initial_heap_size = (String) anApplicationContext.get(UIMAFramework.CAS_INITIAL_HEAP_SIZE);
-			performanceTuningSettings = new Properties();
-			performanceTuningSettings.put(UIMAFramework.CAS_INITIAL_HEAP_SIZE, cas_initial_heap_size);
-		}
-
-		asynchManager = new AsynchAECasManager_impl(rm);
-
-		brokerURI = (String) anApplicationContext.get(UimaAsynchronousEngine.ServerUri);
-		String endpoint = (String) anApplicationContext.get(UimaAsynchronousEngine.Endpoint);
-		int casPoolSize = 1;
-
-		if (anApplicationContext.containsKey(UimaAsynchronousEngine.ReplyWindow))
-		{
-			receiveWindow = ((Integer) anApplicationContext.get(UimaAsynchronousEngine.ReplyWindow)).intValue();
-		}
-
-		if (anApplicationContext.containsKey(UimaAsynchronousEngine.CasPoolSize))
-		{
-			casPoolSize = ((Integer) anApplicationContext.get(UimaAsynchronousEngine.CasPoolSize)).intValue();
-		}
-
-		if (anApplicationContext.containsKey(UimaAsynchronousEngine.Timeout))
-		{
-			processTimeout = ((Integer) anApplicationContext.get(UimaAsynchronousEngine.Timeout)).intValue();
-		}
-
-		if (anApplicationContext.containsKey(UimaAsynchronousEngine.GetMetaTimeout))
-		{
-			metadataTimeout = ((Integer) anApplicationContext.get(UimaAsynchronousEngine.GetMetaTimeout)).intValue();
-		}
-
-		if (anApplicationContext.containsKey(UimaAsynchronousEngine.CpcTimeout))
-		{
-			cpcTimeout = ((Integer) anApplicationContext.get(UimaAsynchronousEngine.CpcTimeout)).intValue();
-		}
-
-		UIMAFramework.getLogger(CLASS_NAME).logrb(Level.CONFIG, CLASS_NAME.getName(), "initialize", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_init_uimaee_client__CONFIG", new Object[] { brokerURI, receiveWindow, casPoolSize, processTimeout, metadataTimeout, cpcTimeout });
-
-		try
-		{
-			initializeProducer(brokerURI, endpoint);
-			initializeConsumer(brokerURI);
-			running = true;
-			sendMetaRequest();
-			waitForMetadataReply();
-			if (abort || !running)
-			{
-				UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, CLASS_NAME.getName(), "initialize", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_aborting_as_WARNING", new Object[] { "Metadata Timeout" });
-				throw new ResourceInitializationException();
-			}
-			else
-			{
-				if (collectionReader != null)
-				{
-					asynchManager.addMetadata(collectionReader.getProcessingResourceMetaData());
-				}
-
-				asynchManager.initialize(casPoolSize, "ApplicationCasPoolContext", performanceTuningSettings);
-				initialized = true;
-				remoteService = true;
-				// running = true;
-
-				for (int i = 0; listeners != null && i < listeners.size(); i++)
-				{
-					((UimaEEStatusCallbackListener) listeners.get(i)).initializationComplete(null);
-				}
-			}
-		}
-		catch (ResourceInitializationException e)
-		{
-			throw e;
-		}
-		catch (Exception e)
-		{
-			throw new ResourceInitializationException(e);
-		}
-		UIMAFramework.getLogger(CLASS_NAME).logrb(Level.CONFIG, CLASS_NAME.getName(), "initialize", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_as_initialized_CONFIG", new Object[] { "" });
-
-	}
-
-	/**
-	 * 
-	 */
-	public String deploy(String[] aDeploymentDescriptorList, Map anApplicationContext) throws Exception
-	{
-		if (aDeploymentDescriptorList == null)
-		{
-			throw new ResourceConfigurationException(UIMA_IllegalArgumentException.ILLEGAL_ARGUMENT, new Object[] { "Null", "DeploymentDescriptorList", "deploy()" });
-		}
-
-		if (aDeploymentDescriptorList.length == 0)
-		{
-			throw new ResourceConfigurationException(ResourceConfigurationException.MANDATORY_VALUE_MISSING, new Object[] { "DeploymentDescriptorList" });
-		}
-		String[] springContextFiles = new String[aDeploymentDescriptorList.length];
-
-		for (int i = 0; i < aDeploymentDescriptorList.length; i++)
-		{
-			springContextFiles[i] = generateSpringContext(aDeploymentDescriptorList[i], anApplicationContext);
-		}
-		return deploySpringContainer(springContextFiles);
-	}
-
-	/**
-	 * First generates a Spring context from a given deploy descriptor and than
-	 * deploys the context into a Spring Container.
-	 * 
-	 * @param aDeploymentDescriptor -
-	 *            deployment descriptor to generate Spring Context from
-	 * @param anApplicationContext -
-	 *            a Map containing properties required by dd2spring
-	 * 
-	 * @return - a unique spring container id
-	 * 
-	 */
-	public String deploy(String aDeploymentDescriptor, Map anApplicationContext) throws Exception
-	{
-		String springContext = generateSpringContext(aDeploymentDescriptor, anApplicationContext);
-		return deploySpringContainer(new String[] { springContext });
-	}
-
-	/**
-	 * Undeploys Spring container with a given container Id. All deployed Spring
-	 * containers are registered in the local registry under a unique id.
-	 * 
-	 */
-	public void undeploy(String aSpringContainerId) throws Exception
-	{
-		UimaEEAdminSpringContext adminContext = null;
-		synchronized (springContainerRegistry)
-		{
-			if (!springContainerRegistry.containsKey(aSpringContainerId))
-			{
-				throw new InvalidContainerException("Invalid Spring container Id:" + aSpringContainerId + ". Unable to undeploy the Spring container");
-			}
-			// Fetch an administrative context which contains a Spring Container
-			adminContext = (UimaEEAdminSpringContext) springContainerRegistry.get(aSpringContainerId);
-			// Fetch instance of the Container from its context
-			ApplicationContext ctx = adminContext.getSpringContainer();
-			// Query the container for objects that implement
-			// ControllerLifecycle interface. These
-			// objects are typically of type AnalysisEngineController or
-			// UimacppServiceController.
-			String[] asyncServiceList = ctx.getBeanNamesForType(org.apache.uima.aae.controller.ControllerLifecycle.class);
-			// Given a valid list of controllers select the first from the list
-			// and
-			// initiate a shutdown. We don't care which controller will be
-			// invoked. In case of
-			// AggregateAnalysisEngineController the terminate event will
-			// propagate all the way
-			// to the top controller in the hierarchy and the shutdown will take
-			// place from there.
-			// If the controller is of kind UimecppServiceController or
-			// PrimitiveAnalysisController
-			// the termination logic will be immediately triggered in the
-			// terminate() method.
-			if (asyncServiceList != null && asyncServiceList.length > 0)
-			{
-				ControllerLifecycle ctrer = (ControllerLifecycle) ctx.getBean(asyncServiceList[0]);
-				// Send a trigger to initiate shutdown.
-				if (ctrer instanceof AnalysisEngineController)
-				{
-					((AnalysisEngineController) ctrer).getControllerLatch().release();
-				}
-				ctrer.terminate();
-			}
-
-			if (ctx instanceof FileSystemXmlApplicationContext)
-			{
-				((FileSystemXmlApplicationContext) ctx).destroy();
-			}
-
-			// Remove the container from a local registry
-			springContainerRegistry.remove(aSpringContainerId);
-		}
-
-	}
-
-	/**
-	 * Use dd2spring to generate Spring context file from a given deployment
-	 * descriptor file.
-	 * 
-	 * @param aDeploymentDescriptor -
-	 *            deployment descriptor to generate Spring Context from
-	 * @param anApplicationContext -
-	 *            a Map containing properties required by dd2spring
-	 * @return - an absolute path to the generated Spring Context file
-	 * 
-	 * @throws Exception -
-	 *             if failure occurs
-	 */
-	private String generateSpringContext(String aDeploymentDescriptor, Map anApplicationContext) throws Exception
-	{
-
-		String dd2SpringXsltFilePath = null;
-		String saxonClasspath = null;
-
-		if (anApplicationContext.containsKey(UimaAsynchronousEngine.DD2SpringXsltFilePath))
-		{
-			dd2SpringXsltFilePath = (String) anApplicationContext.get(UimaAsynchronousEngine.DD2SpringXsltFilePath);
-		}
-		else
-		{
-			throw new ResourceConfigurationException(ResourceConfigurationException.MANDATORY_VALUE_MISSING, new Object[] { "Xslt File Path" });
-		}
-		if (anApplicationContext.containsKey(UimaAsynchronousEngine.SaxonClasspath))
-		{
-			saxonClasspath = (String) anApplicationContext.get(UimaAsynchronousEngine.SaxonClasspath);
-		}
-		else
-		{
-			throw new ResourceConfigurationException(ResourceConfigurationException.MANDATORY_VALUE_MISSING, new Object[] { "Saxon Classpath" });
-		}
-
-		Dd2spring dd2Spring = new Dd2spring();
-		File springContextFile = dd2Spring.convertDd2Spring(aDeploymentDescriptor, dd2SpringXsltFilePath, saxonClasspath, (String) anApplicationContext.get(UimaAsynchronousEngine.UimaEeDebug));
-
-		return springContextFile.getAbsolutePath();
-	}
-
-	protected String deploySpringContainer(String[] springContextFiles) throws ResourceInitializationException
-	{
-		try
-		{
-			for (int i = 0; i < springContextFiles.length; i++)
-			{
-				springContextFiles[i] = "file:" + springContextFiles[i];
-				UIMAFramework.getLogger(CLASS_NAME).logrb(Level.CONFIG, CLASS_NAME.getName(), "deploySpringContainer", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_deploy_container__CONFIG", new Object[] { springContextFiles[i] });
-			}
-
-			ApplicationContext ctx = new FileSystemXmlApplicationContext(springContextFiles);
-			UimaEEAdminSpringContext springAdminContext = new UimaEEAdminSpringContext((FileSystemXmlApplicationContext) ctx);
-			String[] brokerDeployer = ctx.getBeanNamesForType(org.apache.uima.adapter.jms.activemq.BrokerDeployer.class);
-			String[] controllers = ctx.getBeanNamesForType(org.apache.uima.aae.controller.AnalysisEngineController.class);
-			for (int i = 0; controllers != null && i < controllers.length; i++)
-			{
-				AnalysisEngineController cntlr = (AnalysisEngineController) ctx.getBean(controllers[i]);
-				cntlr.setUimaEEAdminContext(springAdminContext);
-				if (cntlr.isTopLevelComponent())
-				{
-					((FileSystemXmlApplicationContext) ctx).setDisplayName(cntlr.getComponentName());
-				}
-			}
-
-			String containerId = new UIDGenerator().nextId();
-			synchronized (springContainerRegistry)
-			{
-				springContainerRegistry.put(containerId, springAdminContext);
-			}
-			return containerId;
-		}
-		catch (Exception e)
-		{
-			e.printStackTrace();
-			throw new ResourceInitializationException(e);
-		}
-
-	}
-
-	protected void deployEmbeddedBroker() throws Exception
-	{
-		// TBI
-	}
-
-	public static void main(String[] args)
-	{
-		try
-		{
-
-			BaseUIMAAsynchronousEngineCommon_impl uimaee = new BaseUIMAAsynchronousEngine_impl();
-
-			Map appContext = new HashMap();
-			appContext.put(UimaAsynchronousEngine.DD2SpringXsltFilePath, args[1]);
-			appContext.put(UimaAsynchronousEngine.SaxonClasspath, args[2]);
-			String containerId = uimaee.deploy(args[0], appContext); // args[1],
-			// args[2]);
-
-			uimaee.undeploy(containerId);
-		}
-		catch (Exception e)
-		{
-		}
-	}
-
-	private static final String copyright = com.ibm.uima.copyright.Copyright.COPYRIGHT;
-}
+package org.apache.uima.adapter.jms.client;
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Properties;
+
+import javax.jms.MessageListener;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.UIMA_IllegalArgumentException;
+import org.apache.uima.aae.AsynchAECasManager_impl;
+import org.apache.uima.aae.client.UimaAsynchronousEngine;
+import org.apache.uima.aae.client.UimaEEStatusCallbackListener;
+import org.apache.uima.aae.controller.AnalysisEngineController;
+import org.apache.uima.aae.controller.ControllerLifecycle;
+import org.apache.uima.aae.message.AsynchAEMessage;
+import org.apache.uima.aae.message.UIMAMessage;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.resource.Resource;
+import org.apache.uima.resource.ResourceConfigurationException;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.ResourceManager;
+import org.apache.uima.resource.ResourceProcessException;
+import org.apache.uima.util.Level;
+import org.apache.uima.adapter.jms.service.Dd2spring;
+import org.apache.uima.aae.UIDGenerator;
+
+import javax.jms.DeliveryMode;
+import javax.jms.Queue;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.command.ActiveMQDestination;
+import org.apache.activemq.command.ActiveMQTextMessage;
+import org.apache.uima.adapter.jms.JmsConstants;
+import org.apache.uima.adapter.jms.activemq.UimaEEAdminSpringContext;
+
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.FileSystemXmlApplicationContext;
+
+/**
+ * Uima EE client code
+ * 
+ * 
+ */
+public class BaseUIMAAsynchronousEngine_impl extends BaseUIMAAsynchronousEngineCommon_impl implements UimaAsynchronousEngine, MessageListener
+{
+	private static final Class CLASS_NAME = BaseUIMAAsynchronousEngine_impl.class;
+
+	/**
+	 * Helper method to create JMS Text Message
+	 */
+	protected TextMessage createTextMessage() throws ResourceInitializationException
+	{
+		return new ActiveMQTextMessage();
+	}
+
+	/**
+	 * Called at the end of collectionProcessingComplete - WAS closes receiving
+	 * thread here
+	 */
+	protected void cleanup() throws Exception
+	{
+	}
+
+	/**
+	 * Return a name of the queue to which the JMS Producer is connected to.
+	 */
+	public String getEndPointName() throws ResourceProcessException
+	{
+		try
+		{
+			return (((ActiveMQDestination) producer.getDestination()).getPhysicalName());
+		}
+		catch (Exception e)
+		{
+			throw new ResourceProcessException(e);
+		}
+	}
+	/**
+	 * Helper method to set common properties in the JMS Message
+	 * @param msg
+	 * @throws Exception
+	 */
+	private void setCommonProperties( TextMessage msg ) throws Exception
+	{
+		//	Identify this client's queue
+		msg.setStringProperty(AsynchAEMessage.MessageFrom, consumerDestination.getQueueName());
+		//	Identify client's broker 
+		msg.setStringProperty(UIMAMessage.ServerURI, brokerURI);
+		//	Indicate that this is Request message
+		msg.setIntProperty(AsynchAEMessage.MessageType, AsynchAEMessage.Request);
+		//	Indicate that this is GetMeta command
+		//	Set the Consumer destination. The service must reply to this destination
+		msg.setJMSReplyTo(consumerDestination);
+	}
+	/**
+	 * Initialize JMS Message with properties relevant to GetMeta request.
+	 */
+	protected void setMetaRequestMessage(TextMessage msg) throws Exception
+	{
+		setCommonProperties(msg);
+		msg.setIntProperty(AsynchAEMessage.Command, AsynchAEMessage.GetMeta);
+		//	Set carge to empty String. This is needed for non-tcp protocols.
+		((ActiveMQTextMessage) msg).setText("");
+	}
+
+	/**
+	 * Initialize JMS Message with properties relevant to Process CAS request.
+	 */
+	protected void setCASMessage(String casReferenceId, CAS aCAS, TextMessage msg) throws ResourceProcessException
+	{
+		try
+		{
+			setCommonProperties(msg);
+			msg.setIntProperty(AsynchAEMessage.Command, AsynchAEMessage.Process);
+			msg.setStringProperty(AsynchAEMessage.CasReference, casReferenceId);
+			msg.setIntProperty(AsynchAEMessage.Payload, AsynchAEMessage.XMIPayload);
+			msg.setText(serializeCAS(aCAS));
+		}
+		catch (Exception e)
+		{
+			throw new ResourceProcessException(e);
+		}
+	}
+	/**
+	 * Initialize JMS Message with properties relevant to CPC request.
+	 */
+	public void setCPCMessage(TextMessage msg) throws Exception
+	{
+		setCommonProperties(msg);
+		msg.setIntProperty(AsynchAEMessage.Command, AsynchAEMessage.CollectionProcessComplete);
+		msg.setIntProperty(AsynchAEMessage.Payload, AsynchAEMessage.None);
+		msg.setBooleanProperty(AsynchAEMessage.RemoveEndpoint, true);
+		msg.setText("");
+	}
+	
+	
+	/**
+	 * Force all threads to stop and than do cleanup of resources.
+	 * 
+	 */
+	public void stop()
+	{
+		UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINEST, CLASS_NAME.getName(), "stop", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_stopping_as_client_INFO", new Object[] {});
+
+		if (!running)
+		{
+			return;
+		}
+
+		running = false;
+
+		try
+		{
+			//	Close JMS 
+			producerSession.close();
+			consumerSession.close();
+			consumer.close();
+			session.close();
+			connection.close();
+			connection = null;
+
+			// Unblock threads
+			if (threadMonitorMap.size() > 0)
+			{
+				Iterator it = threadMonitorMap.keySet().iterator();
+				while (it.hasNext())
+				{
+					long key = ((Long) it.next()).longValue();
+					ThreadMonitor threadMonitor = (ThreadMonitor) threadMonitorMap.get(key);
+					synchronized (threadMonitor.getMonitor())
+					{
+						threadMonitor.setWasSignaled();
+						threadMonitor.getMonitor().notifyAll();
+					}
+				}
+			}
+
+			// Unlock all 3 gates
+			synchronized (cpcGate)
+			{
+				cpcGate.notifyAll();
+			}
+			synchronized (endOfCollectionMonitor)
+			{
+				receivedCpcReply = true;
+				endOfCollectionMonitor.notifyAll();
+			}
+			synchronized (metadataReplyMonitor)
+			{
+				receivedMetaReply = true;
+				metadataReplyMonitor.notifyAll();
+			}
+			UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINEST, CLASS_NAME.getName(), "stop", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_stopped_as_client_INFO", new Object[] {});
+			//	Undeploy all containers from the registry in case the services
+			//	are collocated with this client
+			for (Iterator i = springContainerRegistry.entrySet().iterator(); i.hasNext();)
+			{
+				Map.Entry entry = (Map.Entry) i.next();
+				Object key = entry.getKey();
+				undeploy((String) key);
+			}
+			asynchManager = null;
+			springContainerRegistry.clear();
+			listeners.clear();
+
+			// Cancel any timers
+			Iterator iter = clientCache.values().iterator();
+			while (iter.hasNext())
+			{
+				((ClientRequest) iter.next()).cancelTimer();
+			}
+			clientCache.clear();
+		}
+		catch (Exception e)
+		{
+			e.printStackTrace();
+		}
+		finally
+		{
+			synchronized (this)
+			{
+				try
+				{
+					wait(2000); // Let asynch shutdown threads to stop
+				}
+				catch (Exception e)
+				{
+				}
+			}
+
+		}
+	}
+
+	/**
+	 * Return a new session from an established connection. If the connection is
+	 * not established yet, it will be created.
+	 *
+	 * @param aBrokerURI - URL of the broker
+	 * @return - valid session object
+	 * @throws Exception -
+	 */
+	protected Session getSession(String aBrokerURI) throws Exception
+	{
+		if (connection == null)
+		{
+			ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(aBrokerURI);
+			connection = factory.createConnection();
+			connection.start();
+		}
+		session = connection.createSession(false, 0);
+		return session;
+	}
+	/**
+	 * Create a JMS producer that is connected to a given queue. 
+	 * 
+	 * @param aBrokerURI - broker managing a service queue
+	 * @param aQueueName - service queue to which connection is made
+	 * 
+	 * @throws Exception
+	 */
+	public void initializeProducer(String aBrokerURI, String aQueueName) throws Exception
+	{
+		UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINEST, CLASS_NAME.getName(), "initializeProducer", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_init_jms_producer_INFO", new Object[] { aBrokerURI, aQueueName });
+
+		brokerURI = aBrokerURI;
+		producerSession = getSession(aBrokerURI);
+		Queue producerDestination = producerSession.createQueue(aQueueName);
+		producer = producerSession.createProducer(producerDestination);
+		producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+		return;
+	}
+	/**
+	 * Create a JMS Consumer on a temporary queue. Service replies will be handled by 
+	 * this consumer. 
+	 * 
+	 * @param aBrokerURI 
+	 * @throws Exception
+	 */
+	public void initializeConsumer(String aBrokerURI) throws Exception
+	{
+		consumerSession = getSession(aBrokerURI);
+		consumerDestination = consumerSession.createTemporaryQueue();
+		UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINEST, CLASS_NAME.getName(), "initializeConsumer", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_init_jms_consumer_INFO", new Object[] { aBrokerURI, consumerDestination.getQueueName() });
+		consumer = consumerSession.createConsumer(consumerDestination);
+		consumer.setMessageListener(this);
+	}
+
+	public void initialize(String[] configFiles, Map anApplicationContext) throws ResourceInitializationException
+	{
+		reset();
+
+		if (anApplicationContext != null)
+		{
+			Properties p = new Properties();
+			p.put(UimaAsynchronousEngine.ApplicationContext, anApplicationContext);
+			System.setProperties(p);
+		}
+
+		try
+		{
+
+			deployEmbeddedBroker();
+			deploySpringContainer(configFiles);
+		}
+		catch (Exception e)
+		{
+			e.printStackTrace();
+			throw new ResourceInitializationException(e);
+		}
+		running = true;
+		initialized = true;
+	}
+
+	public void initialize(Map anApplicationContext) throws ResourceInitializationException
+	{
+		reset();
+		Properties performanceTuningSettings = null;
+
+		if (!anApplicationContext.containsKey(UimaAsynchronousEngine.ServerUri))
+		{
+			throw new ResourceInitializationException();
+		}
+		if (!anApplicationContext.containsKey(UimaAsynchronousEngine.Endpoint))
+		{
+			throw new ResourceInitializationException();
+		}
+		ResourceManager rm = null;
+		if (anApplicationContext.containsKey(Resource.PARAM_RESOURCE_MANAGER))
+		{
+			rm = (ResourceManager) anApplicationContext.get(Resource.PARAM_RESOURCE_MANAGER);
+		}
+		else
+		{
+			rm = UIMAFramework.newDefaultResourceManager();
+		}
+
+		if (anApplicationContext.containsKey(UIMAFramework.CAS_INITIAL_HEAP_SIZE))
+		{
+			String cas_initial_heap_size = (String) anApplicationContext.get(UIMAFramework.CAS_INITIAL_HEAP_SIZE);
+			performanceTuningSettings = new Properties();
+			performanceTuningSettings.put(UIMAFramework.CAS_INITIAL_HEAP_SIZE, cas_initial_heap_size);
+		}
+
+		asynchManager = new AsynchAECasManager_impl(rm);
+
+		brokerURI = (String) anApplicationContext.get(UimaAsynchronousEngine.ServerUri);
+		String endpoint = (String) anApplicationContext.get(UimaAsynchronousEngine.Endpoint);
+		int casPoolSize = 1;
+
+		if (anApplicationContext.containsKey(UimaAsynchronousEngine.ReplyWindow))
+		{
+			receiveWindow = ((Integer) anApplicationContext.get(UimaAsynchronousEngine.ReplyWindow)).intValue();
+		}
+
+		if (anApplicationContext.containsKey(UimaAsynchronousEngine.CasPoolSize))
+		{
+			casPoolSize = ((Integer) anApplicationContext.get(UimaAsynchronousEngine.CasPoolSize)).intValue();
+		}
+
+		if (anApplicationContext.containsKey(UimaAsynchronousEngine.Timeout))
+		{
+			processTimeout = ((Integer) anApplicationContext.get(UimaAsynchronousEngine.Timeout)).intValue();
+		}
+
+		if (anApplicationContext.containsKey(UimaAsynchronousEngine.GetMetaTimeout))
+		{
+			metadataTimeout = ((Integer) anApplicationContext.get(UimaAsynchronousEngine.GetMetaTimeout)).intValue();
+		}
+
+		if (anApplicationContext.containsKey(UimaAsynchronousEngine.CpcTimeout))
+		{
+			cpcTimeout = ((Integer) anApplicationContext.get(UimaAsynchronousEngine.CpcTimeout)).intValue();
+		}
+
+		UIMAFramework.getLogger(CLASS_NAME).logrb(Level.CONFIG, CLASS_NAME.getName(), "initialize", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_init_uimaee_client__CONFIG", new Object[] { brokerURI, receiveWindow, casPoolSize, processTimeout, metadataTimeout, cpcTimeout });
+
+		try
+		{
+			initializeProducer(brokerURI, endpoint);
+			initializeConsumer(brokerURI);
+			running = true;
+			sendMetaRequest();
+			waitForMetadataReply();
+			if (abort || !running)
+			{
+				UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, CLASS_NAME.getName(), "initialize", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_aborting_as_WARNING", new Object[] { "Metadata Timeout" });
+				throw new ResourceInitializationException();
+			}
+			else
+			{
+				if (collectionReader != null)
+				{
+					asynchManager.addMetadata(collectionReader.getProcessingResourceMetaData());
+				}
+
+				asynchManager.initialize(casPoolSize, "ApplicationCasPoolContext", performanceTuningSettings);
+				initialized = true;
+				remoteService = true;
+				// running = true;
+
+				for (int i = 0; listeners != null && i < listeners.size(); i++)
+				{
+					((UimaEEStatusCallbackListener) listeners.get(i)).initializationComplete(null);
+				}
+			}
+		}
+		catch (ResourceInitializationException e)
+		{
+			throw e;
+		}
+		catch (Exception e)
+		{
+			throw new ResourceInitializationException(e);
+		}
+		UIMAFramework.getLogger(CLASS_NAME).logrb(Level.CONFIG, CLASS_NAME.getName(), "initialize", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_as_initialized_CONFIG", new Object[] { "" });
+
+	}
+
+	/**
+	 * 
+	 */
+	public String deploy(String[] aDeploymentDescriptorList, Map anApplicationContext) throws Exception
+	{
+		if (aDeploymentDescriptorList == null)
+		{
+			throw new ResourceConfigurationException(UIMA_IllegalArgumentException.ILLEGAL_ARGUMENT, new Object[] { "Null", "DeploymentDescriptorList", "deploy()" });
+		}
+
+		if (aDeploymentDescriptorList.length == 0)
+		{
+			throw new ResourceConfigurationException(ResourceConfigurationException.MANDATORY_VALUE_MISSING, new Object[] { "DeploymentDescriptorList" });
+		}
+		String[] springContextFiles = new String[aDeploymentDescriptorList.length];
+
+		for (int i = 0; i < aDeploymentDescriptorList.length; i++)
+		{
+			springContextFiles[i] = generateSpringContext(aDeploymentDescriptorList[i], anApplicationContext);
+		}
+		return deploySpringContainer(springContextFiles);
+	}
+
+	/**
+	 * First generates a Spring context from a given deploy descriptor and than
+	 * deploys the context into a Spring Container.
+	 * 
+	 * @param aDeploymentDescriptor -
+	 *            deployment descriptor to generate Spring Context from
+	 * @param anApplicationContext -
+	 *            a Map containing properties required by dd2spring
+	 * 
+	 * @return - a unique spring container id
+	 * 
+	 */
+	public String deploy(String aDeploymentDescriptor, Map anApplicationContext) throws Exception
+	{
+		String springContext = generateSpringContext(aDeploymentDescriptor, anApplicationContext);
+		return deploySpringContainer(new String[] { springContext });
+	}
+
+	/**
+	 * Undeploys Spring container with a given container Id. All deployed Spring
+	 * containers are registered in the local registry under a unique id.
+	 * 
+	 */
+	public void undeploy(String aSpringContainerId) throws Exception
+	{
+		UimaEEAdminSpringContext adminContext = null;
+		synchronized (springContainerRegistry)
+		{
+			if (!springContainerRegistry.containsKey(aSpringContainerId))
+			{
+				throw new InvalidContainerException("Invalid Spring container Id:" + aSpringContainerId + ". Unable to undeploy the Spring container");
+			}
+			// Fetch an administrative context which contains a Spring Container
+			adminContext = (UimaEEAdminSpringContext) springContainerRegistry.get(aSpringContainerId);
+			// Fetch instance of the Container from its context
+			ApplicationContext ctx = adminContext.getSpringContainer();
+			// Query the container for objects that implement
+			// ControllerLifecycle interface. These
+			// objects are typically of type AnalysisEngineController or
+			// UimacppServiceController.
+			String[] asyncServiceList = ctx.getBeanNamesForType(org.apache.uima.aae.controller.ControllerLifecycle.class);
+			// Given a valid list of controllers select the first from the list
+			// and
+			// initiate a shutdown. We don't care which controller will be
+			// invoked. In case of
+			// AggregateAnalysisEngineController the terminate event will
+			// propagate all the way
+			// to the top controller in the hierarchy and the shutdown will take
+			// place from there.
+			// If the controller is of kind UimecppServiceController or
+			// PrimitiveAnalysisController
+			// the termination logic will be immediately triggered in the
+			// terminate() method.
+			if (asyncServiceList != null && asyncServiceList.length > 0)
+			{
+				ControllerLifecycle ctrer = (ControllerLifecycle) ctx.getBean(asyncServiceList[0]);
+				// Send a trigger to initiate shutdown.
+				if (ctrer instanceof AnalysisEngineController)
+				{
+					((AnalysisEngineController) ctrer).getControllerLatch().release();
+				}
+				ctrer.terminate();
+			}
+
+			if (ctx instanceof FileSystemXmlApplicationContext)
+			{
+				((FileSystemXmlApplicationContext) ctx).destroy();
+			}
+
+			// Remove the container from a local registry
+			springContainerRegistry.remove(aSpringContainerId);
+		}
+
+	}
+
+	/**
+	 * Use dd2spring to generate Spring context file from a given deployment
+	 * descriptor file.
+	 * 
+	 * @param aDeploymentDescriptor -
+	 *            deployment descriptor to generate Spring Context from
+	 * @param anApplicationContext -
+	 *            a Map containing properties required by dd2spring
+	 * @return - an absolute path to the generated Spring Context file
+	 * 
+	 * @throws Exception -
+	 *             if failure occurs
+	 */
+	private String generateSpringContext(String aDeploymentDescriptor, Map anApplicationContext) throws Exception
+	{
+
+		String dd2SpringXsltFilePath = null;
+		String saxonClasspath = null;
+
+		if (anApplicationContext.containsKey(UimaAsynchronousEngine.DD2SpringXsltFilePath))
+		{
+			dd2SpringXsltFilePath = (String) anApplicationContext.get(UimaAsynchronousEngine.DD2SpringXsltFilePath);
+		}
+		else
+		{
+			throw new ResourceConfigurationException(ResourceConfigurationException.MANDATORY_VALUE_MISSING, new Object[] { "Xslt File Path" });
+		}
+		if (anApplicationContext.containsKey(UimaAsynchronousEngine.SaxonClasspath))
+		{
+			saxonClasspath = (String) anApplicationContext.get(UimaAsynchronousEngine.SaxonClasspath);
+		}
+		else
+		{
+			throw new ResourceConfigurationException(ResourceConfigurationException.MANDATORY_VALUE_MISSING, new Object[] { "Saxon Classpath" });
+		}
+
+		Dd2spring dd2Spring = new Dd2spring();
+		File springContextFile = dd2Spring.convertDd2Spring(aDeploymentDescriptor, dd2SpringXsltFilePath, saxonClasspath, (String) anApplicationContext.get(UimaAsynchronousEngine.UimaEeDebug));
+
+		return springContextFile.getAbsolutePath();
+	}
+
+	protected String deploySpringContainer(String[] springContextFiles) throws ResourceInitializationException
+	{
+		try
+		{
+			for (int i = 0; i < springContextFiles.length; i++)
+			{
+				springContextFiles[i] = "file:" + springContextFiles[i];
+				UIMAFramework.getLogger(CLASS_NAME).logrb(Level.CONFIG, CLASS_NAME.getName(), "deploySpringContainer", JmsConstants.JMS_LOG_RESOURCE_BUNDLE, "UIMAJMS_deploy_container__CONFIG", new Object[] { springContextFiles[i] });
+			}
+
+			ApplicationContext ctx = new FileSystemXmlApplicationContext(springContextFiles);
+			UimaEEAdminSpringContext springAdminContext = new UimaEEAdminSpringContext((FileSystemXmlApplicationContext) ctx);
+			String[] brokerDeployer = ctx.getBeanNamesForType(org.apache.uima.adapter.jms.activemq.BrokerDeployer.class);
+			String[] controllers = ctx.getBeanNamesForType(org.apache.uima.aae.controller.AnalysisEngineController.class);
+			for (int i = 0; controllers != null && i < controllers.length; i++)
+			{
+				AnalysisEngineController cntlr = (AnalysisEngineController) ctx.getBean(controllers[i]);
+				cntlr.setUimaEEAdminContext(springAdminContext);
+				if (cntlr.isTopLevelComponent())
+				{
+					((FileSystemXmlApplicationContext) ctx).setDisplayName(cntlr.getComponentName());
+				}
+			}
+
+			String containerId = new UIDGenerator().nextId();
+			synchronized (springContainerRegistry)
+			{
+				springContainerRegistry.put(containerId, springAdminContext);
+			}
+			return containerId;
+		}
+		catch (Exception e)
+		{
+			e.printStackTrace();
+			throw new ResourceInitializationException(e);
+		}
+
+	}
+
+	protected void deployEmbeddedBroker() throws Exception
+	{
+		// TBI
+	}
+
+	public static void main(String[] args)
+	{
+		try
+		{
+
+			BaseUIMAAsynchronousEngineCommon_impl uimaee = new BaseUIMAAsynchronousEngine_impl();
+
+			Map appContext = new HashMap();
+			appContext.put(UimaAsynchronousEngine.DD2SpringXsltFilePath, args[1]);
+			appContext.put(UimaAsynchronousEngine.SaxonClasspath, args[2]);
+			String containerId = uimaee.deploy(args[0], appContext); // args[1],
+			// args[2]);
+
+			uimaee.undeploy(containerId);
+		}
+		catch (Exception e)
+		{
+		}
+	}
+
+	private static final String copyright = com.ibm.uima.copyright.Copyright.COPYRIGHT;
+}

Propchange: incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/client/BaseUIMAAsynchronousEngine_impl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/client/InvalidContainerException.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/client/InvalidContainerException.java?rev=610045&r1=610044&r2=610045&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/client/InvalidContainerException.java (original)
+++ incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/client/InvalidContainerException.java Tue Jan  8 08:19:46 2008
@@ -1,25 +1,25 @@
-package org.apache.uima.adapter.jms.client;
-
-public class InvalidContainerException extends Exception
-{
-
-	public InvalidContainerException()
-	{
-	}
-
-	public InvalidContainerException(String message)
-	{
-		super(message);
-	}
-
-	public InvalidContainerException(Throwable cause)
-	{
-		super(cause);
-	}
-
-	public InvalidContainerException(String message, Throwable cause)
-	{
-		super(message, cause);
-	}
-
-}
+package org.apache.uima.adapter.jms.client;
+
+public class InvalidContainerException extends Exception
+{
+
+	public InvalidContainerException()
+	{
+	}
+
+	public InvalidContainerException(String message)
+	{
+		super(message);
+	}
+
+	public InvalidContainerException(Throwable cause)
+	{
+		super(cause);
+	}
+
+	public InvalidContainerException(String message, Throwable cause)
+	{
+		super(message, cause);
+	}
+
+}

Propchange: incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/client/InvalidContainerException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/client/UIMAAsynchronousEngine.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/client/UIMAAsynchronousEngine.java?rev=610045&r1=610044&r2=610045&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/client/UIMAAsynchronousEngine.java (original)
+++ incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/client/UIMAAsynchronousEngine.java Tue Jan  8 08:19:46 2008
@@ -1,20 +1,20 @@
-package org.apache.uima.adapter.jms.client;
-
-import java.net.URI;
-
-import org.apache.uima.cas.CAS;
-import org.apache.uima.collection.StatusCallbackListener;
-import org.apache.uima.resource.ResourceInitializationException;
-import org.apache.uima.resource.ResourceProcessException;
-import org.springframework.context.ApplicationContext;
-
-public interface UIMAAsynchronousEngine
-{
-	public void initialize( String[] configFiles ) throws ResourceInitializationException;
-	public void addListener( StatusCallbackListener aListener);
-	public void sendCAS( CAS aCAS ) throws ResourceProcessException;
-	public CAS getCAS() throws Exception;
-	public void process( URI aCollection ) throws ResourceProcessException;
-
-	static final String copyright = com.ibm.uima.copyright.Copyright.COPYRIGHT;
-}
+package org.apache.uima.adapter.jms.client;
+
+import java.net.URI;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.collection.StatusCallbackListener;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.ResourceProcessException;
+import org.springframework.context.ApplicationContext;
+
+public interface UIMAAsynchronousEngine
+{
+	public void initialize( String[] configFiles ) throws ResourceInitializationException;
+	public void addListener( StatusCallbackListener aListener);
+	public void sendCAS( CAS aCAS ) throws ResourceProcessException;
+	public CAS getCAS() throws Exception;
+	public void process( URI aCollection ) throws ResourceProcessException;
+
+	static final String copyright = com.ibm.uima.copyright.Copyright.COPYRIGHT;
+}

Propchange: incubator/uima/sandbox/trunk/uima-ee/uimaj-ee-activemq/src/main/java/org/apache/uima/adapter/jms/client/UIMAAsynchronousEngine.java
------------------------------------------------------------------------------
    svn:eol-style = native