use of it.unibo.arces.wot.sepa.commons.response.Response in project SEPA by arces-wot.
the class QueryProcessor method process.
public synchronized Response process(QueryRequest req, int timeout) {
if (endpointSemaphore != null)
try {
endpointSemaphore.acquire();
} catch (InterruptedException e) {
return new ErrorResponse(500, e.getMessage());
}
// QUERY the endpoint
long start = System.currentTimeMillis();
Response ret = endpoint.query(req, timeout);
long stop = System.currentTimeMillis();
if (endpointSemaphore != null)
endpointSemaphore.release();
logger.debug("* QUERY PROCESSING (" + (stop - start) + " ms) *");
ProcessorBeans.queryTimings(start, stop);
return ret;
}
use of it.unibo.arces.wot.sepa.commons.response.Response in project SEPA by arces-wot.
the class SPUNaive method processInternal.
@Override
public Response processInternal(UpdateResponse update, int timeout) {
logger.debug("* PROCESSING *" + request);
Response ret;
try {
// Query the SPARQL processing service
ret = queryProcessor.process(request, timeout);
if (ret.getClass().equals(ErrorResponse.class)) {
logger.error(ret);
return ret;
}
// Current and previous bindings
BindingsResults results = ((QueryResponse) ret).getBindingsResults();
BindingsResults currentBindings = new BindingsResults(results);
// Initialize the results with the current bindings
BindingsResults added = new BindingsResults(results.getVariables(), null);
BindingsResults removed = new BindingsResults(results.getVariables(), null);
// Create empty bindings if null
if (lastBindings == null)
lastBindings = new BindingsResults(null, null);
logger.debug("Current bindings: " + currentBindings);
logger.debug("Last bindings: " + lastBindings);
// Find removed bindings
long start = System.nanoTime();
for (Bindings solution : lastBindings.getBindings()) {
if (!results.contains(solution) && !solution.isEmpty())
removed.add(solution);
else
results.remove(solution);
}
long stop = System.nanoTime();
logger.debug("Removed bindings: " + removed + " found in " + (stop - start) + " ns");
// Find added bindings
start = System.nanoTime();
for (Bindings solution : results.getBindings()) {
if (!lastBindings.contains(solution) && !solution.isEmpty())
added.add(solution);
}
stop = System.nanoTime();
logger.debug("Added bindings: " + added + " found in " + (stop - start) + " ns");
// Update the last bindings with the current ones
lastBindings = currentBindings;
// Send notification (or end processing indication)
if (!added.isEmpty() || !removed.isEmpty())
ret = new Notification(getUUID(), new ARBindingsResults(added, removed), sequence++);
} catch (Exception e) {
ret = new ErrorResponse(500, e.getMessage());
}
return ret;
}
use of it.unibo.arces.wot.sepa.commons.response.Response in project SEPA by arces-wot.
the class SPUNaive method init.
@Override
public boolean init() {
logger.debug("Process SPARQL query " + request);
// Process the SPARQL query
Response ret = queryProcessor.process(request, ProcessorBeans.getQueryTimeout());
if (ret.getClass().equals(ErrorResponse.class)) {
logger.error("Not initialized");
return false;
}
lastBindings = ((QueryResponse) ret).getBindingsResults();
firstResults = new BindingsResults(lastBindings);
logger.debug("First results: " + firstResults.toString());
return true;
}
use of it.unibo.arces.wot.sepa.commons.response.Response in project SEPA by arces-wot.
the class UpdateProcessor method process.
public synchronized Response process(UpdateRequest req, int timeout) {
if (endpointSemaphore != null)
try {
endpointSemaphore.acquire();
} catch (InterruptedException e) {
return new ErrorResponse(500, e.getMessage());
}
// UPDATE the endpoint
long start = System.currentTimeMillis();
Response ret = endpoint.update(req, timeout);
long stop = System.currentTimeMillis();
if (endpointSemaphore != null)
endpointSemaphore.release();
logger.debug("* UPDATE PROCESSING (" + (stop - start) + " ms) *");
ProcessorBeans.updateTimings(start, stop);
return ret;
}
use of it.unibo.arces.wot.sepa.commons.response.Response in project SEPA by arces-wot.
the class SecureWebsocketServer method onMessage.
@Override
public void onMessage(WebSocket conn, String message) {
logger.debug("@onMessage " + message);
// JWT Validation
Response validation = validateToken(message);
if (validation.getClass().equals(ErrorResponse.class)) {
// Not authorized
jmx.onNotAuthorizedRequest();
logger.warn("NOT AUTHORIZED");
conn.send(validation.toString());
return;
}
super.onMessage(conn, message);
}
Aggregations