com.octo.captcha.service
Class AbstractManageableCaptchaService

java.lang.Object
  extended by com.octo.captcha.service.AbstractCaptchaService
      extended by com.octo.captcha.service.AbstractManageableCaptchaService
All Implemented Interfaces:
AbstractManageableCaptchaServiceMBean, CaptchaService, ManageableCaptchaService
Direct Known Subclasses:
AbstractManageableImageCaptchaService, AbstractManageableSoundCaptchaService, GenericManageableCaptchaService

public abstract class AbstractManageableCaptchaService
extends AbstractCaptchaService
implements AbstractManageableCaptchaServiceMBean, CaptchaService

This class provides default implementation for the management interface. It uses an HashMap to store the timestamps for garbage collection.


Field Summary
 
Fields inherited from class com.octo.captcha.service.AbstractCaptchaService
engine, logger, store
 
Constructor Summary
protected AbstractManageableCaptchaService(CaptchaStore captchaStore, CaptchaEngine captchaEngine, int minGuarantedStorageDelayInSeconds, int maxCaptchaStoreSize)
           
protected AbstractManageableCaptchaService(CaptchaStore captchaStore, CaptchaEngine captchaEngine, int minGuarantedStorageDelayInSeconds, int maxCaptchaStoreSize, int captchaStoreLoadBeforeGarbageCollection)
           
 
Method Summary
 void emptyCaptchaStore()
          Empty the Store
 void garbageCollectCaptchaStore()
          Garbage collect the captcha store, means all old capthca (captcha in the store wich has been stored more than the MinGuarantedStorageDelayInSecond
protected  void garbageCollectCaptchaStore(java.util.Iterator garbageCollectableCaptchaIds)
          Garbage collect the captcha store, means all old captcha (captcha in the store wich has been stored more than the MinGuarantedStorageDelayInSecond
protected  Captcha generateAndStoreCaptcha(java.util.Locale locale, java.lang.String ID)
           
 java.lang.String getCaptchaEngineClass()
          Get the fully qualified class name of the concrete CaptchaEngine used by the service.
 int getCaptchaStoreMaxSize()
           
 int getCaptchaStoreSize()
          Get the curent size of the captcha store
 int getCaptchaStoreSizeBeforeGarbageCollection()
           
 CaptchaEngine getEngine()
           
 int getMinGuarantedStorageDelayInSeconds()
          Get the minimum delay (in seconds) a client can be assured that a captcha generated by the service can be retrieved and a response to its challenge tested
 long getNumberOfCorrectResponses()
          Get the number of correct responses to captcha challenges since the service is up.
 int getNumberOfGarbageCollectableCaptchas()
          Get the number of captchas that can be garbage collected in the captcha store
 long getNumberOfGarbageCollectedCaptcha()
          Get the number of captcha garbage collected since the service is up WARNING : this value won't be significant if the real number is > Long.MAX_VALUE
 long getNumberOfGeneratedCaptchas()
          Get the number of captcha generated since the service is up WARNING : this value won't be significant if the real number is > Long.MAX_VALUE
 long getNumberOfUncorrectResponses()
          Get the number of uncorrect responses to captcha challenges since the service is up.
protected  boolean isCaptchaStoreFull()
           
protected  boolean isCaptchaStoreQuotaReached()
           
 void setCaptchaEngine(CaptchaEngine engine)
          Updates the engine served by this service
 void setCaptchaEngineClass(java.lang.String theClassName)
          Set the fully qualified class name of the concrete CaptchaEngine used by the service
 void setCaptchaStoreMaxSize(int size)
          This max size is used by the service : it will throw a CaptchaServiceException if the store is full when a client ask for a captcha.
 void setCaptchaStoreSizeBeforeGarbageCollection(int captchaStoreSizeBeforeGarbageCollection)
          max captchaStore size before garbage collection of the store
 void setMinGuarantedStorageDelayInSeconds(int theMinGuarantedStorageDelayInSeconds)
          set the minimum delay (in seconds)a client can be assured that a captcha generated by the service can be retrieved and a response to its challenge tested
 java.lang.Boolean validateResponseForID(java.lang.String ID, java.lang.Object response)
          Method to validate a response to the challenge corresponding to the given ticket and remove the coresponding captcha from the store.
 
Methods inherited from class com.octo.captcha.service.AbstractCaptchaService
getChallengeClone, getChallengeForID, getChallengeForID, getQuestionForID, getQuestionForID
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.octo.captcha.service.CaptchaService
getChallengeForID, getChallengeForID, getQuestionForID, getQuestionForID
 

Constructor Detail

AbstractManageableCaptchaService

protected AbstractManageableCaptchaService(CaptchaStore captchaStore,
                                           CaptchaEngine captchaEngine,
                                           int minGuarantedStorageDelayInSeconds,
                                           int maxCaptchaStoreSize)

AbstractManageableCaptchaService

protected AbstractManageableCaptchaService(CaptchaStore captchaStore,
                                           CaptchaEngine captchaEngine,
                                           int minGuarantedStorageDelayInSeconds,
                                           int maxCaptchaStoreSize,
                                           int captchaStoreLoadBeforeGarbageCollection)
Method Detail

getCaptchaEngineClass

public java.lang.String getCaptchaEngineClass()
Get the fully qualified class name of the concrete CaptchaEngine used by the service.

Specified by:
getCaptchaEngineClass in interface ManageableCaptchaService
Returns:
the fully qualified class name of the concrete CaptchaEngine used by the service.

setCaptchaEngineClass

public void setCaptchaEngineClass(java.lang.String theClassName)
                           throws java.lang.IllegalArgumentException
Set the fully qualified class name of the concrete CaptchaEngine used by the service

Specified by:
setCaptchaEngineClass in interface ManageableCaptchaService
Parameters:
theClassName - the fully qualified class name of the CaptchaEngine used by the service
Throws:
java.lang.IllegalArgumentException - if className can't be used as the service CaptchaEngine, either because it can't be instanciated by the service or it is not a ImageCaptchaEngine concrete class.

getEngine

public CaptchaEngine getEngine()
Specified by:
getEngine in interface ManageableCaptchaService
Returns:
the engine served by this service

setCaptchaEngine

public void setCaptchaEngine(CaptchaEngine engine)
Updates the engine served by this service

Specified by:
setCaptchaEngine in interface ManageableCaptchaService

getMinGuarantedStorageDelayInSeconds

public int getMinGuarantedStorageDelayInSeconds()
Get the minimum delay (in seconds) a client can be assured that a captcha generated by the service can be retrieved and a response to its challenge tested

Specified by:
getMinGuarantedStorageDelayInSeconds in interface ManageableCaptchaService
Returns:
the maximum delay in seconds

setMinGuarantedStorageDelayInSeconds

public void setMinGuarantedStorageDelayInSeconds(int theMinGuarantedStorageDelayInSeconds)
set the minimum delay (in seconds)a client can be assured that a captcha generated by the service can be retrieved and a response to its challenge tested

Specified by:
setMinGuarantedStorageDelayInSeconds in interface ManageableCaptchaService
Parameters:
theMinGuarantedStorageDelayInSeconds - the minimum guaranted delay

getNumberOfGeneratedCaptchas

public long getNumberOfGeneratedCaptchas()
Get the number of captcha generated since the service is up WARNING : this value won't be significant if the real number is > Long.MAX_VALUE

Specified by:
getNumberOfGeneratedCaptchas in interface ManageableCaptchaService
Returns:
the number of captcha generated since the service is up

getNumberOfCorrectResponses

public long getNumberOfCorrectResponses()
Get the number of correct responses to captcha challenges since the service is up. WARNING : this value won't be significant if the real number is > Long.MAX_VALUE

Specified by:
getNumberOfCorrectResponses in interface ManageableCaptchaService
Returns:
the number of correct responses since the service is up

getNumberOfUncorrectResponses

public long getNumberOfUncorrectResponses()
Get the number of uncorrect responses to captcha challenges since the service is up. WARNING : this value won't be significant if the real number is > Long.MAX_VALUE

Specified by:
getNumberOfUncorrectResponses in interface ManageableCaptchaService
Returns:
the number of uncorrect responses since the service is up

getCaptchaStoreSize

public int getCaptchaStoreSize()
Get the curent size of the captcha store

Specified by:
getCaptchaStoreSize in interface ManageableCaptchaService
Returns:
the size of the captcha store

getNumberOfGarbageCollectableCaptchas

public int getNumberOfGarbageCollectableCaptchas()
Get the number of captchas that can be garbage collected in the captcha store

Specified by:
getNumberOfGarbageCollectableCaptchas in interface ManageableCaptchaService
Returns:
the number of captchas that can be garbage collected in the captcha store

getNumberOfGarbageCollectedCaptcha

public long getNumberOfGarbageCollectedCaptcha()
Get the number of captcha garbage collected since the service is up WARNING : this value won't be significant if the real number is > Long.MAX_VALUE

Specified by:
getNumberOfGarbageCollectedCaptcha in interface ManageableCaptchaService
Returns:
the number of captcha garbage collected since the service is up

getCaptchaStoreSizeBeforeGarbageCollection

public int getCaptchaStoreSizeBeforeGarbageCollection()
Specified by:
getCaptchaStoreSizeBeforeGarbageCollection in interface ManageableCaptchaService
Returns:
the max captchaStore load before garbage collection of the store

setCaptchaStoreSizeBeforeGarbageCollection

public void setCaptchaStoreSizeBeforeGarbageCollection(int captchaStoreSizeBeforeGarbageCollection)
max captchaStore size before garbage collection of the store

Specified by:
setCaptchaStoreSizeBeforeGarbageCollection in interface ManageableCaptchaService

setCaptchaStoreMaxSize

public void setCaptchaStoreMaxSize(int size)
This max size is used by the service : it will throw a CaptchaServiceException if the store is full when a client ask for a captcha.

Specified by:
setCaptchaStoreMaxSize in interface ManageableCaptchaService

getCaptchaStoreMaxSize

public int getCaptchaStoreMaxSize()
Specified by:
getCaptchaStoreMaxSize in interface ManageableCaptchaService
Returns:
the desired max size of the captcha store

garbageCollectCaptchaStore

protected void garbageCollectCaptchaStore(java.util.Iterator garbageCollectableCaptchaIds)
Garbage collect the captcha store, means all old captcha (captcha in the store wich has been stored more than the MinGuarantedStorageDelayInSecond


garbageCollectCaptchaStore

public void garbageCollectCaptchaStore()
Description copied from interface: ManageableCaptchaService
Garbage collect the captcha store, means all old capthca (captcha in the store wich has been stored more than the MinGuarantedStorageDelayInSecond

Specified by:
garbageCollectCaptchaStore in interface ManageableCaptchaService

emptyCaptchaStore

public void emptyCaptchaStore()
Empty the Store

Specified by:
emptyCaptchaStore in interface ManageableCaptchaService

generateAndStoreCaptcha

protected Captcha generateAndStoreCaptcha(java.util.Locale locale,
                                          java.lang.String ID)
Overrides:
generateAndStoreCaptcha in class AbstractCaptchaService

isCaptchaStoreFull

protected boolean isCaptchaStoreFull()

isCaptchaStoreQuotaReached

protected boolean isCaptchaStoreQuotaReached()

validateResponseForID

public java.lang.Boolean validateResponseForID(java.lang.String ID,
                                               java.lang.Object response)
                                        throws CaptchaServiceException
Method to validate a response to the challenge corresponding to the given ticket and remove the coresponding captcha from the store.

Specified by:
validateResponseForID in interface CaptchaService
Overrides:
validateResponseForID in class AbstractCaptchaService
Parameters:
ID - the ticket provided by the buildCaptchaAndGetID method
Returns:
true if the response is correct, false otherwise.
Throws:
CaptchaServiceException - if the ticket is invalid


Copyright 2003-2009 JCaptcha. All Rights Reserved.