atg.commerce.util
Class RepeatingRequestMonitor

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.commerce.util.RepeatingRequestMonitor
All Implemented Interfaces:
NameContextBindingListener, NameContextElement, NameResolver, AdminableService, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, java.util.EventListener

public class RepeatingRequestMonitor
extends GenericService


The class RepeatingRequestMonitor is designed for use as a session scoped component. It is used to track request threads that register themselves as executing by name and for a designated time period, to ensure that the same request handler is not executed by two request scoped components concurrently (as happens when a user clicks a submit button multiple times).
Form handlers should use this by calling the RepeatingRequestMonitor.isUniqueRequestEntry() method. The boolean return value indicates whether the handler is free to proceed execution, or whether another request scoped component has recently been executing the same method for this session. The handler may specify a timeout duration for this entry, or use the configurable default timeout. After the critical execution, the handler may remove the request entry or have these otherwise expire after the timeout.
For example, a request scoped formhandler may use this in handler methods as follows:

 if (RepeatingRequestMonitor.isUniqueRequestEntry("YourFormHandler.handleSubmit")) {
  try {
        // proceed executing method functionality

        
   }
  finally {
  // when done executing functionality, remove this request entry
   RepeatingRequestMonitor.removeRequestEntry("YourFormHandler.handleSubmit");
   }
  } else {
   // handle case, perhaps create DropletFormException and return
 }
 


Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
RepeatingRequestMonitor()
           
 
Method Summary
protected  void addRequestEntry(java.lang.String pRequestEntry, long pExpirationTimeMillis)
           
 long getDefaultRequestTimeout()
          Returns the default timeout for a request entry.
protected  java.util.Map getRequestEntries()
          Returns the Map of request entries.
protected  boolean isPreviousRequestEntry(java.lang.String pRequestEntry, long pCurrentTimeMillis)
           
 boolean isUniqueRequestEntry(java.lang.String pRequestEntry)
          The isUniqueRequestEntry method attempts ro register a request entry by the supplied name.
 boolean isUniqueRequestEntry(java.lang.String pRequestEntry, long pTimeoutRequested)
          The isUniqueRequestEntry method attempts to register a request entry by the supplied name and for the supplied timeout.
 void removeRequestEntry(java.lang.String pRequestEntry)
          The removeRequestEntry method removes any request entry that exists with the supplied name.
 void setDefaultRequestTimeout(long pDefaultRequestTimeout)
          Specifies the default timeout for a request entry in milliseconds.
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, doStartService, doStopService, getAbsoluteName, getAdminServlet, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static final java.lang.String CLASS_VERSION
Class version string

See Also:
Constant Field Values
Constructor Detail

RepeatingRequestMonitor

public RepeatingRequestMonitor()
Method Detail

setDefaultRequestTimeout

public void setDefaultRequestTimeout(long pDefaultRequestTimeout)
Specifies the default timeout for a request entry in milliseconds.

Parameters:
pDefaultRequestTimeout - a long value

getDefaultRequestTimeout

public long getDefaultRequestTimeout()
Returns the default timeout for a request entry. The default is 3000ms or 3 seconds.

Returns:
a long value

getRequestEntries

protected java.util.Map getRequestEntries()
Returns the Map of request entries.

Returns:
a Map value

isUniqueRequestEntry

public boolean isUniqueRequestEntry(java.lang.String pRequestEntry)
The isUniqueRequestEntry method attempts ro register a request entry by the supplied name. The timeout period is that given by getDefaultRequestTimeout.
This returns true if the request entry is registered, a new entry is added which is a signal that the calling handler may begin execution. This returns false if another request entry is currently registered that has not timed out yet, a signal that the calling handler should fall through.

Parameters:
pRequestEntry - a String value
Returns:
a boolean value indicating whether this request entry is unique and has been registered.

isUniqueRequestEntry

public boolean isUniqueRequestEntry(java.lang.String pRequestEntry,
                                    long pTimeoutRequested)
The isUniqueRequestEntry method attempts to register a request entry by the supplied name and for the supplied timeout.
This returns true if the request entry is registered, a signal that the calling handler may begin execution. This returns false if another request entry is currently registered that has not timed out yet, a signal that the calling handler should fall through.

Parameters:
pRequestEntry - a String value
pTimeoutRequested - a long value
Returns:
a boolean value indicating whether this request entry is unique and has been registered.

removeRequestEntry

public void removeRequestEntry(java.lang.String pRequestEntry)
The removeRequestEntry method removes any request entry that exists with the supplied name.

Parameters:
pRequestEntry - a String value

isPreviousRequestEntry

protected boolean isPreviousRequestEntry(java.lang.String pRequestEntry,
                                         long pCurrentTimeMillis)

addRequestEntry

protected void addRequestEntry(java.lang.String pRequestEntry,
                               long pExpirationTimeMillis)