package net.catpad.infobus;
/**
* Abstract parent class of all communication queue items.
* The logic of the application is contained inside the
* communication queue items. Service thread is simply
* gets the item from its own queue and executes it.
* The item takes care of the business logic.
* NOTE: the item's execute() code executes in the context
* of the service thread which is the recipient of this item.
*
* @author Michael Gertelman
*/
public abstract class CommQueueItem {
/**
* Creation timestamp of this item
*/
private long timestamp;
/**
* ServiceLauncher is the main mediator of the application.
* It should be known to all items
*/
protected ServiceLauncher serviceLauncher;
public CommQueueItem(ServiceLauncher serviceLauncher) {
this.serviceLauncher = serviceLauncher;
timestamp = System.currentTimeMillis();
}
/**
* The subclass will implement the necessary business logic in this method.
* This method executes in the context of the service thread which is the recipient
* of this item
*
* @param serviceId
* @throws CannotExecuteCommQueueItemException
*/
public abstract void execute(ServiceId serviceId) throws CannotExecuteCommQueueItemException, InterruptedException;
/**
* Returns the creation time of this item. Using it one can calculate
* the time this item has spent inside the InfoBus until it was taken out
* by the service thread
*
* @return item creation time
*/
public long getTimestamp() { return timestamp; }
}
|