org.bibalex.daf.handlers.filehandler
Class FTPThreadsPool

java.lang.Object
  extended by org.bibalex.daf.handlers.filehandler.FTPThreadsPool

 class FTPThreadsPool
extends java.lang.Object

A pool of FTP Threads, maintaining a fixed number of connections to the server an reducing the cost of recreating threads. This class is a Singlton (Only one instance can be instantiated).

Author:
Fadi.Edward

Field Summary
private static FTPThreadsPool currentInstance
           
private  java.util.Hashtable<java.lang.String,FTPThread> freeThreads
           
private  java.lang.String hostName
           
private  FileHandlerObservable observable
           
private  java.lang.String password
           
private  int poolSize
           
private  java.util.Hashtable<java.lang.String,FTPThread> usedThreads
           
private  java.lang.String userName
           
 
Constructor Summary
private FTPThreadsPool(java.lang.String hostName, java.lang.String userName, java.lang.String password, int poolSize)
          Private Constructor, preventing any external instantiation of new objects.
private FTPThreadsPool(java.lang.String hostName, java.lang.String userName, java.lang.String password, int poolSize, FileHandlerObservable observable)
          Private Constructor, preventing any external instantiation of new objects.
 
Method Summary
private  FTPThread createThread()
          Create a new Thread.
 void finalize()
          Releases all used threads.
(package private)  FTPThread getThread()
          Retreives a thread, if there exists free threads one of them is returned, if not and the pool size wasn't reached a new thread is created, elsewise this method sends a wait() signal and halts.
static FTPThreadsPool getThreadsPool(java.lang.String hostName, java.lang.String userName, java.lang.String password, int poolSize)
          Implementing a Singleton pattern in retrieving the instance of the Class.
static FTPThreadsPool getThreadsPool(java.lang.String hostName, java.lang.String userName, java.lang.String password, int poolSize, FileHandlerObservable observable)
          Implementing a Singleton pattern in retrieving the instance of the Class.
 void releaseThread(FTPThread threadCopier)
          Release a thread to be returned to the Free Threads Hash.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hostName

private java.lang.String hostName

userName

private java.lang.String userName

password

private java.lang.String password

poolSize

private int poolSize

usedThreads

private java.util.Hashtable<java.lang.String,FTPThread> usedThreads

freeThreads

private java.util.Hashtable<java.lang.String,FTPThread> freeThreads

currentInstance

private static FTPThreadsPool currentInstance

observable

private FileHandlerObservable observable
Constructor Detail

FTPThreadsPool

private FTPThreadsPool(java.lang.String hostName,
                       java.lang.String userName,
                       java.lang.String password,
                       int poolSize)
Private Constructor, preventing any external instantiation of new objects.

Parameters:
hostName - Host Network Name or IP.
userName - User Name.
password - Password.
poolSize - Pool Size.

FTPThreadsPool

private FTPThreadsPool(java.lang.String hostName,
                       java.lang.String userName,
                       java.lang.String password,
                       int poolSize,
                       FileHandlerObservable observable)
Private Constructor, preventing any external instantiation of new objects.

Parameters:
hostName - Host Network Name or IP.
userName - User Name.
password - Password.
poolSize - Pool Size.
observable - FileHandlerObservable object to be assigned to the threads
Method Detail

getThreadsPool

public static FTPThreadsPool getThreadsPool(java.lang.String hostName,
                                            java.lang.String userName,
                                            java.lang.String password,
                                            int poolSize)
Implementing a Singleton pattern in retrieving the instance of the Class.

Parameters:
hostName - Host Network Name or IP.
userName - User Name.
password - Password.
poolSize - Pool Size.
Returns:
The FTPThreadsPool instance.

getThreadsPool

public static FTPThreadsPool getThreadsPool(java.lang.String hostName,
                                            java.lang.String userName,
                                            java.lang.String password,
                                            int poolSize,
                                            FileHandlerObservable observable)
Implementing a Singleton pattern in retrieving the instance of the Class.

Parameters:
hostName - Host Network Name or IP.
userName - User Name.
password - Password.
poolSize - Pool Size.
observable - FileHandlerObservable object to be assigned to the threads
Returns:
The FTPThreadsPool instance.

finalize

public void finalize()
Releases all used threads.

Overrides:
finalize in class java.lang.Object

releaseThread

public void releaseThread(FTPThread threadCopier)
Release a thread to be returned to the Free Threads Hash.

Parameters:
threadCopier - The thread to be freed.

createThread

private FTPThread createThread()
Create a new Thread. This method is only called when the pool size wasn't reached and there is no free threads.

Returns:
an FTPThread thread.

getThread

FTPThread getThread()
Retreives a thread, if there exists free threads one of them is returned, if not and the pool size wasn't reached a new thread is created, elsewise this method sends a wait() signal and halts.

Returns:
an FTPThread instance.