org.norther.tammi.core.thread
Class AbstractExecutor

java.lang.Object
  extended by org.norther.tammi.core.base.Adaptee
      extended by org.norther.tammi.core.thread.AbstractExecutor
All Implemented Interfaces:
Serializable, Executor, ExecutorService, NotificationBroadcaster, NotificationEmitter, Manageable, MBeanDelegate, Startable
Direct Known Subclasses:
DefaultDirectExecutor, DefaultThreadedExecutor

public abstract class AbstractExecutor
extends Adaptee
implements Executor

An abstract implementation of Executor.

Version:
$Id: AbstractExecutor.java,v 1.7 2009/09/28 15:08:43 cvsimp Exp $
Author:
Ilkka Priha
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.norther.tammi.core.base.Adaptee
ADAPTEE_NOTIF_DESCRIPTION, ADAPTEE_NOTIFICATIONS
 
Constructor Summary
AbstractExecutor()
          Constructs a new executor.
 
Method Summary
 boolean awaitTermination(long timeout, TimeUnit unit)
           
 void execute(Runnable task)
           
 int getActiveCount()
          Gets the number of currently running tasks.
 long getCompletedTaskCount()
          Gets the total number of completed tasks.
protected  ExecutorService getExecutor()
          Gets the implementation of the executor.
 long getTaskCount()
          Gets the total number of completed, active or scheduled tasks.
<T> List<Future<T>>
invokeAll(Collection<? extends Callable<T>> tasks)
           
<T> List<Future<T>>
invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
           
<T> T
invokeAny(Collection<? extends Callable<T>> tasks)
           
<T> T
invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
           
 boolean isShutdown()
           
 boolean isStarted()
          Checks whether the startable has been started.
 boolean isTerminated()
           
protected abstract  ExecutorService newExecutor()
          Creates the implementation of the executor.
 void postmanaged()
          This method is called when the implementing adaptee has been managed either during post-registration of the corresponding adapter MBean or just after it is explicitly added to the adapter MBean during run-time.
 void shutdown()
           
 List<Runnable> shutdownNow()
           
 void start()
          Starts the MBean.
 void stop()
          Stops the MBean.
<T> Future<T>
submit(Callable<T> task)
           
 Future<?> submit(Runnable task)
           
<T> Future<T>
submit(Runnable task, T result)
           
 void unmanaged()
          This method is called when the implementing adaptee is unmanaged either during pre-deregistration of the corresponding adapter MBean or just before it is explicitly removed from the adapter MBean during run-time.
 
Methods inherited from class org.norther.tammi.core.base.Adaptee
addAdaptee, addNotificationListener, getAttributeSupport, getBroker, getCanonicalName, getDomain, getFactory, getLoader, getLog, getLog, getMBean, getMBeanServer, getNotificationInfo, getObjectName, getRegistrationTime, getSequenceNumber, hasListeners, isRegistered, premanaged, removeNotificationListener, removeNotificationListener, sendNotification, sendNotification, sendNotification, sendNotification, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractExecutor

public AbstractExecutor()
Constructs a new executor.

Method Detail

postmanaged

public void postmanaged()
Description copied from interface: Manageable
This method is called when the implementing adaptee has been managed either during post-registration of the corresponding adapter MBean or just after it is explicitly added to the adapter MBean during run-time.

Specified by:
postmanaged in interface Manageable
Overrides:
postmanaged in class Adaptee

unmanaged

public void unmanaged()
               throws Exception
Description copied from interface: Manageable
This method is called when the implementing adaptee is unmanaged either during pre-deregistration of the corresponding adapter MBean or just before it is explicitly removed from the adapter MBean during run-time.

Specified by:
unmanaged in interface Manageable
Overrides:
unmanaged in class Adaptee
Throws:
Exception - if the adaptee refused to be unmanaged.

isStarted

public boolean isStarted()
Description copied from interface: Startable
Checks whether the startable has been started.

Specified by:
isStarted in interface Startable
Returns:
true if started, otherwise false.

start

public void start()
           throws Exception
Description copied from interface: Startable
Starts the MBean.

Specified by:
start in interface Startable
Throws:
Exception - if start fails.

stop

public void stop()
Description copied from interface: Startable
Stops the MBean.

Specified by:
stop in interface Startable

awaitTermination

public boolean awaitTermination(long timeout,
                                TimeUnit unit)
                         throws InterruptedException
Specified by:
awaitTermination in interface ExecutorService
Throws:
InterruptedException

isShutdown

public boolean isShutdown()
Specified by:
isShutdown in interface ExecutorService

isTerminated

public boolean isTerminated()
Specified by:
isTerminated in interface ExecutorService

shutdown

public void shutdown()
Specified by:
shutdown in interface ExecutorService

shutdownNow

public List<Runnable> shutdownNow()
Specified by:
shutdownNow in interface ExecutorService

invokeAll

public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks,
                                     long timeout,
                                     TimeUnit unit)
                          throws InterruptedException
Specified by:
invokeAll in interface ExecutorService
Throws:
InterruptedException

invokeAll

public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
                          throws InterruptedException
Specified by:
invokeAll in interface ExecutorService
Throws:
InterruptedException

invokeAny

public <T> T invokeAny(Collection<? extends Callable<T>> tasks,
                       long timeout,
                       TimeUnit unit)
            throws InterruptedException,
                   ExecutionException,
                   TimeoutException
Specified by:
invokeAny in interface ExecutorService
Throws:
InterruptedException
ExecutionException
TimeoutException

invokeAny

public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
            throws InterruptedException,
                   ExecutionException
Specified by:
invokeAny in interface ExecutorService
Throws:
InterruptedException
ExecutionException

submit

public <T> Future<T> submit(Callable<T> task)
Specified by:
submit in interface ExecutorService

submit

public <T> Future<T> submit(Runnable task,
                            T result)
Specified by:
submit in interface ExecutorService

submit

public Future<?> submit(Runnable task)
Specified by:
submit in interface ExecutorService

execute

public void execute(Runnable task)
Specified by:
execute in interface Executor

getCompletedTaskCount

public long getCompletedTaskCount()
Description copied from interface: Executor
Gets the total number of completed tasks.

Returns:
the number of completed tasks.

getActiveCount

public int getActiveCount()
Description copied from interface: Executor
Gets the number of currently running tasks.

Returns:
the number of active tasks.

getTaskCount

public long getTaskCount()
Description copied from interface: Executor
Gets the total number of completed, active or scheduled tasks.

Returns:
the number of any tasks.

getExecutor

protected ExecutorService getExecutor()
Gets the implementation of the executor.

Returns:
the executor implementation or null if not started.

newExecutor

protected abstract ExecutorService newExecutor()
Creates the implementation of the executor.

Returns:
the executor implementation.
Throws:
NullPointerException - for missing resources.


Copyright © 2004 The Norther Organization. All rights reserved.