use of it.unibo.arces.wot.sepa.engine.scheduling.ScheduledRequest in project SEPA by arces-wot.
the class Processor method run.
@Override
public void run() {
while (true) {
// WAIT NEW REQUEST
ScheduledRequest scheduledRequest;
try {
scheduledRequest = queue.waitRequest();
} catch (InterruptedException e1) {
return;
}
Request request = scheduledRequest.getRequest();
if (request.isUpdateRequest()) {
logger.info("Update request #" + request.getToken());
logger.debug(request);
// Process update request
Response ret = updateProcessor.process((UpdateRequest) request, ProcessorBeans.getUpdateTimeout());
// // Notify update result
// setChanged();
// notifyObservers(ret);
queue.addResponse(ret);
if (ret.isUpdateResponse()) {
// updateProcessing = true;
spuManager.process((UpdateResponse) ret);
try {
updateProcessingQueue.waitUpdateEOP();
} catch (InterruptedException e1) {
return;
}
// while (updateProcessing) {
// // Wait for SPUs processing end
// synchronized (updateProcessor) {
// try {
// updateProcessor.wait();
// } catch (InterruptedException e) {
// return;
// }
// }
// }
}
} else if (request.isQueryRequest()) {
logger.info("Query request #" + request.getToken());
logger.debug(request);
Thread queryProcessing = new Thread() {
public void run() {
Response ret = queryProcessor.process((QueryRequest) request, ProcessorBeans.getQueryTimeout());
// setChanged();
// notifyObservers(ret);
queue.addResponse(ret);
}
};
queryProcessing.setName("SEPA Query Processing Thread-" + request.getToken());
queryProcessing.start();
} else if (request.isSubscribeRequest()) {
logger.info("Subscribe request #" + request.getToken());
logger.debug(request);
Response ret = spuManager.subscribe((SubscribeRequest) request, (EventHandler) scheduledRequest.getHandler());
// setChanged();
// notifyObservers(ret);
queue.addResponse(ret);
} else if (request.isUnsubscribeRequest()) {
logger.info("Unsubscribe request #" + request.getToken());
logger.debug(request);
Response ret = spuManager.unsubscribe((UnsubscribeRequest) request);
// setChanged();
// notifyObservers(ret);
queue.addResponse(ret);
}
//
// UpdateRequest request;
// while ((request = updateRequestQueue.poll()) != null) {
// logger.debug("New request: " + request);
//
// // Process update request
// Response ret = updateProcessor.process(request,
// ProcessorBeans.getUpdateTimeout());
//
// // Notify update result
// setChanged();
// notifyObservers(ret);
//
// if (ret.isUpdateResponse()) {
// updateProcessing = true;
//
// spuManager.process((UpdateResponse) ret);
//
// while (updateProcessing) {
// // Wait for SPUs processing end
// synchronized (updateProcessor) {
// try {
// updateProcessor.wait();
// } catch (InterruptedException e) {
// return;
// }
// }
// }
// }
// }
//
// synchronized (updateRequestQueue) {
// try {
// updateRequestQueue.wait();
// } catch (InterruptedException e) {
// logger.error(e.getMessage());
// return;
// }
// }
}
}
Aggregations