You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2007/03/30 15:29:53 UTC
svn commit: r524080 -
/cocoon/trunk/core/cocoon-thread/cocoon-thread-impl/src/main/java/org/apache/cocoon/components/thread/DefaultRunnableManager.java
Author: reinhard
Date: Fri Mar 30 06:29:52 2007
New Revision: 524080
URL: http://svn.apache.org/viewvc?view=rev&rev=524080
Log:
formatting
Modified:
cocoon/trunk/core/cocoon-thread/cocoon-thread-impl/src/main/java/org/apache/cocoon/components/thread/DefaultRunnableManager.java
Modified: cocoon/trunk/core/cocoon-thread/cocoon-thread-impl/src/main/java/org/apache/cocoon/components/thread/DefaultRunnableManager.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-thread/cocoon-thread-impl/src/main/java/org/apache/cocoon/components/thread/DefaultRunnableManager.java?view=diff&rev=524080&r1=524079&r2=524080
==============================================================================
--- cocoon/trunk/core/cocoon-thread/cocoon-thread-impl/src/main/java/org/apache/cocoon/components/thread/DefaultRunnableManager.java (original)
+++ cocoon/trunk/core/cocoon-thread/cocoon-thread-impl/src/main/java/org/apache/cocoon/components/thread/DefaultRunnableManager.java Fri Mar 30 06:29:52 2007
@@ -35,9 +35,9 @@
* The configuration of the <code>DefaultRunnableManager</code>:
*
* <pre>
- * <property name="workerThreadPools">
- * <configurator:bean-map type="org.apache.cocoon.components.thread.ThreadPool" strip-prefix="true"/>
- * </property>
+ * <property name="workerThreadPools">
+ * <configurator:bean-map type="org.apache.cocoon.components.thread.ThreadPool" strip-prefix="true"/>
+ * </property>
* </pre>
*
* </p>
@@ -45,8 +45,7 @@
* @version $Id: DefaultRunnableManager.java 498489 2007-01-21 23:19:09Z
* jjohnston $
*/
-public class DefaultRunnableManager implements InitializingBean,
- RunnableManager, Runnable {
+public class DefaultRunnableManager implements InitializingBean, RunnableManager, Runnable {
// ~ Static fields/initializers
// ---------------------------------------------
@@ -58,9 +57,9 @@
// --------------------------------------------------------
/**
- * Sorted set of <code>ExecutionInfo</code> instances, based on their
- * next execution time.
- */
+ * Sorted set of <code>ExecutionInfo</code> instances, based on their next
+ * execution time.
+ */
protected SortedSet commandStack = new TreeSet();
/** The managed thread pools */
@@ -76,558 +75,523 @@
// ----------------------------------------------------------------
public Log getLogger() {
- return this.logger;
+ return this.logger;
}
public void setLogger(Log l) {
- this.logger = l;
+ this.logger = l;
}
/**
- * Initialize
- */
+ * Initialize
+ */
public void afterPropertiesSet() throws Exception {
- if (workerThreadPools != null) {
- final Iterator iter = workerThreadPools.keySet().iterator();
- while (iter.hasNext()) {
- final String key = (String) iter.next();
- final ThreadPool pool = (ThreadPool) workerThreadPools.get(key);
- synchronized (pools) {
- pools.put(pool.getName(), pool);
- }
- }
- }
-
- // Check if a "default" pool has been created
- final ThreadPool defaultThreadPool = (ThreadPool) pools
- .get(ThreadPool.DEFAULT_THREADPOOL_NAME);
-
- if (null == defaultThreadPool) {
- createPool(ThreadPool.DEFAULT_THREADPOOL_NAME,
- ThreadPool.DEFAULT_QUEUE_SIZE,
- ThreadPool.DEFAULT_MAX_POOL_SIZE,
- ThreadPool.DEFAULT_MIN_POOL_SIZE,
- convertPriority(ThreadPool.DEFAULT_THREAD_PRIORITY),
- ThreadPool.DEFAULT_DAEMON_MODE,
- ThreadPool.DEFAULT_KEEP_ALIVE_TIME,
- ThreadPool.DEFAULT_BLOCK_POLICY,
- ThreadPool.DEFAULT_SHUTDOWN_GRACEFUL,
- ThreadPool.DEFAULT_SHUTDOWN_WAIT_TIME);
- }
- // now start
- this.start();
- }
-
- /**
- * Create a shared ThreadPool
- *
- * @param name
- * The name of the thread pool
- * @param queueSize
- * The size of the queue
- * @param maxPoolSize
- * The maximum number of threads
- * @param minPoolSize
- * The maximum number of threads
- * @param priority
- * The priority of threads created by this pool. This is
- * one of {@link Thread#MIN_PRIORITY},
- * {@link Thread#NORM_PRIORITY}, or
- * {@link Thread#MAX_PRIORITY}
- * @param isDaemon
- * Whether or not thread from the pool should run in
- * daemon mode
- * @param keepAliveTime
- * How long should a thread be alive for new work to be
- * done before it is GCed
- * @param blockPolicy
- * What's the blocking policy is resources are exhausted
- * @param shutdownGraceful
- * Should we wait for the queue to finish all pending
- * commands?
- * @param shutdownWaitTime
- * After what time a normal shutdown should take into
- * account if a graceful shutdown has not come to an end
- *
- * @throws IllegalArgumentException
- * If the pool already exists
- */
- public void createPool(final String name, final int queueSize,
- final int maxPoolSize, final int minPoolSize, final int priority,
- final boolean isDaemon, final long keepAliveTime,
- final String blockPolicy, final boolean shutdownGraceful,
- final int shutdownWaitTimeMs) {
- if (null != pools.get(name)) {
- throw new IllegalArgumentException("ThreadPool \"" + name
- + "\" already exists");
- }
-
- final ThreadPool pool = new DefaultThreadPool();
- pool.setName(name);
- pool.setQueueSize(queueSize);
- pool.setMaxPoolSize(maxPoolSize);
- pool.setMinPoolSize(minPoolSize);
- pool.setPriority(priority);
- pool.setDaemon(isDaemon);
- pool.setBlockPolicy(blockPolicy);
- pool.setShutdownGraceful(shutdownGraceful);
- pool.setShutdownWaitTimeMs(shutdownWaitTimeMs);
- synchronized (pools) {
- pools.put(pool.getName(), pool);
- }
- }
+ if (workerThreadPools != null) {
+ final Iterator iter = workerThreadPools.keySet().iterator();
+ while (iter.hasNext()) {
+ final String key = (String) iter.next();
+ final ThreadPool pool = (ThreadPool) workerThreadPools.get(key);
+ synchronized (pools) {
+ pools.put(pool.getName(), pool);
+ }
+ }
+ }
+
+ // Check if a "default" pool has been created
+ final ThreadPool defaultThreadPool = (ThreadPool) pools.get(ThreadPool.DEFAULT_THREADPOOL_NAME);
+
+ if (null == defaultThreadPool) {
+ createPool(ThreadPool.DEFAULT_THREADPOOL_NAME, ThreadPool.DEFAULT_QUEUE_SIZE,
+ ThreadPool.DEFAULT_MAX_POOL_SIZE, ThreadPool.DEFAULT_MIN_POOL_SIZE,
+ convertPriority(ThreadPool.DEFAULT_THREAD_PRIORITY), ThreadPool.DEFAULT_DAEMON_MODE,
+ ThreadPool.DEFAULT_KEEP_ALIVE_TIME, ThreadPool.DEFAULT_BLOCK_POLICY,
+ ThreadPool.DEFAULT_SHUTDOWN_GRACEFUL, ThreadPool.DEFAULT_SHUTDOWN_WAIT_TIME);
+ }
+ // now start
+ this.start();
+ }
+
+ /**
+ * Create a shared ThreadPool
+ *
+ * @param name
+ * The name of the thread pool
+ * @param queueSize
+ * The size of the queue
+ * @param maxPoolSize
+ * The maximum number of threads
+ * @param minPoolSize
+ * The maximum number of threads
+ * @param priority
+ * The priority of threads created by this pool. This is one of
+ * {@link Thread#MIN_PRIORITY}, {@link Thread#NORM_PRIORITY},
+ * or {@link Thread#MAX_PRIORITY}
+ * @param isDaemon
+ * Whether or not thread from the pool should run in daemon mode
+ * @param keepAliveTime
+ * How long should a thread be alive for new work to be done
+ * before it is GCed
+ * @param blockPolicy
+ * What's the blocking policy is resources are exhausted
+ * @param shutdownGraceful
+ * Should we wait for the queue to finish all pending commands?
+ * @param shutdownWaitTime
+ * After what time a normal shutdown should take into account if
+ * a graceful shutdown has not come to an end
+ *
+ * @throws IllegalArgumentException
+ * If the pool already exists
+ */
+ public void createPool(final String name, final int queueSize, final int maxPoolSize, final int minPoolSize,
+ final int priority, final boolean isDaemon, final long keepAliveTime, final String blockPolicy,
+ final boolean shutdownGraceful, final int shutdownWaitTimeMs) {
+ if (null != pools.get(name)) {
+ throw new IllegalArgumentException("ThreadPool \"" + name + "\" already exists");
+ }
+
+ final ThreadPool pool = new DefaultThreadPool();
+ pool.setName(name);
+ pool.setQueueSize(queueSize);
+ pool.setMaxPoolSize(maxPoolSize);
+ pool.setMinPoolSize(minPoolSize);
+ pool.setPriority(priority);
+ pool.setDaemon(isDaemon);
+ pool.setBlockPolicy(blockPolicy);
+ pool.setShutdownGraceful(shutdownGraceful);
+ pool.setShutdownWaitTimeMs(shutdownWaitTimeMs);
+ synchronized (pools) {
+ pools.put(pool.getName(), pool);
+ }
+ }
+
+ /**
+ * Create a private ThreadPool
+ *
+ * @param queueSize
+ * The size of the queue
+ * @param maxPoolSize
+ * The maximum number of threads
+ * @param minPoolSize
+ * The maximum number of threads
+ * @param priority
+ * The priority of threads created by this pool. This is one of
+ * {@link Thread#MIN_PRIORITY}, {@link Thread#NORM_PRIORITY},
+ * or {@link Thread#MAX_PRIORITY}
+ * @param isDaemon
+ * Whether or not thread from the pool should run in daemon mode
+ * @param keepAliveTime
+ * How long should a thread be alive for new work to be done
+ * before it is GCed
+ * @param blockPolicy
+ * What's the blocking policy is resources are exhausted
+ * @param shutdownGraceful
+ * Should we wait for the queue to finish all pending commands?
+ * @param shutdownWaitTime
+ * After what time a normal shutdown should take into account if
+ * a graceful shutdown has not come to an end
+ *
+ * @return A newly created <code>ThreadPool</code>
+ */
+ public ThreadPool createPool(final int queueSize, final int maxPoolSize, final int minPoolSize, final int priority,
+ final boolean isDaemon, final long keepAliveTime, final String blockPolicy,
+ final boolean shutdownGraceful, final int shutdownWaitTime) {
+ final ThreadPool pool = new DefaultThreadPool();
+ final String name = "anon-" + pool.hashCode();
+ pool.setName(name);
+ pool.setQueueSize(queueSize);
+ pool.setMaxPoolSize(maxPoolSize);
+ pool.setMinPoolSize(minPoolSize);
+ pool.setPriority(priority);
+ pool.setDaemon(isDaemon);
+ pool.setKeepAliveTime(keepAliveTime);
+ pool.setBlockPolicy(blockPolicy);
+ pool.setShutdownGraceful(shutdownGraceful);
+ synchronized (pools) {
+ pools.put(pool.getName(), pool);
+ }
- /**
- * Create a private ThreadPool
- *
- * @param queueSize
- * The size of the queue
- * @param maxPoolSize
- * The maximum number of threads
- * @param minPoolSize
- * The maximum number of threads
- * @param priority
- * The priority of threads created by this pool. This is
- * one of {@link Thread#MIN_PRIORITY},
- * {@link Thread#NORM_PRIORITY}, or
- * {@link Thread#MAX_PRIORITY}
- * @param isDaemon
- * Whether or not thread from the pool should run in
- * daemon mode
- * @param keepAliveTime
- * How long should a thread be alive for new work to be
- * done before it is GCed
- * @param blockPolicy
- * What's the blocking policy is resources are exhausted
- * @param shutdownGraceful
- * Should we wait for the queue to finish all pending
- * commands?
- * @param shutdownWaitTime
- * After what time a normal shutdown should take into
- * account if a graceful shutdown has not come to an end
- *
- * @return A newly created <code>ThreadPool</code>
- */
- public ThreadPool createPool(final int queueSize, final int maxPoolSize,
- final int minPoolSize, final int priority, final boolean isDaemon,
- final long keepAliveTime, final String blockPolicy,
- final boolean shutdownGraceful, final int shutdownWaitTime) {
- final ThreadPool pool = new DefaultThreadPool();
- final String name = "anon-" + pool.hashCode();
- pool.setName(name);
- pool.setQueueSize(queueSize);
- pool.setMaxPoolSize(maxPoolSize);
- pool.setMinPoolSize(minPoolSize);
- pool.setPriority(priority);
- pool.setDaemon(isDaemon);
- pool.setKeepAliveTime(keepAliveTime);
- pool.setBlockPolicy(blockPolicy);
- pool.setShutdownGraceful(shutdownGraceful);
- synchronized (pools) {
- pools.put(pool.getName(), pool);
- }
-
- return pool;
+ return pool;
}
/**
- * Destroy
- */
+ * Destroy
+ */
public void destroy() throws Exception {
- this.stop();
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Disposing all thread pools");
- }
-
- for (final Iterator i = pools.keySet().iterator(); i.hasNext();) {
- final String poolName = (String) i.next();
- final DefaultThreadPool pool = (DefaultThreadPool) pools
- .get(poolName);
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Disposing thread pool " + pool.getName());
- }
-
- pool.shutdown();
-
- if (getLogger().isDebugEnabled()) {
- getLogger()
- .debug("Thread pool " + pool.getName() + " disposed");
- }
- }
-
- try {
- pools.clear();
- } catch (final Throwable t) {
- getLogger().error("Cannot dispose", t);
- }
- }
-
- /**
- * Run a {@link Runnable} in the background using a {@link ThreadPool}
- *
- * @param threadPoolName
- * The thread pool name to be used
- * @param command
- * The {@link Runnable} to execute
- * @param delay
- * the delay befor first run
- * @param interval
- * The interval for repeated runs
- *
- * @throws IllegalArgumentException
- * DOCUMENT ME!
- */
- public void execute(final String threadPoolName, final Runnable command,
- final long delay, long interval) {
- if (delay < 0) {
- throw new IllegalArgumentException("delay < 0");
- }
-
- if (interval < 0) {
- throw new IllegalArgumentException("interval < 0");
- }
-
- ThreadPool pool = (ThreadPool) pools.get(threadPoolName);
-
- if (null == pool) {
- getLogger().warn(
- "ThreadPool \"" + threadPoolName
- + "\" is not known. Will use ThreadPool \""
- + ThreadPool.DEFAULT_THREADPOOL_NAME + "\"");
- pool = (ThreadPool) pools.get(ThreadPool.DEFAULT_THREADPOOL_NAME);
- }
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug(
- "Command entered: " + command + ", pool="
- + (null == pool ? "null" : pool.getName())
- + ", delay=" + delay + ", interval=" + interval);
- }
-
- new ExecutionInfo(pool, command, delay, interval, getLogger());
- }
-
- /**
- * Run a {@link Runnable} in the background using a {@link ThreadPool}
- *
- * @param command
- * The {@link Runnable} to execute
- * @param delay
- * the delay befor first run
- * @param interval
- * The interval for repeated runs
- */
- public void execute(final Runnable command, final long delay,
- final long interval) {
- execute(ThreadPool.DEFAULT_THREADPOOL_NAME, command, delay, interval);
- }
-
- /**
- * Run a {@link Runnable} in the background using a {@link ThreadPool}
- *
- * @param command
- * The {@link Runnable} to execute
- * @param delay
- * the delay befor first run
- */
+ this.stop();
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Disposing all thread pools");
+ }
+
+ for (final Iterator i = pools.keySet().iterator(); i.hasNext();) {
+ final String poolName = (String) i.next();
+ final DefaultThreadPool pool = (DefaultThreadPool) pools.get(poolName);
+
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Disposing thread pool " + pool.getName());
+ }
+
+ pool.shutdown();
+
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Thread pool " + pool.getName() + " disposed");
+ }
+ }
+
+ try {
+ pools.clear();
+ } catch (final Throwable t) {
+ getLogger().error("Cannot dispose", t);
+ }
+ }
+
+ /**
+ * Run a {@link Runnable} in the background using a {@link ThreadPool}
+ *
+ * @param threadPoolName
+ * The thread pool name to be used
+ * @param command
+ * The {@link Runnable} to execute
+ * @param delay
+ * the delay befor first run
+ * @param interval
+ * The interval for repeated runs
+ *
+ * @throws IllegalArgumentException
+ * DOCUMENT ME!
+ */
+ public void execute(final String threadPoolName, final Runnable command, final long delay, long interval) {
+ if (delay < 0) {
+ throw new IllegalArgumentException("delay < 0");
+ }
+
+ if (interval < 0) {
+ throw new IllegalArgumentException("interval < 0");
+ }
+
+ ThreadPool pool = (ThreadPool) pools.get(threadPoolName);
+
+ if (null == pool) {
+ getLogger().warn(
+ "ThreadPool \"" + threadPoolName + "\" is not known. Will use ThreadPool \""
+ + ThreadPool.DEFAULT_THREADPOOL_NAME + "\"");
+ pool = (ThreadPool) pools.get(ThreadPool.DEFAULT_THREADPOOL_NAME);
+ }
+
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug(
+ "Command entered: " + command + ", pool=" + (null == pool ? "null" : pool.getName())
+ + ", delay=" + delay + ", interval=" + interval);
+ }
+
+ new ExecutionInfo(pool, command, delay, interval, getLogger());
+ }
+
+ /**
+ * Run a {@link Runnable} in the background using a {@link ThreadPool}
+ *
+ * @param command
+ * The {@link Runnable} to execute
+ * @param delay
+ * the delay befor first run
+ * @param interval
+ * The interval for repeated runs
+ */
+ public void execute(final Runnable command, final long delay, final long interval) {
+ execute(ThreadPool.DEFAULT_THREADPOOL_NAME, command, delay, interval);
+ }
+
+ /**
+ * Run a {@link Runnable} in the background using a {@link ThreadPool}
+ *
+ * @param command
+ * The {@link Runnable} to execute
+ * @param delay
+ * the delay befor first run
+ */
public void execute(final Runnable command, final long delay) {
- execute(ThreadPool.DEFAULT_THREADPOOL_NAME, command, delay, 0);
+ execute(ThreadPool.DEFAULT_THREADPOOL_NAME, command, delay, 0);
}
/**
- * Run a {@link Runnable} in the background using a {@link ThreadPool}
- *
- * @param command
- * The {@link Runnable} to execute
- */
+ * Run a {@link Runnable} in the background using a {@link ThreadPool}
+ *
+ * @param command
+ * The {@link Runnable} to execute
+ */
public void execute(final Runnable command) {
- execute(ThreadPool.DEFAULT_THREADPOOL_NAME, command, 0, 0);
+ execute(ThreadPool.DEFAULT_THREADPOOL_NAME, command, 0, 0);
}
/**
- * Run a {@link Runnable} in the background using a {@link ThreadPool}
- *
- * @param threadPoolName
- * The thread pool name to be used
- * @param command
- * The {@link Runnable} to execute
- * @param delay
- * the delay befor first run
- */
- public void execute(final String threadPoolName, final Runnable command,
- final long delay) {
- execute(threadPoolName, command, delay, 0);
+ * Run a {@link Runnable} in the background using a {@link ThreadPool}
+ *
+ * @param threadPoolName
+ * The thread pool name to be used
+ * @param command
+ * The {@link Runnable} to execute
+ * @param delay
+ * the delay befor first run
+ */
+ public void execute(final String threadPoolName, final Runnable command, final long delay) {
+ execute(threadPoolName, command, delay, 0);
}
/**
- * Run a {@link Runnable} in the background using a {@link ThreadPool}
- *
- * @param threadPoolName
- * The thread pool name to be used
- * @param command
- * The {@link Runnable} to execute
- */
+ * Run a {@link Runnable} in the background using a {@link ThreadPool}
+ *
+ * @param threadPoolName
+ * The thread pool name to be used
+ * @param command
+ * The {@link Runnable} to execute
+ */
public void execute(final String threadPoolName, final Runnable command) {
- execute(threadPoolName, command, 0, 0);
+ execute(threadPoolName, command, 0, 0);
}
/**
- * Remove a <code>Runnable</code> from the command stack
- *
- * @param command
- * The <code>Runnable</code> to be removed
- */
+ * Remove a <code>Runnable</code> from the command stack
+ *
+ * @param command
+ * The <code>Runnable</code> to be removed
+ */
public void remove(Runnable command) {
- synchronized (commandStack) {
- for (final Iterator i = commandStack.iterator(); i.hasNext();) {
- final ExecutionInfo info = (ExecutionInfo) i.next();
+ synchronized (commandStack) {
+ for (final Iterator i = commandStack.iterator(); i.hasNext();) {
+ final ExecutionInfo info = (ExecutionInfo) i.next();
- if (info.m_command == command) {
- i.remove();
- commandStack.notifyAll();
+ if (info.m_command == command) {
+ i.remove();
+ commandStack.notifyAll();
- return;
- }
- }
- }
+ return;
+ }
+ }
+ }
- getLogger().warn("Could not find command " + command + " for removal");
+ getLogger().warn("Could not find command " + command + " for removal");
}
/**
- * The heart of the command manager
- */
+ * The heart of the command manager
+ */
public void run() {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Entering loop");
- }
-
- while (keepRunning) {
- synchronized (commandStack) {
- try {
- if (commandStack.size() > 0) {
- final ExecutionInfo info = (ExecutionInfo) commandStack
- .first();
- final long delay = info.m_nextRun
- - System.currentTimeMillis();
-
- if (delay > 0) {
- commandStack.wait(delay);
- }
- } else {
- if (getLogger().isDebugEnabled()) {
- getLogger()
- .debug(
- "No commands available. Will just wait for one");
- }
-
- commandStack.wait();
- }
- } catch (final InterruptedException ie) {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("I've been interrupted");
- }
- }
-
- if (keepRunning) {
- if (commandStack.size() > 0) {
- final ExecutionInfo info = (ExecutionInfo) commandStack
- .first();
- final long delay = info.m_nextRun
- - System.currentTimeMillis();
-
- if (delay < 0) {
- info.execute();
- }
- }
- }
- }
- }
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Exiting loop");
- }
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Entering loop");
+ }
+
+ while (keepRunning) {
+ synchronized (commandStack) {
+ try {
+ if (commandStack.size() > 0) {
+ final ExecutionInfo info = (ExecutionInfo) commandStack.first();
+ final long delay = info.m_nextRun - System.currentTimeMillis();
+
+ if (delay > 0) {
+ commandStack.wait(delay);
+ }
+ } else {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("No commands available. Will just wait for one");
+ }
+
+ commandStack.wait();
+ }
+ } catch (final InterruptedException ie) {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("I've been interrupted");
+ }
+ }
+
+ if (keepRunning) {
+ if (commandStack.size() > 0) {
+ final ExecutionInfo info = (ExecutionInfo) commandStack.first();
+ final long delay = info.m_nextRun - System.currentTimeMillis();
+
+ if (delay < 0) {
+ info.execute();
+ }
+ }
+ }
+ }
+ }
+
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Exiting loop");
+ }
}
/**
- * Start the managing thread
- *
- * @throws Exception
- * DOCUMENT ME!
- */
+ * Start the managing thread
+ *
+ * @throws Exception
+ * DOCUMENT ME!
+ */
protected void start() throws Exception {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Starting the heart");
- }
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Starting the heart");
+ }
- keepRunning = true;
- ((ThreadPool) pools.get(ThreadPool.DEFAULT_THREADPOOL_NAME))
- .execute(this);
+ keepRunning = true;
+ ((ThreadPool) pools.get(ThreadPool.DEFAULT_THREADPOOL_NAME)).execute(this);
}
/**
- * Stop the managing thread
- */
+ * Stop the managing thread
+ */
protected void stop() {
- keepRunning = false;
+ keepRunning = false;
- synchronized (commandStack) {
- commandStack.notifyAll();
- }
+ synchronized (commandStack) {
+ commandStack.notifyAll();
+ }
}
/**
- * DOCUMENT ME!
- *
- * @param priority
- * The priority to set as string value.
- *
- * @return The priority as int value.
- */
+ * DOCUMENT ME!
+ *
+ * @param priority
+ * The priority to set as string value.
+ *
+ * @return The priority as int value.
+ */
private int convertPriority(final String priority) {
- if ("MIN".equalsIgnoreCase(priority)) {
- return Thread.MIN_PRIORITY;
- } else if ("NORM".equalsIgnoreCase(priority)) {
- return Thread.NORM_PRIORITY;
- } else if ("MAX".equalsIgnoreCase(priority)) {
- return Thread.MAX_PRIORITY;
- } else {
- getLogger().warn(
- "Unknown thread priority \"" + priority
- + "\". Set to \"NORM\".");
+ if ("MIN".equalsIgnoreCase(priority)) {
+ return Thread.MIN_PRIORITY;
+ } else if ("NORM".equalsIgnoreCase(priority)) {
+ return Thread.NORM_PRIORITY;
+ } else if ("MAX".equalsIgnoreCase(priority)) {
+ return Thread.MAX_PRIORITY;
+ } else {
+ getLogger().warn("Unknown thread priority \"" + priority + "\". Set to \"NORM\".");
- return Thread.NORM_PRIORITY;
- }
+ return Thread.NORM_PRIORITY;
+ }
}
// ~ Inner Classes
// ----------------------------------------------------------
/**
- * The $classType$ class ...
- *
- * @version $Id: DefaultRunnableManager.java 498489 2007-01-21 23:19:09Z
- * jjohnston $
- */
+ * The $classType$ class ...
+ *
+ * @version $Id: DefaultRunnableManager.java 498489 2007-01-21 23:19:09Z
+ * jjohnston $
+ */
private class ExecutionInfo implements Comparable {
- // ~ Instance fields
- // ----------------------------------------------------
+ // ~ Instance fields
+ // ----------------------------------------------------
- /** Our logger */
- final Log m_logger;
+ /** Our logger */
+ final Log m_logger;
- /** DOCUMENT ME! */
- final Runnable m_command;
+ /** DOCUMENT ME! */
+ final Runnable m_command;
- /** DOCUMENT ME! */
- final ThreadPool m_pool;
+ /** DOCUMENT ME! */
+ final ThreadPool m_pool;
- /** DOCUMENT ME! */
- final long m_delay;
+ /** DOCUMENT ME! */
+ final long m_delay;
- /** DOCUMENT ME! */
- final long m_interval;
+ /** DOCUMENT ME! */
+ final long m_interval;
- /** DOCUMENT ME! */
- long m_nextRun = 0;
+ /** DOCUMENT ME! */
+ long m_nextRun = 0;
- // ~ Constructors
- // -------------------------------------------------------
+ // ~ Constructors
+ // -------------------------------------------------------
- /**
+ /**
* Creates a new ExecutionInfo object.
*
* @param pool
- * DOCUMENT ME!
+ * DOCUMENT ME!
* @param command
- * DOCUMENT ME!
+ * DOCUMENT ME!
* @param delay
- * DOCUMENT ME!
+ * DOCUMENT ME!
* @param interval
- * DOCUMENT ME!
+ * DOCUMENT ME!
* @param logger
- * DOCUMENT ME!
+ * DOCUMENT ME!
*/
- ExecutionInfo(final ThreadPool pool, final Runnable command,
- final long delay, final long interval, final Log logger) {
- m_pool = pool;
- m_command = command;
- m_delay = delay;
- m_interval = interval;
- m_logger = logger;
- m_nextRun = System.currentTimeMillis() + delay;
-
- synchronized (commandStack) {
- commandStack.add(this);
- commandStack.notifyAll();
- }
- Thread.yield(); // Give others a chance to run
- }
+ ExecutionInfo(final ThreadPool pool, final Runnable command, final long delay, final long interval,
+ final Log logger) {
+ m_pool = pool;
+ m_command = command;
+ m_delay = delay;
+ m_interval = interval;
+ m_logger = logger;
+ m_nextRun = System.currentTimeMillis() + delay;
+
+ synchronized (commandStack) {
+ commandStack.add(this);
+ commandStack.notifyAll();
+ }
+ Thread.yield(); // Give others a chance to run
+ }
- // ~ Methods
- // ------------------------------------------------------------
+ // ~ Methods
+ // ------------------------------------------------------------
- /**
+ /**
* DOCUMENT ME!
*
* @param other
- * DOCUMENT ME!
+ * DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
- public int compareTo(final Object other) {
- final ExecutionInfo otherInfo = (ExecutionInfo) other;
- int diff = (int) (m_nextRun - otherInfo.m_nextRun);
- if (diff == 0) {
- if (this == other) {
- // Same object, return 0.
- return 0;
- } else {
- // NOT the same object, MUST return non-0 value.
- return System.identityHashCode(this)
- - System.identityHashCode(other);
- }
- }
- return diff;
- }
+ public int compareTo(final Object other) {
+ final ExecutionInfo otherInfo = (ExecutionInfo) other;
+ int diff = (int) (m_nextRun - otherInfo.m_nextRun);
+ if (diff == 0) {
+ if (this == other) {
+ // Same object, return 0.
+ return 0;
+ } else {
+ // NOT the same object, MUST return non-0 value.
+ return System.identityHashCode(this) - System.identityHashCode(other);
+ }
+ }
+ return diff;
+ }
- /**
+ /**
* DOCUMENT ME!
*/
- void execute() {
- if (m_logger.isDebugEnabled()) {
- m_logger.debug("Executing command " + m_command + " in pool \""
- + m_pool.getName() + "\", schedule with interval="
- + m_interval);
- }
-
- synchronized (commandStack) {
- commandStack.remove(this);
- if (m_interval > 0) {
- m_nextRun = System.currentTimeMillis() + m_interval;
- commandStack.add(this);
- }
- }
-
- try {
- m_pool.execute(m_command);
- } catch (final InterruptedException ie) {
- if (m_logger.isDebugEnabled()) {
- m_logger.debug("Interrupted executing command + "
- + m_command);
- }
- } catch (final Throwable t) {
- m_logger.error("Exception executing command " + m_command, t);
- }
- }
+ void execute() {
+ if (m_logger.isDebugEnabled()) {
+ m_logger.debug("Executing command " + m_command + " in pool \"" + m_pool.getName()
+ + "\", schedule with interval=" + m_interval);
+ }
+
+ synchronized (commandStack) {
+ commandStack.remove(this);
+ if (m_interval > 0) {
+ m_nextRun = System.currentTimeMillis() + m_interval;
+ commandStack.add(this);
+ }
+ }
+
+ try {
+ m_pool.execute(m_command);
+ } catch (final InterruptedException ie) {
+ if (m_logger.isDebugEnabled()) {
+ m_logger.debug("Interrupted executing command + " + m_command);
+ }
+ } catch (final Throwable t) {
+ m_logger.error("Exception executing command " + m_command, t);
+ }
+ }
}
/**
- * @param workerThreadPools
- * the workerThreadPools to set
- */
+ * @param workerThreadPools
+ * the workerThreadPools to set
+ */
public void setWorkerThreadPools(Map workerThreadPools) {
- this.workerThreadPools = workerThreadPools;
+ this.workerThreadPools = workerThreadPools;
}
}
Re: svn commit: r524080 - /cocoon/trunk/core/cocoon-thread/cocoon-thread-impl/src/main/java/org/apache/cocoon/components/thread/DefaultRunnableManager.java
Posted by Felix Knecht <fe...@otego.com>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I had a deeper look into the given settings and it seems that a kind
of mix between spaces and tabs is given by default.
Sorry - I'll do my very best to upgrade myself ;-)
Felix
> Felix Knecht wrote:
>> Does exists a CodeStyle template for formatting I can load in
>> Eclipse to avoid needed reformatting?
>>
>> I took the CodeStyle 'Java Conventions [built-in]' from Eclipse
>> 3.2 supposing this is the same as metnioned
>> @http://cocoon.apache.org/community/committer.html (Sun Java
>> Style Guide).
>
> Don't know about eclipse but I noticed that you used tabs instead
> of spaces. Cocoon's standard for indentation is 4 spaces.
>
> Vadim
>
>
>> Felix
>>
>>
>> reinhard@apache.org schrieb:
>>> Author: reinhard Date: Fri Mar 30 06:29:52 2007 New Revision:
>>> 524080
>>>
>>> URL: http://svn.apache.org/viewvc?view=rev&rev=524080 Log:
>>> formatting
>>>
>>> Modified:
>>>
>>>
cocoon/trunk/core/cocoon-thread/cocoon-thread-impl/src/main/java/org/apache/cocoon/components/thread/DefaultRunnableManager.java
>>>
>>>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFGDRii2lZVCB08qHERAkIuAJ4sJyxwjVJspAjr8QfZ3d8tmL56gACeOtzg
A4SWy/UH79Gxj2MViiUKdjI=
=8Tuy
-----END PGP SIGNATURE-----
Re: svn commit: r524080 - /cocoon/trunk/core/cocoon-thread/cocoon-thread-impl/src/main/java/org/apache/cocoon/components/thread/DefaultRunnableManager.java
Posted by Felix Knecht <fe...@apache.org>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I had a deeper look into the given settings and it seems that a kind
of mix between spaces and tabs is given by default.
Sorry - I'll do my very best to upgrade myself ;-)
Felix
> Felix Knecht wrote:
>> Does exists a CodeStyle template for formatting I can load in
>> Eclipse to avoid needed reformatting?
>>
>> I took the CodeStyle 'Java Conventions [built-in]' from Eclipse
>> 3.2 supposing this is the same as metnioned
>> @http://cocoon.apache.org/community/committer.html (Sun Java
>> Style Guide).
>
> Don't know about eclipse but I noticed that you used tabs instead
> of spaces. Cocoon's standard for indentation is 4 spaces.
>
> Vadim
>
>
>> Felix
>>
>>
>> reinhard@apache.org schrieb:
>>> Author: reinhard Date: Fri Mar 30 06:29:52 2007 New Revision:
>>> 524080
>>>
>>> URL: http://svn.apache.org/viewvc?view=rev&rev=524080 Log:
>>> formatting
>>>
>>> Modified:
>>>
>>>
cocoon/trunk/core/cocoon-thread/cocoon-thread-impl/src/main/java/org/apache/cocoon/components/thread/DefaultRunnableManager.java
>>>
>>>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFGDRii2lZVCB08qHERAkIuAJ4sJyxwjVJspAjr8QfZ3d8tmL56gACeOtzg
A4SWy/UH79Gxj2MViiUKdjI=
=8Tuy
-----END PGP SIGNATURE-----
Re: svn commit: r524080 - /cocoon/trunk/core/cocoon-thread/cocoon-thread-impl/src/main/java/org/apache/cocoon/components/thread/DefaultRunnableManager.java
Posted by Vadim Gritsenko <va...@reverycodes.com>.
Felix Knecht wrote:
> Does exists a CodeStyle template for formatting I can load in Eclipse to
> avoid needed reformatting?
>
> I took the CodeStyle 'Java Conventions [built-in]' from Eclipse 3.2
> supposing this is the same as metnioned
> @http://cocoon.apache.org/community/committer.html (Sun Java Style Guide).
Don't know about eclipse but I noticed that you used tabs instead of spaces.
Cocoon's standard for indentation is 4 spaces.
Vadim
> Felix
>
>
> reinhard@apache.org schrieb:
>> Author: reinhard
>> Date: Fri Mar 30 06:29:52 2007
>> New Revision: 524080
>>
>> URL: http://svn.apache.org/viewvc?view=rev&rev=524080
>> Log:
>> formatting
>>
>> Modified:
>> cocoon/trunk/core/cocoon-thread/cocoon-thread-impl/src/main/java/org/apache/cocoon/components/thread/DefaultRunnableManager.java
Re: svn commit: r524080 - /cocoon/trunk/core/cocoon-thread/cocoon-thread-impl/src/main/java/org/apache/cocoon/components/thread/DefaultRunnableManager.java
Posted by Reinhard Poetz <re...@apache.org>.
Felix Knecht wrote:
> Does exists a CodeStyle template for formatting I can load in Eclipse to
> avoid needed reformatting?
>
> I took the CodeStyle 'Java Conventions [built-in]' from Eclipse 3.2
> supposing this is the same as metnioned
> @http://cocoon.apache.org/community/committer.html (Sun Java Style Guide).
At least for me the line intention was totally funny and the code was unreadable.
I also use the Java Convetions by Eclipse and only set tabs as spaces only and
the line width to 120 characters.
--
Reinhard Pötz Independent Consultant, Trainer & (IT)-Coach
{Software Engineering, Open Source, Web Applications, Apache Cocoon}
web(log): http://www.poetz.cc
--------------------------------------------------------------------
Re: svn commit: r524080 - /cocoon/trunk/core/cocoon-thread/cocoon-thread-impl/src/main/java/org/apache/cocoon/components/thread/DefaultRunnableManager.java
Posted by Felix Knecht <fe...@apache.org>.
Does exists a CodeStyle template for formatting I can load in Eclipse to
avoid needed reformatting?
I took the CodeStyle 'Java Conventions [built-in]' from Eclipse 3.2
supposing this is the same as metnioned
@http://cocoon.apache.org/community/committer.html (Sun Java Style Guide).
Felix
reinhard@apache.org schrieb:
> Author: reinhard
> Date: Fri Mar 30 06:29:52 2007
> New Revision: 524080
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=524080
> Log:
> formatting
>
> Modified:
> cocoon/trunk/core/cocoon-thread/cocoon-thread-impl/src/main/java/org/apache/cocoon/components/thread/DefaultRunnableManager.java
>
>