Top Description Fields Constructors Methods
org.apache.sshd.common.util.threads

public Class NoCloseExecutor

extends Object
implements CloseableExecutorService
Class Inheritance
All Implemented Interfaces
org.apache.sshd.common.util.threads.CloseableExecutorService, org.apache.sshd.common.Closeable, java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable, java.util.concurrent.ExecutorService, java.util.concurrent.Executor
Imports
java.io.IOException, java.util.Collection, .Collections, .List, java.util.concurrent.Callable, .ExecutionException, .ExecutorService, .Future, .TimeUnit, .TimeoutException, org.apache.sshd.common.future.CloseFuture, .DefaultCloseFuture, .SshFutureListener, org.apache.sshd.common.util.ValidateUtils

Wraps an ExecutorService as a CloseableExecutorService and avoids calling its shutdown methods when the wrapper is shut down
Author
Apache MINA SSHD Project

Field Summary

Modifier and TypeField and Description
protected final CloseFuture
protected final ExecutorService

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addCloseFutureListener(SshFutureListener<CloseFuture>
The notification SshFutureListener - never null
listener
)

Implements org.apache.sshd.common.Closeable.addCloseFutureListener.

Pre-register a listener to be informed when resource is closed.

public boolean
awaitTermination(long
the maximum time to wait
timeout
,
TimeUnit
the time unit of the timeout argument
unit
)

Implements java.util.concurrent.ExecutorService.awaitTermination.

Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.

public CloseFuture
close(boolean
true if the resource should be shut down abruptly, false for a graceful close
immediately
)

Implements org.apache.sshd.common.Closeable.close.

Close this resource asynchronously and return a future.

public void
execute(Runnable
the runnable task
command
)

Implements java.util.concurrent.Executor.execute.

Executes the given command at some time in the future.

public <T> List<Future<T>>
invokeAll(Collection<? extends Callable<T>>
the collection of tasks
tasks
)

Implements java.util.concurrent.ExecutorService.invokeAll.

Executes the given tasks, returning a list of Futures holding their status and results when all complete.

public <T> List<Future<T>>
invokeAll(Collection<? extends Callable<T>>
the collection of tasks
tasks
,
long
the maximum time to wait
timeout
,
TimeUnit
the time unit of the timeout argument
unit
)

Implements java.util.concurrent.ExecutorService.invokeAll.

Executes the given tasks, returning a list of Futures holding their status and results when all complete or the timeout expires, whichever happens first.

public <T> T
invokeAny(Collection<? extends Callable<T>>
the collection of tasks
tasks
)

Implements java.util.concurrent.ExecutorService.invokeAny.

Executes the given tasks, returning the result of one that has completed successfully (i.e., without throwing an exception), if any do.

public <T> T
invokeAny(Collection<? extends Callable<T>>
the collection of tasks
tasks
,
long
the maximum time to wait
timeout
,
TimeUnit
the time unit of the timeout argument
unit
)

Implements java.util.concurrent.ExecutorService.invokeAny.

Executes the given tasks, returning the result of one that has completed successfully (i.e., without throwing an exception), if any do before the given timeout elapses.

public boolean
isClosed()

Implements org.apache.sshd.common.Closeable.isClosed.

Returns true if this object has been closed.

public boolean
isClosing()

Implements org.apache.sshd.common.Closeable.isClosing.

Returns true if the close(boolean) method has been called.

public boolean
isShutdown()

Implements java.util.concurrent.ExecutorService.isShutdown.

Returns true if this executor has been shut down.

public boolean
isTerminated()

Implements java.util.concurrent.ExecutorService.isTerminated.

Returns true if all tasks have completed following shut down.

public void
removeCloseFutureListener(SshFutureListener<CloseFuture>
The register SshFutureListener - never null. Ignored if not registered or resource already closed
listener
)

Implements org.apache.sshd.common.Closeable.removeCloseFutureListener.

Remove a pre-registered close event listener

public void
shutdown()

Implements java.util.concurrent.ExecutorService.shutdown.

Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.

public List<Runnable>
shutdownNow()

Implements java.util.concurrent.ExecutorService.shutdownNow.

Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.

public <T> Future<T>
submit(Callable<T>
the task to submit
task
)

Implements java.util.concurrent.ExecutorService.submit.

Submits a value-returning task for execution and returns a Future representing the pending results of the task.

public <T> Future<T>
submit(Runnable
the task to submit
task
,
T
the result to return
result
)

Implements java.util.concurrent.ExecutorService.submit.

Submits a Runnable task for execution and returns a Future representing that task.

public Future<?>
submit(Runnable
the task to submit
task
)

Implements java.util.concurrent.ExecutorService.submit.

Submits a Runnable task for execution and returns a Future representing that task.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

closeFutureback to summary
protected final CloseFuture closeFuture
executorback to summary
protected final ExecutorService executor

Constructor Detail

NoCloseExecutorback to summary
public NoCloseExecutor(ExecutorService executor)

Method Detail

addCloseFutureListenerback to summary
public void addCloseFutureListener(SshFutureListener<CloseFuture> listener)

Implements org.apache.sshd.common.Closeable.addCloseFutureListener.

Doc from org.apache.sshd.common.Closeable.addCloseFutureListener.

Pre-register a listener to be informed when resource is closed. If resource is already closed, the listener will be invoked immediately and not registered for future notification

Parameters
listener:SshFutureListener<CloseFuture>

The notification SshFutureListener - never null

Annotations
@Override
awaitTerminationback to summary
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException

Implements java.util.concurrent.ExecutorService.awaitTermination.

Doc from java.util.concurrent.ExecutorService.awaitTermination.

Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.

Parameters
timeout:long

the maximum time to wait

unit:TimeUnit

the time unit of the timeout argument

Returns:boolean

true if this executor terminated and false if the timeout elapsed before termination

Annotations
@Override
Exceptions
InterruptedException:
if interrupted while waiting
closeback to summary
public CloseFuture close(boolean immediately)

Implements org.apache.sshd.common.Closeable.close.

Doc from org.apache.sshd.common.Closeable.close.

Close this resource asynchronously and return a future. Resources support two closing modes: a graceful mode which will cleanly close the resource and an immediate mode which will close the resources abruptly.

Parameters
immediately:boolean

true if the resource should be shut down abruptly, false for a graceful close

Returns:CloseFuture

a CloseFuture representing the close request

Annotations
@Override
executeback to summary
public void execute(Runnable command)

Implements java.util.concurrent.Executor.execute.

Doc from java.util.concurrent.Executor.execute.

Executes the given command at some time in the future. The command may execute in a new thread, in a pooled thread, or in the calling thread, at the discretion of the Executor implementation.

Parameters
command:Runnable

the runnable task

Annotations
@Override
invokeAllback to summary
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException

Implements java.util.concurrent.ExecutorService.invokeAll.

Doc from java.util.concurrent.ExecutorService.invokeAll.

Executes the given tasks, returning a list of Futures holding their status and results when all complete. Future#isDone is true for each element of the returned list. Note that a completed task could have terminated either normally or by throwing an exception. The results of this method are undefined if the given collection is modified while this operation is in progress.

Parameters
<T>
the type of the values returned from the tasks
tasks:Collection<? extends Callable<T>>

the collection of tasks

Returns:List<Future<T>>

a list of Futures representing the tasks, in the same sequential order as produced by the iterator for the given task list, each of which has completed

Annotations
@Override
Exceptions
InterruptedException:
if interrupted while waiting, in which case unfinished tasks are cancelled
invokeAllback to summary
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException

Implements java.util.concurrent.ExecutorService.invokeAll.

Doc from java.util.concurrent.ExecutorService.invokeAll.

Executes the given tasks, returning a list of Futures holding their status and results when all complete or the timeout expires, whichever happens first. Future#isDone is true for each element of the returned list. Upon return, tasks that have not completed are cancelled. Note that a completed task could have terminated either normally or by throwing an exception. The results of this method are undefined if the given collection is modified while this operation is in progress.

Parameters
<T>
the type of the values returned from the tasks
tasks:Collection<? extends Callable<T>>

the collection of tasks

timeout:long

the maximum time to wait

unit:TimeUnit

the time unit of the timeout argument

Returns:List<Future<T>>

a list of Futures representing the tasks, in the same sequential order as produced by the iterator for the given task list. If the operation did not time out, each task will have completed. If it did time out, some of these tasks will not have completed.

Annotations
@Override
Exceptions
InterruptedException:
if interrupted while waiting, in which case unfinished tasks are cancelled
invokeAnyback to summary
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException

Implements java.util.concurrent.ExecutorService.invokeAny.

Doc from java.util.concurrent.ExecutorService.invokeAny.

Executes the given tasks, returning the result of one that has completed successfully (i.e., without throwing an exception), if any do. Upon normal or exceptional return, tasks that have not completed are cancelled. The results of this method are undefined if the given collection is modified while this operation is in progress.

Parameters
<T>
the type of the values returned from the tasks
tasks:Collection<? extends Callable<T>>

the collection of tasks

Returns:T

the result returned by one of the tasks

Annotations
@Override
Exceptions
InterruptedException:
if interrupted while waiting
ExecutionException:
if no task successfully completes
invokeAnyback to summary
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException

Implements java.util.concurrent.ExecutorService.invokeAny.

Doc from java.util.concurrent.ExecutorService.invokeAny.

Executes the given tasks, returning the result of one that has completed successfully (i.e., without throwing an exception), if any do before the given timeout elapses. Upon normal or exceptional return, tasks that have not completed are cancelled. The results of this method are undefined if the given collection is modified while this operation is in progress.

Parameters
<T>
the type of the values returned from the tasks
tasks:Collection<? extends Callable<T>>

the collection of tasks

timeout:long

the maximum time to wait

unit:TimeUnit

the time unit of the timeout argument

Returns:T

the result returned by one of the tasks

Annotations
@Override
Exceptions
InterruptedException:
if interrupted while waiting
ExecutionException:
if no task successfully completes
TimeoutException:
if the given timeout elapses before any task successfully completes
isClosedback to summary
public boolean isClosed()

Implements org.apache.sshd.common.Closeable.isClosed.

Doc from org.apache.sshd.common.Closeable.isClosed.

Returns true if this object has been closed.

Returns:boolean

true if closing

Annotations
@Override
isClosingback to summary
public boolean isClosing()

Implements org.apache.sshd.common.Closeable.isClosing.

Doc from org.apache.sshd.common.Closeable.isClosing.

Returns true if the close(boolean) method has been called. Note that this method will return true even if this isClosed() returns true.

Returns:boolean

true if closing

Annotations
@Override
isShutdownback to summary
public boolean isShutdown()

Implements java.util.concurrent.ExecutorService.isShutdown.

Doc from java.util.concurrent.ExecutorService.isShutdown.

Returns true if this executor has been shut down.

Returns:boolean

true if this executor has been shut down

Annotations
@Override
isTerminatedback to summary
public boolean isTerminated()

Implements java.util.concurrent.ExecutorService.isTerminated.

Doc from java.util.concurrent.ExecutorService.isTerminated.

Returns true if all tasks have completed following shut down. Note that isTerminated is never true unless either shutdown or shutdownNow was called first.

Returns:boolean

true if all tasks have completed following shut down

Annotations
@Override
removeCloseFutureListenerback to summary
public void removeCloseFutureListener(SshFutureListener<CloseFuture> listener)

Implements org.apache.sshd.common.Closeable.removeCloseFutureListener.

Doc from org.apache.sshd.common.Closeable.removeCloseFutureListener.

Remove a pre-registered close event listener

Parameters
listener:SshFutureListener<CloseFuture>

The register SshFutureListener - never null. Ignored if not registered or resource already closed

Annotations
@Override
shutdownback to summary
public void shutdown()

Implements java.util.concurrent.ExecutorService.shutdown.

Doc from java.util.concurrent.ExecutorService.shutdown.

Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. Invocation has no additional effect if already shut down.

This method does not wait for previously submitted tasks to complete execution. Use awaitTermination to do that.

Annotations
@Override
shutdownNowback to summary
public List<Runnable> shutdownNow()

Implements java.util.concurrent.ExecutorService.shutdownNow.

Doc from java.util.concurrent.ExecutorService.shutdownNow.

Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.

This method does not wait for actively executing tasks to terminate. Use awaitTermination to do that.

There are no guarantees beyond best-effort attempts to stop processing actively executing tasks. For example, typical implementations will cancel via Thread#interrupt, so any task that fails to respond to interrupts may never terminate.

Returns:List<Runnable>

list of tasks that never commenced execution

Annotations
@Override
submitback to summary
public <T> Future<T> submit(Callable<T> task)

Implements java.util.concurrent.ExecutorService.submit.

Doc from java.util.concurrent.ExecutorService.submit.

Submits a value-returning task for execution and returns a Future representing the pending results of the task. The Future's get method will return the task's result upon successful completion.

If you would like to immediately block waiting for a task, you can use constructions of the form result = exec.submit(aCallable).get();

Note

The Executors class includes a set of methods that can convert some other common closure-like objects, for example, java.security.PrivilegedAction to Callable form so they can be submitted.

Parameters
<T>
the type of the task's result
task:Callable<T>

the task to submit

Returns:Future<T>

a Future representing pending completion of the task

Annotations
@Override
submitback to summary
public <T> Future<T> submit(Runnable task, T result)

Implements java.util.concurrent.ExecutorService.submit.

Doc from java.util.concurrent.ExecutorService.submit.

Submits a Runnable task for execution and returns a Future representing that task. The Future's get method will return the given result upon successful completion.

Parameters
<T>
the type of the result
task:Runnable

the task to submit

result:T

the result to return

Returns:Future<T>

a Future representing pending completion of the task

Annotations
@Override
submitback to summary
public Future<?> submit(Runnable task)

Implements java.util.concurrent.ExecutorService.submit.

Doc from java.util.concurrent.ExecutorService.submit.

Submits a Runnable task for execution and returns a Future representing that task. The Future's get method will return null upon successful completion.

Parameters
task:Runnable

the task to submit

Returns:Future<?>

a Future representing pending completion of the task

Annotations
@Override