PageRenderTime 2069ms CodeModel.GetById 1826ms RepoModel.GetById 28ms app.codeStats 0ms

/jboss-as-7.1.1.Final/clustering/common/src/main/java/org/jboss/as/clustering/concurrent/ManagedExecutorService.java

#
Java | 170 lines | 72 code | 19 blank | 79 comment | 0 complexity | 2653210e19260ce667539d1e6c56414e MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright 2011, Red Hat, Inc., and individual contributors
  4. * as indicated by the @author tags. See the copyright.txt file in the
  5. * distribution for a full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.jboss.as.clustering.concurrent;
  23. import java.util.Collection;
  24. import java.util.Collections;
  25. import java.util.List;
  26. import java.util.concurrent.Callable;
  27. import java.util.concurrent.ExecutionException;
  28. import java.util.concurrent.Executor;
  29. import java.util.concurrent.ExecutorService;
  30. import java.util.concurrent.Future;
  31. import java.util.concurrent.TimeUnit;
  32. import java.util.concurrent.TimeoutException;
  33. import org.jboss.threads.JBossExecutors;
  34. /**
  35. * ExecutorService decorator whose shutdown methods are no-ops.
  36. * @author Paul Ferraro
  37. */
  38. public class ManagedExecutorService implements ExecutorService {
  39. private final ExecutorService executor;
  40. public ManagedExecutorService(ExecutorService executor) {
  41. this.executor = executor;
  42. }
  43. public ManagedExecutorService(Executor executor) {
  44. this(JBossExecutors.protectedExecutorService(executor));
  45. }
  46. /**
  47. * {@inheritDoc}
  48. * @see java.util.concurrent.Executor#execute(java.lang.Runnable)
  49. */
  50. @Override
  51. public void execute(Runnable command) {
  52. this.executor.execute(command);
  53. }
  54. /**
  55. * {@inheritDoc}
  56. * @see java.util.concurrent.ExecutorService#shutdown()
  57. */
  58. @Override
  59. public void shutdown() {
  60. // Don't shutdown managed executor
  61. }
  62. /**
  63. * {@inheritDoc}
  64. * @see java.util.concurrent.ExecutorService#shutdownNow()
  65. */
  66. @Override
  67. public List<Runnable> shutdownNow() {
  68. // Don't shutdown managed executor
  69. return Collections.emptyList();
  70. }
  71. /**
  72. * {@inheritDoc}
  73. * @see java.util.concurrent.ExecutorService#isShutdown()
  74. */
  75. @Override
  76. public boolean isShutdown() {
  77. return this.executor.isShutdown();
  78. }
  79. /**
  80. * {@inheritDoc}
  81. * @see java.util.concurrent.ExecutorService#isTerminated()
  82. */
  83. @Override
  84. public boolean isTerminated() {
  85. return this.executor.isTerminated();
  86. }
  87. /**
  88. * {@inheritDoc}
  89. * @see java.util.concurrent.ExecutorService#awaitTermination(long, java.util.concurrent.TimeUnit)
  90. */
  91. @Override
  92. public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
  93. return this.executor.isTerminated();
  94. }
  95. /**
  96. * {@inheritDoc}
  97. * @see java.util.concurrent.ExecutorService#submit(java.util.concurrent.Callable)
  98. */
  99. @Override
  100. public <T> Future<T> submit(Callable<T> task) {
  101. return this.executor.submit(task);
  102. }
  103. /**
  104. * {@inheritDoc}
  105. * @see java.util.concurrent.ExecutorService#submit(java.lang.Runnable, java.lang.Object)
  106. */
  107. @Override
  108. public <T> Future<T> submit(Runnable task, T result) {
  109. return this.executor.submit(task, result);
  110. }
  111. /**
  112. * {@inheritDoc}
  113. * @see java.util.concurrent.ExecutorService#submit(java.lang.Runnable)
  114. */
  115. @Override
  116. public Future<?> submit(Runnable task) {
  117. return this.executor.submit(task);
  118. }
  119. /**
  120. * {@inheritDoc}
  121. * @see java.util.concurrent.ExecutorService#invokeAll(java.util.Collection)
  122. */
  123. @Override
  124. public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException {
  125. return this.executor.invokeAll(tasks);
  126. }
  127. /**
  128. * {@inheritDoc}
  129. * @see java.util.concurrent.ExecutorService#invokeAll(java.util.Collection, long, java.util.concurrent.TimeUnit)
  130. */
  131. @Override
  132. public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException {
  133. return this.executor.invokeAll(tasks, timeout, unit);
  134. }
  135. /**
  136. * {@inheritDoc}
  137. * @see java.util.concurrent.ExecutorService#invokeAny(java.util.Collection)
  138. */
  139. @Override
  140. public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException {
  141. return this.executor.invokeAny(tasks);
  142. }
  143. /**
  144. * {@inheritDoc}
  145. * @see java.util.concurrent.ExecutorService#invokeAny(java.util.Collection, long, java.util.concurrent.TimeUnit)
  146. */
  147. @Override
  148. public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
  149. return this.executor.invokeAny(tasks, timeout, unit);
  150. }
  151. }