[jboss-cvs] JBossAS SVN: r91903 - projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jul 31 19:16:59 EDT 2009
Author: david.lloyd at jboss.com
Date: 2009-07-31 19:16:59 -0400 (Fri, 31 Jul 2009)
New Revision: 91903
Added:
projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/CleanupExecutor.java
projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/CompositeTask.java
projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/DelegatingWrappingExecutor.java
projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/DiscardingExecutor.java
projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/ExecutorTask.java
projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/HandoffRejectedExecutionHandler.java
projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/LoggingUncaughtExceptionHandler.java
projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/RejectingExecutor.java
projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/SimpleDirectExecutor.java
Modified:
projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/InitializingExecutor.java
projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossExecutors.java
projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossThread.java
projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/WrappingExecutor.java
projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/WrappingThreadFactory.java
Log:
A bunch more API cleanup
Copied: projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/CleanupExecutor.java (from rev 91879, projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/InitializingExecutor.java)
===================================================================
--- projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/CleanupExecutor.java (rev 0)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/CleanupExecutor.java 2009-07-31 23:16:59 UTC (rev 91903)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.threads;
+
+class CleanupExecutor implements DirectExecutor {
+
+ private final Runnable cleaner;
+ private final DirectExecutor delegate;
+
+ CleanupExecutor(final Runnable cleaner, final DirectExecutor delegate) {
+ this.cleaner = cleaner;
+ this.delegate = delegate;
+ }
+
+ public void execute(final Runnable command) {
+ try {
+ delegate.execute(command);
+ } finally {
+ cleaner.run();
+ }
+ }
+
+ public String toString() {
+ return String.format("%s (cleanup task=%s) -> %s", super.toString(), cleaner, delegate);
+ }
+}
\ No newline at end of file
Added: projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/CompositeTask.java
===================================================================
--- projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/CompositeTask.java (rev 0)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/CompositeTask.java 2009-07-31 23:16:59 UTC (rev 91903)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.threads;
+
+final class CompositeTask implements Runnable {
+
+ private final Runnable[] runnables;
+
+ CompositeTask(final Runnable[] runnables) {
+ this.runnables = runnables;
+ }
+
+ public void run() {
+ for (Runnable runnable : runnables) {
+ runnable.run();
+ }
+ }
+
+ public String toString() {
+ return String.format("%s (%d task(s))", super.toString(), Integer.valueOf(runnables.length));
+ }
+}
Added: projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/DelegatingWrappingExecutor.java
===================================================================
--- projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/DelegatingWrappingExecutor.java (rev 0)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/DelegatingWrappingExecutor.java 2009-07-31 23:16:59 UTC (rev 91903)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.threads;
+
+import java.util.concurrent.Executor;
+import java.util.concurrent.RejectedExecutionException;
+
+class DelegatingWrappingExecutor implements WrappingExecutor {
+
+ private final Executor delegate;
+
+ DelegatingWrappingExecutor(final Executor delegate) {
+ this.delegate = delegate;
+ }
+
+ public void execute(final DirectExecutor directExecutor, final Runnable task) throws RejectedExecutionException {
+ delegate.execute(JBossExecutors.executorTask(directExecutor, task));
+ }
+
+ public String toString() {
+ return String.format("%s -> %s", super.toString(), delegate);
+ }
+}
Added: projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/DiscardingExecutor.java
===================================================================
--- projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/DiscardingExecutor.java (rev 0)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/DiscardingExecutor.java 2009-07-31 23:16:59 UTC (rev 91903)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.threads;
+
+class DiscardingExecutor implements DirectExecutor {
+ static final DiscardingExecutor INSTANCE = new DiscardingExecutor();
+
+ private DiscardingExecutor() {
+ }
+
+ public void execute(final Runnable command) {
+ // nothing
+ }
+
+ public String toString() {
+ return "Discarding executor";
+ }
+}
Added: projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/ExecutorTask.java
===================================================================
--- projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/ExecutorTask.java (rev 0)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/ExecutorTask.java 2009-07-31 23:16:59 UTC (rev 91903)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.threads;
+
+class ExecutorTask implements Runnable {
+
+ private final DirectExecutor executor;
+ private final Runnable task;
+
+ ExecutorTask(final DirectExecutor executor, final Runnable task) {
+ this.executor = executor;
+ this.task = task;
+ }
+
+ public void run() {
+ executor.execute(task);
+ }
+
+ public String toString() {
+ return String.format("%s (Task %s via %s)", super.toString(), task, executor);
+ }
+}
Added: projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/HandoffRejectedExecutionHandler.java
===================================================================
--- projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/HandoffRejectedExecutionHandler.java (rev 0)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/HandoffRejectedExecutionHandler.java 2009-07-31 23:16:59 UTC (rev 91903)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.threads;
+
+import java.util.concurrent.RejectedExecutionHandler;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ThreadPoolExecutor;
+
+class HandoffRejectedExecutionHandler implements RejectedExecutionHandler {
+
+ private final Executor target;
+
+ HandoffRejectedExecutionHandler(final Executor target) {
+ this.target = target;
+ }
+
+ public void rejectedExecution(final Runnable r, final ThreadPoolExecutor executor) {
+ target.execute(r);
+ }
+
+ public String toString() {
+ return String.format("%s -> %s", super.toString(), target);
+ }
+}
Modified: projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/InitializingExecutor.java
===================================================================
--- projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/InitializingExecutor.java 2009-07-31 22:26:53 UTC (rev 91902)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/InitializingExecutor.java 2009-07-31 23:16:59 UTC (rev 91903)
@@ -38,6 +38,6 @@
}
public String toString() {
- return String.format("%s (task=%s) -> %s", super.toString(), initializer, delegate);
+ return String.format("%s (init task=%s) -> %s", super.toString(), initializer, delegate);
}
}
Modified: projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossExecutors.java
===================================================================
--- projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossExecutors.java 2009-07-31 22:26:53 UTC (rev 91902)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossExecutors.java 2009-07-31 23:16:59 UTC (rev 91903)
@@ -24,11 +24,11 @@
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ScheduledExecutorService;
+import java.util.Collection;
import java.security.PrivilegedAction;
import java.security.AccessController;
import java.security.AccessControlContext;
@@ -37,7 +37,7 @@
import org.jboss.logging.Logger;
/**
- *
+ * JBoss thread- and executor-related utility and factory methods.
*/
public final class JBossExecutors {
@@ -54,40 +54,10 @@
}
});
- private static final DirectExecutor DIRECT_EXECUTOR = new DirectExecutor() {
- public void execute(final Runnable command) {
- command.run();
- }
+ private static final DirectExecutorService DIRECT_EXECUTOR_SERVICE = new ProtectedDirectExecutorService(SimpleDirectExecutor.INSTANCE);
+ private static final DirectExecutorService REJECTING_EXECUTOR_SERVICE = new ProtectedDirectExecutorService(RejectingExecutor.INSTANCE);
+ private static final DirectExecutorService DISCARDING_EXECUTOR_SERVICE = new ProtectedDirectExecutorService(DiscardingExecutor.INSTANCE);
- public String toString() {
- return "Direct executor";
- }
- };
-
- private static final DirectExecutor REJECTING_EXECUTOR = new DirectExecutor() {
- public void execute(final Runnable command) {
- throw new RejectedExecutionException();
- }
-
- public String toString() {
- return "Rejecting executor";
- }
- };
-
- private static final DirectExecutor DISCARDING_EXECUTOR = new DirectExecutor() {
- public void execute(final Runnable command) {
- // nothing
- }
-
- public String toString() {
- return "Discarding executor";
- }
- };
-
- private static final DirectExecutorService DIRECT_EXECUTOR_SERVICE = new ProtectedDirectExecutorService(DIRECT_EXECUTOR);
- private static final DirectExecutorService REJECTING_EXECUTOR_SERVICE = new ProtectedDirectExecutorService(REJECTING_EXECUTOR);
- private static final DirectExecutorService DISCARDING_EXECUTOR_SERVICE = new ProtectedDirectExecutorService(DISCARDING_EXECUTOR);
-
// ==================================================
// DIRECT EXECUTORS
// ==================================================
@@ -99,7 +69,7 @@
* @return the direct executor instance
*/
public static DirectExecutor directExecutor() {
- return DIRECT_EXECUTOR;
+ return SimpleDirectExecutor.INSTANCE;
}
/**
@@ -118,7 +88,7 @@
* @return the rejecting executor instance
*/
public static DirectExecutor rejectingExecutor() {
- return REJECTING_EXECUTOR;
+ return RejectingExecutor.INSTANCE;
}
/**
@@ -136,7 +106,7 @@
* @return the discarding executor instance
*/
public static DirectExecutor discardingExecutor() {
- return DISCARDING_EXECUTOR;
+ return DiscardingExecutor.INSTANCE;
}
/**
@@ -247,20 +217,31 @@
* @throws SecurityException if the caller does not have the {@link RuntimePermission}{@code ("modifyThread")} permission
*/
public static DirectExecutor resettingExecutor(final DirectExecutor delegate) throws SecurityException {
- return initializingExecutor(threadLocalResetter(), delegate);
+ return cleanupExecutor(delegate, threadLocalResetter());
}
/**
* Create an executor which runs the given initization task before running its given task.
*
+ * @param delegate the delegate direct executor
* @param initializer the initialization task
- * @param delegate the delegate direct executor
* @return an initializing executor
*/
- public static DirectExecutor initializingExecutor(final Runnable initializer, final DirectExecutor delegate) {
+ public static DirectExecutor initializingExecutor(final DirectExecutor delegate, final Runnable initializer) {
return new InitializingExecutor(initializer, delegate);
}
+ /**
+ * Create an executor which runs the given cleanup task after running its given task.
+ *
+ * @param delegate the delegate direct executor
+ * @param cleaner the cleanup task
+ * @return an initializing executor
+ */
+ public static DirectExecutor cleanupExecutor(final DirectExecutor delegate, final Runnable cleaner) {
+ return new CleanupExecutor(cleaner, delegate);
+ }
+
// ==================================================
// EXECUTORS
// ==================================================
@@ -268,29 +249,36 @@
/**
* An executor which delegates to another executor, wrapping each task in a task wrapper.
*
+ * @param taskWrapper the task wrapper
* @param delegate the delegate executor
- * @param taskWrapper the task wrapper
* @return a wrapping executor
*/
- public static Executor wrappingExecutor(final Executor delegate, final DirectExecutor taskWrapper) {
- return new Executor() {
- public void execute(final Runnable command) {
- delegate.execute(executorTask(taskWrapper, command));
- }
- };
+ public static Executor wrappingExecutor(final DirectExecutor taskWrapper, final Executor delegate) {
+ return executor(wrappingExecutor(delegate), taskWrapper);
}
/**
- * An executor which delegates to another executor, wrapping each task in a task wrapper.
+ * Create a wrapping executor for a delegate executor which creates an {@link #executorTask(DirectExecutor, Runnable)} for
+ * each task.
*
* @param delegate the delegate executor
+ * @return the wrapping executor
+ */
+ public static WrappingExecutor wrappingExecutor(final Executor delegate) {
+ return new DelegatingWrappingExecutor(delegate);
+ }
+
+ /**
+ * An executor which delegates to a wrapping executor, wrapping each task in a task wrapper.
+ *
+ * @param delegate the delegate executor
* @param taskWrapper the task wrapper
* @return a wrapping executor
*/
- public static Executor wrappingExecutor(final WrappingExecutor delegate, final DirectExecutor taskWrapper) {
+ public static Executor executor(final WrappingExecutor delegate, final DirectExecutor taskWrapper) {
return new Executor() {
public void execute(final Runnable command) {
- delegate.execute(command, taskWrapper);
+ delegate.execute(taskWrapper, command);
}
};
}
@@ -362,11 +350,7 @@
* @return the new handoff policy implementation
*/
public static RejectedExecutionHandler handoffPolicy(final Executor target) {
- return new RejectedExecutionHandler() {
- public void rejectedExecution(final Runnable r, final ThreadPoolExecutor executor) {
- target.execute(r);
- }
- };
+ return new HandoffRejectedExecutionHandler(target);
}
// ==================================================
@@ -493,14 +477,18 @@
// ignore
}
}
+
+ public String toString() {
+ return "Thread-local resetting Runnable";
+ }
}
- private static final Runnable NULL_RUNNABLE = new NullRunnable();
-
// ==================================================
// RUNNABLES
// ==================================================
+ private static final Runnable NULL_RUNNABLE = new NullRunnable();
+
/**
* Get the null runnable which does nothing.
*
@@ -542,17 +530,58 @@
* @return an encapsulating task
*/
public static Runnable executorTask(final DirectExecutor executor, final Runnable task) {
- return new Runnable() {
- public void run() {
- executor.execute(task);
- }
- };
+ return new ExecutorTask(executor, task);
}
+ /**
+ * Create a task that is a composite of several other tasks.
+ *
+ * @param runnables the tasks
+ * @return the composite task
+ */
+ public static Runnable compositeTask(final Runnable... runnables) {
+ return new CompositeTask(runnables.clone());
+ }
+
+ /**
+ * Create a task that is a composite of several other tasks.
+ *
+ * @param runnables the tasks
+ * @return the composite task
+ */
+ public static Runnable compositeTask(final Collection<Runnable> runnables) {
+ return new CompositeTask(runnables.toArray(new Runnable[runnables.size()]));
+ }
+
private static void checkAccess(Permission permission) {
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(permission);
}
}
+
+ // ==================================================
+ // UNCAUGHT EXCEPTION HANDLERS
+ // ==================================================
+
+ /**
+ * Get an uncaught exception handler which logs to the given logger.
+ *
+ * @param log the logger
+ * @return the handler
+ */
+ public static Thread.UncaughtExceptionHandler loggingExceptionHandler(final Logger log) {
+ return new LoggingUncaughtExceptionHandler(log);
+ }
+
+ private static final Thread.UncaughtExceptionHandler LOGGING_HANDLER = loggingExceptionHandler(THREAD_ERROR_LOGGER);
+
+ /**
+ * Get an uncaught exception handler which logs to the default error logger.
+ *
+ * @return the handler
+ */
+ public static Thread.UncaughtExceptionHandler loggingExceptionHandler() {
+ return LOGGING_HANDLER;
+ }
}
Modified: projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossThread.java
===================================================================
--- projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossThread.java 2009-07-31 22:26:53 UTC (rev 91902)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/JBossThread.java 2009-07-31 23:16:59 UTC (rev 91903)
@@ -25,7 +25,7 @@
import org.jboss.logging.Logger;
/**
- * A JBoss thread. Supports extra logging and operations.
+ * A JBoss thread. Supports logging and extra operations.
*/
public final class JBossThread extends Thread {
private static final Logger log = Logger.getLogger(JBossThread.class);
Added: projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/LoggingUncaughtExceptionHandler.java
===================================================================
--- projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/LoggingUncaughtExceptionHandler.java (rev 0)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/LoggingUncaughtExceptionHandler.java 2009-07-31 23:16:59 UTC (rev 91903)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.threads;
+
+import org.jboss.logging.Logger;
+
+class LoggingUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
+
+ private final Logger log;
+
+ LoggingUncaughtExceptionHandler(final Logger log) {
+ this.log = log;
+ }
+
+ public void uncaughtException(final Thread thread, final Throwable throwable) {
+ log.errorf(throwable, "Thread %s threw an uncaught exception", thread);
+ }
+
+ public String toString() {
+ return String.format("%s to \"%s\"", super.toString(), log.getName());
+ }
+}
Added: projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/RejectingExecutor.java
===================================================================
--- projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/RejectingExecutor.java (rev 0)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/RejectingExecutor.java 2009-07-31 23:16:59 UTC (rev 91903)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.threads;
+
+import java.util.concurrent.RejectedExecutionException;
+
+class RejectingExecutor implements DirectExecutor {
+ static final RejectingExecutor INSTANCE = new RejectingExecutor();
+
+ private RejectingExecutor() {
+ }
+
+ public void execute(final Runnable command) {
+ throw new RejectedExecutionException();
+ }
+
+ public String toString() {
+ return "Rejecting executor";
+ }
+}
Added: projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/SimpleDirectExecutor.java
===================================================================
--- projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/SimpleDirectExecutor.java (rev 0)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/SimpleDirectExecutor.java 2009-07-31 23:16:59 UTC (rev 91903)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.threads;
+
+class SimpleDirectExecutor implements DirectExecutor {
+
+ static DirectExecutor INSTANCE = new SimpleDirectExecutor();
+
+ private SimpleDirectExecutor() {
+ }
+
+ public void execute(final Runnable command) {
+ command.run();
+ }
+
+ public String toString() {
+ return "Direct executor";
+ }
+}
Modified: projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/WrappingExecutor.java
===================================================================
--- projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/WrappingExecutor.java 2009-07-31 22:26:53 UTC (rev 91902)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/WrappingExecutor.java 2009-07-31 23:16:59 UTC (rev 91903)
@@ -28,5 +28,5 @@
* An executor which runs a task within the given direct executor.
*/
public interface WrappingExecutor {
- void execute(Runnable task, DirectExecutor directExecutor) throws RejectedExecutionException;
+ void execute(DirectExecutor directExecutor, Runnable task) throws RejectedExecutionException;
}
Modified: projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/WrappingThreadFactory.java
===================================================================
--- projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/WrappingThreadFactory.java 2009-07-31 22:26:53 UTC (rev 91902)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/WrappingThreadFactory.java 2009-07-31 23:16:59 UTC (rev 91903)
@@ -35,11 +35,7 @@
}
public Thread newThread(final Runnable r) {
- return delegate.newThread(new Runnable() {
- public void run() {
- taskWrapper.execute(r);
- }
- });
+ return delegate.newThread(JBossExecutors.executorTask(taskWrapper, r));
}
public String toString() {
More information about the jboss-cvs-commits
mailing list