use of it.unibo.arces.wot.sepa.commons.request.Request 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;
// }
// }
}
}
use of it.unibo.arces.wot.sepa.commons.request.Request in project SEPA by arces-wot.
the class SPARQL11Handler method handle.
@Override
public void handle(HttpRequest request, HttpAsyncExchange httpExchange, HttpContext context) throws HttpException, IOException {
Instant start = Instant.now();
// CORS
if (!corsHandling(httpExchange)) {
jmx.corsFailed();
return;
}
// Parsing SPARQL 1.1 request and attach a token
Request sepaRequest = parse(httpExchange);
// Parsing failed
if (sepaRequest == null) {
logger.error("Parsing failed: " + httpExchange.getRequest());
HttpUtilities.sendFailureResponse(httpExchange, HttpStatus.SC_BAD_REQUEST, "Parsing failed: " + httpExchange.getRequest());
jmx.parsingFailed();
return;
}
// Validate
if (!validate(httpExchange.getRequest())) {
logger.error("Validation failed SPARQL: " + sepaRequest.getSPARQL());
HttpUtilities.sendFailureResponse(httpExchange, HttpStatus.SC_BAD_REQUEST, "Validation failed SPARQL: " + sepaRequest.getSPARQL());
jmx.validatingFailed();
return;
}
// Authorize
if (!authorize(httpExchange.getRequest())) {
logger.error("Authorization failed SPARQL: " + sepaRequest.getSPARQL());
HttpUtilities.sendFailureResponse(httpExchange, HttpStatus.SC_UNAUTHORIZED, "Authorization failed SPARQL: " + sepaRequest.getSPARQL());
jmx.authorizingFailed();
return;
}
// Schedule request
scheduler.schedule(sepaRequest, new SPARQL11ResponseHandler(httpExchange, jmx, start));
}
use of it.unibo.arces.wot.sepa.commons.request.Request in project SEPA by arces-wot.
the class WebsocketServer method onMessage.
@Override
public void onMessage(WebSocket conn, String message) {
jmx.onMessage();
logger.debug("Message from: " + conn.getRemoteSocketAddress() + " [" + message + "]");
Request req = parseRequest(message);
if (req == null) {
logger.debug("Failed to parse: " + message);
ErrorResponse response = new ErrorResponse(HttpStatus.SC_BAD_REQUEST, "Failed to parse: " + message);
conn.send(response.toString());
return;
}
scheduler.schedule(req, new WebsocketEventHandler(conn, jmx));
}
Aggregations