TorqueBox 3.1.2

org.torquebox.core.pool
Class SharedPool<T>

java.lang.Object
  extended by org.torquebox.core.pool.SharedPool<T>
Type Parameters:
T - The poolable resource.
All Implemented Interfaces:
Pool<T>
Direct Known Subclasses:
SharedRubyRuntimePool

public class SharedPool<T>
extends Object
implements Pool<T>

A pool implementation that shares a single instance to all consumers.

The pool may be primed with either an instance directly or by providing a factory capable of creating the instance. In the case that a InstanceFactory is used, exactly one instance will be created.

Author:
Bob McWhirter

Field Summary
protected  org.jboss.logging.Logger log
           
 
Constructor Summary
SharedPool()
          Construct.
SharedPool(InstanceFactory<T> factory)
          Construct with an instance factory.
SharedPool(T instance)
          Construct with an instance.
 
Method Summary
 T borrowInstance(String requester)
          Borrow an instance from the pool.
 T borrowInstance(String requester, long timeout)
          Borrow an instance from the pool.
 T getInstance()
          Retrieve the shared instance.
 InstanceFactory<T> getInstanceFactory()
          Retrieve the instance factory to create the initial instance.
 String getName()
          Retrieve the pool name.
 org.jboss.as.naming.context.NamespaceContextSelector getNamespaceContextSelector()
           
 boolean isDeferredUntilRequested()
           
 boolean isDrained()
           
 boolean isLazy()
           
 boolean isStarted()
           
protected  T newInstance()
           
 void releaseInstance(T instance)
          Release an instance back into the pool.
 void setDeferUntilRequested(boolean deferUntilRequested)
           
 void setInstance(T instance)
          Set the shared instance.
 void setInstanceFactory(InstanceFactory<T> factory)
          Set the instance factory to create the initial instance.
 void setName(String name)
          Set the pool name.
 void setNamespaceContextSelector(org.jboss.as.naming.context.NamespaceContextSelector nsContextSelector)
           
 void start()
          Create the pool.
 void startPool()
           
 void stop()
          Destroy the pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected org.jboss.logging.Logger log
Constructor Detail

SharedPool

public SharedPool()
Construct.


SharedPool

public SharedPool(InstanceFactory<T> factory)
Construct with an instance factory.

Parameters:
factory - The factory to create the initial instance.

SharedPool

public SharedPool(T instance)
Construct with an instance.

Parameters:
instance - The initial instance.
Method Detail

setName

public void setName(String name)
Set the pool name.

Parameters:
name - The pool name.

getName

public String getName()
Retrieve the pool name.

Specified by:
getName in interface Pool<T>
Returns:
The pool name.

setInstance

public void setInstance(T instance)
Set the shared instance.

Parameters:
instance - The initial instance.

getInstance

public T getInstance()
Retrieve the shared instance.

Returns:
The shared instance.

setInstanceFactory

public void setInstanceFactory(InstanceFactory<T> factory)
Set the instance factory to create the initial instance.

Parameters:
factory - The instance factory.

getInstanceFactory

public InstanceFactory<T> getInstanceFactory()
Retrieve the instance factory to create the initial instance.

Returns:
The instance factory;

startPool

public void startPool()
               throws Exception
Throws:
Exception

newInstance

protected T newInstance()
                 throws Exception
Throws:
Exception

isLazy

public boolean isLazy()

isStarted

public boolean isStarted()

isDeferredUntilRequested

public boolean isDeferredUntilRequested()

setDeferUntilRequested

public void setDeferUntilRequested(boolean deferUntilRequested)

start

public void start()
           throws Exception
Create the pool.

Throws:
Exception - if an error occurs starting the pool.

stop

public void stop()
Destroy the pool.


borrowInstance

public T borrowInstance(String requester)
                 throws Exception
Description copied from interface: Pool
Borrow an instance from the pool.

Specified by:
borrowInstance in interface Pool<T>
Returns:
The borrowed instance.
Throws:
Exception - if an error occurs.

releaseInstance

public void releaseInstance(T instance)
Description copied from interface: Pool
Release an instance back into the pool.

Specified by:
releaseInstance in interface Pool<T>
Parameters:
instance - The instance to release.

borrowInstance

public T borrowInstance(String requester,
                        long timeout)
                 throws Exception
Description copied from interface: Pool
Borrow an instance from the pool.

Specified by:
borrowInstance in interface Pool<T>
timeout - Wait time to acquire instance.
Returns:
The borrowed instance.
Throws:
Exception - if an error occurs.

setNamespaceContextSelector

public void setNamespaceContextSelector(org.jboss.as.naming.context.NamespaceContextSelector nsContextSelector)

getNamespaceContextSelector

public org.jboss.as.naming.context.NamespaceContextSelector getNamespaceContextSelector()

isDrained

public boolean isDrained()

TorqueBox 3.1.2

Copyright © 2015 JBoss by Red Hat. All Rights Reserved.