From: Scott M S. <st...@us...> - 2004-12-29 22:56:31
|
User: starksm Date: 04/12/29 14:56:19 Modified: src/main/org/jboss/mx/notification Tag: Branch_3_2 AsynchNotificationBroadcasterSupport.java Log: Update to use the org.jboss.util.threadpool version of the thread pool and allow for instance specific notification completion timeout and thread pool. Revision Changes Path No revision No revision 1.3.2.5 +82 -7 jmx/src/main/org/jboss/mx/notification/AsynchNotificationBroadcasterSupport.java Index: AsynchNotificationBroadcasterSupport.java =================================================================== RCS file: /cvsroot/jboss/jmx/src/main/org/jboss/mx/notification/AsynchNotificationBroadcasterSupport.java,v retrieving revision 1.3.2.4 retrieving revision 1.3.2.5 diff -u -r1.3.2.4 -r1.3.2.5 --- AsynchNotificationBroadcasterSupport.java 21 Oct 2004 13:57:22 -0000 1.3.2.4 +++ AsynchNotificationBroadcasterSupport.java 29 Dec 2004 22:56:15 -0000 1.3.2.5 @@ -11,35 +11,97 @@ import org.jboss.logging.Logger; import org.jboss.mx.util.JBossNotificationBroadcasterSupport; -import org.jboss.mx.util.ThreadPool; +import org.jboss.util.threadpool.BasicThreadPool; +import org.jboss.util.threadpool.ThreadPool; /** * A notification broadcaster with asynch notifications * * @author <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>. - * @version $Revision: 1.3.2.4 $ + * @author Sco...@jb... + * @version $Revision: 1.3.2.5 $ */ public class AsynchNotificationBroadcasterSupport extends JBossNotificationBroadcasterSupport { // Attributes ---------------------------------------------------- - private static Logger log = Logger.getLogger(AsynchNotifier.class); + /** The default pool used in the absence of on instance specific one */ + private static ThreadPool defaultPool = new BasicThreadPool("AsynchNotificationBroadcasterSupport"); + /** The default comp*/ + private static long defaultNotificationTimeout; + + /** The instance */ + private long notificationTimeout; + private ThreadPool pool; + + public static synchronized void setDefaultThreadPool(ThreadPool tp) + { + defaultPool = tp; + } - private static ThreadPool pool = new ThreadPool(true); + public static long getDefaultNotificationTimeout() + { + return defaultNotificationTimeout; + } + public static void setDefaultNotificationTimeout(long defaultNotificationTimeout) + { + AsynchNotificationBroadcasterSupport.defaultNotificationTimeout = defaultNotificationTimeout; + } // Constructor --------------------------------------------------- /** * Construct a new Asyncrhonous broadcaster + * Calls this(defaultNotificationTimeout, defaultPool) */ public AsynchNotificationBroadcasterSupport() { - super(); + this(defaultNotificationTimeout, defaultPool); + } + /** + * Construct a new Asyncrhonous broadcaster. Calls + * this(notificationTimeout, defaultPool) + * @param notificationTimeout the notification completion timeout in MS. A + * 0 value means no timeout. + */ + public AsynchNotificationBroadcasterSupport(long notificationTimeout) + { + this(notificationTimeout, defaultPool); + } + /** + * Construct a new Asyncrhonous broadcaster + * @param notificationTimeout - the notification completion timeout in MS. A + * 0 value means no timeout. + * @param pool - the thread pool to use for the asynchronous notifcations + */ + public AsynchNotificationBroadcasterSupport(long notificationTimeout, + ThreadPool pool) + { + this.notificationTimeout = notificationTimeout; + this.pool = pool; } // Public -------------------------------------------------------- + public long getNotificationTimeout() + { + return notificationTimeout; + } + public void setNotificationTimeout(long notificationTimeout) + { + this.notificationTimeout = notificationTimeout; + } + + public ThreadPool getThreadPool() + { + return pool; + } + public void setThreadPool(ThreadPool pool) + { + this.pool = pool; + } + // NotificationBroadcasterSupport overrides ---------------------- /** @@ -53,12 +115,25 @@ Notification notification, Object handback) { - pool.run(new AsynchNotifier(listener, notification, handback)); + AsynchNotifier notifier = new AsynchNotifier(listener, notification, handback); + pool.run(notifier, 0, notificationTimeout); + } + + /** Invoke stop on the thread pool if its not the class default pool. + * + * @param immeadiate the immeadiate flag passed to the TheadPool#stop + */ + protected void stopThreadPool(boolean immeadiate) + { + if( pool != defaultPool ) + { + pool.stop(immeadiate); + } } // Inner classes ------------------------------------------------- - public static class AsynchNotifier + public class AsynchNotifier implements Runnable { NotificationListener listener; |