xmlBlaster 2.1.0 API

org.xmlBlaster.util.pool
Class ResourceWrapper

java.lang.Object
  extended by org.xmlBlaster.util.pool.ResourceWrapper
All Implemented Interfaces:
I_Timeout

public class ResourceWrapper
extends java.lang.Object
implements I_Timeout

Container holds infos about a resource.

All ResourceWrapper are handled in a pool, the 'PoolManager' class.

Author:
ruff@swand.lake.de
See Also:
PoolManager

Field Summary
private static java.lang.String BUSY_TO_IDLE_TIMEOUT
          Constant to mark busy to idle timer events
private  long busyToIdleTimeout
          Max live span of instance since lastAccess in milliseconds
private  java.lang.Object BUSYTOIDLETIMEOUT_MONITOR
          Synchronization helper
private  Timestamp busyToIdleTimeoutHandle
          busyToIdleTimeout handle
private  long creationTime
          Time in milliseconds since January 1, 1970 UTC.
private static java.lang.String IDLE_TO_ERASE_TIMEOUT
          Constant to mark idle to erase timer events
private  long idleToEraseTimeout
          Max live span until 'idle' to 'erase' transition
private  Timestamp idleToEraseTimeoutHandle
          idleToEraseTimeout handle
private  java.lang.String instanceId
          Unique identifier
private  java.lang.String ME
          Nice, unique name for logging output
private  PoolManager poolManager
          My manager
private  java.lang.Object resource
          The resource itself (not interpreted in this context).
 
Constructor Summary
ResourceWrapper(PoolManager poolManager)
          Create a new wrapper for a resource with infinite lifespan.
ResourceWrapper(PoolManager poolManager, java.lang.String instanceId, java.lang.Object resource, long busyToIdleTimeout, long idleToEraseTimeout)
          Create a new wrapper for a user supplied resource.
 
Method Summary
 long busyElapsed()
          How long am i running in busy mode.
 void destroy()
          Cleanup, reset timer and destroy id.
 long getBusyToIdleTimeout()
          Access the overall busy timeout span of this resource.
 long getCreationTime()
          Access the construction date of this ResourceWrapper.
 long getIdleToEraseTimeout()
          Access the overall idle timeout span of this resource.
 java.lang.String getInstanceId()
          Access the unique resource ID.
 java.lang.Object getResource()
          Access the resource object.
(package private)  void init(java.lang.String instanceId, java.lang.Object resource, long busyToIdleTimeout, long idleToEraseTimeout)
          Set resource attributes.
 boolean isBusyExpired()
          Is the resource life span expired?
private  void setBusyToIdle(long val)
          Set timeout and initialize timer.
private  void setIdleToErase(long val)
          Set timeout and initialize timer.
(package private)  void setResource(java.lang.Object resource)
          Set your resource object.
 long spanOfTimeToErase()
          How long to my death.
 long spanOfTimeToIdle()
          How long until i swap from busy to idle.
private  void startBusyToIdleTimeout()
          Start the timeout.
private  void startIdleToEraseTimeout()
          Start the idle to erase timeout.
private  void stopBusyToIdleTimeout()
          Stop the timeout.
private  void stopIdleToEraseTimeout()
          Stop the idle to erase timeout.
 void timeout(java.lang.Object obj)
          A timeout occurred.
(package private)  void toBusy()
          Entering 'busy' state.
(package private)  void toIdle()
          Entering 'idle' state.
 void touchBusy()
          Restart count down in busy mode.
 java.lang.String toXml()
          Dump state of this object into a XML ASCII string.
 java.lang.String toXml(java.lang.String extraOffset)
          Dump state of this object into a XML ASCII string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ME

private java.lang.String ME
Nice, unique name for logging output


instanceId

private java.lang.String instanceId
Unique identifier


resource

private java.lang.Object resource
The resource itself (not interpreted in this context). It is supplied by you.


creationTime

private long creationTime
Time in milliseconds since January 1, 1970 UTC.


BUSY_TO_IDLE_TIMEOUT

private static final java.lang.String BUSY_TO_IDLE_TIMEOUT
Constant to mark busy to idle timer events

See Also:
Constant Field Values

IDLE_TO_ERASE_TIMEOUT

private static final java.lang.String IDLE_TO_ERASE_TIMEOUT
Constant to mark idle to erase timer events

See Also:
Constant Field Values

busyToIdleTimeout

private long busyToIdleTimeout
Max live span of instance since lastAccess in milliseconds


busyToIdleTimeoutHandle

private Timestamp busyToIdleTimeoutHandle
busyToIdleTimeout handle


BUSYTOIDLETIMEOUT_MONITOR

private final java.lang.Object BUSYTOIDLETIMEOUT_MONITOR
Synchronization helper


idleToEraseTimeout

private long idleToEraseTimeout
Max live span until 'idle' to 'erase' transition


idleToEraseTimeoutHandle

private Timestamp idleToEraseTimeoutHandle
idleToEraseTimeout handle


poolManager

private PoolManager poolManager
My manager

Constructor Detail

ResourceWrapper

ResourceWrapper(PoolManager poolManager,
                java.lang.String instanceId,
                java.lang.Object resource,
                long busyToIdleTimeout,
                long idleToEraseTimeout)
Create a new wrapper for a user supplied resource.

Parameters:
poolManager - A reference on my manager
instanceId - The unique ID
If 'null': use ref.hashCode()
resource - Your resource
busyToIdleTimeout - The max. 'busy' life span for this resource
0: infinite
idleToEraseTimeout - The max. 'idle' life span for this resource
0: infinite

ResourceWrapper

ResourceWrapper(PoolManager poolManager)
Create a new wrapper for a resource with infinite lifespan.

You need to call resource(yourResource) after constructing.

Parameters:
poolManager - A reference on my manager
Method Detail

init

void init(java.lang.String instanceId,
          java.lang.Object resource,
          long busyToIdleTimeout,
          long idleToEraseTimeout)
Set resource attributes.

Parameters:
instanceId - The unique identifier
Resource.hashCode() is used if you pass PoolManager.USE_HASH_CODE (== null)
resource - Your resource
busyToIdleTimeout - The max. busy life span.
0: infinite life span
idleToEraseTimeout - The max. 'idle' life span for this resource
0: infinite

toBusy

void toBusy()
Entering 'busy' state.


toIdle

void toIdle()
Entering 'idle' state.


setBusyToIdle

private void setBusyToIdle(long val)
Set timeout and initialize timer.


startBusyToIdleTimeout

private void startBusyToIdleTimeout()
Start the timeout.


stopBusyToIdleTimeout

private void stopBusyToIdleTimeout()
Stop the timeout.


setIdleToErase

private void setIdleToErase(long val)
Set timeout and initialize timer.


startIdleToEraseTimeout

private void startIdleToEraseTimeout()
Start the idle to erase timeout.


stopIdleToEraseTimeout

private void stopIdleToEraseTimeout()
Stop the idle to erase timeout.


timeout

public void timeout(java.lang.Object obj)
A timeout occurred.

This method is a callback through interface I_Timeout.

Specified by:
timeout in interface I_Timeout
Parameters:
The - timeout type, BUSY_TO_IDLE_TIMEOUT or IDLE_TO_ERASE_TIMEOUT

isBusyExpired

public boolean isBusyExpired()
Is the resource life span expired?

Returns:
true/false

busyElapsed

public long busyElapsed()
How long am i running in busy mode.

Returns:
Milliseconds since creation or -1 if not known

spanOfTimeToErase

public long spanOfTimeToErase()
How long to my death.

Returns:
Milliseconds to idleToEraseTimeout
0 for infinite idle life

spanOfTimeToIdle

public long spanOfTimeToIdle()
How long until i swap from busy to idle.

Returns:
Milliseconds to busyToIdleTimeout
0 for infinite life
-1 if busyToIdleTimeout occurred already

touchBusy

public void touchBusy()
Restart count down in busy mode.


getInstanceId

public java.lang.String getInstanceId()
Access the unique resource ID.

Returns:
The unique ID of this resource

getResource

public java.lang.Object getResource()
Access the resource object.

Returns:
Your resource object

setResource

void setResource(java.lang.Object resource)
Set your resource object.

Parameters:
The - new resource

getBusyToIdleTimeout

public long getBusyToIdleTimeout()
Access the overall busy timeout span of this resource.

Returns:
timeout span in milliseconds

getIdleToEraseTimeout

public long getIdleToEraseTimeout()
Access the overall idle timeout span of this resource.

Returns:
timeout span in milliseconds

destroy

public void destroy()
Cleanup, reset timer and destroy id.


getCreationTime

public long getCreationTime()
Access the construction date of this ResourceWrapper.

Returns:
Time in milliseconds since midnight, January 1, 1970 UTC

toXml

public final java.lang.String toXml()
Dump state of this object into a XML ASCII string.

Returns:
internal state of this ResourceWrapper as a XML ASCII string

toXml

public final java.lang.String toXml(java.lang.String extraOffset)
Dump state of this object into a XML ASCII string.

Parameters:
extraOffset - indenting of tags for nice output
Returns:
internal state of this ResourceWrapper as a XML ASCII string

xmlBlaster 2.1.0 API

Copyright © 1999-2011 The xmlBlaster.org contributers.