All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.extropia.net.JavaCGIBridgePool

java.lang.Object
   |
   +----com.extropia.net.JavaCGIBridgePool

public class JavaCGIBridgePool
extends Object
implements Runnable
This is a class that manages the creation and reuse of previously created JavaCGIBridge Objects. This is useful in two cases.

First, if your applet requires using JavaCGIBridge many times during its life, it can be wasteful to keep creating new JavaCGIBridge objects for use. The JavaCGIBridgePool class creates a new JavaCGIBridge if none are available and it hands back an existing idle JavaCGIBridge Object otherwise for reuse.

Second, if you methods in the JavaCGIBridge which cause it to return control back to the main applet thread before it has actually finished with the HTTP communication, then JavaCGIBridgePool also takes into account the status of the JavaCGIBridge objects in deciding whether or not to hand it to the user. If the JavaCGIBridge object claims it is still processing an HTTP request in another thread, then the JavaCGIBridgePool will pass over that object and look at the next one or create a new instance if no more is available.

In addition, if you turn on the feature, a separate thread will be spawned which will periodically check if there are any JavaCGIBridge objects that have timed out. These will be stopped and the observers of the timed out JavaCGIBridge object will be notified of the exception.

Most traditional object pool implementations require explicit check in and check out procedures so that the pool knows that the object has been handed back in for reuse. JavaCGIBridgePool does not operate this way. Since JavaCGIBridge objects know when they are done processing and have their state set to IDLE, the JavaCGIBridgePool reclaims these objects at that point. Therefore, it is important to always use JavaCGIBridgePool to get the next JavaCGIBridge object after each request instead of reusing it on your own. If you plan on reusing a JavaCGIBridge object on your own, it is better if you create it yourself. However, if you create your own, you will lose a lot of the built in logic of the JavaCGIBridgePool class.

Design note: This class is meant to be used as a singleton. However, instead of simply containing static methods, you need to instantiate this class. The reason for this is that browsers tend to run all applets in a single java virtual machine. Using a class singleton instead of an instantiated object singleton would therefore introduce subtle bugs if multiple applets provide different defaults to the Pool. If you wish to use a class singleton mechanism, I would suggest creating a wrapper class that has a JavaCGIBridgePool static member. This could be an advantage if you are explicitly designing your application to share JavaCGIBridge objects between applets.

Version:
2.00, 18 Jul 1998
Author:
Gunther Birznieks, Marty Hall

Variable Index

 o _defaultEndDataSeparator
This is the default end of data separator that will be assigned to the JavaCGIBridge object when it is handed out from the pool.
 o _defaultFieldSeparator
This is the default field separator that will be assigned to the JavaCGIBridge object when it is handed out from the pool.
 o _defaultParseAsRaw
This is the default value for the ParseAsRaw flag that will be assigned to JavaCGIBridge objects when they are handed out from the pool.
 o _defaultParsedNotifyInterval
This is the default notification interval that will be assigned to the JavaCGIBridge object when it is handed out from the pool.
 o _defaultRawNotifyInterval
This is the default notification interval that will be assigned to the JavaCGIBridge object when it is handed out from the pool.
 o _defaultRecordSeparator
This is the default record separator that will be assigned to the JavaCGIBridge object when it is handed out from the pool.
 o _defaultStartDataSeparator
This is the default start of data separator that will be assigned to the JavaCGIBridge object when it is handed out from the pool.
 o _defaultTimeOut
This is the default CGI Timeout in milliseconds.
 o _javaCGIBridgeVector
Vector that contains JavaCGIBridge objects.
 o _maxObjects
Maximum number of JavaCGIBridge objects to have in the pool.
 o _maxSpareObjects
Maximum number of IDLE JavaCGIBridge objects to keep around.
 o _threadCleaner
Thread containing a reference to the thread which checks for cleanup
 o _threadCleanTime
int containing how many milliseconds to sleep before checking to see if any JavaCGIBridge objects need cleaning up.

Constructor Index

 o JavaCGIBridgePool()

Method Index

 o _getJavaCGIBridge(boolean)
Obtains a JavaCGIBridge or JavaCGIBridgeExtension object from the pool depending on the type of object passed as a parameter.
 o cleanPool()
Checks the pool to see if any JavaCGIBridge objects have timed out.
 o clearPool()
Clears out the pool of JavaCGIBridge objects.
 o getCleanTime()
Returns the time in milliseconds that a thread will wait before waking up and seeing whether any JavaCGIBridge objects in the pool need cleaning out.
 o getDefaultEndDataSeparator()
Returns the default End of Data separator value to be assigned to the JavaCGIBridge object when it is handed out from the pool.
 o getDefaultFieldSeparator()
Returns the default field separator value to be assigned to the JavaCGIBridge object when it is handed out from the pool.
 o getDefaultParseAsRaw()
Returns the default ParseAsRaw value to be assigned to the JavaCGIBridge object when it is handed out from the pool.
 o getDefaultParsedNotifyInterval()
Returns the default ParsedNotifyInterval value to be assigned to the JavaCGIBridge object when it is handed out from the pool.
 o getDefaultRawNotifyInterval()
Returns the default RawNotifyInterval value to be assigned to the JavaCGIBridge object when it is handed out from the pool.
 o getDefaultRecordSeparator()
Returns the default record separator value to be assigned to the JavaCGIBridge object when it is handed out from the pool.
 o getDefaultStartDataSeparator()
Returns the default Start of Data separator value to be assigned to the JavaCGIBridge object when it is handed out from the pool.
 o getDefaultTimeOut()
Returns the default communication time out in milliseconds for the class.
 o getJavaCGIBridge()
Obtains a free JavaCGIBridge object or creates a new one if none are available.
 o getJavaCGIBridgeExtension()
Obtains a free JavaCGIBridgeExtension object or creates a new one if none are available.
 o getMaxObjects()
Returns a value indicating the maximum number of objects the JavaCGIBridgePool is allowed to hold.
 o getMaxSpareObjects()
Returns a value indicating the maximum number of objects the JavaCGIBridgePool keeps lying around in the IDLE state.
 o removeJavaCGIBridge(JavaCGIBridge)
Removes a particular JavaCGIBridge object from the pool.
 o run()
Thread that cleans up timed out JavaCGIBridge objects.
 o setCleanTime(int)
Sets the time between when the JavaCGIBridgePool's thread will check if objects in the pool have timed out and need to be cleaned.
 o setDefaultEndDataSeparator(String)
Sets the default End of Data value to be assigned to the JavaCGIBridge object when it is handed out from the pool.
 o setDefaultFieldSeparator(String)
Sets the default field separator value to be assigned to the JavaCGIBridge object when it is handed out from the pool.
 o setDefaultParseAsRaw(boolean)
Sets the default ParseAsRaw value to be assigned to the JavaCGIBridge object when it is handed out from the pool.
 o setDefaultParsedNotifyInterval(int)
Sets the default ParsedNotifyInterval value to be assigned to the JavaCGIBridge object when it is handed out from the pool.
 o setDefaultRawNotifyInterval(int)
Sets the default RawNotifyInterval value to be assigned to the JavaCGIBridge object when it is handed out from the pool.
 o setDefaultRecordSeparator(String)
Sets the default record separator value to be assigned to the JavaCGIBridge object when it is handed out from the pool.
 o setDefaultStartDataSeparator(String)
Sets the default Start of Data value to be assigned to the JavaCGIBridge object when it is handed out from the pool.
 o setDefaultTimeOut(int)
Sets the default communication time out in milliseconds for the class.
 o setMaxObjects(int)
Sets the maximum number of objects the JavaCGIBridgePool can hold.
 o setMaxSpareObjects(int)
Sets the maximum number of spare IDLE objects the JavaCGIBridgePool keeps lying around.

Variables

 o _javaCGIBridgeVector
 private Vector _javaCGIBridgeVector
Vector that contains JavaCGIBridge objects. This data structure is the virtual "pool" of JavaCGIBridges.

 o _threadCleanTime
 private int _threadCleanTime
int containing how many milliseconds to sleep before checking to see if any JavaCGIBridge objects need cleaning up. The default, 0, means no automatic clean up occurs.

 o _threadCleaner
 private Thread _threadCleaner
Thread containing a reference to the thread which checks for cleanup

 o _maxSpareObjects
 private int _maxSpareObjects
Maximum number of IDLE JavaCGIBridge objects to keep around. 0 means keep all of them around.

 o _maxObjects
 private int _maxObjects
Maximum number of JavaCGIBridge objects to have in the pool. Default is unlimited (0). Be careful with this setting! You may have a severe performance loss if you set up an upper limit. Do this only if you are really concerned about RAM and object creation time overhead for your platform.

 o _defaultTimeOut
 private int _defaultTimeOut
This is the default CGI Timeout in milliseconds. For example, a value of 10000 will tell the class to throw a JavaCGIBridgeTimeOutException if the data is not retrieved within 10 seconds of having initiated a data transfer.

 o _defaultParseAsRaw
 private boolean _defaultParseAsRaw
This is the default value for the ParseAsRaw flag that will be assigned to JavaCGIBridge objects when they are handed out from the pool.

 o _defaultParsedNotifyInterval
 private int _defaultParsedNotifyInterval
This is the default notification interval that will be assigned to the JavaCGIBridge object when it is handed out from the pool.

 o _defaultRawNotifyInterval
 private int _defaultRawNotifyInterval
This is the default notification interval that will be assigned to the JavaCGIBridge object when it is handed out from the pool.

 o _defaultStartDataSeparator
 private String _defaultStartDataSeparator
This is the default start of data separator that will be assigned to the JavaCGIBridge object when it is handed out from the pool.

 o _defaultEndDataSeparator
 private String _defaultEndDataSeparator
This is the default end of data separator that will be assigned to the JavaCGIBridge object when it is handed out from the pool.

 o _defaultFieldSeparator
 private String _defaultFieldSeparator
This is the default field separator that will be assigned to the JavaCGIBridge object when it is handed out from the pool.

 o _defaultRecordSeparator
 private String _defaultRecordSeparator
This is the default record separator that will be assigned to the JavaCGIBridge object when it is handed out from the pool.

Constructors

 o JavaCGIBridgePool
 public JavaCGIBridgePool()

Methods

 o getJavaCGIBridge
 public JavaCGIBridge getJavaCGIBridge()
Obtains a free JavaCGIBridge object or creates a new one if none are available.

Returns:
JavaCGIBridge
See Also:
getJavaCGIBridgeExtension
 o getJavaCGIBridgeExtension
 public JavaCGIBridgeExtension getJavaCGIBridgeExtension()
Obtains a free JavaCGIBridgeExtension object or creates a new one if none are available.

Returns:
JavaCGIBridgeExtension
See Also:
getJavaCGIBridge
 o _getJavaCGIBridge
 private synchronized JavaCGIBridge _getJavaCGIBridge(boolean useExtension)
Obtains a JavaCGIBridge or JavaCGIBridgeExtension object from the pool depending on the type of object passed as a parameter.

Note, if you set an upper limit on the maximum number of objects the JavaCGIBridgePool can hold, then this method will block until an object is freed if no more slots are available. It is recommended that you not set an upper limit unless you have a very good architectural reason for doing so in your application.

Parameters:
useExtension - flag to indicate whether to return a JavaCGIBridge or JavaCGIBridgeExtension
Returns:
JavaCGIBridge
See Also:
getJavaCGIBridge, getJavaCGIBridgeExtension, getMaxObjects, setMaxObjects
 o removeJavaCGIBridge
 public synchronized boolean removeJavaCGIBridge(JavaCGIBridge jcb)
Removes a particular JavaCGIBridge object from the pool. If the status is not idle, the object will not be removed.

Parameters:
jcb - JavaCGIBridge object to remove
Returns:
boolean returns true if object was removed
See Also:
cleanPool
 o clearPool
 public synchronized void clearPool()
Clears out the pool of JavaCGIBridge objects. Objects not currently in use are removed from the pool. Objects current in use are kept in the pool.

See Also:
removeJavaCGIBridge
 o getMaxObjects
 public int getMaxObjects()
Returns a value indicating the maximum number of objects the JavaCGIBridgePool is allowed to hold. Zero (the default) indicates unlimited number of JavaCGIBridge objects can be created.

Returns:
int maximum number of JavaCGIBridge objects the JavaCGIBridgePool can hold
See Also:
setMaxObjects, getJavaCGIBridge, getJavaCGIBridgeExtension
 o setMaxObjects
 public void setMaxObjects(int max)
Sets the maximum number of objects the JavaCGIBridgePool can hold. Zero (the default) indicates unlimited number of JavaCGIBridge objects can be created.

Parameters:
max - maximum number of JavaCGIBridge objects the JavaCGIBridgePool can hold
See Also:
getMaxObjects, getJavaCGIBridge, getJavaCGIBridgeExtension
 o getMaxSpareObjects
 public int getMaxSpareObjects()
Returns a value indicating the maximum number of objects the JavaCGIBridgePool keeps lying around in the IDLE state. It is useful to lower this if you want to conserve RAM and you think there might be a point in your software where many objects would be created at once. This might occur if many asynchronous requests need to be serviced. Zero (the default) indicates unlimited number of JavaCGIBridge IDLE objects can be left hanging around. This value is used when the cleanPool() method tries to clean out unnecessary or timed out objects.

See Also:
setMaxSpareObjects, cleanPool
 o setMaxSpareObjects
 public void setMaxSpareObjects(int max)
Sets the maximum number of spare IDLE objects the JavaCGIBridgePool keeps lying around. It is useful to lower this value if you want to conserve RAM and you think there might be a point in your software where many objects would be created at once which you don't want to keep around for the life of the program

See Also:
getMaxSpareObjects, cleanPool
 o getCleanTime
 public int getCleanTime()
Returns the time in milliseconds that a thread will wait before waking up and seeing whether any JavaCGIBridge objects in the pool need cleaning out.

Returns:
int time in miiliseconds for thread to wake up for cleaning up the JavaCGIBridgePool
See Also:
setCleanTime, cleanPool
 o setCleanTime
 public void setCleanTime(int cleanUpTime)
Sets the time between when the JavaCGIBridgePool's thread will check if objects in the pool have timed out and need to be cleaned. If the time is 0 (default), then no thread cleans up automatically. If the time is positive, then this method actually creates and starts the thread that watches the objects for cleanup.

Parameters:
cleanUpTime - the time in milliseconds before checking objects for clean up.
See Also:
getCleanTime, cleanPool
 o run
 public void run()
Thread that cleans up timed out JavaCGIBridge objects. It wakes up at a user defined interval and checks the objects for time out then. Note that this thread will not start unless setCleanTime() has been called with a time other than 0.

See Also:
getCleanTime, setCleanTime
 o cleanPool
 public synchronized void cleanPool()
Checks the pool to see if any JavaCGIBridge objects have timed out. If they have, it shuts down the object, notifies the observers of the timeout exception, and then gets removed from the pool.

This method is generally called from within the pool's clean up thread. However, this method has been made public in case you want to deterministically call this routine at various stages in your program.

The cleanPool will also make sure that no more than the maxSpareObjects will exist in the pool.

See Also:
removeJavaCGIBridge, getCleanTime, setCleanTime, clearPool, getMaxSpareObjects, setMaxSpareObjects
 o getDefaultTimeOut
 public int getDefaultTimeOut()
Returns the default communication time out in milliseconds for the class. The default is initially set to 10 seconds. When the object retrieves data from a URL, it must get the data within timeout milliseconds or a JavaCGIBridgeTimeOutException is thrown.

Returns:
default communication time out in milliseconds
See Also:
setDefaultTimeOut
 o setDefaultTimeOut
 public void setDefaultTimeOut(int t)
Sets the default communication time out in milliseconds for the class. The default is initially set to 10 seconds. When the object retrieves data from a URL, it must get the data within timeout milliseconds or a JavaCGIBridgeTimeOutException is thrown.

Parameters:
t - default communication time out in milliseconds
See Also:
getDefaultTimeOut
 o getDefaultParseAsRaw
 public boolean getDefaultParseAsRaw()
Returns the default ParseAsRaw value to be assigned to the JavaCGIBridge object when it is handed out from the pool. The default value for this parameter is false.

Returns:
default ParseAsRaw value to be assigned
See Also:
setDefaultParseAsRaw
 o setDefaultParseAsRaw
 public void setDefaultParseAsRaw(boolean b)
Sets the default ParseAsRaw value to be assigned to the JavaCGIBridge object when it is handed out from the pool. The default value for this parameter is initially set to false.

Parameters:
b - default ParseAsRaw value to be assigned
See Also:
getDefaultParseAsRaw
 o getDefaultParsedNotifyInterval
 public int getDefaultParsedNotifyInterval()
Returns the default ParsedNotifyInterval value to be assigned to the JavaCGIBridge object when it is handed out from the pool. The default value for this parameter is 0.

Returns:
default ParsedNotifyInterval value to be assigned
See Also:
setDefaultParsedNotifyInterval
 o setDefaultParsedNotifyInterval
 public void setDefaultParsedNotifyInterval(int i)
Sets the default ParsedNotifyInterval value to be assigned to the JavaCGIBridge object when it is handed out from the pool. The default value for this parameter is initially set to 0.

Parameters:
i - default ParsedNotifyInterval value to be assigned
See Also:
getDefaultParsedNotifyInterval
 o getDefaultRawNotifyInterval
 public int getDefaultRawNotifyInterval()
Returns the default RawNotifyInterval value to be assigned to the JavaCGIBridge object when it is handed out from the pool. The default value for this parameter is 0.

Returns:
default RawNotifyInterval value to be assigned
See Also:
setDefaultRawNotifyInterval
 o setDefaultRawNotifyInterval
 public void setDefaultRawNotifyInterval(int i)
Sets the default RawNotifyInterval value to be assigned to the JavaCGIBridge object when it is handed out from the pool. The default value for this parameter is initially set to 0.

Parameters:
i - default RawNotifyInterval value to be assigned
See Also:
getDefaultRawNotifyInterval
 o getDefaultStartDataSeparator
 public String getDefaultStartDataSeparator()
Returns the default Start of Data separator value to be assigned to the JavaCGIBridge object when it is handed out from the pool. The default value for this parameter is "<!--start of data-->\n".

Returns:
default start of data separator value to be assigned
See Also:
setDefaultStartDataSeparator
 o setDefaultStartDataSeparator
 public void setDefaultStartDataSeparator(String s)
Sets the default Start of Data value to be assigned to the JavaCGIBridge object when it is handed out from the pool. The default value for this parameter is initially set to "<!--start of data-->\n".

Parameters:
s - default start of data value to be assigned
See Also:
getDefaultStartDataSeparator
 o getDefaultEndDataSeparator
 public String getDefaultEndDataSeparator()
Returns the default End of Data separator value to be assigned to the JavaCGIBridge object when it is handed out from the pool. The default value for this parameter is "<!--end of data-->".

Returns:
default end of data value to be assigned
See Also:
setDefaultEndData
 o setDefaultEndDataSeparator
 public void setDefaultEndDataSeparator(String s)
Sets the default End of Data value to be assigned to the JavaCGIBridge object when it is handed out from the pool. The default value for this parameter is initially set to "<!--end of data-->".

Parameters:
s - default end of data value to be assigned
See Also:
getDefaultEndData
 o getDefaultFieldSeparator
 public String getDefaultFieldSeparator()
Returns the default field separator value to be assigned to the JavaCGIBridge object when it is handed out from the pool. The default value for this parameter is "|".

Returns:
default field separator value to be assigned
See Also:
setDefaultFieldSeparator
 o setDefaultFieldSeparator
 public void setDefaultFieldSeparator(String s)
Sets the default field separator value to be assigned to the JavaCGIBridge object when it is handed out from the pool. The default value for this parameter is initially set to "|".

Parameters:
s - default field separator value to be assigned
See Also:
getDefaultFieldSeparator
 o getDefaultRecordSeparator
 public String getDefaultRecordSeparator()
Returns the default record separator value to be assigned to the JavaCGIBridge object when it is handed out from the pool. The default value for this parameter is "\n".

Returns:
default record separator value to be assigned
See Also:
setDefaultRecordSeparator
 o setDefaultRecordSeparator
 public void setDefaultRecordSeparator(String s)
Sets the default record separator value to be assigned to the JavaCGIBridge object when it is handed out from the pool. The default value for this parameter is initially set to "\n".

Parameters:
s - default record separator value to be assigned
See Also:
getDefaultRecordSeparator

All Packages  Class Hierarchy  This Package  Previous  Next  Index