[jboss-svn-commits] JBL Code SVN: r9119 - in labs/jbossesb/trunk/product: core/listeners/src/org/jboss/soa/esb/listeners and 7 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Jan 30 02:32:30 EST 2007
Author: kevin.conner at jboss.com
Date: 2007-01-30 02:32:29 -0500 (Tue, 30 Jan 2007)
New Revision: 9119
Added:
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/LifecycleUtil.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/RegistryUtil.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/AbstractManagedLifecycle.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/AbstractThreadedManagedLifecycle.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycle.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleController.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleEventListener.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleException.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleState.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleStateEvent.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleThreadEventListener.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleThreadState.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleThreadStateEvent.java
Removed:
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/internal/soa/esb/listeners/
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/AbstractManagedListener.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerManager.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerManagerFactory.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerController.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerControllerService.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/ListenerManagerService.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/ListenerManagerServiceMBean.java
Modified:
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerUtil.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/StandAloneBootStrapper.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/State.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/ConfigurationController.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/ConfigurationControllerService.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListener.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/HttpListener.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/MessageAwareListener.java
labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/ListenerManagerBaseTest.java
labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/ListenerManagerFTPIntegrationTest.java
labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/ListenerManagerFileUnitTest.java
labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/ListenerManagerJDBCUnitTest.java
labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/ListenerManagerJMSXntegrationTest.java
labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerControllerBaseTest.java
labs/jbossesb/trunk/product/install/jboss-service.xml
Log:
Changed listener/gateway to lifecycle model: JBESB-357
Deleted: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/AbstractManagedListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/AbstractManagedListener.java 2007-01-30 06:44:10 UTC (rev 9118)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/AbstractManagedListener.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -1,279 +0,0 @@
-/*
- * 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.listeners;
-
-import java.util.Observable;
-import java.util.Observer;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-import org.apache.log4j.Logger;
-import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.addressing.EPR;
-import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.services.registry.RegistryException;
-import org.jboss.soa.esb.util.Util;
-
-/**
- * All ESB 'managed' listeners (gateways and message) should extend this class.
- *
- * <p/> Responsibility as an Observable is to notify Observers when it is ready
- * to run (Boolean.TRUE) and when it's not (Boolean.FALSE)
- *
- * <br/> It must be a Runnable that will be started in a thread forked and
- * controlled by a ListenerManager (the _controller)
- *
- * <br/> It is supposed to manage it's own thread pool of 'actions' (the
- * _execService)
- *
- * @author <a
- * href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
- * @since Version 4.0
- *
- */
-public abstract class AbstractManagedListener extends Observable implements
- Runnable, Observer
-{
- public abstract boolean isMessageAware();
-
- public abstract boolean initializeRun();
-
- public abstract boolean finalizeRun();
-
- public abstract void waitForEventAndProcess(long maxWaitMillis);
-
- // disable default constructor
- private AbstractManagedListener()
- {
- }
-
- /**
- * public constructor
- *
- * @param controller
- * ListenerManager - the controlling process
- * @param config
- * ConfigTree - Containing 'static' configuration for this
- * instance
- * @throws ConfigurationException
- */
- protected AbstractManagedListener(ListenerManager controller,
- ConfigTree config) throws ConfigurationException
- {
- _pauseLapseInMillis = 50;
- _defaultMaxThreads = 1;
- _controller = controller;
- _config = config;
-
- _logger = Logger.getLogger(this.getClass());
- checkMyParms();
- } // ________________________________
-
- protected void checkMyParms() throws ConfigurationException
- {
- _eprCategoryName = _config
- .getAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG);
- _eprName = _config.getAttribute(ListenerTagNames.SERVICE_NAME_TAG);
-
- String attr = _config.getAttribute(ListenerTagNames.MAX_THREADS_TAG);
-
- if (!Util.isNullString(attr))
- {
- try
- {
- _maxThreads = Integer.parseInt(attr);
- }
- catch (Exception e)
- {
- attr = null;
- }
- }
-
- if (Util.isNullString(attr))
- {
- _maxThreads = _defaultMaxThreads;
- _logger.debug("Missing or invalid "
- + ListenerTagNames.MAX_THREADS_TAG + " attribute"
- + " - Using default value of <" + _maxThreads + ">");
- }
- } // ________________________________
-
- protected void registerProcess() throws RegistryException
- {
- _bRegistered = false;
-
- _controller.register(_config, _epr);
-
- _bRegistered = true;
- } // ________________________________
-
- protected void unregisterProcess() throws RegistryException
- {
- if (_bRegistered)
- _controller.unRegister(_eprCategoryName, _eprName, _epr);
- } // ________________________________
-
- /**
- * Wait until the registration process finished, a PickupCourier was
- * obtained , and the pool thread is instantiated
- */
- public void waitUntilReady()
- {
- while (null == _execService)
- {
- try
- {
- Thread.sleep(_pauseLapseInMillis);
- }
- catch (InterruptedException e)
- {
- _logger.warn(this.getClass().getSimpleName()
- + " startup interrupted", e);
- }
- }
- } // ________________________________
-
- // Child threads will send a -1 when their run() method ends
- // we need to prevent picking up Messages when there are no available
- // threads in pool
- public void update(Observable o, Object arg)
- {
- if (arg instanceof Integer)
- updateThreadCount((Integer) arg);
- } // ________________________________
-
- public boolean hasActiveTreads()
- {
- return _qRunningThreads > 0;
- } // ________________________________
-
- protected void resetThreadCount()
- {
- synchronized (_synchThreads)
- {
- _qRunningThreads = 0;
- }
- } // ________________________________
-
- protected void updateThreadCount(Integer i)
- {
- synchronized (_synchThreads)
- {
- _qRunningThreads += i.intValue();
- }
- // _logger.debug("Thread pool ("+getClass().getSimpleName()+") used
- // ="+_qRunningThreads+"/"+_maxThreads);
- } // ________________________________
-
- protected String obtainAttribute(String p_sAtt, String p_sDefault)
- throws ConfigurationException
- {
- _logger.debug("Reading value for " + p_sAtt);
- String sVal = _config.getAttribute(p_sAtt);
- if ((null == sVal) && (null == p_sDefault))
- throw new ConfigurationException("Missing or invalid <" + p_sAtt
- + "> attribute");
-
- return (null != sVal) ? sVal : p_sDefault;
- } // ________________________________
-
- /**
- * Loops until controlling process determines <br/>Invokes appropriate
- * Courier to obtain incoming ESB Messages <br/>When one is received,
- * instantiates an action processing pipeline to process it
- */
- public void run()
- {
- _logger.debug("run() method of " + this.getClass().getSimpleName()
- + " started on thread " + Thread.currentThread().getName());
-
- if (initializeRun())
- {
- // Instantiate the pool thread and set active count to zero
- _execService = Executors.newFixedThreadPool(_maxThreads);
- resetThreadCount();
-
- setChanged();
- notifyObservers(Boolean.TRUE);
-
- while (_controller.continueLooping())
- {
- // Only pickup a message when a thread is available
- if (_qRunningThreads >= _maxThreads)
- {
- // _logger.debug("+++++++++++"+Thread.currentThread()+_qRunningThreads);
- try
- {
- Thread.sleep(_pauseLapseInMillis);
- }
- catch (InterruptedException e)
- {
- break;
- }
- continue;
- }
-
- long lWait = _controller.millisToWait();
- if (lWait > 0)
- waitForEventAndProcess(Math.min(lWait, 100));
- }
- setChanged();
- notifyObservers(Boolean.FALSE);
- }
-
- finalizeRun();
-
- // shutdown should wait for all child threads to finish
- if (null != _execService)
- _execService.shutdown();
-
- _logger.debug("run() method of " + this.getClass().getSimpleName()
- + " finished on thread " + Thread.currentThread().getName());
- } // _______________________________
-
- protected ConfigTree _config;
-
- protected ListenerManager _controller;
-
- protected boolean _bRegistered;
-
- protected String _eprCategoryName;
-
- protected String _eprName;
-
- protected EPR _epr;
-
- protected int _maxThreads;
-
- protected int _defaultMaxThreads;
-
- protected long _pauseLapseInMillis;
-
- protected ExecutorService _execService;
-
- private Object _synchThreads = new Short((short) -1);
-
- private int _qRunningThreads;
-
- protected Logger _logger;
-}
Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/LifecycleUtil.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/LifecycleUtil.java (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/LifecycleUtil.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -0,0 +1,213 @@
+/*
+ * 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.listeners;
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycle;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException;
+import org.jboss.soa.esb.parameters.ParamRepositoryException;
+import org.jboss.soa.esb.parameters.ParamRepositoryFactory;
+import org.xml.sax.SAXException;
+
+/**
+ * Lifecycle helper methods
+ * @author kevin
+ */
+public class LifecycleUtil
+{
+ /**
+ * Default constructor.
+ */
+ private LifecycleUtil()
+ {
+ }
+
+ /**
+ * Get the managed listeners from the specified parameter entry in the repository.
+ * @param param The listener parameter.
+ * @return The managed listeners.
+ *
+ * @throws ParamRepositoryException For errors associated with accessing the parameter repository.
+ * @throws SAXException For errors associated with parsing the configuration.
+ * @throws ManagedLifecycleException For errors associated with the managed instance.
+ */
+ public static List<ManagedLifecycle> getListeners(final String param)
+ throws ParamRepositoryException, SAXException, ManagedLifecycleException
+ {
+ return getListeners(getConfigTree(param)) ;
+ }
+
+ /**
+ * Get the managed listeners from the specified config tree.
+ * @param tree The config tree.
+ * @return The managed listeners.
+ *
+ * @throws ManagedLifecycleException For errors associated with the managed instance.
+ */
+ public static List<ManagedLifecycle> getListeners(final ConfigTree tree)
+ throws ManagedLifecycleException
+ {
+ return getManagedInstances(tree, ListenerTagNames.LISTENER_CLASS_TAG) ;
+ }
+
+ /**
+ * Get the managed gateways from the specified parameter entry in the repository.
+ * @param param The gateway parameter.
+ * @return The managed gateways.
+ *
+ * @throws ParamRepositoryException For errors associated with accessing the parameter repository.
+ * @throws SAXException For errors associated with parsing the configuration.
+ * @throws ManagedLifecycleException For errors associated with the managed instance.
+ */
+ public static List<ManagedLifecycle> getGateways(final String param)
+ throws ParamRepositoryException, SAXException, ManagedLifecycleException
+ {
+ return getGateways(getConfigTree(param)) ;
+ }
+
+ /**
+ * Get the managed gateways from the specified config tree.
+ * @param tree The config tree.
+ * @return The managed gateways.
+ *
+ * @throws ManagedLifecycleException For errors associated with the managed instance.
+ */
+ public static List<ManagedLifecycle> getGateways(final ConfigTree tree)
+ throws ManagedLifecycleException
+ {
+ return getManagedInstances(tree, ListenerTagNames.GATEWAY_CLASS_TAG) ;
+ }
+
+ /**
+ * Get the managed instances from the specified config tree.
+ * @param tree The config tree.
+ * @return The managed instances.
+ *
+ * @throws ParamRepositoryException For errors associated with accessing the parameter repository.
+ * @throws SAXException For errors associated with parsing the configuration.
+ * @throws ManagedLifecycleException For errors associated with the managed instance.
+ */
+ private static List<ManagedLifecycle> getManagedInstances(final ConfigTree tree, final String classTag)
+ throws ManagedLifecycleException
+ {
+ final ArrayList<ManagedLifecycle> instances = new ArrayList<ManagedLifecycle>() ;
+
+ for(ConfigTree child : tree.getAllChildren())
+ {
+ final String classname = child.getAttribute(classTag) ;
+ if (classname != null)
+ {
+ final Class instanceClass ;
+ try
+ {
+ instanceClass = loadClass(classname) ;
+ }
+ catch (final ClassNotFoundException cnfe)
+ {
+ throw new ManagedLifecycleException("Could not locate managed instance " + classname) ;
+ }
+
+ if (!ManagedLifecycle.class.isAssignableFrom(instanceClass))
+ {
+ throw new ManagedLifecycleException("Managed instance " + classname + " does not implement ManagedLifecycle") ;
+ }
+
+ final Constructor constructor ;
+ try
+ {
+ constructor = instanceClass.getConstructor(new Class[] {ConfigTree.class}) ;
+ }
+ catch (final NoSuchMethodException nsme)
+ {
+ throw new ManagedLifecycleException("Managed instance " + classname + " does not have correct constructor") ;
+ }
+ final ManagedLifecycle instance ;
+ try
+ {
+ instance = (ManagedLifecycle)constructor.newInstance(child) ;
+ }
+ catch (final Exception ex)
+ {
+ throw new ManagedLifecycleException("Unexpected exception while instantiating managed instance", ex) ;
+ }
+ instances.add(instance) ;
+ }
+ }
+
+ return instances ;
+ }
+
+ /**
+ * Get the config tree from the specified parameter entry in the repository.
+ * @param param The parameter.
+ * @return The config tree.
+ *
+ * @throws ParamRepositoryException For errors associated with accessing the parameter repository.
+ * @throws SAXException For errors associated with parsing the configuration.
+ */
+ public static ConfigTree getConfigTree(final String param)
+ throws ParamRepositoryException, SAXException
+ {
+ final String xml = ParamRepositoryFactory.getInstance().get(param) ;
+ final ConfigTree tree = ConfigTree.fromXml(xml) ;
+
+ tree.setAttribute("configSource", "param-repository:" + param) ;
+ return tree ;
+ }
+
+ /**
+ * Load the specified class.
+ * @param classname The name of the class to load.
+ * @return The specified class.
+ * @throws ClassNotFoundException If the class cannot be found.
+ */
+ private static Class loadClass(final String classname)
+ throws ClassNotFoundException
+ {
+ final ClassLoader threadClassLoader = Thread.currentThread().getContextClassLoader() ;
+ if (threadClassLoader != null)
+ {
+ try
+ {
+ return threadClassLoader.loadClass(classname) ;
+ }
+ catch (final ClassNotFoundException cnfe) {} // ignore
+ }
+
+ final ClassLoader classLoader = LifecycleUtil.class.getClassLoader() ;
+ if (classLoader != null)
+ {
+ try
+ {
+ return classLoader.loadClass(classname) ;
+ }
+ catch (final ClassNotFoundException cnfe) {} // ignore
+ }
+
+ return Class.forName(classname, true, ClassLoader.getSystemClassLoader()) ;
+ }
+}
Property changes on: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/LifecycleUtil.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date
Name: svn:eol-style
+ native
Deleted: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerManager.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerManager.java 2007-01-30 06:44:10 UTC (rev 9118)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerManager.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -1,81 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and others contributors as indicated
- * by the @authors tag. All rights reserved.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * 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,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- * (C) 2005-2006,
- * @author JBoss Inc.
- */
-
-package org.jboss.soa.esb.listeners;
-
-import java.text.SimpleDateFormat;
-import java.util.Observer;
-
-import org.jboss.soa.esb.addressing.EPR;
-import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.services.registry.RegistryException;
-
-/**
- * ListenerManager interface.
- * <p/> An implementation of this intervace controls the lifecycle of a set of child listener processes
- */
-public interface ListenerManager extends Runnable, Observer
-{
-
- public static final String PARM_RELOAD_SECS = "parameterReloadSecs";
- public static final String PARM_END_TIME = "endTime";
-
- // Attribute names to denote listener class to be instantiated in a child thread
- // This attribute is not in the root node but in first level child elements
- public static final String PARM_GATEWAY_CLASS = "gatewayClass";
- public static final String PARM_LISTENER_CLASS = "listenerClass";
- public static final SimpleDateFormat s_oDateParse = new SimpleDateFormat("yyyyMMdd hh:mm:ss");
-
- // Will return when all controlled processes are up and running (max 20 seconds)
- public void waitUntilReady() throws InterruptedException;
- // Will return when all controlled processes are up and running (max = arg0)
- public void waitUntilReady(long maxWaitMillis) throws InterruptedException;
- // Method to request an orderly shutdown of the managing process and it's children
- public abstract void requestEnd();
- // Child threads will invoke this method to continue or end their own process
- public abstract boolean continueLooping();
- // This manager determines maximum time that child processes can wait for an event
- public abstract long millisToWait();
-
- public abstract State getState();
-
- /**
- * Register an EPR in the registry.
- *
- * @param config - a config tree containing the deployment-configuration of the service.
- * @param epr - the epr (EndPoint Reference) of the service.
- *
- * @throws RegistryException
- */
- public abstract void register(ConfigTree config, EPR epr)
- throws RegistryException;
-
- /**
- * Unregister the EPR from the registry.
- *
- * @param serviceCategoryName - name of the category of the service ('Content Based Routing')
- * @param serviceName - name of the service ("
- * @param epr
- * @throws RegistryException
- */
- public abstract void unRegister(String serviceCategoryName, String serviceName, EPR epr) throws RegistryException;
-
-}
\ No newline at end of file
Deleted: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerManagerFactory.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerManagerFactory.java 2007-01-30 06:44:10 UTC (rev 9118)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerManagerFactory.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -1,40 +0,0 @@
-package org.jboss.soa.esb.listeners;
-
-import org.jboss.internal.soa.esb.command.CommandQueueException;
-import org.jboss.internal.soa.esb.listeners.DefaultListenerManager;
-import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.helpers.ConfigTree;
-
-public class ListenerManagerFactory
-{
- private static final ListenerManagerFactory _instance = new ListenerManagerFactory();
- private ListenerManagerFactory() {}
-
- public static ListenerManagerFactory getInstance() {return _instance; }
-
- public ListenerManager getListenerManager(String parametersName)
- throws ConfigurationException
- {
- try
- {
- return new DefaultListenerManager(parametersName);
- }
- catch (CommandQueueException ex)
- {
- throw new ConfigurationException(ex);
- }
- }
-
- public ListenerManager getListenerManager(ConfigTree tree)
- throws ConfigurationException
- {
- try
- {
- return new DefaultListenerManager(tree);
- }
- catch (CommandQueueException ex)
- {
- throw new ConfigurationException(ex);
- }
- }
-}
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java 2007-01-30 06:44:10 UTC (rev 9118)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -38,6 +38,10 @@
/** Threading */
public static final String MAX_THREADS_TAG = "maxThreads";
+ /* Reloading */
+ public static final String RELOAD_SECONDS_TAG = "parameterReloadSecs";
+ public static final String END_TIME_TAG = "endTime";
+
/** Registry */
public static final String SERVICE_CATEGORY_NAME_TAG = "service-category";
public static final String SERVICE_NAME_TAG = "service-name";
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerUtil.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerUtil.java 2007-01-30 06:44:10 UTC (rev 9118)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerUtil.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -55,82 +55,6 @@
{
}
- /**
- * ListenerManager Launcher.
- *
- * @param parametersName
- * String - used to retrieve the ConfigTree with run time
- * configuration values
- * @param inNewThread
- * boolean - if 'true' will launch the ListenerManager in a new
- * thread, and wait until controlled listeners are up and running
- * <br/> if false, will instantiate and run the Controller in
- * current thread - flow control will only return to invoker once
- * the controller's run() method has finished
- * @return ListenerManager
- * @throws ConfigurationException
- */
-
- public static ListenerManager launchManager(String parametersName,
- boolean inNewThread) throws ConfigurationException
- {
- ListenerManager manager = ListenerManagerFactory.getInstance()
- .getListenerManager(parametersName);
- return launchManager(manager, inNewThread) ;
- }
-
- /**
- * ListenerManager Launcher.
- *
- * @param parametersName
- * String - used to retrieve the ConfigTree with run time
- * configuration values
- * @param inNewThread
- * boolean - if 'true' will launch the ListenerManager in a new
- * thread, and wait until controlled listeners are up and running
- * <br/> if false, will instantiate and run the Controller in
- * current thread - flow control will only return to invoker once
- * the controller's run() method has finished
- * @return ListenerManager
- * @throws ConfigurationException
- */
- public static ListenerManager launchManager(ConfigTree tree,
- boolean inNewThread) throws ConfigurationException
- {
- ListenerManager manager = ListenerManagerFactory.getInstance()
- .getListenerManager(tree);
- if (inNewThread)
- {
- new Thread(manager).start();
- }
- else
- {
- StringBuilder sb = new StringBuilder(
- "You are running a ListenerManager in your own thread")
- .append(" - It won't return until it's run() method ends");
- _logger.warn(sb.toString());
- manager.run();
- }
- return manager;
- } // ________________________________
-
- private static ListenerManager launchManager(final ListenerManager manager, final boolean inNewThread)
- {
- if (inNewThread)
- {
- new Thread(manager).start();
- }
- else
- {
- StringBuilder sb = new StringBuilder(
- "You are running a ListenerManager in your own thread")
- .append(" - It won't return until it's run() method ends");
- _logger.warn(sb.toString());
- manager.run();
- }
- return manager;
- } // ________________________________
-
public static EPR tryToDeliver(Message message, String category, String name)
throws CourierException, RegistryException, MalformedEPRException
{
@@ -401,6 +325,31 @@
}
} // ________________________________
+ /**
+ * Find an attribute in the tree (arg 0) or assign default value (arg 2)
+ *
+ * @param p_oP
+ * ConfigTree - look for attributes in this Element only
+ * @param p_sAtt
+ * String - Name of attribute to find
+ * @param p_sDefault
+ * String -default value if requested attribute is not there
+ * @return String - value of attribute, or default value (if null)
+ * @throws ConfigurationException -
+ * If requested attribute not found and no default value
+ * supplied by invoker
+ */
+ public static String obtainAtt (ConfigTree p_oP, String p_sAtt, String p_sDefault)
+ throws ConfigurationException
+ {
+ String sVal = p_oP.getAttribute(p_sAtt);
+ if ((null == sVal) && (null == p_sDefault))
+ throw new ConfigurationException(
+ "Missing or invalid <" + p_sAtt + "> attribute");
+
+ return (null != sVal) ? sVal : p_sDefault;
+ } // ________________________________
+
private static final boolean LOGWARN = true;
private static void warnDefault(String tag, String defaultValue)
Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/RegistryUtil.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/RegistryUtil.java (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/RegistryUtil.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -0,0 +1,230 @@
+/*
+ * 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.listeners;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.util.EPRManager;
+import org.jboss.soa.esb.common.Environment;
+import org.jboss.soa.esb.common.ModulePropertyManager;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.services.registry.Registry;
+import org.jboss.soa.esb.services.registry.RegistryException;
+import org.jboss.soa.esb.services.registry.RegistryFactory;
+
+import com.arjuna.common.util.propertyservice.PropertyManager;
+
+/**
+ * Extraction of common registry utility methods.
+ * @author kevin
+ */
+public class RegistryUtil
+{
+ /**
+ * The logger for this class.
+ */
+ private static final Logger logger = Logger.getLogger(RegistryUtil.class) ;
+
+ /**
+ * The lock for the registry.
+ */
+ private static final Lock registryLock = new ReentrantLock() ;
+
+ /**
+ * Get the EPR manager.
+ * @return The EPR manager.
+ */
+ public static EPRManager getEprManager()
+ {
+ final PropertyManager manager = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE) ;
+ final String dir = manager.getProperty(Environment.REGISTRY_FILE_HELPER_DIR, ".") ;
+ return EPRManager.getInstance(dir) ;
+ }
+
+ /**
+ * Register a service with the EPR manager.
+ * @param name The service name
+ * @param address The service address
+ * @throws RegistryException for registration errors.
+ */
+ private static void register(final String name, final EPR address)
+ throws RegistryException
+ {
+ try
+ {
+ getEprManager().saveEPR(name, address) ;
+ }
+ catch (final IOException ioe)
+ {
+ logger.error("Cannot register service", ioe) ;
+ throw new RegistryException("Cannot register service", ioe) ;
+ }
+ }
+
+ /**
+ * Unregister a service with the EPR manager.
+ * @param name The service name
+ */
+ private static void unregister(final String name)
+ {
+ try
+ {
+ getEprManager().removeEPR(name) ;
+ }
+ catch (final IOException ioe)
+ {
+ logger.warn("Failed to unregister service", ioe) ;
+ }
+ }
+
+ /**
+ * Register an EPR in the registry.
+ *
+ * @param config a config tree containing the deployment-configuration of the service.
+ * @param epr the epr (EndPoint Reference) of the service.
+ *
+ * @throws RegistryException for registration errors.
+ */
+ public static void register(final ConfigTree config, final EPR epr)
+ throws RegistryException
+ {
+ final String category = config.getAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG) ;
+ final String name = config.getAttribute(ListenerTagNames.SERVICE_NAME_TAG) ;
+
+ if ("eprManager".equalsIgnoreCase(category))
+ {
+ register(name, epr) ;
+ }
+ else
+ {
+ final String serviceDescription = config.getAttribute(ListenerTagNames.SERVICE_DESCRIPTION_TAG) ;
+ final String eprDescription = config.getAttribute(ListenerTagNames.EPR_DESCRIPTION_TAG) ;
+ final Registry registry = RegistryFactory.getRegistry() ;
+
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("Registering < " + name + ", " + epr + " >") ;
+ }
+
+ registryLock.lock();
+ try
+ {
+ registry.registerEPR(category, name,
+ serviceDescription, epr, eprDescription) ;
+ }
+ finally
+ {
+ registryLock.unlock() ;
+ }
+ }
+ }
+
+ /**
+ * Unregister the EPR from the registry.
+ *
+ * @param category The category name of the service
+ * @param name The name of the service
+ * @param epr The service EPR.
+ */
+ public static void unregister(final String category, final String name, final EPR epr)
+ {
+ if ("eprManager".equalsIgnoreCase(category))
+ {
+ unregister(name) ;
+ }
+ else
+ {
+ registryLock.lock() ;
+ try
+ {
+ final Registry registry = RegistryFactory.getRegistry() ;
+ registry.unRegisterEPR(category, name, epr) ;
+ }
+ catch (final RegistryException re)
+ {
+ logger.warn("Failed to unregister service", re) ;
+ }
+ finally
+ {
+ registryLock.unlock() ;
+ }
+ }
+ }
+
+ /**
+ * Get the EPRs associated with the specified service.
+ * @param category The category name of the service
+ * @param name The name of the service
+ * @return The collection of EPRs associated with the specified service.
+ *
+ * @throws RegistryException for registration errors.
+ */
+ public static Collection<EPR> getEprs(final String category, final String name)
+ throws RegistryException
+ {
+ if ("eprManager".equalsIgnoreCase(category))
+ {
+ final EPR epr ;
+ try
+ {
+ epr = getEprManager().loadEPR(name) ;
+ }
+ catch (final IOException ioe)
+ {
+ throw new RegistryException("No EPRs found for <" + category
+ + "><" + name + ">") ;
+ }
+ return Arrays.asList(new EPR[] {epr}) ;
+ }
+
+ final Registry reg = RegistryFactory.getRegistry() ;
+ RegistryException eReg = null ;
+ for (int count = 0; count < 5; count++)
+ {
+ try
+ {
+ return reg.findEPRs(category, name) ;
+ }
+ catch (final RegistryException re)
+ {
+ if (null == eReg)
+ eReg = re ;
+ try
+ {
+ Thread.sleep(500) ;
+ }
+ catch (final InterruptedException ie)
+ {
+ break ;
+ }
+ }
+ }
+ throw eReg ;
+ }
+}
Property changes on: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/RegistryUtil.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date
Name: svn:eol-style
+ native
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/StandAloneBootStrapper.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/StandAloneBootStrapper.java 2007-01-30 06:44:10 UTC (rev 9118)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/StandAloneBootStrapper.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -28,16 +28,11 @@
import org.apache.log4j.xml.DOMConfigurator;
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.listeners.config.ConfigurationController;
-import org.jboss.soa.esb.listeners.gateway.GatewayListenerController;
public class StandAloneBootStrapper
{
private ConfigurationController _confController;
- private ListenerManager _manager;
-
- private GatewayListenerController _gatewayController;
-
private static Logger _logger = Logger
.getLogger(StandAloneBootStrapper.class);
@@ -131,20 +126,7 @@
_confController = initiateController(configFile.getAbsolutePath(),
validationFileName, gatewayConfig, listenerConfig);
- listenerConfig = new File(sParent, listenerConfig)
- .getAbsolutePath();
- _logger
- .debug("starting message aware listener with config file - " + listenerConfig);
- _manager = ListenerUtil.launchManager(listenerConfig, true);
- _manager.waitUntilReady();
-
- gatewayConfig = new File(sParent, gatewayConfig).getAbsolutePath();
- _logger
- .info("starting gateway listener with config file - " + gatewayConfig);
- _gatewayController = new GatewayListenerController(gatewayConfig);
- new Thread(_gatewayController).start();
-
- _logger.info("Listeners Ready");
+ _logger.info("Listeners Ready");
}
catch (ConfigurationException ex)
{
@@ -152,12 +134,6 @@
throw ex;
}
- catch (InterruptedException e)
- {
- requestEnd();
-
- throw new ConfigurationException("Thread interrupted", e);
- }
catch (Exception ex)
{
requestEnd();
@@ -169,9 +145,11 @@
public void requestEnd ()
{
- if (null != _gatewayController) _gatewayController.requestEnd();
- if (null != _manager) _manager.requestEnd();
- if (null != _confController) _confController.requestEnd();
+ if (_confController != null)
+ {
+ _confController.requestEnd();
+ _confController.waitUntilEnded() ;
+ }
runAfter();
} // ________________________________
@@ -212,28 +190,12 @@
ConfigurationController conf = new ConfigurationController(configFile
.toString(), validationName);
- new Thread(conf).start();
-
- boolean terminate = false;
-
- for (int i1 = 0; (i1 < 10) && !terminate; i1++)
+ if (listenerFile.exists() && gatewayFile.exists())
{
- if (listenerFile.exists() && gatewayFile.exists())
- return conf;
- else
- {
- try
- {
- Thread.sleep(800); // TODO magic number
- }
- catch (InterruptedException ex)
- {
- terminate = true;
- }
- }
+ new Thread(conf).start() ;
+ return conf;
}
-
- conf.requestEnd();
+
throw new ConfigurationException(
"Unable to generate gateway and listener configurations");
} // ________________________________
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/State.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/State.java 2007-01-30 06:44:10 UTC (rev 9118)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/State.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -28,9 +28,6 @@
public enum State {
Uninitialised, Loading_parameters, Running, Ready, Shutting_down, Done_OK, Exception_thrown;
- private int m_iCompletionCode = 0;
- private Throwable m_oThrowable = null;
-
/**
* Is this state instance in one of the states leading up to (but not including) the "Ready" state.
* @return True if this state instance in one of the states leading up to (but not including)
@@ -39,36 +36,4 @@
public boolean isGettingReady() {
return (this.ordinal() < Ready.ordinal());
}
-
- /**
- * Get the completion code.
- * @return The completion code.
- */
- public int getCompletionCode() {
- return m_iCompletionCode;
- }
-
- /**
- * Get the exception.
- * @return Get the exception.
- */
- public Throwable getThrowable() {
- return m_oThrowable;
- }
-
- /**
- * Set the completion code.
- * @param completionCode The completionCode value.
- */
- public void setCompletionCode(int completionCode) {
- m_iCompletionCode = completionCode;
- }
-
- /**
- * Set the exception.
- * @param thrown The Exception.
- */
- public void setThrowable(Throwable thrown) {
- m_oThrowable = thrown;
- }
}
\ No newline at end of file
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/ConfigurationController.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/ConfigurationController.java 2007-01-30 06:44:10 UTC (rev 9118)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/ConfigurationController.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -29,10 +29,19 @@
import java.io.InputStream;
import java.io.StringReader;
import java.util.Date;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
import javax.xml.transform.stream.StreamSource;
import org.apache.log4j.Logger;
+import org.jboss.soa.esb.listeners.LifecycleUtil;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleController;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycle;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException;
import org.jboss.soa.esb.parameters.ParamRepositoryFactory;
import org.xml.sax.InputSource;
/**
@@ -46,14 +55,21 @@
public class ConfigurationController implements Runnable
{
private static final int SLEEP_MILLIS = 1000; // default interval between parameter reloads
+ private static final int ENDED_MILLIS = 20000; // default interval between parameter reloads
private static final String JBOSSESB_XSD = "/jbossesb-1.0.xsd";
private final Logger mLogger = Logger.getLogger(this.getClass());
+ private final Lock endedLock = new ReentrantLock() ;
+ private final Condition endedChanged = endedLock.newCondition() ;
+ private final Condition endRequested = endedLock.newCondition() ;
private final String mConfigFileName;
private final String mValidationFileName;
private final File mConfigDirectory;
+ private final String mListenerConfigFile;
+ private final String mGatewayConfigFile;
private long mPreviousFileTimestamp;
- private volatile boolean mIsEndRequested;
- private volatile boolean ended;
+ private boolean mIsEndRequested;
+ private boolean ended;
+ private ManagedLifecycleController controller ;
/**
* Start the Controller externally.
@@ -90,6 +106,10 @@
File configFile = new File(configFileName);
File parent = configFile.getParentFile();
mConfigDirectory = (null!=parent) ? parent : new File("");
+ final File listenerConfigFile = new File(mConfigDirectory, Generator.ESB_CONFIG_XML_FILE) ;
+ mListenerConfigFile = listenerConfigFile.getAbsolutePath() ;
+ final File gatewayConfigFile = new File(mConfigDirectory, Generator.ESB_CONFIG_GATEWAY_XML_FILE) ;
+ mGatewayConfigFile = gatewayConfigFile.getAbsolutePath() ;
//Try to obtain a handle to the validation file (xsd)
if (validationFileName==null) {
mValidationFileName=JBOSSESB_XSD;
@@ -104,25 +124,21 @@
* validated and new set jbossesb-listener.xml and jbossesb-gateway.xml is created for the
* current server.
*/
- public void run()
+ public void run()
{
mLogger.info("Configuration Controller instance started.");
try {
if (mConfigFileName!=null) {
- while (!mIsEndRequested) {
+ do {
processConfiguration() ;
- try {
- Thread.sleep(SLEEP_MILLIS);
- } catch (InterruptedException ie) {
- mLogger.warn("Could not sleep." + ie.getMessage(),ie);
- }
- }
+ } while(!waitForRequestedEnd(SLEEP_MILLIS)) ;
+ stopController() ;
} else {
mLogger.fatal("The name of the configuran file was null: " + mConfigFileName);
}
} finally {
mLogger.info("Exiting Config Controller...");
- ended = true;
+ setEnded(true) ;
}
}
@@ -131,14 +147,122 @@
* @return True if this controller instance has ended, otherwise false..
*/
public boolean hasEnded() {
- return ended;
+ endedLock.lock() ;
+ try
+ {
+ return ended ;
+ }
+ finally
+ {
+ endedLock.unlock() ;
+ }
}
+
+ /**
+ * Set the ended flag.
+ * @param ended The value of the ended flag.
+ */
+ private void setEnded(final boolean ended)
+ {
+ endedLock.lock() ;
+ try
+ {
+ this.ended = ended ;
+ endedChanged.signalAll() ;
+ }
+ finally
+ {
+ endedLock.unlock() ;
+ }
+ }
+
+ /**
+ * Wait until the ended flag has been set.
+ * @return true if the ended flag has been set, false otherwise
+ */
+ public boolean waitUntilEnded()
+ {
+ return waitUntilEnded(ENDED_MILLIS) ;
+ }
+
+ /**
+ * Wait until the ended flag has been set.
+ * @param maxDelay The maximum time to wait for the flag to be set.
+ * @return true if the ended flag has been set, false otherwise
+ */
+ public boolean waitUntilEnded(final long maxDelay)
+ {
+ final long endTime = System.currentTimeMillis() + maxDelay ;
+ endedLock.lock() ;
+ try
+ {
+ try
+ {
+ while (!ended)
+ {
+ final long delay = endTime - System.currentTimeMillis() ;
+ if ((delay <= 0) || !endedChanged.await(delay, TimeUnit.MILLISECONDS))
+ {
+ break ;
+ }
+ }
+ }
+ catch (final InterruptedException ie) {} // ignore
+
+ return ended ;
+ }
+ finally
+ {
+ endedLock.unlock() ;
+ }
+ }
+
+ /**
+ * Wait for a request to end.
+ * @param maxDelay The maximum time to wait in milliseconds.
+ */
+ public boolean waitForRequestedEnd(final long maxDelay)
+ {
+ final long endTime = System.currentTimeMillis() + maxDelay ;
+ endedLock.lock() ;
+ try
+ {
+ try
+ {
+ while (!mIsEndRequested)
+ {
+ final long delay = endTime - System.currentTimeMillis() ;
+ if ((delay <= 0) || !endRequested.await(delay, TimeUnit.MILLISECONDS))
+ {
+ break ;
+ }
+ }
+ }
+ catch (final InterruptedException ie) {} // ignore
+
+ return mIsEndRequested ;
+ }
+ finally
+ {
+ endedLock.unlock() ;
+ }
+ }
/**
* To request the end of processing.
*/
- public void requestEnd() {
+ public void requestEnd()
+ {
+ endedLock.lock() ;
+ try
+ {
mIsEndRequested = true;
+ endRequested.signalAll() ;
+ }
+ finally
+ {
+ endedLock.unlock() ;
+ }
}
/**
@@ -179,6 +303,21 @@
Generator generator = new Generator(new ByteArrayInputStream(configXml.getBytes()));
generator.generate(mConfigDirectory);
mLogger.info("Parameter reload completed.");
+ stopController() ;
+
+ final List<ManagedLifecycle> instances = LifecycleUtil.getListeners(mListenerConfigFile) ;
+ instances.addAll(LifecycleUtil.getGateways(mGatewayConfigFile)) ;
+
+ controller = new ManagedLifecycleController(instances) ;
+ try
+ {
+ controller.start() ;
+ }
+ catch (final ManagedLifecycleException mle)
+ {
+ controller = null ;
+ mLogger.error("Unexpected exception starting controller", mle) ;
+ }
} else {
StringBuffer buffer = new StringBuffer("The configuration file "
+ mConfigFileName + "\n did not pass validation for the following reasons: \n");
@@ -225,4 +364,24 @@
}
return false;
}
+
+ /**
+ * Stop the controller if it is active.
+ */
+ private void stopController()
+ {
+ if (controller != null)
+ {
+ try
+ {
+ controller.stop();
+ }
+ catch (final ManagedLifecycleException mle)
+ {
+ mLogger.error("Unexpected exception stopping controller", mle) ;
+ System.out.println(mle.getMessage()) ;
+ }
+ controller = null ;
+ }
+ }
}
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/ConfigurationControllerService.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/ConfigurationControllerService.java 2007-01-30 06:44:10 UTC (rev 9118)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/ConfigurationControllerService.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -47,6 +47,7 @@
confDir = uri.getPath();
String configFile = confDir + configurationFile;
configurationController = new ConfigurationController(configFile,null);
+// TODO tidy up
new Thread(configurationController).start();
}
/**
@@ -56,6 +57,7 @@
{
logger.info("shutting down message aware listener...");
configurationController.requestEnd();
+ configurationController.waitUntilEnded() ;
}
/**
* Gets the config file. The name of the file can be set in the jboss-service.xml.
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java 2007-01-30 06:44:10 UTC (rev 9118)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -42,6 +42,11 @@
import org.jboss.soa.esb.couriers.CourierFactory;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.listeners.ListenerUtil;
+import org.jboss.soa.esb.listeners.RegistryUtil;
+import org.jboss.soa.esb.listeners.lifecycle.AbstractThreadedManagedLifecycle;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleThreadState;
import org.jboss.soa.esb.services.registry.RegistryException;
import org.jboss.soa.esb.util.Util;
@@ -55,7 +60,7 @@
* @since Version 4.0
*
*/
-public abstract class AbstractFileGateway implements Runnable
+public abstract class AbstractFileGateway extends AbstractThreadedManagedLifecycle
{
abstract File[] getFileList(String suffix) throws GatewayException;
@@ -69,62 +74,56 @@
abstract void getDefaultComposer() throws GatewayException;
- protected AbstractFileGateway()
+ protected AbstractFileGateway(ConfigTree config) throws ConfigurationException, RegistryException, GatewayException
{
- }
-
- protected AbstractFileGateway(GatewayListenerController commandListener,
- ConfigTree config) throws ConfigurationException, RegistryException, GatewayException
- {
- _config = config;
- _controller = commandListener;
- _sleepBetweenPolls = 10000; // milliseconds
- checkMyParms();
+ super(config) ;
+ _config = config;
+ _sleepBetweenPolls = 10000; // milliseconds
+ checkMyParms();
} // __________________________________
+
+ /**
+ * Handle the initialisation of the managed instance.
+ *
+ * @throws ManagedLifecycleException for errors while initialisation.
+ */
+ protected void doInitialise()
+ throws ManagedLifecycleException
+ {
+ try
+ {
+ _targetEprs = RegistryUtil.getEprs(_targetServiceCategory,_targetServiceName);
+ if (null == _targetEprs || _targetEprs.size() < 1)
+ throw new ManagedLifecycleException("EPR <" + _targetServiceName + "> not found in registry") ;
+ }
+ catch (final RegistryException re)
+ {
+ throw new ManagedLifecycleException("Unexpected registry exception", re) ;
+ }
+
+ try
+ {
+ RegistryUtil.register(_config, _myEpr);
+ }
+ catch (final RegistryException re)
+ {
+ throw new ManagedLifecycleException("Unexpected error during registration for epr " + _myEpr, re);
+ }
+ }
- public void run()
- {
- _logger.debug("run() method of " + this.getClass().getSimpleName()
- + " started on thread " + Thread.currentThread().getName());
- if (null != _serviceName)
- try
- {
- _controller.register(_config, _myEpr);
- }
- catch (RegistryException e1)
- {
- _logger.warn("unable to register service", e1);
- }
+ /**
+ * Execute on the thread.
+ */
+ protected void doRun()
+ {
+ if (_logger.isDebugEnabled())
+ {
+ _logger.debug("run() method of " + this.getClass().getSimpleName()
+ + " started on thread " + Thread.currentThread().getName());
+ }
- boolean bSleep = false;
-
- while (_controller.continueLooping())
+ do
{
- // only sleep in between - not the first time
- if (bSleep)
- {
- long lUntil = System.currentTimeMillis() + _sleepBetweenPolls;
- while (System.currentTimeMillis() < lUntil)
- {
- try
- {
- // TODO magic number
-
- Thread.sleep(1000);
- }
- catch (InterruptedException e)
- {
- lUntil = 0;
- }
- if (!_controller.continueLooping())
- break;
- }
- }
- else
- bSleep = true;
- if (!_controller.continueLooping())
- break;
-
File[] fileList;
try
{
@@ -181,8 +180,7 @@
}
catch (Exception e)
{
- _logger.error("Problems with file EPR", e);
- }
+ _logger.error("Problems with file EPR", e); }
}
_courier = CourierFactory.getCourier(current);
if (_courier
@@ -299,22 +297,25 @@
}
}
}
+ while (!waitForRunningStateChange(ManagedLifecycleThreadState.STOPPING, _sleepBetweenPolls)) ;
- if (null != _serviceName)
- {
- try
- {
- _controller.unRegister(_serviceCategory, _serviceName, _myEpr);
- }
- catch (RegistryException e1)
- {
- _logger.warn("unable to unRegister service", e1);
- }
- }
-
- _logger.debug("run() method of " + this.getClass().getSimpleName()
+ if (_logger.isDebugEnabled())
+ {
+ _logger.debug("run() method of " + this.getClass().getSimpleName()
+ " finished on thread " + Thread.currentThread().getName());
+ }
} // ________________________________
+
+ /**
+ * Handle the destroy of the managed instance.
+ *
+ * @throws ManagedLifecycleException for errors while destroying.
+ */
+ protected void doDestroy()
+ throws ManagedLifecycleException
+ {
+ RegistryUtil.unregister(_serviceCategory, _serviceName, _myEpr);
+ }
/**
* Check for mandatory and optional attributes in parameter tree
@@ -323,19 +324,14 @@
* if mandatory atts are not right or actionClass not in
* classpath
*/
- protected void checkMyParms() throws ConfigurationException, RegistryException, GatewayException
+ private void checkMyParms() throws ConfigurationException, RegistryException, GatewayException
{
// Third arg is null - Exception will be thrown if attribute is not
// found
- _targetServiceCategory = _controller.obtainAtt(_config,
+ _targetServiceCategory = ListenerUtil.obtainAtt(_config,
ListenerTagNames.TARGET_SERVICE_CATEGORY_TAG, null);
- _targetServiceName = _controller.obtainAtt(_config,
+ _targetServiceName = ListenerUtil.obtainAtt(_config,
ListenerTagNames.TARGET_SERVICE_NAME_TAG, null);
- _targetEprs = _controller.getEprs(_targetServiceCategory,
- _targetServiceName);
- if (null == _targetEprs || _targetEprs.size() < 1)
- throw new ConfigurationException("EPR <" + _targetServiceName
- + "> not found in registry");
// Polling interval
String sAux = _config
@@ -366,12 +362,12 @@
{
// INPUT directory and suffix (used for FileFilter)
String url = _config.getAttribute(ListenerTagNames.URL_TAG);
- String sInpDir = (null != url) ? new URL(url).getFile() : _controller
- .obtainAtt(_config, ListenerTagNames.FILE_INPUT_DIR_TAG, null);
+ String sInpDir = (null != url) ? new URL(url).getFile() :
+ ListenerUtil.obtainAtt(_config, ListenerTagNames.FILE_INPUT_DIR_TAG, null);
_inputDirectory = fileFromString(sInpDir);
seeIfOkToWorkOnDir(_inputDirectory);
- _inputSuffix = _controller.obtainAtt(_config,
+ _inputSuffix = ListenerUtil.obtainAtt(_config,
ListenerTagNames.FILE_INPUT_SFX_TAG, null);
_inputSuffix = _inputSuffix.trim();
if (_inputSuffix.length() < 1)
@@ -379,7 +375,7 @@
+ ListenerTagNames.FILE_INPUT_SFX_TAG + " attribute");
// WORK suffix (will rename in input directory)
- _workingSuffix = _controller.obtainAtt(_config,
+ _workingSuffix = ListenerUtil.obtainAtt(_config,
ListenerTagNames.FILE_WORK_SFX_TAG, ".esbWork").trim();
if (_workingSuffix.length() < 1)
throw new ConfigurationException("Invalid " + ListenerTagNames.FILE_WORK_SFX_TAG
@@ -390,12 +386,12 @@
// ERROR directory and suffix (defaults to input dir and ".esbError"
// suffix)
- String sErrDir = _controller.obtainAtt(_config,
+ String sErrDir = ListenerUtil.obtainAtt(_config,
ListenerTagNames.FILE_ERROR_DIR_TAG, sInpDir);
_errorDirectory = fileFromString(sErrDir);
seeIfOkToWorkOnDir(_errorDirectory);
- _errorSuffix = _controller.obtainAtt(_config,
+ _errorSuffix = ListenerUtil.obtainAtt(_config,
ListenerTagNames.FILE_ERROR_SFX_TAG, ".esbError").trim();
if (_errorSuffix.length() < 1)
throw new ConfigurationException("Invalid "
@@ -406,7 +402,7 @@
+ _errorSuffix + ">");
// Do users wish to delete files that were processed OK ?
- String sPostDel = _controller.obtainAtt(_config,
+ String sPostDel = ListenerUtil.obtainAtt(_config,
ListenerTagNames.FILE_POST_DEL_TAG, "false").trim();
_deleteAfterOK = Boolean.parseBoolean(sPostDel);
if (_deleteAfterOK)
@@ -414,11 +410,11 @@
// POST (done) directory and suffix (defaults to input dir and
// ".esbDone" suffix)
- String sPostDir = _controller.obtainAtt(_config,
+ String sPostDir = ListenerUtil.obtainAtt(_config,
ListenerTagNames.FILE_POST_DIR_TAG, sInpDir);
_postProcessDirectory = fileFromString(sPostDir);
seeIfOkToWorkOnDir(_postProcessDirectory);
- _postProcessSuffix = _controller.obtainAtt(_config,
+ _postProcessSuffix = ListenerUtil.obtainAtt(_config,
ListenerTagNames.FILE_POST_SFX_TAG, ".esbDone").trim();
if (_postProcessDirectory.equals(_inputDirectory))
{
@@ -503,8 +499,6 @@
protected ConfigTree _config;
- protected GatewayListenerController _controller;
-
protected long _sleepBetweenPolls; // milliseconds
protected String _serviceCategory, _serviceName;
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java 2007-01-30 06:44:10 UTC (rev 9118)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -39,22 +39,17 @@
public class FileGatewayListener extends AbstractFileGateway
{
- protected FileGatewayListener()
- {
- }
+ /**
+ * serial version uid for this class
+ */
+ private static final long serialVersionUID = 8457176329093772449L;
- public FileGatewayListener(GatewayListenerController commandListener,
- ConfigTree config) throws ConfigurationException, RegistryException, GatewayException
+ public FileGatewayListener(ConfigTree config) throws ConfigurationException, RegistryException, GatewayException
{
- super(commandListener, config);
+ super(config);
_fileFilter = new FileEndsWith(_inputSuffix);
}
- protected void checkMyParms() throws ConfigurationException, RegistryException, GatewayException
- {
- super.checkMyParms();
- }
-
@Override
protected void seeIfOkToWorkOnDir(File p_oDir) throws GatewayException
{
Deleted: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerController.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerController.java 2007-01-30 06:44:10 UTC (rev 9118)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerController.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -1,815 +0,0 @@
-/*
- * 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.listeners.gateway;
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Constructor;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.log4j.Logger;
-import org.jboss.internal.soa.esb.command.CommandQueue;
-import org.jboss.internal.soa.esb.command.CommandQueueException;
-import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.addressing.EPR;
-import org.jboss.soa.esb.addressing.util.EPRManager;
-import org.jboss.soa.esb.common.Environment;
-import org.jboss.soa.esb.common.ModulePropertyManager;
-import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.listeners.ListenerTagNames;
-import org.jboss.soa.esb.parameters.ParamRepositoryException;
-import org.jboss.soa.esb.parameters.ParamRepositoryFactory;
-import org.jboss.soa.esb.services.registry.Registry;
-import org.jboss.soa.esb.services.registry.RegistryException;
-import org.jboss.soa.esb.services.registry.RegistryFactory;
-import org.jboss.soa.esb.util.Util;
-import org.xml.sax.SAXException;
-
-import com.arjuna.common.util.propertyservice.PropertyManager;
-
-public class GatewayListenerController implements Runnable
-{
- private static Map<String, Long> _paramFileTimeStamps = new ConcurrentHashMap<String, Long>();
-
- private static String _sRldSecs = null;
-
- public static void main (String[] args) throws Exception
- {
- GatewayListenerController oProc = new GatewayListenerController(args[0]);
- oProc.run();
- GatewayListenerController.State oS = oProc.getState();
-
- if (null != oS.getException())
- {
- _logger.error("GatewayListener <" + args[0] + "> FAILED\n", oS
- .getException());
- }
- System.exit(oS.getCompletionCode());
- } // ________________________________
-
- public static final String RELOAD_SECONDS_TAG = "parameterReloadSecs";
-
- public static final String END_TIME_TAG = "endTime";
-
- // Attribute name that denotes listener class to be instantiated in a child
- // thread
- // This attribute is not in the root node but in first level child
- // ConfigTrees
- public static final String GATEWAY_CLASS_TAG = "gatewayClass";
-
- /**
- * Obtain a shallow copy of needed atributes in this object's last loaded
- * parameter tree <p/>The local bject is cloned so child threads can use it
- * as they choose to without interfering with the environment
- * <p />
- * Listener processes controlled by this object should keep a reference to
- * this object at construction time, and not call this method again unless
- * they specifically need updated values. Parameter reload could have
- * happened since last call
- *
- * @return Map - a shallow copy of the attributes Map
- */
- @SuppressWarnings("unchecked")
- public Map<String, Object> getControllerAttributes ()
- {
- return (Map<String, Object>) _attributes.clone();
- }
-
- public State getState ()
- {
- return _status;
- }
-
- public static enum State
- {
- Loading_parameters, Running, Shutting_down, Done_OK, Exception_thrown;
- int m_iCompletionCode = 0;
-
- Exception m_oException = null;
-
- public int getCompletionCode ()
- {
- return m_iCompletionCode;
- };
-
- public Exception getException ()
- {
- return m_oException;
- }
- };
-
- /**
- * Package private default constructor.
- */
- protected GatewayListenerController ()
- {
- }
-
- /**
- * Construct a Listener Manager from the named repository based
- * configuration.
- *
- * @param p_sParameterName
- * Name of the Repository entry containing the configuration.
- * @throws ConfigurationException
- * Unable to load/use the named configuration.
- */
- public GatewayListenerController (String p_sParameterName) throws ConfigurationException, IOException, ParamRepositoryException, SAXException
- {
- this(GatewayListenerController.getListenerConfig(p_sParameterName));
- _sParametersName = p_sParameterName;
- }
-
- /**
- * Construct a Listener Manager using the specified listener configuration.
- *
- * @param config
- * The configuration.
- * @throws ConfigurationException
- * Unable to load/use the supplied configuration.
- */
- public GatewayListenerController (ConfigTree config) throws ConfigurationException
- {
- _config = config;
- _status = State.Loading_parameters;
-
- try
- {
- checkParms(_config);
- }
- catch (ConfigurationException e)
- {
- String configSource = config.getAttribute("configSource");
- _status = State.Exception_thrown;
- _status.m_oException = e;
- _logger
- .fatal(
- "Listener configuration and startup error. Config Source: " + (configSource != null ? configSource : "unknown"),
- e);
- throw e;
- }
- }
-
- /**
- * Load the named listener configuration from the configured parameter
- * repository.
- *
- * @param reposParam
- * The name of the repository entry containing the Listener
- * configuration.
- * @return Listener Configuration as {@link ConfigTree}.
- * @throws IOException
- * Unable to access the repository.
- * @throws ParamRepositoryException
- * Unable to access the configuration in the repository.
- * @throws SAXException
- * Unable to parse the configuration.
- */
- private static ConfigTree getListenerConfig (String reposParam)
- throws IOException, ParamRepositoryException, SAXException
- {
- String sXml = ParamRepositoryFactory.getInstance().get(reposParam);
- ConfigTree config = ConfigTree.fromXml(sXml);
-
- config.setAttribute("configSource", "param-repository:" + reposParam);
-
- return config;
- }
-
- /**
- * Check to see if all needed parameters are there, and assign default
- * values to some of them
- *
- * @param p_oP
- * ConfigTree - Where to look for the mandatory/optional
- * configuration attributes
- * @throws ConfigurationException -
- * If attributes are wrong or not enough for a proper runtime
- * configuration
- */
- public void checkParms (ConfigTree p_oP) throws ConfigurationException
- {
- // We've just loaded - set to false until next reload requested
- _reloadRequested = false;
- if (null != _sParametersName)
- {
- File file = new File(_sParametersName);
- if (file.exists())
- _paramFileTimeStamps.put(_sParametersName, file.lastModified());
- }
-
- try
- {
- _commandQueue = createCommandQueue(p_oP);
-
- // Open the command queue...
- if (null != _commandQueue) _commandQueue.open(p_oP);
-
- setNextReloadTime(p_oP);
- // if END_TIME_TAG not set try to run forever
- // not a good practice if command queue is not set
- // Expected date format is "yyyyMMdd hh:mm:ss"
- String sEndT = p_oP.getAttribute(END_TIME_TAG);
- _endTime = (null == sEndT) ? Long.MAX_VALUE : _dateFormat.parse(sEndT)
- .getTime();
-
- if (null == sEndT)
- {
- String sMsg = (null == _commandQueue) ? " - Listener will run until parent container/process terminates." : " - Listener will run until stopped by command sent to queue.";
- _logger.info("No value specified for: " + END_TIME_TAG + sMsg);
- }
- }
- catch (ParseException ex)
- {
- throw new ConfigurationException(ex);
- }
- catch (CommandQueueException ex)
- {
- throw new ConfigurationException(ex);
- }
- } // ________________________________
-
- private void setNextReloadTime (ConfigTree tree)
- {
- // if RELOAD_SECONDS_TAG not set, and no command queue
- // then reload every 10 minutes
- // If there is a command queue, run until command is received
- _sRldSecs = tree.getAttribute(RELOAD_SECONDS_TAG);
-
- synchronized (_synchReload)
- {
- _nextReload = (null != _sRldSecs) ? System.currentTimeMillis() + 1000 * Long
- .parseLong(_sRldSecs) : (null == _commandQueue) ? Long.MAX_VALUE : System
- .currentTimeMillis() + _defaultReloadMillis;
- }
-
- if (null == _sRldSecs)
- {
- String sMsg = (null == _commandQueue) ? " - Using default of " + _sRldSecs : " - Listener will run until stopped by command sent to queue";
- _logger
- .warn("No value specified for: " + RELOAD_SECONDS_TAG + sMsg);
- }
-
- } // ________________________________
-
- /**
- * Factory method for creating the command queue.
- *
- * @param config
- * GatewayListener config.
- * @return GatewayListener CommandQueue instance.
- */
- private CommandQueue createCommandQueue (ConfigTree config)
- {
- String commandQueueClass = config.getAttribute("command-queue-class");
-
- if (commandQueueClass != null)
- {
- try
- {
- return (CommandQueue) Class.forName(commandQueueClass)
- .newInstance();
- }
- catch (Exception e)
- {
- _logger
- .error(
- "Failed to instantiate CommandQueue [" + commandQueueClass + "]. Defaulting to no Command Queue",
- e);
- }
- }
-
- return _defaultCommandQueue;
- }
-
- /**
- * Allows a default command queue to be set statically for all
- * GatewayListener instances.
- *
- * @param defaultCommandQueue
- * The defaultCommandQueue to set.
- */
- public static void setDefaultCommandQueue (CommandQueue defaultCommandQueue)
- {
- GatewayListenerController._defaultCommandQueue = defaultCommandQueue;
- }
-
- /**
- * Main execution loop <p/> Will continue to run until either <p/>a) run
- * time is expired <p/>b) quiesce command is received in command queue
- * <p/>For every child element that contains a PARM_LISTENER_CLASS
- * attribute, this method will try to launch a child thread instantiating an
- * object of that class, and will call it's run() method <p/>Once all child
- * processes are trigered, the main thread will either <p/>1) wait for a
- * message in the command queue (if one was configured) until next reload or
- * end of run period expired <p/>or 2) Just sleep if there's no command
- * queue to listen on
- */
- public void run ()
- {
- boolean relaunch = true;
- while (endNotRequested())
- {
- _status = State.Running;
-
- if (relaunch) for (ConfigTree oCurr : _config.getAllChildren())
- tryToLaunchGateway(oCurr);
-
- waitForCmdOrSleep();
-
- if (endRequested())
- {
- break;
- }
-
- relaunch = false;
- if (isReloadNeeded())
- try
- {
- if (_sParametersName != null)
- {
- _status = State.Loading_parameters;
- _logger
- .info("Reloading parameters _____________________________________________________");
- ConfigTree oNew = GatewayListenerController
- .getListenerConfig(_sParametersName);
- checkParms(oNew);
- _config = oNew;
- relaunch = true;
- }
- else
- checkParms(_config);
- }
- catch (Exception e)
- {
- _logger
- .error(
- "Failed to reload parameters" + " - Continuing with cached version",
- e);
- }
- }
- // _status = State.Shutting_down;
-
- _status = State.Done_OK;
- _status.m_iCompletionCode = 0;
- _logger
- .info("Finishing_____________________________________________________");
-
- // Close the command queue...
- try
- {
- if (null != _commandQueue) _commandQueue.close();
- }
- catch (CommandQueueException e)
- {
- _logger.error("Error closing Command Queue.", e);
- }
- } // ________________________________
-
- private void tryToLaunchGateway (ConfigTree p_oP)
- {
- String sClass = p_oP.getAttribute(GATEWAY_CLASS_TAG);
- if (Util.isNullString(sClass)) return;
-
- try
- {
- Class oListener = Class.forName(sClass);
- Constructor oConst = oListener.getConstructor(new Class[] { this
- .getClass(), ConfigTree.class });
- Runnable oRun = (Runnable) oConst
- .newInstance(new Object[] { this, p_oP });
- new Thread(oRun).start();
- }
- catch (Exception e)
- {
- _logger.error("Cannot launch <" + sClass + ">\n", e);
- e.printStackTrace();
- }
- } // ________________________________
-
- long millisToWait ()
- {
- synchronized (_synchReload)
- {
- return Math.min(_nextReload, _endTime) - System.currentTimeMillis();
- }
- } // ________________________________
-
- private void waitForCmdOrSleep ()
- {
-
- long lToGo = millisToWait();
-
- if (null == _commandQueue)
- {
- _logger.debug("About to sleep " + lToGo);
- // No command queue nor topic - Just sleep until time
- // exhausted, or thread interrupted
- try
- {
- while ((lToGo = millisToWait()) > 0)
- Thread.sleep(500);
- }
- catch (InterruptedException e)
- {
- _endTime = 0; // mark as end requested and return
- }
- return;
- }
- // Wait for commands until time exhausted or command received
- // Note that received commands might change time variables (reload/end)
- // that's why time to go is recalculated on each cycle
- while ((lToGo = millisToWait()) > 0)
- {
- try
- {
- _logger
- .info("Waiting for command ... timeout=" + lToGo + " millis");
-
- String oM = _commandQueue.receiveCommand(lToGo);
- if (null == oM)
- {
- return;
- }
- processCommand(oM);
- if (endRequested() || isReloadNeeded())
- {
- break;
- }
- }
- catch (CommandQueueException eJ)
- {
- _logger.info("receive on command queue failed", eJ);
- }
- }
- } // ________________________________
-
- /**
- * Processes the command that has been received in the command queue (or
- * topic) <p/>_endRequested, _reloadRequested, and _endTime could be changed
- *
- * <p/> <p/><TABLE border="1"> <COLGROUP> <COL width="200"/> <COL
- * width="400"/> </COLGROUP>
- * <TR>
- * <TD align="center">message text</TD>
- * <TD align="center">effect</TD>
- * </TR>
- * <TR>
- * <TD>shutdown*</TD>
- * <TD>End time will be immediately set to 'now' - quiesce process will
- * start - Child threads will be allowed to finish normally</TD>
- * </TR>
- * <TR>
- * <TD>reload param*</TD>
- * <TD>Parameters will be immediately reloaded, and listener reconfigured
- * with new values</TD>
- * </TR>
- * <TR>
- * <TD>endTime yyyyMMdd hh:mm:ss</TD>
- * <TD>End time will be set to new value. If hh:mm:ss is not supplied =>
- * end of day assumed (23:59:59)</TD>
- * </TR>
- * </TABLE> * startsWith() <p/>
- *
- * @param p_oMsg
- * Message received from the command queue.
- *
- */
- private void processCommand (String sTxt)
- {
- if (null == sTxt) return;
-
- String sLow = sTxt.trim().toLowerCase();
- if (sLow.startsWith("shutdown"))
- {
- _endRequested = true;
- _logger.info("Shutdown has been requested");
- return;
- }
- if (sLow.startsWith("reload param"))
- {
- _reloadRequested = true;
- _logger.info("Request for parameter reload has been received");
- return;
- }
- String[] sa = sLow.split("\\s+");
- if (sa.length > 1 && "endtime".equals(sa[0]))
- {
- try
- {
- String sDate = sa[1];
- String sTime = (sa.length < 3 || null == sa[2]) ? "23:59:59" : sa[2];
- Date oEnd = _dateFormat.parse(sDate + " " + sTime);
- _logger.info("New end date set to : " + oEnd);
- _endTime = oEnd.getTime();
- }
- catch (Exception eDat)
- {
- _logger.info("Problems with endTime command", eDat);
- }
- }
- } // ________________________________
-
- /**
- * Accessor to determine if execution time is expired or shutdown requested
- *
- * @return boolean if processing has to stop (all child threads will be
- * allowed to finish)
- */
- public boolean endRequested ()
- {
- return _endRequested || System.currentTimeMillis() >= _endTime;
- }
-
- public void requestEnd ()
- {
- _endRequested = true;
- _endTime = 0;
- }
-
- /**
- * Accessor to determine if execution time is not expired, and no shutdown
- * request received
- *
- * @return boolean - true if run time has not expired and quiesce has not
- * been requested
- */
- public boolean endNotRequested ()
- {
- return !endRequested();
- }
-
- /**
- * Provide a common accessor to determine if parameters have to be reloaded
- * <p/> For child threads this means thread execution has to end
- * </p>
- * Child processes should only call this method when they are idle (as
- * opposed to in the middle of executing a unit of work)
- *
- * @return boolean - true if it's time to reload parameters
- */
- private boolean isReloadNeeded ()
- {
- // command to reload was received - force reload
- if (_reloadRequested) return refreshNextReload();
-
- // Still not time to reload
- if (System.currentTimeMillis() < _nextReload) return false;
-
- if (null == _sParametersName) return refreshNextReload();
-
- File paramFile = new File(_sParametersName);
- if (!paramFile.exists()) return refreshNextReload();
-
- // check the TS on the file.
- Long previousTimeStamp = _paramFileTimeStamps.get(_sParametersName);
- if (null == previousTimeStamp) return refreshNextReload();
-
- Long currentTimeStamp = paramFile.lastModified();
- if (!previousTimeStamp.equals(currentTimeStamp))
- return refreshNextReload();
-
- setNextReloadTime(_config);
- return false;
- }
-
- private boolean refreshNextReload ()
- {
- setNextReloadTime(_config);
- return true;
- }
-
- /**
- * Helper accessor for child processes that provides info to determine if
- * they can continue with yet another execution cycle
- *
- * @return boolean - true if runtime is not expired and not time yet to
- * reload parameters
- */
- public boolean continueLooping ()
- {
- return (endNotRequested() && !isReloadNeeded());
- } // ________________________________
-
- /**
- * Find an attribute in the tree (arg 0) or assign default value (arg 2)
- *
- * @param p_oP
- * ConfigTree - look for attributes in this Element only
- * @param p_sAtt
- * String - Name of attribute to find
- * @param p_sDefault
- * String -default value if requested attribute is not there
- * @return String - value of attribute, or default value (if null)
- * @throws ConfigurationException -
- * If requested attribute not found and no default value
- * supplied by invoker
- */
- public String obtainAtt (ConfigTree p_oP, String p_sAtt, String p_sDefault)
- throws ConfigurationException
- {
- String sVal = p_oP.getAttribute(p_sAtt);
- if ((null == sVal) && (null == p_sDefault))
- throw new ConfigurationException(
- "Missing or invalid <" + p_sAtt + "> attribute");
-
- return (null != sVal) ? sVal : p_sDefault;
- } // ________________________________
-
- private static EPRManager getEprManager ()
- {
- PropertyManager manager = ModulePropertyManager
- .getPropertyManager(ModulePropertyManager.CORE_MODULE);
- String sDir = manager.getProperty(Environment.REGISTRY_FILE_HELPER_DIR,
- ".");
- return EPRManager.getInstance(sDir);
- }
-
- public Collection<EPR> getEprs (String category, String name)
- throws RegistryException
- {
- if ("eprManager".equals(category))
- {
- Collection<EPR> ret = new ArrayList<EPR>();
- try
- {
- ret.add(getEprManager().loadEPR(name));
- return ret;
- }
- catch (IOException e)
- {
- throw new RegistryException(
- "No EPRs found for <" + category + "><" + name + ">");
- }
- }
-
- Registry reg = RegistryFactory.getRegistry();
- RegistryException eReg = null;
- for (int i1 = 0; i1 < 5; i1++)
- {
- try
- {
- return reg.findEPRs(category, name);
- }
- catch (RegistryException e)
- {
- if (null == eReg) eReg = e;
- try
- {
- Thread.sleep(500);
- }
- catch (InterruptedException eInt)
- {
- break;
- }
- }
- }
- throw eReg;
- }
-
- /**
- * @deprecated use register (ConfigTree config, EPR address) instead.
- * @param name
- * @param address
- */
- public void register (String name, EPR address)
- {
- try
- {
- getEprManager().saveEPR(name, address);
- }
- catch (IOException e)
- {
- _logger.fatal("Cannot register service", e);
- }
- } // ________________________________
-
- /**
- * @deprecated use unRegister (String serviceCategoryName, String
- * serviceName, EPR epr) instead.
- * @param name
- */
- public void unRegister (String name)
- {
- try
- {
- getEprManager().removeEPR(name);
- }
- catch (IOException e)
- {
- _logger.fatal("Cannot un-register service", e);
- }
- } // ________________________________
-
- /**
- * Register an EPR in the registry.
- *
- * @param config -
- * a config tree containing the deployment-configuration of the
- * service.
- * @param epr -
- * the epr (EndPoint Reference) of the service.
- *
- * @throws RegistryException
- */
- public void register (ConfigTree config, EPR epr) throws RegistryException
- {
- String serviceCategoryName = config
- .getAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG);
- String serviceName = config
- .getAttribute(ListenerTagNames.SERVICE_NAME_TAG);
- if ("eprManager".equalsIgnoreCase(serviceCategoryName))
- {
- register(serviceName, epr);
- return;
- }
- String serviceDescription = config
- .getAttribute(ListenerTagNames.SERVICE_DESCRIPTION_TAG);
- String eprDescription = config
- .getAttribute(ListenerTagNames.EPR_DESCRIPTION_TAG);
- Registry registry = RegistryFactory.getRegistry();
- registry.registerEPR(serviceCategoryName, serviceName,
- serviceDescription, epr, eprDescription);
- }
-
- /**
- * Unregister the EPR from the registry.
- *
- * @param serviceCategoryName -
- * name of the category of the service ('Content Based Routing')
- * @param serviceName -
- * name of the service ("
- * @param epr
- * @throws RegistryException
- */
- public void unRegister (String serviceCategoryName, String serviceName,
- EPR epr) throws RegistryException
- {
- if ("eprManager".equalsIgnoreCase(serviceCategoryName))
- {
- unRegister(serviceName);
- return;
- }
- Registry registry = RegistryFactory.getRegistry();
- registry.unRegisterEPR(serviceCategoryName, serviceName, epr);
- }
-
- private CommandQueue _commandQueue;
-
- private static CommandQueue _defaultCommandQueue = null;
-
- private static Logger _logger = Logger
- .getLogger(GatewayListenerController.class);
-
- private String _sParametersName;
-
- private ConfigTree _config;
-
- private boolean _reloadRequested;
-
- private boolean _endRequested;
-
- private long _nextReload = Long.MAX_VALUE;
-
- private long _endTime = Long.MAX_VALUE;
-
- protected int _defaultReloadMillis = 180000; // default interval between
-
- // parameter reloads
-
- public static final SimpleDateFormat _dateFormat = new SimpleDateFormat(
- "yyyyMMdd hh:mm:ss");
-
- private State _status = null;
-
- private Object _synchReload = new Short((short) 0);
-
- private HashMap<String, Object> _attributes;
-} // ____________________________________________________________________________
Deleted: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerControllerService.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerControllerService.java 2007-01-30 06:44:10 UTC (rev 9118)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerControllerService.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -1,75 +0,0 @@
-/*
- * 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.listeners.gateway;
-
-import java.net.URI;
-
-import org.apache.log4j.Logger;
-import org.jboss.system.ServiceMBeanSupport;
-/**
- * Service to manage the gateways when deployed to the appserver.
- *
- * @author Kurt Stam
- *
- */
-public class GatewayListenerControllerService extends ServiceMBeanSupport implements GatewayListenerControllerServiceMBean
-{
- private GatewayListenerController gatewayListController;
- private Logger logger = Logger.getLogger(this.getClass());
- private String gatewayConfigFile="jbossesb-gateway.xml";
- /**
- * Starts the gateways.
- */
- protected void startService() throws Exception
- {
- logger.info("starting message aware listener with config file " + gatewayConfigFile);
- String confDir = System.getProperty("jboss.server.config.url");
- URI uri = new URI(confDir);
- confDir = uri.getPath();
- String configFile = confDir + gatewayConfigFile;
- System.setProperty("juddi.propertiesFile", confDir + "juddi.properties");
- gatewayListController = new GatewayListenerController(configFile);
- new Thread(gatewayListController).start();
- }
- /**
- * Stops the gateways.
- */
- protected void stopService() throws Exception
- {
- logger.info("shutting down message aware listener...");
- gatewayListController.requestEnd();
- }
- /**
- * Gets the gateway config file. This can be set in the jboss-service.xml.
- */
- public String getGatewayConfigFile() {
- return gatewayConfigFile;
- }
- /**
- * Sets the gateway config file.
- */
- public void setGatewayConfigFile(String gatewayConfigFile) {
- this.gatewayConfigFile = gatewayConfigFile;
- }
-
-
-}
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java 2007-01-30 06:44:10 UTC (rev 9118)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -52,37 +52,97 @@
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.helpers.NamingContext;
import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.listeners.ListenerUtil;
+import org.jboss.soa.esb.listeners.RegistryUtil;
+import org.jboss.soa.esb.listeners.lifecycle.AbstractThreadedManagedLifecycle;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleThreadState;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.format.MessageFactory;
import org.jboss.soa.esb.services.registry.RegistryException;
-public class JmsGatewayListener implements Runnable
+public class JmsGatewayListener extends AbstractThreadedManagedLifecycle
{
- public JmsGatewayListener (GatewayListenerController commandListener,
- ConfigTree listenerConfig) throws ConfigurationException
+ /**
+ * serial version uid for this class
+ */
+ private static final long serialVersionUID = 5070422864110923930L;
+
+ public JmsGatewayListener (ConfigTree listenerConfig) throws ConfigurationException
{
- _config = listenerConfig;
- _controller = commandListener;
- _sleepForRetries = 3000; // milliseconds TODO magic number
- checkMyParms();
+ super(listenerConfig) ;
+ _config = listenerConfig;
+ _sleepForRetries = 3000; // milliseconds TODO magic number
+ checkMyParms();
} // __________________________________
- public void run ()
- {
- _logger
- .debug("run() method of " + this.getClass().getSimpleName() + " started on thread " + Thread
- .currentThread().getName());
- if (null != _serviceName) try
- {
- _controller.register(_config, _myEpr);
- }
- catch (RegistryException e1)
- {
- _logger.warn("unable to register service", e1);
- }
+
+ /**
+ * Handle the initialisation of the managed instance.
+ *
+ * @throws ManagedLifecycleException for errors while initialisation.
+ */
+ protected void doInitialise()
+ throws ManagedLifecycleException
+ {
+ try
+ {
+ _targetEprs = RegistryUtil.getEprs(_targetServiceCategory,_targetServiceName);
+ if (null == _targetEprs || _targetEprs.size() < 1)
+ throw new ManagedLifecycleException("EPR <" + _targetServiceName + "> not found in registry") ;
+ }
+ catch (final RegistryException re)
+ {
+ throw new ManagedLifecycleException("Unexpected registry exception", re) ;
+ }
+
+ if (_serviceName != null)
+ {
+ try
+ {
+ RegistryUtil.register(_config, _myEpr);
+ }
+ catch (final RegistryException re)
+ {
+ throw new ManagedLifecycleException("Unexpected error during registration for epr " + _myEpr, re);
+ }
+ }
+
+ try
+ {
+ prepareMessageReceiver();
+ }
+ catch (final JMSException jmse)
+ {
+ if (_serviceName != null)
+ {
+ RegistryUtil.unregister(_serviceCategory, _serviceName, _myEpr) ;
+ }
+ throw new ManagedLifecycleException("Unexpected JMS error from prepareMessageReceiver", jmse);
+ }
+ catch (final ConfigurationException ce)
+ {
+ if (_serviceName != null)
+ {
+ RegistryUtil.unregister(_serviceCategory, _serviceName, _myEpr) ;
+ }
+ throw new ManagedLifecycleException("Unexpected configuration exception from prepareMessageReceiver", ce);
+ }
+ }
+
+ /**
+ * Execute on the thread.
+ */
+ protected void doRun()
+ {
+ if (_logger.isDebugEnabled())
+ {
+ _logger.debug("run() method of " + this.getClass().getSimpleName() +
+ " started on thread " + Thread.currentThread().getName());
+ }
- while (_controller.continueLooping())
+ while (isRunning())
{
javax.jms.Message msgIn = receiveOne();
if (null != msgIn)
@@ -150,41 +210,52 @@
}
}
- if (null != _serviceName) try
- {
- _controller.unRegister(_serviceCategory, _serviceName, _myEpr);
- }
- catch (RegistryException e1)
- {
- _logger.warn("unable to unRegister service", e1);
- }
-
- if (null != _messageReceiver) try
- {
- _messageReceiver.close();
- }
- catch (Exception e1)
- {/* Tried my best - Just continue */
- }
- if (null != _queueSession) try
- {
- _queueSession.close();
- }
- catch (Exception e1)
- {/* Tried my best - Just continue */
- }
- if (null != _queueConnection) try
- {
- _queueConnection.close();
- }
- catch (Exception e2)
- {/* Tried my best - Just continue */
- }
_logger
.debug("run() method of " + this.getClass().getSimpleName() + " finished on thread " + Thread
.currentThread().getName());
} // ________________________________
+ /**
+ * Handle the destroy of the managed instance.
+ *
+ * @throws ManagedLifecycleException for errors while destroying.
+ */
+ protected void doDestroy()
+ throws ManagedLifecycleException
+ {
+ if (_messageReceiver != null)
+ {
+ try
+ {
+ _messageReceiver.close();
+ }
+ catch (final JMSException jmse) {} // ignore
+ }
+
+ if (_queueSession != null)
+ {
+ try
+ {
+ _queueSession.close();
+ }
+ catch (final JMSException jmse) {} // ignore
+ }
+
+ if (_queueConnection != null)
+ {
+ try
+ {
+ _queueConnection.close();
+ }
+ catch (final JMSException jmse) {} // ignore
+ }
+
+ if (_serviceName != null)
+ {
+ RegistryUtil.unregister(_serviceCategory, _serviceName, _myEpr) ;
+ }
+ }
+
/**
* Check for mandatory and optional attributes in parameter tree
*
@@ -194,44 +265,22 @@
*/
protected void checkMyParms () throws ConfigurationException
{
- try
- {
- // Third arg is null - Exception will be thrown if attribute is not
- // found
- _targetServiceCategory = _controller.obtainAtt(_config,
- ListenerTagNames.TARGET_SERVICE_CATEGORY_TAG, null);
- _targetServiceName = _controller.obtainAtt(_config,
- ListenerTagNames.TARGET_SERVICE_NAME_TAG, null);
- _targetEprs = _controller.getEprs(_targetServiceCategory,
- _targetServiceName);
- if (null == _targetEprs || _targetEprs.size() < 1)
- throw new ConfigurationException(
- "EPR <" + _targetServiceName + "> not found in registry");
-
- _queueName = _controller.obtainAtt(_config,
- JMSEpr.DESTINATION_NAME_TAG, null);
-
- resolveComposerClass();
-
- // No problem if selector is null - everything in queue will be returned
- _messageSelector = _config.getAttribute(JMSEpr.MESSAGE_SELECTOR_TAG);
- _logger
- .debug("No value specified for: " + JMSEpr.MESSAGE_SELECTOR_TAG + " - All messages in queue will be received by this listener");
-
- prepareMessageReceiver();
- }
- catch (JMSException ex)
- {
- _logger.warn("Received underlying JMS exception from prepareMessageReceiver.", ex);
-
- throw new ConfigurationException(ex);
- }
- catch (RegistryException ex)
- {
- _logger.warn("Problem with registry.", ex);
-
- throw new ConfigurationException(ex);
- }
+ // Third arg is null - Exception will be thrown if attribute is not
+ // found
+ _targetServiceCategory = ListenerUtil.obtainAtt(_config,
+ ListenerTagNames.TARGET_SERVICE_CATEGORY_TAG, null);
+ _targetServiceName = ListenerUtil.obtainAtt(_config,
+ ListenerTagNames.TARGET_SERVICE_NAME_TAG, null);
+
+ _queueName = ListenerUtil.obtainAtt(_config,
+ JMSEpr.DESTINATION_NAME_TAG, null);
+
+ resolveComposerClass();
+
+ // No problem if selector is null - everything in queue will be returned
+ _messageSelector = _config.getAttribute(JMSEpr.MESSAGE_SELECTOR_TAG);
+ _logger
+ .debug("No value specified for: " + JMSEpr.MESSAGE_SELECTOR_TAG + " - All messages in queue will be received by this listener");
} // ________________________________
protected void resolveComposerClass () throws ConfigurationException
@@ -273,18 +322,18 @@
_queueSession = null;
_queue = null;
- String sJndiURL = _controller.obtainAtt(_config, JMSEpr.JNDI_URL_TAG,
+ String sJndiURL = ListenerUtil.obtainAtt(_config, JMSEpr.JNDI_URL_TAG,
NamingContext.JBOSS_PROVIDER_URL);
if (null == _config.getAttribute(JMSEpr.JNDI_URL_TAG))
_logger
.debug("No value specified for " + JMSEpr.JNDI_URL_TAG + " attribute" + " - Using default of: '" + sJndiURL + "'");
- String sJndiContextFactory = _controller.obtainAtt(_config,
+ String sJndiContextFactory = ListenerUtil.obtainAtt(_config,
JMSEpr.JNDI_CONTEXT_FACTORY_TAG,
NamingContext.JBOSS_INITIAL_CONTEXT_FACTORY);
if (null == _config.getAttribute(JMSEpr.JNDI_CONTEXT_FACTORY_TAG))
_logger
.debug("No value specified for " + JMSEpr.JNDI_CONTEXT_FACTORY_TAG + " attribute" + " - Using default of: '" + sJndiContextFactory + "'");
- String sJndiPkgPrefix = _controller.obtainAtt(_config,
+ String sJndiPkgPrefix = ListenerUtil.obtainAtt(_config,
JMSEpr.JNDI_PKG_PREFIX_TAG, NamingContext.JBOSS_PROVIDER_URL);
if (null == _config.getAttribute(JMSEpr.JNDI_PKG_PREFIX_TAG))
_logger
@@ -295,7 +344,7 @@
throw new ConfigurationException(
"Unable fo obtain jndi context <" + sJndiURL + "," + sJndiContextFactory + "," + sJndiPkgPrefix + ">");
- String sFactClass = _controller.obtainAtt(_config,
+ String sFactClass = ListenerUtil.obtainAtt(_config,
JMSEpr.CONNECTION_FACTORY_TAG, "ConnectionFactory");
if (null == _config.getAttribute(JMSEpr.CONNECTION_FACTORY_TAG))
_logger
@@ -345,29 +394,15 @@
*/
protected javax.jms.Message receiveOne ()
{
- while (_controller.continueLooping())
+ while (isRunning())
try
{
- long lWait = _controller.millisToWait();
- if (lWait < 1) return null;
- javax.jms.Message ret = _messageReceiver.receive(Math.min(
- lWait, 100));
+ javax.jms.Message ret = _messageReceiver.receive(200);
if (null != ret) return ret;
- try
- {
- Thread.sleep(100);
- }
- catch (InterruptedException e)
- {
- break;
- }
}
catch (JMSException oJ)
{
- _logger
- .error(
- "JMS error on receive. Attempting JMS Destination reconnect.",
- oJ);
+ _logger.error("JMS error on receive. Attempting JMS Destination reconnect.",oJ);
try
{
prepareMessageReceiver();
@@ -376,16 +411,7 @@
catch (Exception e)
{
_logger.error("Reconnecting to Queue", e);
- try
- {
- Thread.sleep(_sleepForRetries);
- }
- catch (InterruptedException e1)
- { // Just return
- _logger.error("Unexpected thread interupt exception.",
- e);
- return null;
- }
+ waitForRunningStateChange(ManagedLifecycleThreadState.STOPPING, _sleepForRetries) ;
}
}
return null;
@@ -471,8 +497,6 @@
protected ConfigTree _config;
- protected GatewayListenerController _controller;
-
protected final long _sleepForRetries; // milliseconds
protected String _serviceCategory, _serviceName;
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener.java 2007-01-30 06:44:10 UTC (rev 9118)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -41,17 +41,18 @@
public class RemoteGatewayListener extends FileGatewayListener
{
- protected RemoteGatewayListener(){}
-
- public RemoteGatewayListener(GatewayListenerController commandListener,
- ConfigTree config) throws ConfigurationException, RegistryException, GatewayException {
- super(commandListener, config);
+ /**
+ * serial version uid for this class
+ */
+ private static final long serialVersionUID = 8505559166811233906L;
+
+ public RemoteGatewayListener(ConfigTree config) throws ConfigurationException, RegistryException, GatewayException {
+ super(config);
+ checkMyParms() ;
}
- protected void checkMyParms() throws ConfigurationException, RegistryException, GatewayException
+ private void checkMyParms() throws ConfigurationException, RegistryException, GatewayException
{
- super.checkMyParms();
-
try
{
File temp = File.createTempFile("FTPdown", ".tmp");
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListener.java 2007-01-30 06:44:10 UTC (rev 9118)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListener.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -28,6 +28,7 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -51,6 +52,11 @@
import org.jboss.soa.esb.helpers.persist.JdbcCleanConn;
import org.jboss.soa.esb.helpers.persist.SimpleDataSource;
import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.listeners.ListenerUtil;
+import org.jboss.soa.esb.listeners.RegistryUtil;
+import org.jboss.soa.esb.listeners.lifecycle.AbstractThreadedManagedLifecycle;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleThreadState;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.format.MessageFactory;
import org.jboss.soa.esb.services.registry.RegistryException;
@@ -74,64 +80,80 @@
* @since Version 4.0
*
*/
-public class SqlTableGatewayListener implements Runnable
+public class SqlTableGatewayListener extends AbstractThreadedManagedLifecycle
{
- public SqlTableGatewayListener (GatewayListenerController commandListener,
- ConfigTree config) throws ConfigurationException
+ /**
+ * serial version uid for this class
+ */
+ private static final long serialVersionUID = -4394272471377134121L;
+
+ public SqlTableGatewayListener(ConfigTree config)
+ throws ConfigurationException
{
- _config = config;
- _controller = commandListener;
- _sleepBetweenPolls = 10000; // milliseconds TODO magic number
- checkMyParms();
+ super(config) ;
+ _config = config;
+ _sleepBetweenPolls = 10000; // milliseconds TODO magic number
+ checkMyParms();
} // __________________________________
+
+ /**
+ * Handle the initialisation of the managed instance.
+ *
+ * @throws ManagedLifecycleException for errors while initialisation.
+ */
+ protected void doInitialise()
+ throws ManagedLifecycleException
+ {
+ try
+ {
+ _targetEprs = RegistryUtil.getEprs(_targetServiceCategory,_targetServiceName);
+ if (null == _targetEprs || _targetEprs.size() < 1)
+ throw new ManagedLifecycleException("EPR <" + _targetServiceName + "> not found in registry") ;
+ }
+ catch (final RegistryException re)
+ {
+ throw new ManagedLifecycleException("Unexpected registry exception", re) ;
+ }
+
+ if (_serviceName != null)
+ {
+ try
+ {
+ RegistryUtil.register(_config, _myEpr);
+ }
+ catch (final RegistryException re)
+ {
+ throw new ManagedLifecycleException("Unexpected error during registration for epr " + _myEpr, re);
+ }
+ }
+ try
+ {
+ prepareStatements();
+ }
+ catch (final SQLException sqle)
+ {
+ if (_serviceName != null)
+ {
+ RegistryUtil.unregister(_serviceCategory, _serviceName, _myEpr) ;
+ }
+ throw new ManagedLifecycleException("Unexpected error initialising statements", sqle);
+ }
+ }
- public void run ()
- {
- _logger
- .debug("run() method of " + this.getClass().getSimpleName() + " started on thread " + Thread
- .currentThread().getName());
+ /**
+ * Execute on the thread.
+ */
+ protected void doRun()
+ {
+ if (_logger.isDebugEnabled())
+ {
+ _logger.debug("doRun() method of " + this.getClass().getSimpleName() +
+ " started on thread " + Thread.currentThread().getName());
+ }
- if (null != _serviceName)
+ do
{
- try
- {
- _controller.register(_config, _myEpr);
- }
- catch (RegistryException e1)
- {
- _logger.warn("unable to register service", e1);
- }
- }
-
- boolean bSleep = false;
-
- while (_controller.continueLooping())
- {
- // only sleep in between - not the first time
- if (bSleep)
- {
- long lUntil = System.currentTimeMillis() + _sleepBetweenPolls;
- while (System.currentTimeMillis() < lUntil)
- {
- try
- {
- // TODO magic number
-
- Thread.sleep(1000);
- }
- catch (InterruptedException e)
- {
- lUntil = 0;
- }
- if (!_controller.continueLooping()) break;
- }
- }
- else
- bSleep = true;
-
- if (!_controller.continueLooping()) break;
-
for (Map<String, Object> row : pollForCandidates())
{
_currentRow = row;
@@ -220,25 +242,33 @@
}
}
}
+ while (!waitForRunningStateChange(ManagedLifecycleThreadState.STOPPING, _sleepBetweenPolls)) ;
- if (null != _serviceName)
- {
- try
- {
- _controller.unRegister(_serviceCategory, _serviceName, _myEpr);
- }
- catch (RegistryException e1)
- {
- _logger.warn("unable to unRegister service", e1);
- }
- }
-
- if (null != _dbConn) _dbConn.release();
- _logger
- .debug("run() method of " + this.getClass().getSimpleName() + " finished on thread " + Thread
- .currentThread().getName());
+ if (_logger.isDebugEnabled())
+ {
+ _logger.debug("run() method of " + this.getClass().getSimpleName() +
+ " finished on thread " + Thread.currentThread().getName());
+ }
} // ________________________________
+ /**
+ * Handle the destroy of the managed instance.
+ *
+ * @throws ManagedLifecycleException for errors while destroying.
+ */
+ protected void doDestroy()
+ throws ManagedLifecycleException
+ {
+ if (_dbConn != null)
+ {
+ _dbConn.release();
+ }
+ if (_serviceName != null)
+ {
+ RegistryUtil.unregister(_serviceCategory, _serviceName, _myEpr) ;
+ }
+ }
+
/**
* Check for mandatory and optional attributes in parameter tree
*
@@ -246,151 +276,127 @@
* if mandatory atts are not right or actionClass not in
* classpath
*/
- protected void checkMyParms () throws ConfigurationException
+ private void checkMyParms () throws ConfigurationException
{
- try
+ // Third arg is null - Exception will be thrown if attribute is not
+ // found
+ _targetServiceCategory = ListenerUtil.obtainAtt(_config,
+ ListenerTagNames.TARGET_SERVICE_CATEGORY_TAG, null);
+ _targetServiceName = ListenerUtil.obtainAtt(_config,
+ ListenerTagNames.TARGET_SERVICE_NAME_TAG, null);
+
+ // Polling interval
+ String sAux = _config
+ .getAttribute(ListenerTagNames.POLL_LATENCY_SECS_TAG);
+
+ if (!Util.isNullString(sAux))
{
- // Third arg is null - Exception will be thrown if attribute is not
- // found
- _targetServiceCategory = _controller.obtainAtt(_config,
- ListenerTagNames.TARGET_SERVICE_CATEGORY_TAG, null);
- _targetServiceName = _controller.obtainAtt(_config,
- ListenerTagNames.TARGET_SERVICE_NAME_TAG, null);
- _targetEprs = _controller.getEprs(_targetServiceCategory,
- _targetServiceName);
- if (null == _targetEprs || _targetEprs.size() < 1)
- throw new ConfigurationException(
- "EPR <" + _targetServiceName + "> not found in registry");
-
- // Polling interval
- String sAux = _config
- .getAttribute(ListenerTagNames.POLL_LATENCY_SECS_TAG);
-
- if (!Util.isNullString(sAux))
+ try
{
- try
- {
- _sleepBetweenPolls = 1000 * Long.parseLong(sAux);
- }
- catch (NumberFormatException e)
- {
- _logger
- .warn("Invalid poll latency - keeping default of " + (_sleepBetweenPolls / 1000));
- }
+ _sleepBetweenPolls = 1000 * Long.parseLong(sAux);
}
- else
+ catch (NumberFormatException e)
{
_logger
- .warn("No value specified for: " + ListenerTagNames.POLL_LATENCY_SECS_TAG + " - Using default of " + (_sleepBetweenPolls / 1000));
+ .warn("Invalid poll latency - keeping default of " + (_sleepBetweenPolls / 1000));
}
-
- resolveComposerClass();
-
- _driver = _controller.obtainAtt(_config, JDBCEpr.DRIVER_TAG, null);
- _url = _controller.obtainAtt(_config, JDBCEpr.URL_TAG, null);
- _user = _controller.obtainAtt(_config, JDBCEpr.USERNAME_TAG, null);
- _password = _controller.obtainAtt(_config, JDBCEpr.PASSWORD_TAG, "");
-
- _tableName = _config.getAttribute(ListenerTagNames.SQL_TABLE_NAME_TAG);
- if (null == _tableName)
- _tableName = _config.getRequiredAttribute(JDBCEpr.TABLE_NAME_TAG);
- if (Util.isNullString(_tableName))
- throw new ConfigurationException("Empty or invalid table name");
-
- _selectFields = _controller.obtainAtt(_config,
- ListenerTagNames.SQL_SELECT_FIELDS_TAG, "*");
- if (Util.isNullString(_selectFields))
- throw new ConfigurationException(
- "Empty or invalid list of select fields");
- _keyFields = _config.getAttribute(ListenerTagNames.SQL_KEY_FIELDS_TAG);
- if (null == _keyFields)
- _keyFields = _config.getRequiredAttribute(JDBCEpr.MESSAGE_ID_COLUMN_TAG);
- if (Util.isNullString(_keyFields))
- throw new ConfigurationException(
- "Empty or invalid list of key fields");
- _inProcessField = _config
- .getAttribute(ListenerTagNames.SQL_IN_PROCESS_FIELD_TAG);
- if (null == _inProcessField)
- _inProcessField = _config.getAttribute(JDBCEpr.STATUS_COLUMN_TAG);
- if (Util.isNullString(_inProcessField))
- throw new ConfigurationException(
- "A valid inProcessField attribute must be specified");
-
- _where = _controller.obtainAtt(_config,
- ListenerTagNames.SQL_WHERE_CONDITION_TAG, "");
- if (_where.trim().length() < 1)
- _logger
- .debug("No value specified for: " + ListenerTagNames.SQL_WHERE_CONDITION_TAG);
- _orderBy = _controller.obtainAtt(_config,
- ListenerTagNames.SQL_ORDER_BY_TAG, "");
- if (_orderBy.trim().length() < 1)
- _logger
- .debug("No value specified for: " + ListenerTagNames.SQL_ORDER_BY_TAG);
- _inProcessVals = _controller.obtainAtt(_config,
- ListenerTagNames.SQL_IN_PROCESS_VALUES_TAG,
- DEFAULT_IN_PROCESS_STATES);
-
- _deleteAfterOK = Boolean.parseBoolean(_controller.obtainAtt(_config,
- ListenerTagNames.SQL_POST_DEL_TAG, "false"));
- if (null == _config.getAttribute(ListenerTagNames.SQL_POST_DEL_TAG))
- _logger
- .debug("No value specified for: " + ListenerTagNames.SQL_POST_DEL_TAG + " - trigger row will not be deleted - 'in process field' will be used to show processing status");
-
- if (_inProcessVals.length() < 4)
- throw new ConfigurationException(
- "Parameter <" + ListenerTagNames.SQL_IN_PROCESS_VALUES_TAG + "> must be at least 4 characters long (PWED)");
-
- _columns = _selectFields.split(",");
- if (_columns.length < 1)
- throw new ConfigurationException("Empty list of select fields");
-
- _keys = _keyFields.split(",");
- if (!"*".equals(_selectFields))
+ }
+ else
+ {
+ _logger
+ .warn("No value specified for: " + ListenerTagNames.POLL_LATENCY_SECS_TAG + " - Using default of " + (_sleepBetweenPolls / 1000));
+ }
+
+ resolveComposerClass();
+
+ _driver = ListenerUtil.obtainAtt(_config, JDBCEpr.DRIVER_TAG, null);
+ _url = ListenerUtil.obtainAtt(_config, JDBCEpr.URL_TAG, null);
+ _user = ListenerUtil.obtainAtt(_config, JDBCEpr.USERNAME_TAG, null);
+ _password = ListenerUtil.obtainAtt(_config, JDBCEpr.PASSWORD_TAG, "");
+
+ _tableName = _config.getAttribute(ListenerTagNames.SQL_TABLE_NAME_TAG);
+ if (null == _tableName)
+ _tableName = _config.getRequiredAttribute(JDBCEpr.TABLE_NAME_TAG);
+ if (Util.isNullString(_tableName))
+ throw new ConfigurationException("Empty or invalid table name");
+
+ _selectFields = ListenerUtil.obtainAtt(_config,
+ ListenerTagNames.SQL_SELECT_FIELDS_TAG, "*");
+ if (Util.isNullString(_selectFields))
+ throw new ConfigurationException(
+ "Empty or invalid list of select fields");
+ _keyFields = _config.getAttribute(ListenerTagNames.SQL_KEY_FIELDS_TAG);
+ if (null == _keyFields)
+ _keyFields = _config.getRequiredAttribute(JDBCEpr.MESSAGE_ID_COLUMN_TAG);
+ if (Util.isNullString(_keyFields))
+ throw new ConfigurationException(
+ "Empty or invalid list of key fields");
+ _inProcessField = _config
+ .getAttribute(ListenerTagNames.SQL_IN_PROCESS_FIELD_TAG);
+ if (null == _inProcessField)
+ _inProcessField = _config.getAttribute(JDBCEpr.STATUS_COLUMN_TAG);
+ if (Util.isNullString(_inProcessField))
+ throw new ConfigurationException(
+ "A valid inProcessField attribute must be specified");
+
+ _where = ListenerUtil.obtainAtt(_config,
+ ListenerTagNames.SQL_WHERE_CONDITION_TAG, "");
+ if (_where.trim().length() < 1)
+ _logger
+ .debug("No value specified for: " + ListenerTagNames.SQL_WHERE_CONDITION_TAG);
+ _orderBy = ListenerUtil.obtainAtt(_config,
+ ListenerTagNames.SQL_ORDER_BY_TAG, "");
+ if (_orderBy.trim().length() < 1)
+ _logger
+ .debug("No value specified for: " + ListenerTagNames.SQL_ORDER_BY_TAG);
+ _inProcessVals = ListenerUtil.obtainAtt(_config,
+ ListenerTagNames.SQL_IN_PROCESS_VALUES_TAG,
+ DEFAULT_IN_PROCESS_STATES);
+
+ _deleteAfterOK = Boolean.parseBoolean(ListenerUtil.obtainAtt(_config,
+ ListenerTagNames.SQL_POST_DEL_TAG, "false"));
+ if (null == _config.getAttribute(ListenerTagNames.SQL_POST_DEL_TAG))
+ _logger
+ .debug("No value specified for: " + ListenerTagNames.SQL_POST_DEL_TAG + " - trigger row will not be deleted - 'in process field' will be used to show processing status");
+
+ if (_inProcessVals.length() < 4)
+ throw new ConfigurationException(
+ "Parameter <" + ListenerTagNames.SQL_IN_PROCESS_VALUES_TAG + "> must be at least 4 characters long (PWED)");
+
+ _columns = _selectFields.split(",");
+ if (_columns.length < 1)
+ throw new ConfigurationException("Empty list of select fields");
+
+ _keys = _keyFields.split(",");
+ if (!"*".equals(_selectFields))
+ {
+ Set<String> colSet = new HashSet<String>(Arrays.asList(_columns));
+ if (_keys.length < 1)
+ throw new ConfigurationException("Empty list of keyFields");
+ for (String currKey : _keys)
{
- Set<String> colSet = new HashSet<String>(Arrays.asList(_columns));
- if (_keys.length < 1)
- throw new ConfigurationException("Empty list of keyFields");
- for (String currKey : _keys)
+ if (colSet.contains(currKey)) continue;
+ else
{
- if (colSet.contains(currKey)) continue;
- else
- {
- StringBuilder sb = new StringBuilder().append(
- "All key field names in the <").append(
- ListenerTagNames.SQL_KEY_FIELDS_TAG).append(
- "> attribute must be in the ").append(
- ListenerTagNames.SQL_SELECT_FIELDS_TAG).append(
- "list - '").append(currKey)
- .append("' is not there");
- ;
- throw new ConfigurationException(sb.toString());
- }
+ StringBuilder sb = new StringBuilder().append(
+ "All key field names in the <").append(
+ ListenerTagNames.SQL_KEY_FIELDS_TAG).append(
+ "> attribute must be in the ").append(
+ ListenerTagNames.SQL_SELECT_FIELDS_TAG).append(
+ "list - '").append(currKey)
+ .append("' is not there");
+ throw new ConfigurationException(sb.toString());
}
}
- prepareStatements();
}
- catch (RegistryException ex)
- {
- _logger.error("Could not contact Registry during configuration.", ex);
-
- throw new ConfigurationException(ex);
- }
} // ________________________________
- protected void prepareStatements () throws ConfigurationException
+ protected void prepareStatements () throws SQLException
{
- try
- {
- _PSscan = getDbConn().prepareStatement(scanStatement());
- _PSsel4U = getDbConn().prepareStatement(selectForUpdStatement());
- _PSupdate = getDbConn().prepareStatement(updateStatement());
- _PSdeleteRow = getDbConn().prepareStatement(deleteStatement());
- return;
- }
- catch (Exception e)
- {
- throw new ConfigurationException(e);
- }
+ _PSscan = getDbConn().prepareStatement(scanStatement());
+ _PSsel4U = getDbConn().prepareStatement(selectForUpdStatement());
+ _PSupdate = getDbConn().prepareStatement(updateStatement());
+ _PSdeleteRow = getDbConn().prepareStatement(deleteStatement());
} // ________________________________
/*
@@ -498,22 +504,15 @@
* @throws ConfigurationException -
* if problems are encountered
*/
- protected JdbcCleanConn getDbConn () throws ConfigurationException
+ protected JdbcCleanConn getDbConn()
{
- try
+ if (null == _dbConn)
{
- if (null == _dbConn)
- {
- DataSource oDS = new SimpleDataSource(_driver, _url, _user,
- _password);
- _dbConn = new JdbcCleanConn(oDS);
- }
- return _dbConn;
+ DataSource oDS = new SimpleDataSource(_driver, _url, _user,
+ _password);
+ _dbConn = new JdbcCleanConn(oDS);
}
- catch (IllegalArgumentException ex)
- {
- throw new ConfigurationException(ex);
- }
+ return _dbConn;
} // ________________________________
/**
@@ -786,8 +785,6 @@
protected ConfigTree _config;
- protected GatewayListenerController _controller;
-
protected long _sleepBetweenPolls; // milliseconds
protected String _serviceCategory, _serviceName;
@@ -829,7 +826,7 @@
public static enum ROW_STATE
{
Pending, Working, Error, Done
- };
+ }
public static final String DEFAULT_IN_PROCESS_STATES = "PWED";
} // ____________________________________________________________________________
Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/AbstractManagedLifecycle.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/AbstractManagedLifecycle.java (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/AbstractManagedLifecycle.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -0,0 +1,429 @@
+/*
+ * 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.listeners.lifecycle;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+/**
+ * This class represents the lifecycle for a managed instance.
+ *
+ * @author kevin
+ */
+public abstract class AbstractManagedLifecycle implements ManagedLifecycle, Serializable
+{
+ /**
+ * The logger for this class.
+ */
+ private static final Logger logger = Logger.getLogger(AbstractManagedLifecycle.class) ;
+
+ /**
+ * The name of the attribute specifying the termination period.
+ */
+ public static final String PARAM_TERMINATION_PERIOD = "terminationPeriod" ;
+
+ /**
+ * The lock used for state operations.
+ */
+ private final Lock stateLock = new ReentrantLock() ;
+ /**
+ * The condition used for state changes.
+ */
+ private final Condition stateChanged = stateLock.newCondition() ;
+
+ /**
+ * The state of the managed instance.
+ */
+ private transient ManagedLifecycleState state = ManagedLifecycleState.CONSTRUCTED ;
+ /**
+ * The maximum amount of time to wait for termination.
+ */
+ private long terminationPeriod = 60000 ;
+
+ /**
+ * The list of listeners associated with this managed instance.
+ */
+ private Set<ManagedLifecycleEventListener> listeners = new CopyOnWriteArraySet<ManagedLifecycleEventListener>() ;
+
+ /**
+ * Construct the managed lifecycle.
+ * @param config The configuration associated with this instance.
+ * @throws ConfigurationException for configuration errors during initialisation.
+ */
+ protected AbstractManagedLifecycle(final ConfigTree config)
+ throws ConfigurationException
+ {
+ final String terminationPeriodVal = config.getAttribute(PARAM_TERMINATION_PERIOD) ;
+ if (terminationPeriodVal != null)
+ {
+ try
+ {
+ this.terminationPeriod = (Long.parseLong(terminationPeriodVal) * 1000) ;
+ }
+ catch (final NumberFormatException nfe)
+ {
+ throw new ConfigurationException("Failed to parse " +
+ PARAM_TERMINATION_PERIOD + " value of " + terminationPeriodVal) ;
+ }
+ }
+
+ if (logger.isDebugEnabled())
+ {
+ logger.debug(PARAM_TERMINATION_PERIOD + " value " + terminationPeriod) ;
+ }
+ }
+
+ /**
+ * Initialise the managed instance.
+ * <p/>
+ * This method is called after the managed instance has been instantiated so that
+ * configuration options can be validated.
+ *
+ * @throws ManagedLifecycleException for errors during initialisation.
+ */
+ public final void initialise()
+ throws ManagedLifecycleException
+ {
+ changeState(ManagedLifecycleState.INITIALISING) ;
+ try
+ {
+ doInitialise() ;
+ changeState(ManagedLifecycleState.INITIALISED) ;
+ }
+ catch (final ManagedLifecycleException mle)
+ {
+ changeState(ManagedLifecycleState.DESTROYED) ;
+ throw mle ;
+ }
+ catch (final Exception ex)
+ {
+ logger.warn("Unexpected exception caught while initialisation", ex) ;
+ changeState(ManagedLifecycleState.DESTROYED) ;
+ throw new ManagedLifecycleException(ex) ;
+ }
+ }
+
+ /**
+ * Handle the initialisation of the managed instance.
+ *
+ * @throws ManagedLifecycleException for errors while initialisation.
+ */
+ protected abstract void doInitialise()
+ throws ManagedLifecycleException ;
+
+ /**
+ * Start the managed instance.
+ * <p/>
+ * This method is called to inform the managed instance that it can initialise
+ * resources prior to enabling the service.
+ */
+ public final void start()
+ throws ManagedLifecycleException
+ {
+ changeState(ManagedLifecycleState.STARTING) ;
+ try
+ {
+ doStart() ;
+ changeState(ManagedLifecycleState.STARTED) ;
+ }
+ catch (final ManagedLifecycleException mle)
+ {
+ changeState(ManagedLifecycleState.STOPPED) ;
+ throw mle ;
+ }
+ catch (final Exception ex)
+ {
+ logger.warn("Unexpected exception caught while starting", ex) ;
+ changeState(ManagedLifecycleState.STOPPED) ;
+ throw new ManagedLifecycleException(ex) ;
+ }
+ }
+
+ /**
+ * Handle the start of the managed instance.
+ *
+ * @throws ManagedLifecycleException for errors while starting.
+ */
+ protected abstract void doStart()
+ throws ManagedLifecycleException ;
+
+ /**
+ * Stop the managed instance.
+ * <p/>
+ * This method is called to inform the managed instance that it must disable
+ * resources associated with the running service. The service may choose to
+ * disable the resources asynchronously provided that any subsequent call to
+ * {@link #start()} or {@link #destroy()} blocks until these resources have been
+ * disabled.
+ */
+ public final void stop()
+ throws ManagedLifecycleException
+ {
+ changeState(ManagedLifecycleState.STOPPING) ;
+ try
+ {
+ doStop() ;
+ }
+ catch (final ManagedLifecycleException mle)
+ {
+ throw mle ;
+ }
+ catch (final Exception ex)
+ {
+ logger.warn("Unexpected exception caught while stopping", ex) ;
+ throw new ManagedLifecycleException(ex) ;
+ }
+ finally
+ {
+ changeState(ManagedLifecycleState.STOPPED) ;
+ }
+ }
+
+ /**
+ * Handle the stop of the managed instance.
+ *
+ * @throws ManagedLifecycleException for errors while stopping.
+ */
+ protected abstract void doStop()
+ throws ManagedLifecycleException ;
+
+ /**
+ * Destroy the managed instance.
+ * <p/>
+ * This method is called prior to the release of the managed instance. All
+ * resources associated with this managed instance should be released as the
+ * instance will no longer be used.
+ */
+ public final void destroy()
+ throws ManagedLifecycleException
+ {
+ changeState(ManagedLifecycleState.DESTROYING) ;
+ try
+ {
+ doDestroy() ;
+ }
+ catch (final ManagedLifecycleException mle)
+ {
+ throw mle ;
+ }
+ catch (final Exception ex)
+ {
+ logger.warn("Unexpected exception caught while destroying", ex) ;
+ throw new ManagedLifecycleException(ex) ;
+ }
+ finally
+ {
+ changeState(ManagedLifecycleState.DESTROYED) ;
+ }
+ }
+
+ /**
+ * Handle the destroy of the managed instance.
+ *
+ * @throws ManagedLifecycleException for errors while destroying.
+ */
+ protected abstract void doDestroy()
+ throws ManagedLifecycleException ;
+
+ /**
+ * Get the state of the managed instance.
+ * @return The managed instance state.
+ */
+ public ManagedLifecycleState getState()
+ {
+ stateLock.lock() ;
+ try
+ {
+ return state ;
+ }
+ finally
+ {
+ stateLock.unlock() ;
+ }
+ }
+
+ /**
+ * Change the state of the managed instance.
+ * @param newState The new state of the managed instance.
+ * @throws ManagedLifecycleException
+ */
+ protected void changeState(final ManagedLifecycleState newState)
+ throws ManagedLifecycleException
+ {
+ final ManagedLifecycleState origState ;
+ stateLock.lock() ;
+ try
+ {
+ if (!state.canTransition(newState))
+ {
+ throw new ManagedLifecycleException("Invalid state change from " + state + " to " + newState) ;
+ }
+ origState = state ;
+ state = newState ;
+ stateChanged.signalAll() ;
+ }
+ finally
+ {
+ stateLock.unlock() ;
+ }
+ fireStateChangedEvent(origState, newState) ;
+ }
+
+ /**
+ * Get the termination period for this service.
+ * @return The termination period.
+ */
+ protected long getTerminationPeriod()
+ {
+ return terminationPeriod ;
+ }
+
+ /**
+ * Wait until the managed instance has transitioned into the DESTROYED state.
+ * @return true if the transition occurs within the expected period, false otherwise.
+ */
+ public boolean waitUntilDestroyed()
+ {
+ return waitUntilDestroyed(getTerminationPeriod()) ;
+ }
+
+ /**
+ * Wait until the managed instance has transitioned into the DESTROYED state.
+ * @param transitionPeriod The maximum delay expected for the transition, specified in milliseconds.
+ * @return true if the transition occurs within the expected period, false otherwise.
+ */
+ public boolean waitUntilDestroyed(final long transitionPeriod)
+ {
+ return waitForStateChange(ManagedLifecycleState.DESTROYED, transitionPeriod) ;
+ }
+
+ /**
+ * Wait until the managed instance has transitioned into the specified state.
+ * @param state The expected state.
+ * @param transitionPeriod The maximum delay expected for the transition, specified in milliseconds.
+ * @return true if the transition occurs within the expected period, false otherwise.
+ */
+ protected boolean waitForStateChange(final ManagedLifecycleState state, final long transitionPeriod)
+ {
+ try
+ {
+ stateLock.lock() ;
+ try
+ {
+ if (this.state != state)
+ {
+ final long end = System.currentTimeMillis() + transitionPeriod ;
+ while(this.state != state)
+ {
+ final long delay = end - System.currentTimeMillis() ;
+ if (delay <= 0)
+ {
+ break ;
+ }
+ stateChanged.await(delay, TimeUnit.MILLISECONDS) ;
+ }
+ }
+ return (this.state == state) ;
+ }
+ finally
+ {
+ stateLock.unlock() ;
+ }
+ }
+ catch (final InterruptedException ie)
+ {
+ if (logger.isInfoEnabled())
+ {
+ logger.info("Interrupted while waiting for state change") ;
+ }
+
+ stateLock.lock() ;
+ try
+ {
+ return (this.state == state) ;
+ }
+ finally
+ {
+ stateLock.unlock() ;
+ }
+ }
+ }
+
+ /**
+ * Add a managed lifecycle event listener.
+ * @param listener The listener.
+ */
+ public void addManagedLifecycleEventListener(final ManagedLifecycleEventListener listener)
+ {
+ listeners.add(listener) ;
+ }
+
+ /**
+ * Remove a managed lifecycle event listener.
+ * @param listener The listener.
+ */
+ public void removeManagedLifecycleEventListener(final ManagedLifecycleEventListener listener)
+ {
+ listeners.remove(listener) ;
+ }
+
+ /**
+ * Fire the state changed event.
+ * @param origState The original state, prior to transition
+ * @param newState The new state after transition
+ */
+ private void fireStateChangedEvent(final ManagedLifecycleState origState, final ManagedLifecycleState newState)
+ {
+ if (listeners.size() > 0)
+ {
+ final ManagedLifecycleStateEvent event = new ManagedLifecycleStateEvent(this, origState, newState) ;
+ for(ManagedLifecycleEventListener listener: listeners)
+ {
+ listener.stateChanged(event) ;
+ }
+ }
+ }
+
+ /**
+ * Deserialise this managed lifecycle.
+ * @param in The input stream.
+ * @throws IOException for errors generated by the input stream.
+ * @throws ClassNotFoundException For classpath errors.
+ */
+ private void readObject(final ObjectInputStream in)
+ throws IOException, ClassNotFoundException
+ {
+ in.defaultReadObject() ;
+ state = ManagedLifecycleState.CONSTRUCTED ;
+ }
+}
Property changes on: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/AbstractManagedLifecycle.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/AbstractThreadedManagedLifecycle.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/AbstractThreadedManagedLifecycle.java (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/AbstractThreadedManagedLifecycle.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -0,0 +1,352 @@
+/*
+ * 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.listeners.lifecycle;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+
+/**
+ * This class provides threaded support for a managed instance.
+ *
+ * @author kevin
+ */
+public abstract class AbstractThreadedManagedLifecycle extends AbstractManagedLifecycle implements Runnable
+{
+ /**
+ * The logger for this class.
+ */
+ private static final Logger logger = Logger.getLogger(AbstractThreadedManagedLifecycle.class) ;
+
+ /**
+ * The lock used for managing the running state.
+ */
+ private final Lock runningLock = new ReentrantLock() ;
+ /**
+ * The condition used for running state changes.
+ */
+ private final Condition runningChanged = runningLock.newCondition() ;
+
+ /**
+ * The running state.
+ */
+ private transient ManagedLifecycleThreadState state = ManagedLifecycleThreadState.STOPPED ;
+
+ /**
+ * The list of listeners associated with this managed instance.
+ */
+ private Set<ManagedLifecycleThreadEventListener> listeners = new CopyOnWriteArraySet<ManagedLifecycleThreadEventListener>() ;
+
+
+ /**
+ * Construct the threaded managed lifecycle.
+ * @param config The configuration associated with this instance.
+ * @throws ConfigurationException for configuration errors during initialisation.
+ */
+ protected AbstractThreadedManagedLifecycle(final ConfigTree config)
+ throws ConfigurationException
+ {
+ super(config) ;
+ }
+
+ /**
+ * Handle the start of the managed instance.
+ *
+ * @throws ManagedLifecycleException for errors while starting.
+ */
+ protected void doStart()
+ throws ManagedLifecycleException
+ {
+ runningLock.lock() ;
+ try
+ {
+ if (!waitUntilStopped())
+ {
+ throw new ManagedLifecycleException("Thread still active from previous start") ;
+ }
+ setRunning(ManagedLifecycleThreadState.RUNNING) ;
+ }
+ finally
+ {
+ runningLock.unlock() ;
+ }
+ final Thread thread = new Thread(this) ;
+ thread.start() ;
+ }
+
+ /**
+ * The thread execution method.
+ */
+ public final void run()
+ {
+ try
+ {
+ changeState(ManagedLifecycleState.RUNNING) ;
+ doRun() ;
+ }
+ catch (final Throwable th)
+ {
+ logger.warn("Unexpected error from doRun()", th) ;
+ }
+ finally
+ {
+ setRunning(ManagedLifecycleThreadState.STOPPED) ;
+ }
+ }
+
+ /**
+ * Execute on the thread.
+ */
+ protected abstract void doRun() ;
+
+ /**
+ * Handle the stop of the managed instance.
+ *
+ * @throws ManagedLifecycleException for errors while stopping.
+ */
+ protected void doStop()
+ throws ManagedLifecycleException
+ {
+ runningLock.lock() ;
+ try
+ {
+ if (!isRunning())
+ {
+ throw new ManagedLifecycleException("Thread is not running") ;
+ }
+ setRunning(ManagedLifecycleThreadState.STOPPING) ;
+ }
+ finally
+ {
+ runningLock.unlock() ;
+ }
+ }
+
+ /**
+ * Handle the destroy of the managed instance.
+ *
+ * @throws ManagedLifecycleException for errors while destroying.
+ */
+ protected void doDestroy()
+ throws ManagedLifecycleException
+ {
+ if (!waitUntilStopped())
+ {
+ throw new ManagedLifecycleException("Thread still active") ;
+ }
+ }
+
+ /**
+ * Is the associated thread still running?
+ * @return true if the thread is still running, false otherwise.
+ */
+ public boolean isRunning()
+ {
+ return checkState(ManagedLifecycleThreadState.RUNNING) ;
+ }
+
+ /**
+ * Is the associated thread stopped?
+ * @return true if the thread is stopped, false otherwise.
+ */
+ public boolean isStopped()
+ {
+ return checkState(ManagedLifecycleThreadState.STOPPED) ;
+ }
+
+ /**
+ * Is the associated thread stopping?
+ * @return true if the thread is stopped, false otherwise.
+ */
+ public boolean isStopping()
+ {
+ return checkState(ManagedLifecycleThreadState.STOPPING) ;
+ }
+
+ /**
+ * Check the state against the specified value.
+ * @param state The expected state.
+ * @return True if the thread is in the expected state, false otherwise.
+ */
+ private boolean checkState(final ManagedLifecycleThreadState state)
+ {
+ runningLock.lock() ;
+ try
+ {
+ return (this.state == state) ;
+ }
+ finally
+ {
+ runningLock.unlock() ;
+ }
+ }
+
+ /**
+ * Set the running state.
+ * @param state The new running state.
+ */
+ protected void setRunning(final ManagedLifecycleThreadState newState)
+ {
+ final ManagedLifecycleThreadState origState ;
+ runningLock.lock() ;
+ try
+ {
+ origState = state ;
+ state = newState ;
+ runningChanged.signalAll() ;
+ }
+ finally
+ {
+ runningLock.unlock() ;
+ }
+ fireStateChangedEvent(origState, newState) ;
+ }
+
+ /**
+ * Wait until the associated thread has stopped.
+ * @return true if the thread stops within the expected period, false otherwise.
+ */
+ public boolean waitUntilStopped()
+ {
+ return waitUntilStopped(getTerminationPeriod()) ;
+ }
+
+ /**
+ * Wait until the associated thread has stopped.
+ * @param terminationPeriod The maximum delay expected for the termination, specified in milliseconds.
+ * @return true if the thread stops within the expected period, false otherwise.
+ */
+ public boolean waitUntilStopped(final long terminationPeriod)
+ {
+ return waitForRunningStateChange(ManagedLifecycleThreadState.STOPPED, terminationPeriod) ;
+ }
+
+ /**
+ * Wait until the running state has the specified value.
+ * @param state The expected running state value.
+ * @param terminationPeriod The maximum delay expected for the termination, specified in milliseconds.
+ * @return true if the state has the specified value within the expected period, false otherwise.
+ */
+ protected boolean waitForRunningStateChange(final ManagedLifecycleThreadState state, final long terminationPeriod)
+ {
+ try
+ {
+ runningLock.lock() ;
+ try
+ {
+ if (this.state != state)
+ {
+ final long end = System.currentTimeMillis() + terminationPeriod ;
+ while(this.state != state)
+ {
+ final long delay = end - System.currentTimeMillis() ;
+ if (delay <= 0)
+ {
+ break ;
+ }
+ runningChanged.await(delay, TimeUnit.MILLISECONDS) ;
+ }
+ }
+ return (this.state == state) ;
+ }
+ finally
+ {
+ runningLock.unlock() ;
+ }
+ }
+ catch (final InterruptedException ie)
+ {
+ if (logger.isInfoEnabled())
+ {
+ logger.info("Interrupted while waiting for running state change") ;
+ }
+
+ runningLock.lock() ;
+ try
+ {
+ return (this.state == state) ;
+ }
+ finally
+ {
+ runningLock.unlock() ;
+ }
+ }
+ }
+
+ /**
+ * Add a managed lifecycle thread event listener.
+ * @param listener The listener.
+ */
+ public void addManagedLifecycleThreadEventListener(final ManagedLifecycleThreadEventListener listener)
+ {
+ listeners.add(listener) ;
+ }
+
+ /**
+ * Remove a managed lifecycle thread event listener.
+ * @param listener The listener.
+ */
+ public void removeManagedLifecycleThreadEventListener(final ManagedLifecycleThreadEventListener listener)
+ {
+ listeners.remove(listener) ;
+ }
+
+ /**
+ * Fire the state changed event.
+ * @param origState The original state, prior to transition
+ * @param newState The new state after transition
+ */
+ private void fireStateChangedEvent(final ManagedLifecycleThreadState origState, final ManagedLifecycleThreadState newState)
+ {
+ if (listeners.size() > 0)
+ {
+ final ManagedLifecycleThreadStateEvent event = new ManagedLifecycleThreadStateEvent(this, origState, newState) ;
+ for(ManagedLifecycleThreadEventListener listener: listeners)
+ {
+ listener.stateChanged(event) ;
+ }
+ }
+ }
+
+ /**
+ * Deserialise this managed lifecycle.
+ * @param in The input stream.
+ * @throws IOException for errors generated by the input stream.
+ * @throws ClassNotFoundException For classpath errors.
+ */
+ private void readObject(final ObjectInputStream in)
+ throws IOException, ClassNotFoundException
+ {
+ in.defaultReadObject() ;
+ state = ManagedLifecycleThreadState.STOPPED ;
+ }
+}
Property changes on: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/AbstractThreadedManagedLifecycle.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycle.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycle.java (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycle.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -0,0 +1,99 @@
+/*
+ * 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.listeners.lifecycle;
+
+public interface ManagedLifecycle
+{
+
+ /**
+ * Initialise the managed instance.
+ * <p/>
+ * This method is called after the managed instance has been instantiated so that
+ * configuration options can be validated.
+ *
+ * @throws ManagedLifecycleException for errors during initialisation.
+ */
+ public void initialise()
+ throws ManagedLifecycleException ;
+
+ /**
+ * Start the managed instance.
+ * <p/>
+ * This method is called to inform the managed instance that it can initialise
+ * resources prior to enabling the service.
+ */
+ public void start()
+ throws ManagedLifecycleException ;
+
+ /**
+ * Stop the managed instance.
+ * <p/>
+ * This method is called to inform the managed instance that it must disable
+ * resources associated with the running service. The service may choose to
+ * disable the resources asynchronously provided that any subsequent call to
+ * {@link #start()} or {@link #destroy()} blocks until these resources have been
+ * disabled.
+ */
+ public void stop()
+ throws ManagedLifecycleException ;
+
+ /**
+ * Destroy the managed instance.
+ * <p/>
+ * This method is called prior to the release of the managed instance. All
+ * resources associated with this managed instance should be released as the
+ * instance will no longer be used.
+ */
+ public void destroy()
+ throws ManagedLifecycleException ;
+
+ /**
+ * Get the state of the managed instance.
+ * @return The managed instance state.
+ */
+ public ManagedLifecycleState getState() ;
+
+ /**
+ * Wait until the managed instance has transitioned into the DESTROYED state.
+ * @return true if the transition occurs within the expected period, false otherwise.
+ */
+ public boolean waitUntilDestroyed() ;
+
+ /**
+ * Wait until the managed instance has transitioned into the DESTROYED state.
+ * @param transitionPeriod The maximum delay expected for the transition, specified in milliseconds.
+ * @return true if the transition occurs within the expected period, false otherwise.
+ */
+ public boolean waitUntilDestroyed(final long transitionPeriod) ;
+
+ /**
+ * Add a managed lifecycle event listener.
+ * @param listener The listener.
+ */
+ public void addManagedLifecycleEventListener(final ManagedLifecycleEventListener listener) ;
+
+ /**
+ * Remove a managed lifecycle event listener.
+ * @param listener The listener.
+ */
+ public void removeManagedLifecycleEventListener(final ManagedLifecycleEventListener listener) ;
+}
\ No newline at end of file
Property changes on: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycle.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleController.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleController.java (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleController.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -0,0 +1,206 @@
+package org.jboss.soa.esb.listeners.lifecycle;
+
+import java.util.Collection;
+
+/**
+ * Controller class to manage the lifecycles of a set of managed instances.
+ * @author kevin
+ */
+public class ManagedLifecycleController
+{
+ /**
+ * The managed lifecycle instances.
+ */
+ private final ManagedLifecycle[] instances ;
+
+ /**
+ * Construct the controller to manage the specified managed lifecycle instances.
+ * @param lifecycles The managed lifecycle instances.
+ */
+ public ManagedLifecycleController(final Collection<ManagedLifecycle> lifecycles)
+ {
+ final int numInstances = (lifecycles == null ? 0 : lifecycles.size()) ;
+ instances = lifecycles.toArray(new ManagedLifecycle[numInstances]) ;
+ }
+
+ /**
+ * Start the lifecyles for the managed instances.
+ * <p/>
+ * The managed instances will be left in the destroyed state if an error occurs.
+ * @throws ManagedLifecycleException For errors during the lifecycle start.
+ */
+ public void start()
+ throws ManagedLifecycleException
+ {
+ initialiseInstances() ;
+ startInstances() ;
+ }
+
+ /**
+ * Restart the lifecyles for the managed instances.
+ * <p/>
+ * The managed instances will be left in the destroyed state if an error occurs.
+ * @throws ManagedLifecycleException For errors during the lifecycle restart.
+ */
+ public void restart()
+ throws ManagedLifecycleException
+ {
+ stopInstances() ;
+ startInstances() ;
+ }
+
+ /**
+ * Stop the lifecyles for the managed instances.
+ * <p/>
+ * The managed instances will be left in the destroyed state if an error occurs.
+ * @throws ManagedLifecycleException For errors during the lifecycle stop.
+ */
+ public void stop()
+ throws ManagedLifecycleException
+ {
+ stopInstances() ;
+ destroyInstances() ;
+ }
+
+ /**
+ * Initialise the managed instances.
+ * @throws ManagedLifecycleException For errors during initialisation.
+ */
+ private void initialiseInstances()
+ throws ManagedLifecycleException
+ {
+ final int numInstances = instances.length ;
+ for(int count = 0 ; count < numInstances ; count++)
+ {
+ final ManagedLifecycle instance = instances[count] ;
+ try
+ {
+ instance.initialise() ;
+ }
+ catch (final ManagedLifecycleException mle)
+ {
+ if (count > 0)
+ {
+ destroyInstances(count-1) ;
+ }
+ throw mle ;
+ }
+ }
+ }
+
+ /**
+ * Start the managed instances.
+ * @throws ManagedLifecycleException For errors during starting.
+ */
+ private void startInstances()
+ throws ManagedLifecycleException
+ {
+ final int numInstances = instances.length ;
+ for(int count = 0 ; count < numInstances ; count++)
+ {
+ final ManagedLifecycle instance = instances[count] ;
+ try
+ {
+ instance.start() ;
+ }
+ catch (final ManagedLifecycleException mle)
+ {
+ if (count > 0)
+ {
+ stopInstances(count-1) ;
+ destroyInstances(numInstances-1) ;
+ }
+ throw mle ;
+ }
+ }
+ }
+
+ /**
+ * Stop the managed instances.
+ * @throws ManagedLifecycleException For errors during stopping.
+ */
+ private void stopInstances()
+ throws ManagedLifecycleException
+ {
+ final int numInstances = instances.length ;
+ for(int count = numInstances-1 ; count >= 0 ; count--)
+ {
+ final ManagedLifecycle instance = instances[count] ;
+ try
+ {
+ instance.stop() ;
+ }
+ catch (final ManagedLifecycleException mle)
+ {
+ if (count > 0)
+ {
+ stopInstances(count-1) ;
+ destroyInstances(numInstances-1) ;
+ }
+ throw mle ;
+ }
+ }
+ }
+
+ /**
+ * Destroy the managed instances.
+ * @throws ManagedLifecycleException For errors during destruction.
+ */
+ private void destroyInstances()
+ throws ManagedLifecycleException
+ {
+ final int numInstances = instances.length ;
+ for(int count = numInstances-1 ; count >= 0 ; count--)
+ {
+ final ManagedLifecycle instance = instances[count] ;
+ try
+ {
+ instance.destroy() ;
+ }
+ catch (final ManagedLifecycleException mle)
+ {
+ if (count > 0)
+ {
+ destroyInstances(count-1) ;
+ }
+ throw mle ;
+ }
+ }
+ }
+
+ /**
+ * Silently stop a partial set of the managed instances.
+ * @param firstInstance The index of the first instance to stop
+ */
+ private void stopInstances(final int firstInstance)
+ throws ManagedLifecycleException
+ {
+ for(int count = firstInstance ; count >= 0 ; count--)
+ {
+ final ManagedLifecycle instance = instances[count] ;
+ try
+ {
+ instance.stop() ;
+ }
+ catch (final ManagedLifecycleException mle) {} // Ignore exception
+ }
+ }
+
+ /**
+ * Silently destroy a partial set of the managed instances.
+ * @param firstInstance The index of the first instance to stop
+ */
+ private void destroyInstances(final int firstInstance)
+ throws ManagedLifecycleException
+ {
+ for(int count = firstInstance ; count >= 0 ; count--)
+ {
+ final ManagedLifecycle instance = instances[count] ;
+ try
+ {
+ instance.destroy() ;
+ }
+ catch (final ManagedLifecycleException mle) {} // Ignore exception
+ }
+ }
+}
Property changes on: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleController.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleEventListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleEventListener.java (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleEventListener.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -0,0 +1,38 @@
+/*
+ * 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.listeners.lifecycle;
+
+import java.util.EventListener;
+
+/**
+ * This interface represents the lifecycle events generated by a managed instance.
+ *
+ * @author kevin
+ */
+public interface ManagedLifecycleEventListener extends EventListener
+{
+ /**
+ * The state of the managed instance has changed.
+ * @param event The managed lifecycle state event.
+ */
+ public void stateChanged(final ManagedLifecycleStateEvent event) ;
+}
Property changes on: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleEventListener.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleException.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleException.java (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleException.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -0,0 +1,69 @@
+/*
+ * 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.listeners.lifecycle;
+
+/**
+ * Exception representing errors in a managed lifecycle.
+ * @author kevin
+ */
+public class ManagedLifecycleException extends Exception
+{
+ /**
+ * serial version UID of this exception.
+ */
+ private static final long serialVersionUID = -2461030864678547990L;
+
+ /**
+ * Construct a default managed lifecycle exception.
+ */
+ public ManagedLifecycleException()
+ {
+ }
+
+ /**
+ * Construct a managed lifecycle exception with the specified message.
+ * @param message The exception message.
+ */
+ public ManagedLifecycleException(final String message)
+ {
+ super(message);
+ }
+
+ /**
+ * Construct a managed lifecycle exception with the associated cause.
+ * @param cause The associated cause.
+ */
+ public ManagedLifecycleException(final Throwable cause)
+ {
+ super(cause);
+ }
+
+ /**
+ * Construct a managed lifecycle exception with the specified message and associated cause.
+ * @param message The exception message.
+ * @param cause The associated cause.
+ */
+ public ManagedLifecycleException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
Property changes on: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleException.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleState.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleState.java (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleState.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -0,0 +1,61 @@
+/*
+ * 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.listeners.lifecycle;
+
+/**
+ * This enumeration represents the lifecycle state of a managed instance.
+ * <p/>
+ * Allowable transitions are as follows
+ * <table border="1">
+ * <thead>
+ * <tr><th>Originating state</th><th>New states</th></tr>
+ * </thead>
+ * <tbody>
+ * <tr><td>CONSTRUCTED</td><td>INITIALISING</td></tr>
+ * <tr><td>INITIALISING</td><td>INITIALISED, DESTROYED</td></tr>
+ * <tr><td>INITIALISED</td><td>STARTING, DESTROYED</td></tr>
+ * <tr><td>STARTING</td><td>STARTED, STOPPED</td></tr>
+ * <tr><td>STARTED</td><td>RUNNING, STOPPING</td></tr>
+ * <tr><td>RUNNING</td><td>STOPPING</td></tr>
+ * <tr><td>STOPPING</td><td>STOPPED</td></tr>
+ * <tr><td>STOPPED</td><td>STARTING, DESTROYING</td></tr>
+ * <tr><td>DESTROYING</td><td>DESTROYED</td></tr>
+ * </tbody>
+ * </table>
+ *
+ * @author kevin
+ */
+public enum ManagedLifecycleState
+{
+ CONSTRUCTED { public boolean canTransition(final ManagedLifecycleState newState) { return (newState == INITIALISING) ;}} ,
+ INITIALISING { public boolean canTransition(final ManagedLifecycleState newState) { return ((newState == INITIALISED) || (newState == DESTROYED)) ;}} ,
+ INITIALISED { public boolean canTransition(final ManagedLifecycleState newState) { return ((newState == STARTING) || (newState == DESTROYED)) ;}} ,
+ STARTING { public boolean canTransition(final ManagedLifecycleState newState) { return ((newState == STARTED) || (newState == STOPPED)) ;}} ,
+ STARTED { public boolean canTransition(final ManagedLifecycleState newState) { return ((newState == RUNNING) || (newState == STOPPING)) ;}} ,
+ RUNNING { public boolean canTransition(final ManagedLifecycleState newState) { return (newState == STOPPING) ;}} ,
+ STOPPING { public boolean canTransition(final ManagedLifecycleState newState) { return (newState == STOPPED) ;}} ,
+ STOPPED { public boolean canTransition(final ManagedLifecycleState newState) { return ((newState == STARTING) || (newState == DESTROYING)) ;}} ,
+ DESTROYING { public boolean canTransition(final ManagedLifecycleState newState) { return (newState == DESTROYED) ;}} ,
+ DESTROYED { public boolean canTransition(final ManagedLifecycleState newState) { return false ;}} ;
+
+ public abstract boolean canTransition(final ManagedLifecycleState newState) ;
+}
Property changes on: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleState.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleStateEvent.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleStateEvent.java (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleStateEvent.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -0,0 +1,90 @@
+/*
+ * 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.listeners.lifecycle;
+
+import java.util.EventObject;
+
+public class ManagedLifecycleStateEvent extends EventObject
+{
+ /**
+ * The serial version uid for this event.
+ */
+ private static final long serialVersionUID = 194745476487653243L;
+
+ /**
+ * The original state, prior to transition.
+ */
+ private final ManagedLifecycleState origState ;
+ /**
+ * The new state, after transition.
+ */
+ private final ManagedLifecycleState newState ;
+
+ /**
+ * Construct the managed lifecycle state event.
+ * @param instance The managed instance
+ * @param origState The original state, prior to transition
+ * @param newState The new state after transition
+ */
+ public ManagedLifecycleStateEvent(final ManagedLifecycle instance, final ManagedLifecycleState origState, final ManagedLifecycleState newState)
+ {
+ super(instance) ;
+ this.origState = origState ;
+ this.newState = newState ;
+ }
+
+ /**
+ * Get the managed lifecycle instance.
+ * @return The managed lifecycle instance.
+ */
+ public ManagedLifecycle getManagedInstance()
+ {
+ return (ManagedLifecycle)getSource() ;
+ }
+
+ /**
+ * Get the original state, prior to transition.
+ * @return The original state.
+ */
+ public ManagedLifecycleState getOriginalState()
+ {
+ return origState ;
+ }
+
+ /**
+ * Get the new state after transition.
+ * @return The new state.
+ */
+ public ManagedLifecycleState getNewState()
+ {
+ return newState ;
+ }
+
+ /**
+ * Return a String representation of this event.
+ * @return The string representation of this event.
+ */
+ public String toString()
+ {
+ return getClass().getName() + "[instance=" + getManagedInstance() + ", original state " + origState + ", new state " + newState + "]" ;
+ }
+}
Property changes on: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleStateEvent.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleThreadEventListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleThreadEventListener.java (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleThreadEventListener.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -0,0 +1,38 @@
+/*
+ * 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.listeners.lifecycle;
+
+import java.util.EventListener;
+
+/**
+ * This interface represents the lifecycle events generated by a threaded managed instance.
+ *
+ * @author kevin
+ */
+public interface ManagedLifecycleThreadEventListener extends EventListener
+{
+ /**
+ * The state of the managed instance thread has changed.
+ * @param event The managed lifecycle state event.
+ */
+ public void stateChanged(final ManagedLifecycleThreadStateEvent event) ;
+}
Property changes on: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleThreadEventListener.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleThreadState.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleThreadState.java (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleThreadState.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -0,0 +1,31 @@
+/*
+ * 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.listeners.lifecycle;
+
+/**
+ * This enumeration represents the lifecycle state of a thread in an managed instance.
+ * @author kevin
+ */
+public enum ManagedLifecycleThreadState
+{
+ STOPPED, RUNNING, STOPPING
+}
Property changes on: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleThreadState.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleThreadStateEvent.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleThreadStateEvent.java (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleThreadStateEvent.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -0,0 +1,91 @@
+/*
+ * 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.listeners.lifecycle;
+
+import java.util.EventObject;
+
+public class ManagedLifecycleThreadStateEvent extends EventObject
+{
+ /**
+ * The serial version uid for this event.
+ */
+ private static final long serialVersionUID = 7417604654035419987L;
+
+ /**
+ * The original state, prior to transition.
+ */
+ private final ManagedLifecycleThreadState origState ;
+ /**
+ * The new state, after transition.
+ */
+ private final ManagedLifecycleThreadState newState ;
+
+ /**
+ * Construct the managed lifecycle state event.
+ * @param instance The managed instance
+ * @param origState The original state, prior to transition
+ * @param newState The new state after transition
+ */
+ public ManagedLifecycleThreadStateEvent(final AbstractThreadedManagedLifecycle instance,
+ final ManagedLifecycleThreadState origState, final ManagedLifecycleThreadState newState)
+ {
+ super(instance) ;
+ this.origState = origState ;
+ this.newState = newState ;
+ }
+
+ /**
+ * Get the managed lifecycle instance.
+ * @return The managed lifecycle instance.
+ */
+ public ManagedLifecycle getManagedInstance()
+ {
+ return (ManagedLifecycle)getSource() ;
+ }
+
+ /**
+ * Get the original state, prior to transition.
+ * @return The original state.
+ */
+ public ManagedLifecycleThreadState getOriginalState()
+ {
+ return origState ;
+ }
+
+ /**
+ * Get the new state after transition.
+ * @return The new state.
+ */
+ public ManagedLifecycleThreadState getNewState()
+ {
+ return newState ;
+ }
+
+ /**
+ * Return a String representation of this event.
+ * @return The string representation of this event.
+ */
+ public String toString()
+ {
+ return getClass().getName() + "[instance=" + getManagedInstance() + ", original state " + origState + ", new state " + newState + "]" ;
+ }
+}
Property changes on: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleThreadStateEvent.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date
Name: svn:eol-style
+ native
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/HttpListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/HttpListener.java 2007-01-30 06:44:10 UTC (rev 9118)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/HttpListener.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -21,6 +21,10 @@
*/
package org.jboss.soa.esb.listeners.message;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
import javax.management.MBeanServer;
import org.apache.log4j.Logger;
@@ -32,11 +36,12 @@
import org.jboss.remoting.transport.Connector;
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.listeners.AbstractManagedListener;
import org.jboss.soa.esb.listeners.ListenerInitializationException;
-import org.jboss.soa.esb.listeners.ListenerManager;
-import org.jboss.soa.esb.listeners.State;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.listeners.lifecycle.AbstractManagedLifecycle;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException;
import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.util.Util;
/**
* Http listener implementation using the JBoss Remoting channel.
@@ -59,227 +64,302 @@
* @author <a href="mailto:johan.kumps at telenet.be">Johan Kumps</a>
*
*/
-public class HttpListener extends AbstractManagedListener implements ServerInvocationHandler {
+public class HttpListener extends AbstractManagedLifecycle implements ServerInvocationHandler {
+
+ /**
+ * serial version uid for this class
+ */
+ private static final long serialVersionUID = -2939297462625444965L;
- /* The logger for this class */
- protected Logger logger = Logger.getLogger(HttpListener.class);
+ /* The logger for this class */
+ protected Logger logger = Logger.getLogger(HttpListener.class);
+
+ /* The url this listener will listen on */
+ private static final String LISTEN_HTTP_URL = "listenHttpUrl";
+
+ /* The url to listen on */
+ public String listenHttpUrl = null;
+
+ /* The default transport this listener will listen on */
+ private static final String transport = "http";
+
+ /* The default hostname this listener will listen on */
+ private static final String host = "localhost";
+
+ /* The default port this listener will listen on */
+ private static final int port = 5400;
+
+ /**
+ * The default maximum thread count.
+ */
+ private static final int defaultMaxThreads = 1 ;
+
+ /**
+ * The config for this listener.
+ */
+ private final ConfigTree config ;
+
+ /**
+ * The remoting connector.
+ */
+ private Connector connector ;
+ /**
+ * The maximum thread count.
+ */
+ private int maxThreads ;
+ /**
+ * The executor service for the tasks.
+ */
+ private ExecutorService executor ;
+
+ /**
+ * Constructor initialising this HttpListener
+ *
+ * @param commandListener
+ * @param listenerConfig
+ * @param actionDefinitionFactory
+ * @throws ConfigurationException
+ * @throws ListenerInitializationException
+ */
+ public HttpListener(final ConfigTree config)
+ throws ConfigurationException
+ {
+ super(config) ;
+ this.config = config ;
+ checkParams() ;
+ }
+
+ /**
+ * Handle the initialisation of the managed instance.
+ *
+ * @throws ManagedLifecycleException for errors while initialisation.
+ */
+ protected void doInitialise()
+ throws ManagedLifecycleException
+ {
+ // nothing to initialise here.
+ }
- /* Boolean indicating whether the info logging level is enabled */
- protected boolean info = this.logger.isInfoEnabled();
+ /**
+ * Handle the start of the managed instance.
+ *
+ * @throws ManagedLifecycleException for errors while starting.
+ */
+ protected void doStart()
+ throws ManagedLifecycleException
+ {
+ checkExecutorTermination() ;
+
+ final Connector connector ;
+ try
+ {
+ final InvokerLocator locator = new InvokerLocator(listenHttpUrl);
+ connector = new Connector(locator);
+ connector.create();
+
+ connector.addInvocationHandler("HttpInvocationHandler", this);
+
+ // Starting the server deamon
+ connector.start();
+
+ if (logger.isInfoEnabled())
+ {
+ logger.info("Started HttpListener deamon with locator uri of: " + listenHttpUrl);
+ }
+ }
+ catch (final Exception ex)
+ {
+ logger.warn("Unexpected error starting HttpListener", ex) ;
+ throw new ManagedLifecycleException(ex) ;
+ }
+
+ this.connector = connector ;
+ executor = Executors.newFixedThreadPool(maxThreads) ;
+ }
- /* The url this listener will listen on */
- private static final String LISTEN_HTTP_URL = "listenHttpUrl";
-
- /* The url to listen on */
- public String listenHttpUrl = null;
-
- /* The default transport this listener will listen on */
- private static final String transport = "http";
-
- /* The default hostname this listener will listen on */
- private static final String host = "localhost";
-
- /* The default port this listener will listen on */
- private static final int port = 5400;
-
- /**
- * Constructor initialising this HttpListener
- *
- * @param commandListener
- * @param listenerConfig
- * @param actionDefinitionFactory
- * @throws ConfigurationException
- * @throws ListenerInitializationException
- */
- public HttpListener(ListenerManager esbListenerController,
- ConfigTree configuration) throws ConfigurationException,
- ListenerInitializationException {
- super(esbListenerController, configuration);
-
- this.checkParams();
- this.initServer();
-
- }
-
- /*
- * Method being invoked when a request comes in.
- *
- * (non-Javadoc)
- *
- * @see org.jboss.remoting.ServerInvocationHandler#invoke(org.jboss.remoting.InvocationRequest)
- */
- @SuppressWarnings("unchecked")
- public Object invoke(InvocationRequest invocationRequest) throws Throwable {
- // Retrieving the real payload of this invocationRequest
- Object payload = invocationRequest.getParameter();
-
- if (this.logger.isInfoEnabled()) {
- this.logger
- .info("HttpInvocationListener is invoked...The given payload is : "
- + payload);
- }
- if (payload instanceof Message){
- // Start the action processing pipeline
- ActionProcessingPipeline pipelineRunner = new ActionProcessingPipeline(
- (Message)payload, this._config);
- //this.pipelineExecutorPool.submit(pipelineRunner);
- //The above does not invoke the process action, using the following instead.
- new Thread(pipelineRunner).start();
- } else {
- this.logger.error("Unsupported HttpListener message type: " + payload.getClass().getName());
- }
-
- return payload;
- }
- /**
- * Adds a callback handler that will listen for callbacks from the server
- * invoker handler.
- *
- * @param callbackHandler
- */
- public void addListener(InvokerCallbackHandler callbackHandler) {
- // NO OP as do not handling callback listeners in this example
- }
-
- /**
- * Removes the callback handler that was listening for callbacks from the
- * server invoker handler.
- *
- * @param callbackHandler
- */
- public void removeListener(InvokerCallbackHandler callbackHandler) {
- // NO OP as do not handling callback listeners in this example
- }
-
- /**
- * set the mbean server that the handler can reference
- *
- * @param server
- */
- public void setMBeanServer(MBeanServer server) {
- // NO OP as do not need reference to MBeanServer for this handler
- }
-
- /**
- * set the invoker that owns this handler
- *
- * @param invoker
- */
- public void setInvoker(ServerInvoker invoker) {
- // NO OP as do not need reference back to the server invoker
- }
-
- /**
- * Method getting the url this HttpListener instance is listening on
- *
- * @return the current listenHttpUrl
- */
- public String getListenHttpUrl() {
- return listenHttpUrl;
- }
-
- /**
- * Method setting the listenHttpUrl property to listen on
- *
- * @param listenHttpUrl
- * the listenHttpUrl to be used by this HttpListener instance
- */
- public void setListenHttpUrl(String listenHttpUrl) {
- this.listenHttpUrl = listenHttpUrl;
- }
-
- /**
- * Check for mandatory and optional attributes in parameter tree
- */
- private void checkParams() throws ConfigurationException {
- // listener url
- this.listenHttpUrl = this._config.getAttribute(LISTEN_HTTP_URL);
- if (this.listenHttpUrl == null) {
- this.listenHttpUrl = this.getDefaultListenHttpUrl();
- if (this.logger.isInfoEnabled()){
- this.logger
- .info("Attribute listenHttpUrl has not been set on the HttpListener. Using default "
- + this.getDefaultListenHttpUrl());
- }
- }
- }
-
- /**
- * Method returning the default listenHttpUrl for this HttpListener instance
- *
- * @return the default listen url
- */
- private String getDefaultListenHttpUrl() {
- return HttpListener.transport + "://" + HttpListener.host + ":"
- + HttpListener.port;
- }
-
- /**
- * Method initialising the remoting deamon
- *
- * @throws ListenerInitialisationException
- *
- * @throws ListenerInitializationException
- * when something goes wrong during remoting deamon startup
- */
- private void initServer() throws ListenerInitializationException {
- try {
- InvokerLocator locator = new InvokerLocator(this.listenHttpUrl);
- if (this.logger.isInfoEnabled()) {
- this.logger
- .info("Starting remoting server with locator uri of: "
- + this.listenHttpUrl);
- }
- Connector connector = new Connector(locator);
- connector.create();
-
- connector.addInvocationHandler("HttpInvocationHandler", this);
-
- // Starting the server deamon
- connector.start();
-
- if (this.logger.isInfoEnabled()) {
- this.logger.info("HttpListener deamon started successfully!");
- }
- } catch (Throwable thrown) {
- State newState = State.Exception_thrown;
- newState.setThrowable(thrown);
- throw new ListenerInitializationException(thrown.getMessage(), thrown);
- }
- }
-
- @Override
- public void waitForEventAndProcess(long maxWaitMillis) {
- // Not using this method in this AbstractManagedListener.
- try {
- Thread.sleep(maxWaitMillis);
- } catch (InterruptedException e) {
- logger.error("Unexpected interrupt exception.", e);
- }
- }
-
- /* (non-Javadoc)
- * @see org.jboss.soa.esb.listeners.AbstractManagedListener#isMessageAware()
- */
- @Override
- public boolean isMessageAware() {
- return true;
- }
-
- /* (non-Javadoc)
- * @see org.jboss.soa.esb.listeners.AbstractManagedListener#initializeRun()
- */
- @Override
- public boolean initializeRun() {
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.jboss.soa.esb.listeners.AbstractManagedListener#finalizeRun()
- */
- @Override
- public boolean finalizeRun() {
- return false;
- }
-
+ /**
+ * Handle the stop of the managed instance.
+ *
+ * @throws ManagedLifecycleException
+ * for errors while stopping.
+ */
+ protected void doStop()
+ throws ManagedLifecycleException
+ {
+ try
+ {
+ connector.stop() ;
+ connector.destroy() ;
+ }
+ finally
+ {
+ connector = null ;
+ }
+ executor.shutdown() ;
+ }
+
+ /**
+ * Handle the destroy of the managed instance.
+ *
+ * @throws ManagedLifecycleException for errors while destroying.
+ */
+ protected void doDestroy()
+ throws ManagedLifecycleException
+ {
+ checkExecutorTermination() ;
+ }
+
+ /**
+ * Check that the existing executor has been closed down.
+ * @throws ManagedLifecycleException If executor tasks are still active.
+ */
+ private void checkExecutorTermination()
+ throws ManagedLifecycleException
+ {
+ if (executor != null)
+ {
+ try
+ {
+ try
+ {
+ if (!executor.awaitTermination(getTerminationPeriod(), TimeUnit.MILLISECONDS))
+ {
+ throw new ManagedLifecycleException("Tasks remain active in executor") ;
+ }
+ }
+ catch (final InterruptedException ie)
+ {
+ throw new ManagedLifecycleException("Interrupted waiting for active tasks to terminate") ;
+ }
+ }
+ finally
+ {
+ executor = null ;
+ }
+ }
+ }
+
+ /*
+ * Method being invoked when a request comes in.
+ *
+ * (non-Javadoc)
+ *
+ * @see org.jboss.remoting.ServerInvocationHandler#invoke(org.jboss.remoting.InvocationRequest)
+ */
+ @SuppressWarnings("unchecked")
+ public Object invoke(InvocationRequest invocationRequest) throws Throwable {
+ Object payload = invocationRequest.getParameter();
+
+ if (logger.isInfoEnabled()) {
+ logger.info("HttpInvocationListener is invoked...The given payload is : " + payload);
+ }
+ if (payload instanceof Message){
+ final ActionProcessingPipeline pipelineRunner = new ActionProcessingPipeline((Message)payload, config) ;
+ executor.execute(pipelineRunner) ;
+ } else {
+ logger.error("Unsupported HttpListener message type: " + payload.getClass().getName());
+ }
+
+ return payload;
+ }
+ /**
+ * Adds a callback handler that will listen for callbacks from the server
+ * invoker handler.
+ *
+ * @param callbackHandler
+ */
+ public void addListener(InvokerCallbackHandler callbackHandler) {
+ // NO OP as do not handling callback listeners in this example
+ }
+
+ /**
+ * Removes the callback handler that was listening for callbacks from the
+ * server invoker handler.
+ *
+ * @param callbackHandler
+ */
+ public void removeListener(InvokerCallbackHandler callbackHandler) {
+ // NO OP as do not handling callback listeners in this example
+ }
+
+ /**
+ * set the mbean server that the handler can reference
+ *
+ * @param server
+ */
+ public void setMBeanServer(MBeanServer server) {
+ // NO OP as do not need reference to MBeanServer for this handler
+ }
+
+ /**
+ * set the invoker that owns this handler
+ *
+ * @param invoker
+ */
+ public void setInvoker(ServerInvoker invoker) {
+ // NO OP as do not need reference back to the server invoker
+ }
+
+ /**
+ * Method getting the url this HttpListener instance is listening on
+ *
+ * @return the current listenHttpUrl
+ */
+ public String getListenHttpUrl() {
+ return listenHttpUrl;
+ }
+
+ /**
+ * Method setting the listenHttpUrl property to listen on
+ *
+ * @param listenHttpUrl
+ * the listenHttpUrl to be used by this HttpListener instance
+ */
+ public void setListenHttpUrl(String listenHttpUrl) {
+ this.listenHttpUrl = listenHttpUrl;
+ }
+
+ /**
+ * Check for mandatory and optional attributes in parameter tree
+ */
+ private void checkParams()
+ throws ConfigurationException
+ {
+ // listener url
+ listenHttpUrl = config.getAttribute(LISTEN_HTTP_URL);
+ if (listenHttpUrl == null)
+ {
+ listenHttpUrl = getDefaultListenHttpUrl();
+ if (logger.isInfoEnabled())
+ {
+ logger.info("Attribute listenHttpUrl has not been set on the HttpListener. Using default "
+ + getDefaultListenHttpUrl());
+ }
+ }
+
+ final String maxThreadVal = config.getAttribute(ListenerTagNames.MAX_THREADS_TAG) ;
+
+ if (!Util.isNullString(maxThreadVal))
+ {
+ try
+ {
+ maxThreads = Integer.parseInt(maxThreadVal) ;
+ }
+ catch (NumberFormatException nfe)
+ {
+ maxThreads = defaultMaxThreads ;
+ logger.warn("Invalid " + ListenerTagNames.MAX_THREADS_TAG + " attribute, defaulting to <" + maxThreads + ">") ;
+ }
+ }
+ }
+
+ /**
+ * Method returning the default listenHttpUrl for this HttpListener instance
+ *
+ * @return the default listen url
+ */
+ private String getDefaultListenHttpUrl() {
+ return HttpListener.transport + "://" + HttpListener.host + ":"
+ + HttpListener.port;
+ }
}
Deleted: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/ListenerManagerService.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/ListenerManagerService.java 2007-01-30 06:44:10 UTC (rev 9118)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/ListenerManagerService.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -1,99 +0,0 @@
-/*
- * 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.listeners.message;
-
-import java.io.File;
-import java.net.URI;
-
-import org.apache.log4j.Logger;
-import org.jboss.soa.esb.listeners.ListenerManager;
-import org.jboss.soa.esb.listeners.ListenerUtil;
-import org.jboss.system.ServiceMBeanSupport;
-
-/**
- * Service supporting the listener manager service.
- */
-public class ListenerManagerService extends ServiceMBeanSupport implements ListenerManagerServiceMBean
-{
- /**
- * The logger instance.
- */
- private final Logger logger = Logger.getLogger(getClass()) ;
-
- /**
- * The listener manager.
- */
- private ListenerManager listenerManager ;
-
- /**
- * The message aware config file.
- */
- private String messageAwareConfigFile = "jbossesb-listener.xml" ;
-
- /**
- * Starts the listener manager service.
- * @throws Exception For errors
- */
- protected void startService()
- throws Exception
- {
- final String confURL = System.getProperty("jboss.server.config.url") ;
- final URI confDirURI = new URI(confURL) ;
- final File confDir = new File(confDirURI) ;
- final File configFile = new File(confDir, messageAwareConfigFile) ;
- final String configFilePath = configFile.getAbsolutePath() ;
- logger.info("Starting listener manager service, config file: " + configFilePath) ;
-
- listenerManager = ListenerUtil.launchManager(configFilePath, true) ;
- listenerManager.waitUntilReady() ;
- }
-
- /**
- * Stops the listener manager service.
- */
- protected void stopService()
- {
- logger.info("Stopping listener manager service") ;
- if (listenerManager != null)
- {
- listenerManager.requestEnd() ;
- }
- }
-
- /**
- * Get the message aware configuration file.
- * @return The message aware configuration file.
- */
- public String getMessageAwareConfigFile()
- {
- return messageAwareConfigFile ;
- }
-
- /**
- * Set the message aware configuration file.
- * @param messageAwareConfigFile The message aware configuration file.
- */
- public void setMessageAwareConfigFile(final String messageAwareConfigFile)
- {
- this.messageAwareConfigFile = messageAwareConfigFile ;
- }
-}
Deleted: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/ListenerManagerServiceMBean.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/ListenerManagerServiceMBean.java 2007-01-30 06:44:10 UTC (rev 9118)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/ListenerManagerServiceMBean.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -1,40 +0,0 @@
-/*
- * 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.listeners.message;
-
-import org.jboss.system.ServiceMBean;
-/**
- * Interface for listener manager service MBean
- */
-public interface ListenerManagerServiceMBean extends ServiceMBean
-{
- /**
- * Get the message aware configuration file.
- * @return The message aware configuration file.
- */
- public String getMessageAwareConfigFile() ;
- /**
- * Set the message aware configuration file.
- * @param messageAwareConfigFile The message aware configuration file.
- */
- public void setMessageAwareConfigFile(final String messageAwareConfigFile) ;
-}
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/MessageAwareListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/MessageAwareListener.java 2007-01-30 06:44:10 UTC (rev 9118)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/MessageAwareListener.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -23,19 +23,29 @@
package org.jboss.soa.esb.listeners.message;
import java.lang.reflect.Method;
+import java.util.Observable;
+import java.util.Observer;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import org.apache.log4j.Logger;
import org.jboss.internal.soa.esb.couriers.PickUpOnlyCourier;
import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.addressing.MalformedEPRException;
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.couriers.TwoWayCourier;
import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.listeners.AbstractManagedListener;
-import org.jboss.soa.esb.listeners.ListenerManager;
import org.jboss.soa.esb.listeners.ListenerTagNames;
import org.jboss.soa.esb.listeners.ListenerUtil;
+import org.jboss.soa.esb.listeners.RegistryUtil;
+import org.jboss.soa.esb.listeners.lifecycle.AbstractThreadedManagedLifecycle;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleThreadState;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.services.registry.RegistryException;
import org.jboss.soa.esb.util.Util;
@@ -51,23 +61,28 @@
* @since Version 4.0
*/
-public class MessageAwareListener extends AbstractManagedListener
+public class MessageAwareListener extends AbstractThreadedManagedLifecycle implements Observer
{
- /**
+ /**
+ * serial version uid for this class
+ */
+ private static final long serialVersionUID = -9198018611828254359L;
+
+ /**
* public constructor
*
- * @param controller
- * ListenerManager - the controlling process
* @param config
* ConfigTree - Containing 'static' configuration for this
* instance
* @throws ConfigurationException
*/
- public MessageAwareListener (ListenerManager controller, ConfigTree config)
+ public MessageAwareListener(final ConfigTree config)
throws ConfigurationException
{
- super(controller, config);
- } // _______________________________
+ super(config);
+ _config = config ;
+ checkMyParms() ;
+ }
/**
* Check for mandatory and optional attributes in parameter tree
@@ -78,8 +93,24 @@
*/
protected void checkMyParms () throws ConfigurationException
{
- super.checkMyParms();
+ _eprCategoryName = _config.getAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG);
+ _eprName = _config.getAttribute(ListenerTagNames.SERVICE_NAME_TAG);
+ final String maxThreadVal = _config.getAttribute(ListenerTagNames.MAX_THREADS_TAG) ;
+
+ if (!Util.isNullString(maxThreadVal))
+ {
+ try
+ {
+ _maxThreads = Integer.parseInt(maxThreadVal) ;
+ }
+ catch (NumberFormatException nfe)
+ {
+ _maxThreads = _defaultMaxThreads ;
+ _logger.warn("Invalid " + ListenerTagNames.MAX_THREADS_TAG + " attribute, defaulting to <" + _maxThreads + ">") ;
+ }
+ }
+
if (Util.isNullString(_eprCategoryName))
throw new ConfigurationException(
"Missing or invalid " + ListenerTagNames.SERVICE_CATEGORY_NAME_TAG);
@@ -92,114 +123,120 @@
throw new ConfigurationException(
"Missing or invalid " + ListenerTagNames.EPR_TAG + " element");
_epr = ListenerUtil.assembleEpr(eprElement);
- // _logger.debug(EPRHelper.toXMLString(_epr));
- } // ________________________________
-
- @Override
- public boolean isMessageAware ()
- {
- return true;
+
+ String latency = _config.getAttribute(ListenerTagNames.POLL_LATENCY_SECS_TAG);
+ long lSeconds = 10;
+ if (null != latency)
+ {
+ try
+ {
+ lSeconds = Integer.parseInt(latency);
+ }
+ catch (NumberFormatException e)
+ {
+ _logger.warn("Invalid number format <" + latency + "> using default value (" + lSeconds + ")");
+ }
+ }
+ _latencySecs = lSeconds ;
}
+
+ /**
+ * Handle the initialisation of the managed instance.
+ *
+ * @throws ManagedLifecycleException for errors while initialisation.
+ */
+ protected void doInitialise()
+ throws ManagedLifecycleException
+ {
+ final TwoWayCourier pickUpCourier ;
+ try
+ {
+ pickUpCourier = CourierFactory.getPickupCourier(_epr) ;
+ try
+ {
+ final Method setPollLatency = pickUpCourier.getClass().getMethod(
+ "setPollLatency", new Class[] { Long.class });
+ setPollLatency.invoke(pickUpCourier, new Long(1000 * _latencySecs));
+ }
+ catch (final NoSuchMethodException nsme)
+ {
+ // OK, just leave it null
+ }
+ catch (final Exception ex)
+ {
+ throw new ManagedLifecycleException("Problems invoking setPollLatency(long)", ex) ;
+ }
+ }
+ catch (final MalformedEPRException mepre)
+ {
+ throw new ManagedLifecycleException("Malformed EPR: " + _epr) ;
+ }
+ catch (final CourierException ce)
+ {
+ throw new ManagedLifecycleException("No appropriate courier can be obtained for " + _epr, ce);
+ }
+
+ _pickUpCourier = pickUpCourier ;
+
+ try
+ {
+ RegistryUtil.register(_config, _epr);
+ }
+ catch (final RegistryException re)
+ {
+ CourierUtil.cleanCourier(_pickUpCourier);
+ throw new ManagedLifecycleException("Unexpected error during registration for epr " + _epr, re);
+ }
+ }
+
+ /**
+ * Handle the start of the managed instance.
+ *
+ * @throws ManagedLifecycleException for errors while starting.
+ */
+ protected void doStart()
+ throws ManagedLifecycleException
+ {
+ checkExecutorTermination() ;
+
+ _execService = Executors.newFixedThreadPool(_maxThreads) ;
+
+ super.doStart() ;
+ }
+
+ /**
+ * Execute on the thread.
+ */
+ protected void doRun()
+ {
+ if (_logger.isDebugEnabled())
+ {
+ _logger.debug("doRun() method of " + this.getClass().getSimpleName()
+ + " started on thread " + Thread.currentThread().getName());
+ }
+
+ while (isRunning())
+ {
+ // Only pickup a message when a thread is available
+ if (getActiveThreadCount() >= _maxThreads)
+ {
+ waitForRunningStateChange(ManagedLifecycleThreadState.STOPPING, _pauseLapseInMillis) ;
+ }
+ else
+ {
+ waitForEventAndProcess(100) ;
+ }
+ }
+ if (null != _execService)
+ _execService.shutdown();
- @Override
- public boolean initializeRun ()
- {
- try
- {
- registerProcess();
- }
- catch (Exception re)
- {
- _logger.fatal("Could not register service " + re
- .getLocalizedMessage(), re);
- try
- {
- Thread.sleep(1000);
- }
- catch (Exception iE)
- {/* OK do nothing */
- }
- return false;
- }
- try
- {
- Method setPollLatency = null;
- _pickUpCourier = CourierFactory.getPickupCourier(_epr);
- try
- {
- setPollLatency = _pickUpCourier.getClass().getMethod(
- "setPollLatency", new Class[] { Long.class });
- }
- catch (NoSuchMethodException e)
- {
- // OK, just leave it null
- }
-
- if (null != setPollLatency)
- {
- String latency = _config
- .getAttribute(ListenerTagNames.POLL_LATENCY_SECS_TAG);
- long lSeconds = 10;
- if (null != latency)
- {
- try
- {
- lSeconds = Integer.parseInt(latency);
- }
- catch (NumberFormatException e)
- {
- _logger
- .warn("Invalid number format <" + latency + "> using default value (" + lSeconds + ")");
- }
- }
-
- try
- {
- setPollLatency.invoke(_pickUpCourier, new Long(
- 1000 * lSeconds));
- }
- catch (Exception e)
- {
- _logger.warn("Problems invoking setPollLatency(long)", e);
- return false;
- }
- }
-
- return true;
- }
- catch (MalformedEPRException ex)
- {
- _logger.fatal("Malformed EPR: " + _epr);
-
- return false;
- }
- catch (CourierException e)
- {
- _logger.fatal("No appropriate courier can be obtained for " + _epr
- .toString(), e);
- return false;
- }
- } // ________________________________
-
- @Override
- public boolean finalizeRun ()
- {
- try
- {
- CourierUtil.cleanCourier(_pickUpCourier);
- unregisterProcess();
- return true;
- }
- catch (RegistryException re)
- {
- _logger.warn("Could not un register service " + re
- .getLocalizedMessage());
- return false;
- }
-
- } // ________________________________
-
- @Override
+ if (_logger.isDebugEnabled())
+ {
+ _logger.debug("run() method of " + this.getClass().getSimpleName()
+ + " finished on thread " + Thread.currentThread().getName());
+ }
+ }
+
public void waitForEventAndProcess (long maxWaitMillis)
{
Message message = null;
@@ -237,6 +274,100 @@
}
} // ________________________________
+
+ /**
+ * Handle the destroy of the managed instance.
+ *
+ * @throws ManagedLifecycleException for errors while destroying.
+ */
+ protected void doDestroy()
+ throws ManagedLifecycleException
+ {
+ checkExecutorTermination() ;
+
+ CourierUtil.cleanCourier(_pickUpCourier);
+
+ RegistryUtil.unregister(_eprCategoryName, _eprName, _epr) ;
+ }
+
+ /**
+ * Check that the existing executor has been closed down.
+ * @throws ManagedLifecycleException If executor tasks are still active.
+ */
+ private void checkExecutorTermination()
+ throws ManagedLifecycleException
+ {
+ if (_execService != null)
+ {
+ try
+ {
+ try
+ {
+ if (!_execService.awaitTermination(getTerminationPeriod(), TimeUnit.MILLISECONDS))
+ {
+ throw new ManagedLifecycleException("Tasks remain active in executor") ;
+ }
+ }
+ catch (final InterruptedException ie)
+ {
+ throw new ManagedLifecycleException("Interrupted waiting for active tasks to terminate") ;
+ }
+ }
+ finally
+ {
+ _execService = null ;
+ }
+ }
+ }
+
+ // Child threads will send a -1 when their run() method ends
+ // we need to prevent picking up Messages when there are no available
+ // threads in pool
+ public void update(Observable o, Object arg)
+ {
+ if (arg instanceof Integer)
+ updateThreadCount((Integer) arg);
+ }
- protected PickUpOnlyCourier _pickUpCourier;
+ private int getActiveThreadCount()
+ {
+ synchronized (_synchThreads)
+ {
+ return _qRunningThreads ;
+ }
+ }
+
+ private void updateThreadCount(Integer i)
+ {
+ synchronized (_synchThreads)
+ {
+ _qRunningThreads += i.intValue();
+ }
+ }
+
+ private ConfigTree _config;
+
+ private String _eprCategoryName;
+
+ private String _eprName;
+
+ private EPR _epr;
+
+ private int _maxThreads;
+
+ private int _defaultMaxThreads;
+
+ private long _latencySecs;
+
+ private long _pauseLapseInMillis = 50 ;
+
+ private ExecutorService _execService;
+
+ private Object _synchThreads = new Short((short) -1);
+
+ private int _qRunningThreads;
+
+ private Logger _logger = Logger.getLogger(MessageAwareListener.class);
+
+ private PickUpOnlyCourier _pickUpCourier;
}
Modified: labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/ListenerManagerBaseTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/ListenerManagerBaseTest.java 2007-01-30 06:44:10 UTC (rev 9118)
+++ labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/ListenerManagerBaseTest.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -190,8 +190,6 @@
}
};
- ListenerManager _manager;
-
private static String mDbDriver;
private static String mDbUrl;
Modified: labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/ListenerManagerFTPIntegrationTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/ListenerManagerFTPIntegrationTest.java 2007-01-30 06:44:10 UTC (rev 9118)
+++ labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/ListenerManagerFTPIntegrationTest.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -24,6 +24,7 @@
import java.io.FileInputStream;
import java.net.URI;
+import java.util.List;
import java.util.UUID;
import junit.framework.Assert;
@@ -35,6 +36,8 @@
import org.jboss.soa.esb.addressing.eprs.FileEpr;
import org.jboss.soa.esb.couriers.CourierFactory;
import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleController;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycle;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.format.MessageFactory;
@@ -95,10 +98,10 @@
_returnFile.delete();
- // launch listener manager in a child thread
- _manager = ListenerUtil.launchManager(tree, true);
- _logger.debug("Waiting for all child listeners to start");
- _manager.waitUntilReady();
+ final List<ManagedLifecycle> instances = LifecycleUtil.getListeners(tree) ;
+ final ManagedLifecycleController controller = new ManagedLifecycleController(instances) ;
+ controller.start() ;
+
_logger.debug(" All child listeners ready");
// JUST FOR THIS TEST:
@@ -110,12 +113,12 @@
Thread.sleep(250 * howMany);
- _logger.debug("going to EndRequested");
- _manager.requestEnd();
- _logger.debug("back from EndRequested");
+ _logger.debug("going to stop");
+ controller.stop();
+ _logger.debug("back from stop");
Assert.assertEquals(THE_TEXT, stringFromFile(_returnFile));
-
+
_returnFile.delete();
}
Modified: labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/ListenerManagerFileUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/ListenerManagerFileUnitTest.java 2007-01-30 06:44:10 UTC (rev 9118)
+++ labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/ListenerManagerFileUnitTest.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -25,6 +25,7 @@
import java.io.File;
import java.io.FileInputStream;
import java.net.URI;
+import java.util.List;
import java.util.UUID;
import org.jboss.internal.soa.esb.couriers.DeliverOnlyCourier;
@@ -33,6 +34,8 @@
import org.jboss.soa.esb.addressing.eprs.FileEpr;
import org.jboss.soa.esb.couriers.CourierFactory;
import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleController;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycle;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.format.MessageFactory;
@@ -133,9 +136,11 @@
configFile));
final ConfigTree newTreeEPRElement = newTree.getAllChildren()[0].getFirstChild("EPR");
newTreeEPRElement.setAttribute(ListenerTagNames.URL_TAG, tmpDirForm) ;
- _manager = ListenerUtil.launchManager(newTree, true);
- _logger.debug("Waiting for all child listeners to start");
- _manager.waitUntilReady();
+
+ final List<ManagedLifecycle> instances = LifecycleUtil.getListeners(newTree) ;
+ final ManagedLifecycleController controller = new ManagedLifecycleController(instances) ;
+ controller.start() ;
+
_logger.debug(" All child listeners ready");
// JUST FOR THIS TEST:
@@ -147,9 +152,9 @@
Thread.sleep(150 * howMany);
- _logger.debug("going to EndRequested");
- _manager.requestEnd();
- _logger.debug("back from EndRequested");
+ _logger.debug("going to stop");
+ controller.stop();
+ _logger.debug("back from stop");
assertEquals(THE_TEXT, stringFromFile(_returnFile));
Modified: labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/ListenerManagerJDBCUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/ListenerManagerJDBCUnitTest.java 2007-01-30 06:44:10 UTC (rev 9118)
+++ labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/ListenerManagerJDBCUnitTest.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -26,6 +26,7 @@
import java.net.URI;
import java.sql.SQLException;
import java.sql.Statement;
+import java.util.List;
import java.util.UUID;
import org.jboss.internal.soa.esb.couriers.DeliverOnlyCourier;
@@ -34,6 +35,8 @@
import org.jboss.soa.esb.addressing.eprs.JDBCEpr;
import org.jboss.soa.esb.couriers.CourierFactory;
import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleController;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycle;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.format.MessageFactory;
@@ -130,9 +133,10 @@
eprElement.setAttribute("username", getDbUser());
eprElement.setAttribute("password", getDbPassword());
- _manager = ListenerUtil.launchManager(newTree, true);
- _logger.debug("Waiting for all child listeners to start");
- _manager.waitUntilReady();
+ final List<ManagedLifecycle> instances = LifecycleUtil.getListeners(newTree) ;
+ final ManagedLifecycleController controller = new ManagedLifecycleController(instances) ;
+ controller.start() ;
+
_logger.debug(" All child listeners ready");
// JUST FOR THIS TEST:
@@ -144,9 +148,9 @@
Thread.sleep(150 * howMany);
- _logger.debug("going to EndRequested");
- _manager.requestEnd();
- _logger.debug("back from EndRequested");
+ _logger.debug("going to stop");
+ controller.stop();
+ _logger.debug("back from stop");
assertEquals(THE_TEXT, stringFromFile(_returnFile));
Modified: labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/ListenerManagerJMSXntegrationTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/ListenerManagerJMSXntegrationTest.java 2007-01-30 06:44:10 UTC (rev 9118)
+++ labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/ListenerManagerJMSXntegrationTest.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -24,6 +24,7 @@
import java.io.FileInputStream;
import java.net.URI;
+import java.util.List;
import java.util.UUID;
import junit.framework.Assert;
@@ -34,6 +35,8 @@
import org.jboss.soa.esb.addressing.eprs.JMSEpr;
import org.jboss.soa.esb.couriers.CourierFactory;
import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleController;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycle;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.format.MessageFactory;
@@ -112,9 +115,10 @@
final ConfigTree newTree = ConfigTree.fromInputStream(new FileInputStream(
configFile));
- _manager = ListenerUtil.launchManager(newTree, true);
- _logger.debug("Waiting for all child listeners to start");
- _manager.waitUntilReady();
+ final List<ManagedLifecycle> instances = LifecycleUtil.getListeners(newTree) ;
+ final ManagedLifecycleController controller = new ManagedLifecycleController(instances) ;
+ controller.start() ;
+
_logger.debug(" All child listeners ready");
// JUST FOR THIS TEST:
@@ -126,9 +130,9 @@
Thread.sleep(150 * howMany);
- _logger.debug("going to EndRequested");
- _manager.requestEnd();
- _logger.debug("back from EndRequested");
+ _logger.debug("going to stop");
+ controller.stop();
+ _logger.debug("back from stop");
Assert.assertEquals(THE_TEXT, stringFromFile(_returnFile));
Modified: labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerControllerBaseTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerControllerBaseTest.java 2007-01-30 06:44:10 UTC (rev 9118)
+++ labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerControllerBaseTest.java 2007-01-30 07:32:29 UTC (rev 9119)
@@ -38,8 +38,6 @@
public class GatewayListenerControllerBaseTest extends BaseTest
{
- GatewayListenerController _controller;
-
private static String mDbDriver;
private static String mDbUrl;
Modified: labs/jbossesb/trunk/product/install/jboss-service.xml
===================================================================
--- labs/jbossesb/trunk/product/install/jboss-service.xml 2007-01-30 06:44:10 UTC (rev 9118)
+++ labs/jbossesb/trunk/product/install/jboss-service.xml 2007-01-30 07:32:29 UTC (rev 9119)
@@ -8,25 +8,8 @@
<attribute name="ConfigurationFile">jbossesb.xml</attribute>
<depends>jboss.org:service=JBossESBDependencies</depends>
<depends>jboss.org:service=JuddiRMI</depends>
- </mbean>
- <!-- Starts the listener controler -->
- <mbean code="org.jboss.soa.esb.listeners.message.ListenerManagerService"
- name="jboss.org:service=ListenerManager"
- description="ESB Aware Listener">
- <attribute name="MessageAwareConfigFile">jbossesb-listener.xml</attribute>
- <depends>jboss.org:service=JBossESBDependencies</depends>
- <depends>jboss.org:service=ConfigurationController</depends>
<depends>jboss.jca:service=DataSourceBinding,name=JBossESBDS</depends>
</mbean>
- <!-- Starts the gateway controller -->
- <mbean code="org.jboss.soa.esb.listeners.gateway.GatewayListenerControllerService"
- name="jboss.org:service=GatewayListenerController"
- description="Gateway Listener">
- <attribute name="GatewayConfigFile">jbossesb-gateway.xml</attribute>
- <depends>jboss.org:service=JBossESBDependencies</depends>
- <depends>jboss.jca:service=DataSourceBinding,name=JBossESBDS</depends>
- <depends>jboss.org:service=ListenerManager</depends>
- </mbean>
<loader-repository>
org.jboss.soa.esb:loader=jbossesb.sar
</loader-repository>
More information about the jboss-svn-commits
mailing list