pt.digitalis.iss
Class ISSImpl

java.lang.Object
  extended by pt.digitalis.iss.ISSImpl
All Implemented Interfaces:
ISS, ISSRequestManagement

public class ISSImpl
extends Object
implements ISSRequestManagement, ISS

This is an implementation of the ISS interface. Objects of this class perform the process scheduling management duties.
It exposes methods to the client that allows process delegation, estimated execution time inquiry and result fetching.
Internally it manages the synchronously or asynchronously process execution and a number of parameters that control the mode assignment to the processes.
The initial values of these parameters can be set externally in a properties file.
ISS is an acronym for Intelligent Scheduling System.
The asynchronicity threshold is reevaluated every time an asynchronous request is served and every "N" received requests to do load balance. When the ISS is serving requests asynchronously it is important to reevaluate often the threshold to prevent further performance degrading.

Author:
Rodrigo Gonçalves rgoncalves@digitalis.pt

Constructor Summary
ISSImpl(String id, Properties configurationParameters, pt.digitalis.log.ILogWrapper logger)
          Constructor.
 
Method Summary
 boolean areTooManyWorkers()
          Tests if the current number of workers is above the current limit
 boolean canExecuteMoreRequestsSynchronously()
          Tests if we can serve more requests synchronously.
 boolean canHaveMoreWorkers()
          Tests if we can launch more workers
 ServiceRequest delegate(IProcess process)
          Overload of the delegate() method.
 ServiceRequest delegate(IProcess aProcess, String id)
          Delegates the process execution to the ISS.
 boolean existsRequest(String id)
          This method informs if a request with a given id is already being served, was served or is waiting.
 ServiceRequest fetchResults(String requestID)
          Returns the execution results to the Client.
 long getEstimatedTimeOfExecution(String requestID)
          The method uses statistical information from the waitingQueueStats engine.
 ServiceRequest getWaitingRequest()
          This method is part of the public interface exposed to the Worker.
 boolean isStatisticsDumpEnabled()
          Returns the value of the statistics logging control flag.
 void notifyWorkerFinished()
          Synchronized to guarantee the activeWorkers consistency.
 void returnRequest(ServiceRequest returnedRequest)
          This method is part of the public interface exposed to the Worker.
 void setStatisticsDumpEnabled(boolean showStatistics)
          Sets the value of the statistics logging control flag.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ISSImpl

public ISSImpl(String id,
               Properties configurationParameters,
               pt.digitalis.log.ILogWrapper logger)
Constructor. Builds a new ISS object with the given id and loads it's configuration from the supplied Properties object. If none is given then a default configuration is loaded.

Parameters:
id - the ISS id
configurationParameters - the configuration parameters
logger - the logger for ISS to use
Method Detail

delegate

public ServiceRequest delegate(IProcess aProcess,
                               String id)
Description copied from interface: ISS
Delegates the process execution to the ISS. Clients call this method to apply for a request service.

Specified by:
delegate in interface ISS
Parameters:
aProcess - the process to execute
id - an explicit id for the request
Returns:
the service request associated to the process passed
See Also:
Internally the method decides if the request is executed synchronously or asynchronously. If there's enough capacity to serve the request synchronously, it is executed immediately. Otherwise the request is queued for later execution.

In synchronous execution mode the method returns the service request after the process execution has finished. In asynchronous mode it will place the newly created service request on the queue and return it with the queued state.
The method is also responsible for collecting statistical measures and submit them to the statistics engine.

If an incoming request is already being served or has been served lately the request is returned with an updated status.
Implementation Note: If this method is qualified with synchronized the client threads will not be able to call it if another client is executing it. In such situation, these threads will block waiting for the method's control and the ISS will operate in SYNCHRONOUS mode.

delegate

public ServiceRequest delegate(IProcess process)
Description copied from interface: ISS
Overload of the delegate() method. The client uses this variant if it does not wishes to pass an id of its own.

Specified by:
delegate in interface ISS
Parameters:
process - the process to execute
Returns:
the service request associated to the process passed
See Also:
This form forces automatic id generation.

existsRequest

public boolean existsRequest(String id)
Description copied from interface: ISS
This method informs if a request with a given id is already being served, was served or is waiting. Clients should use this method when the id is supplied externally to find if a request is already in the system.

Specified by:
existsRequest in interface ISS
Parameters:
id - the id of the request
Returns:
T if the request is on the index, F otherwise
See Also:
ISS.existsRequest(String)

getWaitingRequest

public ServiceRequest getWaitingRequest()
This method is part of the public interface exposed to the Worker. It's purpose is to encapsulate the retrieval of a request waiting to be served from the waitingProcesses. The method is synchronized to ensure queue consistency.

Specified by:
getWaitingRequest in interface ISSRequestManagement
Returns:
a queued request
See Also:
ISSRequestManagement.getWaitingRequest()

returnRequest

public void returnRequest(ServiceRequest returnedRequest)
This method is part of the public interface exposed to the Worker. It's purpose is to serve as a callback method to the Worker. It's through this method that the asynchronously served request is returned to the ISS.
The returned request is stored on the ISS and statistical measures regarding the request service are collected and added to the waitingQueueStats engine.
If there are still requests waiting to be served the Worker is notified.
After a request is returned the asynchronicityThreshold must be reevaluated. The method is synchronized to ensure queue consistency.

Specified by:
returnRequest in interface ISSRequestManagement
Parameters:
returnedRequest - the serviced request
See Also:
ISSRequestManagement.returnRequest(pt.digitalis.iss.ServiceRequest)

fetchResults

public ServiceRequest fetchResults(String requestID)
Returns the execution results to the Client.

Specified by:
fetchResults in interface ISS
Parameters:
requestID - the request id
Returns:
the request execution results

getEstimatedTimeOfExecution

public long getEstimatedTimeOfExecution(String requestID)
The method uses statistical information from the waitingQueueStats engine. If a client asks the ETE of a synchronously served request the method returns 0. This makes sense for two reasons: 1) A synchronously served request client blocks while the request is being served. 2) The request is not on the waiting queue so it will not have a "queue position" This method uses waitingQueueStats as data source.

Specified by:
getEstimatedTimeOfExecution in interface ISS
Parameters:
requestID - the id of the process
Returns:
the estimated time of execution for the given process in milliseconds

isStatisticsDumpEnabled

public boolean isStatisticsDumpEnabled()
Description copied from interface: ISS
Returns the value of the statistics logging control flag.

Specified by:
isStatisticsDumpEnabled in interface ISS
Returns:
the statisticsDumpEnabled value
See Also:
ISS.isStatisticsDumpEnabled()

setStatisticsDumpEnabled

public void setStatisticsDumpEnabled(boolean showStatistics)
Description copied from interface: ISS
Sets the value of the statistics logging control flag.

Specified by:
setStatisticsDumpEnabled in interface ISS
Parameters:
showStatistics - the statisticsDumpEnabled new value
See Also:
ISS.setStatisticsDumpEnabled(boolean)

notifyWorkerFinished

public void notifyWorkerFinished()
Synchronized to guarantee the activeWorkers consistency.

Specified by:
notifyWorkerFinished in interface ISSRequestManagement
See Also:
ISSRequestManagement.notifyWorkerFinished()

canHaveMoreWorkers

public boolean canHaveMoreWorkers()
Tests if we can launch more workers

Returns:
true if the current number of workers is still bellow the current limit

canExecuteMoreRequestsSynchronously

public boolean canExecuteMoreRequestsSynchronously()
Tests if we can serve more requests synchronously. Takes into account the running sync processes and the running async workers

Returns:
true if the current number of workers + sync process is still bellow the current limit

areTooManyWorkers

public boolean areTooManyWorkers()
Description copied from interface: ISSRequestManagement
Tests if the current number of workers is above the current limit

Specified by:
areTooManyWorkers in interface ISSRequestManagement
Returns:
true if there are more workers the allowed
See Also:
ISSRequestManagement.areTooManyWorkers()


Copyright © 2010 Digitalis Informática Lda. All Rights Reserved.