org.jmx4odp.pool
Class AbstractContextPool

java.lang.Object
  extended by org.jmx4odp.pool.AbstractContextPool
All Implemented Interfaces:
ContextPool
Direct Known Subclasses:
OrderedContextPool, RoundRobbinContextPool

public abstract class AbstractContextPool
extends java.lang.Object
implements ContextPool

This pool does not implement a getAailableContext method, that is implemented by the overriding class. Each implemntation class should implemeney a different strategy for finding the next available context. All other methods, such as adding new contexts to the pool, updating status, and fetching specific context should remain the same

Author:
Lucas McGregor

Field Summary
 
Fields inherited from interface org.jmx4odp.pool.ContextPool
DOWN_SERVICE_RETRY_WAIT, INSTANCE_ID, SERVICE_NAME, SERVICE_STATUS, STATUS_DOWN, STATUS_DOWN_DATE, STATUS_UNKOWN, STATUS_UP
 
Constructor Summary
AbstractContextPool()
          Creates a new instance of ServiceContextContainer
 
Method Summary
 void addContext(javax.naming.Context ctx)
          Add a loaded context to this pool.
 boolean checkIfContextIsUp(javax.naming.Context ctx)
          This is a utility function mostly intended for subclasses.
abstract  javax.naming.Context getAvailableContext()
          This needs to be implemented by whatever the strategey of the child class is.
 javax.naming.Context getContext(javax.naming.Context ctx)
          Given a context, it will look for the INSTANCE_ID property and find the matching context in the pool.
 javax.naming.Context getContext(int i)
          Given an index it will return this specific context from the pool.
 javax.naming.Context getContext(java.lang.String id)
          Given an index it will return this specific ontext from the pool
 int getNumberOfServices()
           
 java.lang.String getServiceName()
          Getter for property serviceName.
 java.lang.String getStatus(javax.naming.Context ctx)
          Given a context, it will return the status of this context: STATUS_UNKOWN, STATUS_UP, or STATUS_DOWN
 java.lang.String getStatus(int index)
          return the status of the instance at the given index
 java.lang.String getStatus(java.lang.String id)
          return the status of the instance at the given index
protected  boolean markContextDown(javax.naming.Context ctx)
          This function is private, because it needs to only accept contexts that are known to be refs to the one kept in this pool.
protected  boolean markContextUp(javax.naming.Context ctx)
          This function is private, because it needs to only accept contexts that are known to be refs to the one kept in this pool.
 boolean markDown(javax.naming.Context ctx)
          Given a context, find the matching on in the system (In case this is a copy and not a ref) and then set it to down.
 boolean markDown(int index)
          Given a context, find the matching on in the system (In case this is a copy and not a ref) and then set it to down.
 boolean markDown(java.lang.String id)
          Given a context, find the matching on in the system (In case this is a copy and not a ref) and then set it to down.
 boolean markUp(javax.naming.Context ctx)
          Given a context, find the matching on in the system (In case this is a copy and not a ref) and then set it to down.
 boolean markUp(int index)
          Given a context, find the matching on in the system (In case this is a copy and not a ref) and then set it to down.
 boolean markUp(java.lang.String id)
          Given a context, find the matching on in the system (In case this is a copy and not a ref) and then set it to down.
 void setServiceName(java.lang.String name)
          Setter for property serviceName.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractContextPool

public AbstractContextPool()
Creates a new instance of ServiceContextContainer

Method Detail

getServiceName

public java.lang.String getServiceName()
Getter for property serviceName.

Specified by:
getServiceName in interface ContextPool
Returns:
Value of property serviceName.

setServiceName

public void setServiceName(java.lang.String name)
Setter for property serviceName. If this value is set, it will be added to each context that is added to the pool in its environment with the key ContextPool.SERVICE_NAME This is useful when trying to match contexts with pools outside of this object.

Specified by:
setServiceName in interface ContextPool
Parameters:
serviceName - New value of property serviceName.

getNumberOfServices

public int getNumberOfServices()
Specified by:
getNumberOfServices in interface ContextPool
Returns:
the number of services is the pool

getContext

public javax.naming.Context getContext(int i)
                                throws javax.naming.NamingException
Given an index it will return this specific context from the pool. This is the equivalent of calling contexts.get(Integer.toString(i))

Specified by:
getContext in interface ContextPool
Parameters:
i - index of the context in the pool
Throws:
javax.naming.NamingException - if there is no matching Context

getContext

public javax.naming.Context getContext(java.lang.String id)
                                throws javax.naming.NamingException
Given an index it will return this specific ontext from the pool

Specified by:
getContext in interface ContextPool
Parameters:
id - (usually the index) of the context
Throws:
javax.naming.NamingException - if there is no matching Context

getContext

public javax.naming.Context getContext(javax.naming.Context ctx)
                                throws javax.naming.NamingException
Given a context, it will look for the INSTANCE_ID property and find the matching context in the pool. If it does not exists, it will throw an Exception

Specified by:
getContext in interface ContextPool
Parameters:
context - containing the id property.
Throws:
javax.naming.NamingException - if there is no matching Context

getStatus

public java.lang.String getStatus(int index)
return the status of the instance at the given index

Specified by:
getStatus in interface ContextPool

getStatus

public java.lang.String getStatus(java.lang.String id)
return the status of the instance at the given index

Specified by:
getStatus in interface ContextPool

getStatus

public java.lang.String getStatus(javax.naming.Context ctx)
Given a context, it will return the status of this context: STATUS_UNKOWN, STATUS_UP, or STATUS_DOWN

Specified by:
getStatus in interface ContextPool

markUp

public boolean markUp(int index)
Given a context, find the matching on in the system (In case this is a copy and not a ref) and then set it to down. If there is not match, this will do nothing.

Specified by:
markUp in interface ContextPool
Parameters:
index - of the service service context to mark as up
Returns:
true if it is able to mark the context as up

markUp

public boolean markUp(java.lang.String id)
Given a context, find the matching on in the system (In case this is a copy and not a ref) and then set it to down. If there is not match, this will do nothing.

Specified by:
markUp in interface ContextPool
Parameters:
if - of the service context to mark as up
Returns:
true if it is able to mark the context as up

markUp

public boolean markUp(javax.naming.Context ctx)
Given a context, find the matching on in the system (In case this is a copy and not a ref) and then set it to down. If there is not match, this will do nothing.

Specified by:
markUp in interface ContextPool
Parameters:
Context, - service context to mark as up
Returns:
true if it is able to mark the context as up

markDown

public boolean markDown(int index)
Given a context, find the matching on in the system (In case this is a copy and not a ref) and then set it to down. If there is not match, this will do nothing.

Specified by:
markDown in interface ContextPool
Parameters:
index - of the service service context to mark as down
Returns:
true if it is able to mark the context as down

markDown

public boolean markDown(java.lang.String id)
Given a context, find the matching on in the system (In case this is a copy and not a ref) and then set it to down. If there is not match, this will do nothing.

Specified by:
markDown in interface ContextPool
Parameters:
if - of the service context to mark as down
Returns:
true if it is able to mark the context as down

markDown

public boolean markDown(javax.naming.Context ctx)
Given a context, find the matching on in the system (In case this is a copy and not a ref) and then set it to down. If there is not match, this will do nothing.

Specified by:
markDown in interface ContextPool
Parameters:
Context, - service context to mark as down
Returns:
true if it is able to mark the context as down

markContextDown

protected boolean markContextDown(javax.naming.Context ctx)
This function is private, because it needs to only accept contexts that are known to be refs to the one kept in this pool. It will mark that context down. If it gets a null ctx, it will return false. If there is an exception while changing the props, it will return false. Otherwise, it returns a true to indicate that it could update the status.


markContextUp

protected boolean markContextUp(javax.naming.Context ctx)
This function is private, because it needs to only accept contexts that are known to be refs to the one kept in this pool. It will mark that context up. If it gets a null ctx, it will return false. If there is an exception while changing the props, it will return false. Otherwise, it returns a true to indicate that it could update the status.


getAvailableContext

public abstract javax.naming.Context getAvailableContext()
                                                  throws NoObjectsInPoolException
This needs to be implemented by whatever the strategey of the child class is.

Specified by:
getAvailableContext in interface ContextPool
Throws:
NoObjectsInPoolException

checkIfContextIsUp

public boolean checkIfContextIsUp(javax.naming.Context ctx)
This is a utility function mostly intended for subclasses. It provides a single function that will check: If the cotext.STATUS == STATUS_UP If not, then check to see if the down date was more than down.service.retry.wait ms ago. If so, flip the status back to STATUS_UP and return true. If the down.service.retry.wait is set, then it will never reset the status and will return false.

Returns:

addContext

public void addContext(javax.naming.Context ctx)
                throws javax.naming.NamingException
Add a loaded context to this pool. This requires that the context is not null and has the following attributes set: If there is a serviceName set on this pool. it will be added to the context environment under the service.name (Context.SERVICE_NAME) value.

Specified by:
addContext in interface ContextPool
Throws:
javax.naming.NamingException - if we cannot add this context to this pool.