org.objectweb.proactive
Class Service

java.lang.Object
  extended by org.objectweb.proactive.Service

public class Service
extends java.lang.Object

Service is a utility class that provides many useful methods to serve requests. It is usually instantiated once at the begining of the runActivity() method of an active object in order to be used for serving requests. For instance :

 public void runActivity(org.objectweb.proactive.Body body) {
   org.objectweb.proactive.Service service = new org.objectweb.proactive.Service(body);
 ...
 }
 
For intance the live method of the bounded buffer example :
  public void runActivity(org.objectweb.proactive.Body body) {
    org.objectweb.proactive.Service service = new org.objectweb.proactive.Service(body);
    while (body.isActive()) {
      if (count == 0) {
        // if the buffer is empty
        service.blockingServeOldest("put"); // Serve the first buffer.put call
      } else if (count == size) {
        // if the buffer is full
        service.blockingServeOldest("get"); // Serve the first buffer.get call
      } else {
        // if the buffer is neither empty nor full
        service.blockingServeOldest(); // Serve the first buffer.xxx call
      }
    }
  }
 

Since:
ProActive 0.9
Version:
1.0, 2001/10/23
Author:
ProActive Team
See Also:
RunActive

Nested Class Summary
protected  class Service.AcceptAllRequestFilter
          AcceptAllRequestFilter is a RequestFilter that matches any request
protected  class Service.FlushingServeOldestRequestProcessor
          FlushingServeOldestRequestProcessor is a RequestProcessor that serves only the oldest request accepted by the given RequestFilter and removes all other requests accepted by that same Filter
protected  class Service.FlushingServeYoungestRequestProcessor
          FlushingServeYoungestRequestProcessor is a RequestProcessor that serves only the youngest request accepted by the given RequestFilter and removes all other requests accepted by that same Filter
protected  class Service.RequestFilterOnMethodName
          RequestFilterOnMethodName is a RequestFilter that matches only request of a given method name.
protected  class Service.ServingRequestProcessor
          ServingRequestProcessor is a simple RequestProcessor that serves and removes all requests accepted by a given RequestFilter
 
Field Summary
protected  Body body
           
protected  LifeCycleController lifeCycleController
           
protected  BlockingRequestQueue requestQueue
           
 
Constructor Summary
Service(Body body)
          Creates a new intance of Service based on the given body.
 
Method Summary
 Request blockingGetOldest()
          Returns the oldest request from the queue If no request is available the method block until one request can be returned The request queue is unchanged by this call
 Request blockingGetYoungest()
          Returns the youngest request from the queue If no request is available the method block until one request can be returned The request queue is unchanged by this call
 Request blockingRemoveOldest()
          Blocks the calling thread until there is a request available Returns immediately if there is already one.
 Request blockingRemoveOldest(long timeout)
          Blocks the calling thread until there is a request available but try to limit the time the thread is blocked to timeout.
 Request blockingRemoveOldest(RequestFilter requestFilter)
          Blocks the calling thread until there is a request that can be accepted be the given RequestFilter.
 Request blockingRemoveOldest(RequestFilter requestFilter, long timeout)
          Blocks the calling thread until there is a request that can be accepted be the given RequestFilter, but tries to limit the time the thread is blocked to timeout.
 Request blockingRemoveOldest(java.lang.String methodName)
          Blocks the calling thread until there is a request of name methodName Returns immediately if there is already one.
 Request blockingRemoveYoungest()
          Blocks the calling thread until there is a request available Returns immediately if there is already one.
 Request blockingRemoveYoungest(long timeout)
          Blocks the calling thread until there is a request available but try to limit the time the thread is blocked to timeout.
 Request blockingRemoveYoungest(RequestFilter requestFilter)
          Blocks the calling thread until there is a request that can be accepted be the given RequestFilter.
 Request blockingRemoveYoungest(RequestFilter requestFilter, long timeout)
          Blocks the calling thread until there is a request that can be accepted be the given RequestFilter, but tries to limit the time the thread is blocked to the timeout.
 Request blockingRemoveYoungest(java.lang.String methodName)
          Blocks the calling thread until there is a request of name methodName Returns immediately if there is already one.
 void blockingServeOldest()
          Serves the oldest request in the request queue.
 void blockingServeOldest(long timeout)
          Serves the oldest request in request queue.
 void blockingServeOldest(RequestFilter requestFilter)
          Serves the oldest request matching the criteria given be the filter.
 void blockingServeOldest(RequestFilter requestFilter, long timeout)
          Serves the oldest request matching the criteria given be the filter.
 void blockingServeOldest(java.lang.String methodName)
          Serves the oldest request for a method of name methodName.
 void blockingServeYoungest()
          Serves the youngest request in the request queue.
 void blockingServeYoungest(long timeout)
          Serves the youngest request in request queue.
 void blockingServeYoungest(RequestFilter requestFilter)
          Serves the youngest request matching the criteria given be the filter.
 void blockingServeYoungest(RequestFilter requestFilter, long timeout)
          Serves the youngest request matching the criteria given be the filter.
 void blockingServeYoungest(java.lang.String methodName)
          Serves the youngest request for a method of name methodName.
 void fifoServing()
          Invoke the default FIFO policy to pick up the requests from the request queue.
 void flushAll()
          Removes all request from the queue.
 void flushingServeOldest()
          Serves the oldest request and discard all other requests.
 void flushingServeOldest(RequestFilter requestFilter)
          Serves the oldest request accepted by the given filter and discards all the other requests also accepted by this sasme filter.
 void flushingServeOldest(java.lang.String methodName)
          Serves the oldest request for the method named methodName and discards all the other requests of the same name.
 void flushingServeYoungest()
          Serves the youngest request and discard all other requests.
 void flushingServeYoungest(RequestFilter requestFilter)
          Serves the most recent request (youngest) accepted by the given filter and discards all the other requests also accepted by this sasme filter.
 void flushingServeYoungest(java.lang.String methodName)
          Serves the most recent request (youngest) for the method named methodName and discards all the other requests of the same name.
 Request getOldest()
          Returns the oldest request from the queue or null if the queue is empty The request queue is unchanged by this call
 Request getOldest(RequestFilter requestFilter)
          Returns the oldest request that matches the criteria defined by the given filter The request queue is unchanged by this call
 Request getOldest(java.lang.String methodName)
          Returns the oldest request whose method name is s or null if no match The request queue is unchanged by this call
 int getRequestCount()
          Returns the number of request(s) in the queue
 Request getYoungest()
          Returns the youngest request from the queue or null if the queue is empty The request queue is unchanged by this call
 Request getYoungest(RequestFilter requestFilter)
          Returns the youngest request that matches the criteria defined by the given filter The request queue is unchanged by this call
 Request getYoungest(java.lang.String methodName)
          Returns the youngest request whose method name is s or null if no match The request queue is unchanged by this call
 boolean hasRequestToServe()
          true if and only if at least one request is available
 boolean hasRequestToServe(java.lang.String methodName)
          true if and only if at least one request with the given name is available
 void lifoServing()
          Invoke the LIFO policy to pick up the requests from the request queue.
 void serve(Request request)
          Serves the request given in parameter
 void serveAll(RequestFilter requestFilter)
          Serves all requests accepted by the given filter.
 void serveAll(java.lang.String methodName)
          Serves all requests for the method named methodName.
 void serveOldest()
          Serves the oldest request in the request queue.
 void serveOldest(RequestFilter requestFilter)
          Serves the oldest request matching the criteria given be the filter.
 void serveOldest(java.lang.String methodName)
          Serves the oldest request for a method of name methodName.
 void serveYoungest()
          Serves the youngest request in the request queue.
 void serveYoungest(RequestFilter requestFilter)
          Serves the youngest request matching the criteria given be the filter.
 void serveYoungest(java.lang.String methodName)
          Serves the youngest request for a method of name methodName.
 java.lang.String toString()
           
 void waitForRequest()
          blocks until a request is available or until the body terminate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

body

protected Body body

requestQueue

protected BlockingRequestQueue requestQueue

lifeCycleController

protected LifeCycleController lifeCycleController
Constructor Detail

Service

public Service(Body body)
Creates a new intance of Service based on the given body.

Parameters:
body - the body that helper service is for.
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

serve

public void serve(Request request)
Serves the request given in parameter

Parameters:
request - the request to be served

fifoServing

public void fifoServing()
Invoke the default FIFO policy to pick up the requests from the request queue. This does not return until the body terminate, as the active thread enters in an infinite loop for processing the request in the FIFO order.


lifoServing

public void lifoServing()
Invoke the LIFO policy to pick up the requests from the request queue. This does not return until the body terminate, as the active thread enters in an infinite loop for processing the request in the LIFO order.


blockingServeOldest

public void blockingServeOldest()
Serves the oldest request in the request queue. The method blocks if there is no request until one request is received or until the body terminates.


blockingServeOldest

public void blockingServeOldest(long timeout)
Serves the oldest request in request queue. The method blocks if there is no request until one request is received or until the body terminates. The method does not block more than the given timeout.

Parameters:
timeout - how long the thread can be blocked for.

blockingServeOldest

public void blockingServeOldest(RequestFilter requestFilter,
                                long timeout)
Serves the oldest request matching the criteria given be the filter. The method blocks if there is no matching request until one matching request is received or until the body terminates. The method does not block more than the given timeout.

Parameters:
requestFilter - The request filter accepting the request
timeout - the timeout in ms

blockingServeOldest

public void blockingServeOldest(java.lang.String methodName)
Serves the oldest request for a method of name methodName. The method blocks if there is no matching request until one matching request is received or until the body terminates.

Parameters:
methodName - The name of the request to serve

blockingServeOldest

public void blockingServeOldest(RequestFilter requestFilter)
Serves the oldest request matching the criteria given be the filter. The method blocks if there is no matching request until one matching request is received or until the body terminates.

Parameters:
requestFilter - The request filter accepting the request

serveOldest

public void serveOldest()
Serves the oldest request in the request queue. If there is no request, the method returns with no effect.


serveOldest

public void serveOldest(java.lang.String methodName)
Serves the oldest request for a method of name methodName. If no matching request is found, the method returns with no effect.

Parameters:
methodName - The name of the request to serve

serveOldest

public void serveOldest(RequestFilter requestFilter)
Serves the oldest request matching the criteria given be the filter. If no matching request is found, the method returns with no effect.

Parameters:
requestFilter - The request filter accepting the request

blockingServeYoungest

public void blockingServeYoungest()
Serves the youngest request in the request queue. The method blocks if there is no request until one request is received or until the body terminates.


blockingServeYoungest

public void blockingServeYoungest(long timeout)
Serves the youngest request in request queue. The method blocks if there is no request until one request is received or until the body terminates. The method does not block more than the given timeout.

Parameters:
timeout - : for how long the thread can be blocked.

blockingServeYoungest

public void blockingServeYoungest(java.lang.String methodName)
Serves the youngest request for a method of name methodName. The method blocks if there is no matching request until one matching request is received or until the body terminates.

Parameters:
methodName - The name of the request to serve

blockingServeYoungest

public void blockingServeYoungest(RequestFilter requestFilter)
Serves the youngest request matching the criteria given be the filter. The method blocks if there is no matching request until one matching request is received or until the body terminates.

Parameters:
requestFilter - The request filter accepting the request

blockingServeYoungest

public void blockingServeYoungest(RequestFilter requestFilter,
                                  long timeout)
Serves the youngest request matching the criteria given be the filter. The method blocks if there is no matching request until one matching request is received or until the body terminates. The method does not block more than the given timeout.

Parameters:
requestFilter - The request filter accepting the request
timeout - : for how long the thread can be blocked.

serveYoungest

public void serveYoungest()
Serves the youngest request in the request queue. If there is no request, the method returns with no effect.


serveYoungest

public void serveYoungest(java.lang.String methodName)
Serves the youngest request for a method of name methodName. If no matching request is found, the method returns with no effect.

Parameters:
methodName - The name of the request to serve

serveYoungest

public void serveYoungest(RequestFilter requestFilter)
Serves the youngest request matching the criteria given be the filter. If no matching request is found, the method returns with no effect.

Parameters:
requestFilter - The request filter accepting the request

serveAll

public void serveAll(java.lang.String methodName)
Serves all requests for the method named methodName. If there is no request matching the method name, no request is served. All served requests are removed from the RequestQueue.

Parameters:
methodName - The name of the request to serve

serveAll

public void serveAll(RequestFilter requestFilter)
Serves all requests accepted by the given filter. All served requests are removed from the RequestQueue.

Parameters:
requestFilter - The request filter accepting the request

flushingServeYoungest

public void flushingServeYoungest()
Serves the youngest request and discard all other requests. After the call the youngest request is served and the request queue is empty. If the request queue is already empty before the call the method has no effect


flushingServeYoungest

public void flushingServeYoungest(java.lang.String methodName)
Serves the most recent request (youngest) for the method named methodName and discards all the other requests of the same name. The most recent request is the one served. If there is no match, no request is served or removed. All requests of method name methodName are removed from the request queue.

Parameters:
methodName - The name of the request to serve and flush

flushingServeYoungest

public void flushingServeYoungest(RequestFilter requestFilter)
Serves the most recent request (youngest) accepted by the given filter and discards all the other requests also accepted by this sasme filter. The most recent request is the one served. If there is no match, no request is served or removed. All requests accepted by the filter are removed from the request queue.

Parameters:
requestFilter - The request filter accepting requests

flushingServeOldest

public void flushingServeOldest()
Serves the oldest request and discard all other requests. After the call the oldest request is served and the request queue is empty. If the request queue is already empty before the call the method has no effect


flushingServeOldest

public void flushingServeOldest(java.lang.String methodName)
Serves the oldest request for the method named methodName and discards all the other requests of the same name. The oldest request is the one served. If there is no match, no request is served or removed. All requests of method name methodName are removed from the request queue.

Parameters:
methodName - The name of the request to serve and flush

flushingServeOldest

public void flushingServeOldest(RequestFilter requestFilter)
Serves the oldest request accepted by the given filter and discards all the other requests also accepted by this sasme filter. The oldest request is the one served. If there is no match, no request is served or removed. All requests accepted by the filter are removed from the request queue.

Parameters:
requestFilter - The request filter accepting requests

waitForRequest

public void waitForRequest()
blocks until a request is available or until the body terminate


hasRequestToServe

public boolean hasRequestToServe()
true if and only if at least one request is available

Returns:
true if a request is available, false else.

hasRequestToServe

public boolean hasRequestToServe(java.lang.String methodName)
true if and only if at least one request with the given name is available

Returns:
true if a request with the given name is available, false else.

getRequestCount

public int getRequestCount()
Returns the number of request(s) in the queue

Returns:
the number of request(s) in the queue.

flushAll

public void flushAll()
Removes all request from the queue. No request is served.


getOldest

public Request getOldest()
Returns the oldest request from the queue or null if the queue is empty The request queue is unchanged by this call

Returns:
the oldest request or null

getOldest

public Request getOldest(java.lang.String methodName)
Returns the oldest request whose method name is s or null if no match The request queue is unchanged by this call

Parameters:
methodName - the name of the method to look for
Returns:
the oldest matching request or null

getOldest

public Request getOldest(RequestFilter requestFilter)
Returns the oldest request that matches the criteria defined by the given filter The request queue is unchanged by this call

Parameters:
requestFilter - the filter accepting request on a given criteria
Returns:
the oldest matching request or null

blockingGetOldest

public Request blockingGetOldest()
Returns the oldest request from the queue If no request is available the method block until one request can be returned The request queue is unchanged by this call

Returns:
the oldest request or null

getYoungest

public Request getYoungest()
Returns the youngest request from the queue or null if the queue is empty The request queue is unchanged by this call

Returns:
the youngest request or null

getYoungest

public Request getYoungest(java.lang.String methodName)
Returns the youngest request whose method name is s or null if no match The request queue is unchanged by this call

Parameters:
methodName - the name of the method to look for
Returns:
the youngest matching request or null

getYoungest

public Request getYoungest(RequestFilter requestFilter)
Returns the youngest request that matches the criteria defined by the given filter The request queue is unchanged by this call

Parameters:
requestFilter - the filter accepting request on a given criteria
Returns:
the youngest matching request or null

blockingGetYoungest

public Request blockingGetYoungest()
Returns the youngest request from the queue If no request is available the method block until one request can be returned The request queue is unchanged by this call

Returns:
the oldest request or null

blockingRemoveOldest

public Request blockingRemoveOldest(RequestFilter requestFilter)
Blocks the calling thread until there is a request that can be accepted be the given RequestFilter. Returns immediately if there is already one. The request returned is non null unless the thread has been asked not to wait anymore.

Parameters:
requestFilter - the request filter that select the request to be returned
Returns:
the oldest request found in the queue that is accepted by the filter.

blockingRemoveOldest

public Request blockingRemoveOldest(RequestFilter requestFilter,
                                    long timeout)
Blocks the calling thread until there is a request that can be accepted be the given RequestFilter, but tries to limit the time the thread is blocked to timeout. Returns immediately if there is already one. The request returned is non null unless the thread has been asked not to wait anymore.

Parameters:
requestFilter - the request filter that select the request to be returned
timeout - : for how long the thread can be blocked.
Returns:
the oldest request found in the queue that is accepted by the filter.

blockingRemoveOldest

public Request blockingRemoveOldest(java.lang.String methodName)
Blocks the calling thread until there is a request of name methodName Returns immediately if there is already one. The request returned is non null unless the thread has been asked not to wait anymore.

Parameters:
methodName - the name of the method to wait for
Returns:
the oldest request of name methodName found in the queue.

blockingRemoveOldest

public Request blockingRemoveOldest()
Blocks the calling thread until there is a request available Returns immediately if there is already one. The request returned is non null unless the thread has been asked not to wait anymore.

Returns:
the oldest request found in the queue.

blockingRemoveOldest

public Request blockingRemoveOldest(long timeout)
Blocks the calling thread until there is a request available but try to limit the time the thread is blocked to timeout. Returns immediately if there is already one. The request returned is non null if a request has been found during the given time.

Parameters:
timeout - : for how long the thread can be blocked.
Returns:
the oldest request found in the queue or null.

blockingRemoveYoungest

public Request blockingRemoveYoungest(RequestFilter requestFilter)
Blocks the calling thread until there is a request that can be accepted be the given RequestFilter. Returns immediately if there is already one. The request returned is non null unless the thread has been asked not to wait anymore.

Parameters:
requestFilter - the request filter that select the request to be returned
Returns:
the youngest request found in the queue that is accepted by the filter.

blockingRemoveYoungest

public Request blockingRemoveYoungest(RequestFilter requestFilter,
                                      long timeout)
Blocks the calling thread until there is a request that can be accepted be the given RequestFilter, but tries to limit the time the thread is blocked to the timeout. Returns immediately if there is already one. The request returned is non null unless the thread has been asked not to wait anymore.

Parameters:
requestFilter - the request filter that select the request to be returned
timeout - : for how long the thread can be blocked.
Returns:
the youngest request found in the queue that is accepted by the filter.

blockingRemoveYoungest

public Request blockingRemoveYoungest(java.lang.String methodName)
Blocks the calling thread until there is a request of name methodName Returns immediately if there is already one. The request returned is non null unless the thread has been asked not to wait anymore.

Parameters:
methodName - the name of the method to wait for
Returns:
the youngest request of name methodName found in the queue.

blockingRemoveYoungest

public Request blockingRemoveYoungest()
Blocks the calling thread until there is a request available Returns immediately if there is already one. The request returned is non null unless the thread has been asked not to wait anymore.

Returns:
the youngest request found in the queue.

blockingRemoveYoungest

public Request blockingRemoveYoungest(long timeout)
Blocks the calling thread until there is a request available but try to limit the time the thread is blocked to timeout. Returns immediately if there is already one. The request returned is non null if a request has been found during the given time.

Parameters:
timeout - : for how long the thread can be blocked.
Returns:
the youngest request found in the queue or null.


Copyright 2001-2007 INRIA All Rights Reserved.