// Attributes
// ------------------------------------------------------------------------
- private final Class<T> fDataType;
- private final int fRequestId; // A unique request ID
- private final int fIndex; // The index (rank) of the requested event
- private final int fNbRequested; // The number of requested events (ALL_DATA for all)
- private final int fBlockSize; // The maximum number of events per chunk
- private int fNbRead; // The number of reads so far
+ private final Class<T> fDataType;
+ private final ExecutionType fExecType;
+ private final int fRequestId; // A unique request ID
+ private final int fIndex; // The index (rank) of the requested event
+ private final int fNbRequested; // The number of requested events (ALL_DATA for all)
+ private final int fBlockSize; // The maximum number of events per chunk
+ private int fNbRead; // The number of reads so far
private final Object lock;
- private boolean fRequestCompleted;
- private boolean fRequestFailed;
- private boolean fRequestCanceled;
+ private boolean fRequestRunning = false;
+ private boolean fRequestCompleted = false;
+ private boolean fRequestFailed = false;
+ private boolean fRequestCanceled = false;
private T[] fData; // Data object
* @param dataType the requested data type
*/
public TmfDataRequest(Class<T> dataType) {
- this(dataType, 0, ALL_DATA, DEFAULT_BLOCK_SIZE);
+ this(dataType, 0, ALL_DATA, DEFAULT_BLOCK_SIZE, ExecutionType.SHORT);
+ }
+
+ public TmfDataRequest(Class<T> dataType, ExecutionType execType) {
+ this(dataType, 0, ALL_DATA, DEFAULT_BLOCK_SIZE, execType);
}
/**
* @param nbRequested the number of data items requested
*/
public TmfDataRequest(Class<T> dataType, int index) {
- this(dataType, index, ALL_DATA, DEFAULT_BLOCK_SIZE);
+ this(dataType, index, ALL_DATA, DEFAULT_BLOCK_SIZE, ExecutionType.SHORT);
+ }
+
+ public TmfDataRequest(Class<T> dataType, int index, ExecutionType execType) {
+ this(dataType, index, ALL_DATA, DEFAULT_BLOCK_SIZE, execType);
}
/**
* @param blockSize the number of data items per block
*/
public TmfDataRequest(Class<T> dataType, int index, int nbRequested) {
- this(dataType, index, nbRequested, DEFAULT_BLOCK_SIZE);
+ this(dataType, index, nbRequested, DEFAULT_BLOCK_SIZE, ExecutionType.SHORT);
+ }
+
+ public TmfDataRequest(Class<T> dataType, int index, int nbRequested, ExecutionType execType) {
+ this(dataType, index, nbRequested, DEFAULT_BLOCK_SIZE, execType);
}
/**
* @param blockSize the number of data items per block
*/
public TmfDataRequest(Class<T> dataType, int index, int nbRequested, int blockSize) {
+ this(dataType, index, nbRequested, blockSize, ExecutionType.SHORT);
+ }
+
+ public TmfDataRequest(Class<T> dataType, int index, int nbRequested, int blockSize, ExecutionType execType) {
fRequestId = fRequestNumber++;
fDataType = dataType;
fIndex = index;
fNbRequested = nbRequested;
fBlockSize = blockSize;
+ fExecType = execType;
fNbRead = 0;
lock = new Object();
-
- Tracer.trace("Request #" + fRequestId + " (" + getClass().getName() + ", " + fDataType.getName() + ") created");
+ if (Tracer.isRequestTraced()) Tracer.traceRequest(this, "created");
}
/**
*/
@SuppressWarnings("unused")
private TmfDataRequest(TmfDataRequest<T> other) {
- fRequestId = 0;
- fDataType = null;
- fIndex = 0;
- fNbRequested = 0;
- fBlockSize = 0;
- fNbRead = 0;
- lock = new Object();
+ this(null, 0, ALL_DATA, DEFAULT_BLOCK_SIZE);
}
// ------------------------------------------------------------------------
return fIndex;
}
+ /**
+ * @return the index of the first event requested
+ */
+ public ExecutionType getExecType() {
+ return fExecType;
+ }
+
/**
* @return the number of requested events (ALL_DATA = all)
*/
return fNbRead;
}
+ /**
+ * @return indicates if the request is completed
+ */
+ public boolean isRunning() {
+ return fRequestRunning;
+ }
+
/**
* @return indicates if the request is completed
*/
*/
public abstract void handleData();
+ public void handleStarted() {
+ }
+
/**
* Handle the completion of the request. It is called when there is no more
* data available either because:
*/
public void handleCompleted() {
if (fRequestFailed) {
- Tracer.trace("Request #" + fRequestId + " failed, completed");
+ if (Tracer.isRequestTraced()) Tracer.traceRequest(this, "failed");
handleFailure();
}
else if (fRequestCanceled) {
- Tracer.trace("Request #" + fRequestId + " cancelled, completed");
+ if (Tracer.isRequestTraced()) Tracer.traceRequest(this, "cancelled");
handleCancel();
}
else {
- Tracer.trace("Request #" + fRequestId + " succeeded, completed");
+ if (Tracer.isRequestTraced()) Tracer.traceRequest(this, "succeeded");
handleSuccess();
}
}
}
}
+ /**
+ * Called by the request processor upon starting to service the request.
+ */
+ public void start() {
+ if (Tracer.isRequestTraced()) Tracer.traceRequest(this, "starting");
+ synchronized(lock) {
+ fRequestRunning = true;
+ lock.notify();
+ }
+ handleStarted();
+ if (Tracer.isRequestTraced()) Tracer.traceRequest(this, "started");
+ }
+
/**
* Called by the request processor upon completion.
*/
public void done() {
+ if (Tracer.isRequestTraced()) Tracer.traceRequest(this, "completing");
synchronized(lock) {
+ fRequestRunning = false;
fRequestCompleted = true;
lock.notify();
}