## com.sun.grizzly
Class DefaultPipeline

    java.lang.Object
      java.util.AbstractCollection<E>
          java.util.AbstractList<E>
              java.util.AbstractSequentialList<E>
                  java.util.LinkedList<Callable>
                      com.sun.grizzly.DefaultPipeline

All Implemented Interfaces:
  Pipeline<Callable>, Serializable, Cloneable, Iterable<Callable>, Collection<Callable>, Deque<Callable>, List<Callable>, Queue<Callable>

    public class DefaultPipeline

extends LinkedList<Callable>
implements Pipeline<Callable>

Simple Thread Pool based on the wait/notify/synchronized mechanism.

Author:
  Jean-Francois Arcand
See Also:
  Serialized Form

Field Summary
`protected int` `initialByteBufferSize` The initial ByteBuffer size for newly created WorkerThread instances
`protected boolean` `isStarted` Has the pipeline already started
`protected int` `maxQueueSizeInBytes` Maximum pending connection before refusing requests.
`protected int` `maxThreads` The maximum number of Thread
`protected int` `minSpareThreads` The minimum numbers of spare `WorkerThreadImpl`
`protected int` `minThreads` The minimum numbers of `WorkerThreadImpl`
`protected String` `name` The name of this Pipeline
`protected int` `port` The port used.
`protected int` `priority` The Thread Priority
`protected int` `threadCount` The number of `WorkerThreadImpl`
`protected int` `threadsIncrement` The increment number used when adding new thread.
`protected int` `waitingThreads` The number of thread waiting for works.
`protected WorkerThreadImpl[]` `workerThreads` `WorkerThreadImpl` amanged by this pipeline.

Fields inherited from class java.util.AbstractList
`modCount`

Constructor Summary
`DefaultPipeline()`
`DefaultPipeline(int maxThreads, int minThreads, String name, int port)`
`DefaultPipeline(int maxThreads, int minThreads, String name, int port, int priority)`

Method Summary
`void` `execute(Callable callable)` Add a `Callable` to the execution queue.
`boolean` `expireKey(SelectionKey key)` Invoked when the `SelectionKeyHandler` is about to expire a SelectionKey.
`int` `geMaxQueueSize()` Get the maximum pending connections this `Pipeline` can handle.
`ByteBufferFactory.ByteBufferType` `getByteBufferType()` The `ByteBufferTypel` used to create the `ByteBuffer` associated with `WorkerThreadImpl`s created by this instance.
`int` `getCurrentThreadCount()` Return current thread count
`int` `getCurrentThreadsBusy()` Return the curent number of threads that are currently processing a task.
`int` `getInitialByteBufferSize()` Get the initial WorkerThreadImpl `ByteBuffer` size
`int` `getMaxSpareThreads()` Return the maximum spare thread.
`int` `getMaxThreads()` Return the number of threads used by this pipeline.
`int` `getMinSpareThreads()` Return the minimum spare thread.
`String` `getName()` Return the name of this `Pipeline`
`int` `getTaskQueuedCount()` The number of `Task` currently queued
`int` `getWaitingThread()` Return the number of waiting threads.
`protected void` `increaseWorkerThread(int increment, boolean startThread)` Create new `WorkerThreadImpl`.
`void` `initPipeline()` Init the `Pipeline` by initializing the required `WorkerThreadImpl`.
`boolean` `interruptThread(long threadID)` Interrupt the `Thread` using it thread id
`boolean` `isEmpty()` Return `true` if the size of this `LinkedList` minus the current waiting threads is lower than zero.
`void` `setByteBufferType(ByteBufferFactory.ByteBufferType byteBufferType)` Set the `ByteBufferTypel` to use when creating the `ByteBuffer` associated with `WorkerThreadImpl`s created by this instance.
`void` `setInitialByteBufferSize(int size)` Set the initial WorkerThreadImpl `ByteBuffer` size
`void` `setMaxQueueSize(int maxQueueSizeInBytesCount)` Set the maximum pending connection this `Pipeline` can handle.
`void` `setMaxThreads(int maxThreads)` Set the number of threads used by this pipeline.
`void` `setMinSpareThreads(int minSpareThreads)` Set the minimum spare thread this `Pipeline` can handle.
`void` `setMinThreads(int minThreads)` Set the minimum thread this `Pipeline` will creates when initializing.
`void` `setName(String name)` Set the name of this `Pipeline`
`void` `setPort(int port)` Set the port used by this `Pipeline`
`void` `setPriority(int priority)` Set the thread priority of the `Pipeline`
`void` `setThreadsIncrement(int threadsIncrement)` Set the number the `Pipeline` will use when increasing the thread pool
`void` `startPipeline()` Start the `Pipeline` and all associated `WorkerThreadImpl`
`void` `stopPipeline()` Stop the `Pipeline` and all associated `WorkerThreadImpl`
`String` `toString()`
`Callable` `waitForIoTask()` Return a `Callable` object available in the pipeline.

Methods inherited from class java.util.LinkedList
`add, add, addAll, addAll, addFirst, addLast, clear, clone, contains, descendingIterator, element, get, getFirst, getLast, indexOf, lastIndexOf, listIterator, offer, offerFirst, offerLast, peek, peekFirst, peekLast, poll, pollFirst, pollLast, pop, push, remove, remove, remove, removeFirst, removeFirstOccurrence, removeLast, removeLastOccurrence, set, size, toArray, toArray`

Methods inherited from class java.util.AbstractSequentialList
`iterator`

Methods inherited from class java.util.AbstractList
`equals, hashCode, listIterator, removeRange, subList`

Methods inherited from class java.util.AbstractCollection
`containsAll, removeAll, retainAll`

Methods inherited from class java.lang.Object
`finalize, getClass, notify, notifyAll, wait, wait, wait`

Methods inherited from interface com.sun.grizzly.Pipeline
`size`

Methods inherited from interface java.util.List
`containsAll, equals, hashCode, iterator, listIterator, removeAll, retainAll, subList`

Methods inherited from interface java.util.Deque
`iterator`

Field Detail

### waitingThreads

    protected int waitingThreads

  The number of thread waiting for works.

### maxThreads

    protected int maxThreads

  The maximum number of Thread

### minThreads

    protected int minThreads

  The minimum numbers of `WorkerThreadImpl`

### minSpareThreads

    protected int minSpareThreads

  The minimum numbers of spare `WorkerThreadImpl`

### port

    protected int port

  The port used.

### threadCount

    protected int threadCount

  The number of `WorkerThreadImpl`

### name

    protected String name

  The name of this Pipeline

### priority

    protected int priority

  The Thread Priority

### isStarted

    protected boolean isStarted

  Has the pipeline already started

### workerThreads

    protected transient WorkerThreadImpl[] workerThreads

  `WorkerThreadImpl` amanged by this pipeline.

### maxQueueSizeInBytes

    protected int maxQueueSizeInBytes

  Maximum pending connection before refusing requests.

### threadsIncrement

    protected int threadsIncrement

  The increment number used when adding new thread.

### initialByteBufferSize

    protected int initialByteBufferSize

  The initial ByteBuffer size for newly created WorkerThread instances

Constructor Detail

### DefaultPipeline

    public DefaultPipeline()

### DefaultPipeline

    public DefaultPipeline(int maxThreads,
                           int minThreads,
                           String name,
                           int port,
                           int priority)

### DefaultPipeline

    public DefaultPipeline(int maxThreads,
                           int minThreads,
                           String name,
                           int port)

Method Detail

### initPipeline

    public void initPipeline()

  Init the `Pipeline` by initializing the required `WorkerThreadImpl`. Default value is `maxThreads`

  Specified by:
    `initPipeline` in interface `Pipeline<Callable>`

### startPipeline

    public void startPipeline()

  Start the `Pipeline` and all associated `WorkerThreadImpl`

  Specified by:
    `startPipeline` in interface `Pipeline<Callable>`

### stopPipeline

    public void stopPipeline()

  Stop the `Pipeline` and all associated `WorkerThreadImpl`

  Specified by:
    `stopPipeline` in interface `Pipeline<Callable>`

### increaseWorkerThread

    protected void increaseWorkerThread(int increment,
                                        boolean startThread)

  Create new `WorkerThreadImpl`. This method must be invoked from a synchronized block.

  Parameters:
    `increment` - - how many additional `WorkerThreadImpl` objects to add
    `startThread` - - should newly added `WorkerThreadImpl` objects be started after creation?

### interruptThread

    public boolean interruptThread(long threadID)

  Interrupt the `Thread` using it thread id

  Parameters:
    `threadID` - - id of `Thread` to interrupt
  Returns:
    boolean, was Thread interrupted successfully ?

### execute

    public void execute(Callable callable)
                 throws PipelineFullException

  Add a `Callable` to the execution queue. If there is thread available, the Callable will be automatically executed. If there is no thread available, the Callable will be queued until a thread becomes free. If the queue reach it's maximum (see `#getMaxQueueSize`), the Callable will be rejected. If the Callable is an instance of `ContextTask`, the associated `SelectionKey` will be cancelled and the `Context` recycled. Finally a `PipelineFullException` will be propagated.

  Specified by:
    `execute` in interface `Pipeline<Callable>`
  Parameters:
    `callable` - a `Callable` to add to this Pipeline
  Throws:
    `{@link` - PipelineFullException} if Pipeline is full
    `PipelineFullException`

### waitForIoTask

    public Callable waitForIoTask()

  Return a `Callable` object available in the pipeline. All Threads will synchronize on that method

  Specified by:
    `waitForIoTask` in interface `Pipeline<Callable>`
  Returns:
    `Callable`

### expireKey

    public boolean expireKey(SelectionKey key)

  Invoked when the `SelectionKeyHandler` is about to expire a SelectionKey.

  Parameters:
    `key` - - A `SelectionKey` to expire
  Returns:
    true if the `SelectionKeyHandler` should expire the `SelectionKey`, false if not.

### isEmpty

    public boolean isEmpty()

  Return `true` if the size of this `LinkedList` minus the current waiting threads is lower than zero.

  Specified by:
    `isEmpty` in interface `Collection<Callable>`
  Specified by:
    `isEmpty` in interface `List<Callable>`
  Overrides:
    `isEmpty` in class `AbstractCollection<Callable>`

### getWaitingThread

    public int getWaitingThread()

  Return the number of waiting threads.

  Specified by:
    `getWaitingThread` in interface `Pipeline<Callable>`
  Returns:
    number of waiting threads

### setMaxThreads

    public void setMaxThreads(int maxThreads)

  Set the number of threads used by this pipeline.

  Specified by:
    `setMaxThreads` in interface `Pipeline<Callable>`
  Parameters:
    `maxThreads` - maximum number of threads to use

### getMaxThreads

    public int getMaxThreads()

  Return the number of threads used by this pipeline.

  Specified by:
    `getMaxThreads` in interface `Pipeline<Callable>`
  Returns:
    maximum number of threads

### getCurrentThreadCount

    public int getCurrentThreadCount()

  Return current thread count

  Specified by:
    `getCurrentThreadCount` in interface `Pipeline<Callable>`
  Returns:
    current thread count

### getCurrentThreadsBusy

    public int getCurrentThreadsBusy()

  Return the curent number of threads that are currently processing a task.

  Specified by:
    `getCurrentThreadsBusy` in interface `Pipeline<Callable>`
  Returns:
    current busy thread count

### getMaxSpareThreads

    public int getMaxSpareThreads()

  Return the maximum spare thread.

  Returns:
    maximum spare thread count

### getMinSpareThreads

    public int getMinSpareThreads()

  Return the minimum spare thread.

  Returns:
    minimum spare thread count

### setMinSpareThreads

    public void setMinSpareThreads(int minSpareThreads)

  Set the minimum spare thread this `Pipeline` can handle.

  Parameters:
    `minSpareThreads` - minimum number of spare threads to handle

### setPriority

    public void setPriority(int priority)

  Set the thread priority of the `Pipeline`

  Specified by:
    `setPriority` in interface `Pipeline<Callable>`
  Parameters:
    `priority` - thread priority to use

### setName

    public void setName(String name)

  Set the name of this `Pipeline`

  Specified by:
    `setName` in interface `Pipeline<Callable>`
  Parameters:
    `name` - Pipeline name to use

### getName

    public String getName()

  Return the name of this `Pipeline`

  Specified by:
    `getName` in interface `Pipeline<Callable>`
  Returns:
    the name of this `Pipeline`

### setPort

    public void setPort(int port)

  Set the port used by this `Pipeline`

  Parameters:
    `port` - the port used by this `Pipeline`

### setMinThreads

    public void setMinThreads(int minThreads)

  Set the minimum thread this `Pipeline` will creates when initializing.

  Specified by:
    `setMinThreads` in interface `Pipeline<Callable>`
  Parameters:
    `minThreads` - the minimum number of threads.

### toString

    public String toString()

  Overrides:
    `toString` in class `AbstractCollection<Callable>`

### setThreadsIncrement

    public void setThreadsIncrement(int threadsIncrement)

  Set the number the `Pipeline` will use when increasing the thread pool

  Specified by:
    `setThreadsIncrement` in interface `Pipeline<Callable>`
  Parameters:
    `threadsIncrement` - amount to increase thread pool by

### getTaskQueuedCount

    public int getTaskQueuedCount()

  The number of `Task` currently queued

  Returns:
    number of queued connections

### setMaxQueueSize

    public void setMaxQueueSize(int maxQueueSizeInBytesCount)

  Set the maximum pending connection this `Pipeline` can handle.

  Specified by:
    `setMaxQueueSize` in interface `Pipeline<Callable>`
  Parameters:
    `maxQueueSizeInBytesCount` - maximum queue size (in bytes) this Pipeline should use

### geMaxQueueSize

    public int geMaxQueueSize()

  Get the maximum pending connections this `Pipeline` can handle.

  Returns:
    maximum queue size (in bytes) this Pipeline is using

### getInitialByteBufferSize

    public int getInitialByteBufferSize()

  Get the initial WorkerThreadImpl `ByteBuffer` size

  Returns:
    initial WorkerThreadImpl `ByteBuffwaitingThreadser` size

### setInitialByteBufferSize

    public void setInitialByteBufferSize(int size)

  Set the initial WorkerThreadImpl `ByteBuffer` size

  Parameters:
    `size` - initial WorkerThreadImpl `ByteBuffer` size

### getByteBufferType

    public ByteBufferFactory.ByteBufferType getByteBufferType()

  The `ByteBufferTypel` used to create the `ByteBuffer` associated with `WorkerThreadImpl`s created by this instance.

  Returns:
    The `ByteBufferTypel` used to create the `ByteBuffer` associated with `WorkerThreadImpl`s created by this instance.

### setByteBufferType

    public void setByteBufferType(ByteBufferFactory.ByteBufferType byteBufferType)

  Set the `ByteBufferTypel` to use when creating the `ByteBuffer` associated with `WorkerThreadImpl`s created by this instance.

  Parameters:
    `byteBufferType` - The ByteBuffer type.

Copyright © 2008 SUN Microsystems. All Rights Reserved.