use of it.unibo.arces.wot.sepa.commons.exceptions.SEPAProcessingException in project SEPA by arces-wot.
the class Processor method processUpdate.
public synchronized Response processUpdate(InternalUpdateRequest update) {
InternalUpdateRequest preRequest = update;
if (spuManager.doUpdateARQuadsExtraction(update)) {
try {
preRequest = ARQuadsAlgorithm.extractARQuads(update, queryProcessor);
} catch (SEPAProcessingException | SPARQL11ProtocolException | SEPASparqlParsingException e) {
return new ErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, "update_processing", e.getMessage());
}
}
// PRE-UPDATE processing
spuManager.subscriptionsProcessingPreUpdate(preRequest);
// Endpoint UPDATE
Response ret;
try {
ret = updateEndpoint(preRequest);
} catch (SEPASecurityException | IOException e) {
return new ErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, "sparql11endpoint", e.getMessage());
}
// STOP processing?
if (ret.isError()) {
logger.error("*** UPDATE ENDPOINT PROCESSING FAILED *** " + ret);
spuManager.abortSubscriptionsProcessing();
return ret;
}
// POST-UPDATE processing
spuManager.subscriptionsProcessingPostUpdate(ret);
return ret;
}
use of it.unibo.arces.wot.sepa.commons.exceptions.SEPAProcessingException in project SEPA by arces-wot.
the class SPUNaive method postUpdateInternalProcessing.
@Override
public Notification postUpdateInternalProcessing(UpdateResponse res) throws SEPAProcessingException {
logger.log(Level.getLevel("spu"), "@postUpdateInternalProcessing");
Response ret = null;
// Query the SPARQL processing service
try {
logger.log(Level.getLevel("spu"), "Query endpoint");
ret = manager.processQuery(subscribe);
} catch (SEPASecurityException | IOException e) {
if (logger.isTraceEnabled())
e.printStackTrace();
logger.log(Level.getLevel("spu"), "SEPASecurityException " + e.getMessage());
throw new SEPAProcessingException("postUpdateInternalProcessing exception " + e.getMessage());
}
if (ret.isError()) {
logger.log(Level.getLevel("spu"), "SEPAProcessingException " + ret);
throw new SEPAProcessingException("postUpdateInternalProcessing exception " + ret.toString());
}
// 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.trace("Current bindings: " + currentBindings);
logger.trace("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.trace("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.trace("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()) {
logger.log(Level.getLevel("spu"), "Send notification");
return new Notification(getSPUID(), new ARBindingsResults(added, removed));
}
logger.log(Level.getLevel("spu"), "Nothing to be notified");
return null;
}
use of it.unibo.arces.wot.sepa.commons.exceptions.SEPAProcessingException in project SEPA by arces-wot.
the class SPU method run.
@Override
public void run() {
while (running.get()) {
synchronized (preProcessing) {
try {
while (!preProcessing.get()) {
logger.log(Level.getLevel("spu"), "Pre-processing wait...");
preProcessing.wait();
}
preProcessing.set(false);
} catch (InterruptedException e) {
logger.log(Level.getLevel("spu"), "SPU interrupted. Send EOP and exist.");
manager.endOfProcessing(this);
return;
}
// PRE processing
logger.log(Level.getLevel("spu"), "* PRE PROCESSING *");
try {
preUpdateInternalProcessing(request);
} catch (SEPAProcessingException e) {
SPUManagerBeans.preProcessingException();
logger.error(e.getMessage());
if (logger.isTraceEnabled())
e.printStackTrace();
}
}
// End of processing
logger.log(Level.getLevel("spu"), "Send EOP");
manager.endOfProcessing(this);
synchronized (postProcessing) {
try {
while (!postProcessing.get()) {
logger.log(Level.getLevel("spu"), "Post-processing wait...");
postProcessing.wait();
}
postProcessing.set(false);
} catch (InterruptedException e) {
logger.log(Level.getLevel("spu"), "SPU interrupted. Send EOP and exist.");
manager.endOfProcessing(this);
return;
}
if (!response.isError()) {
// POST processing
logger.log(Level.getLevel("spu"), "* POST PROCESSING *");
try {
Notification notify = postUpdateInternalProcessing((UpdateResponse) response);
if (notify != null) {
logger.log(Level.getLevel("spu"), "notifyEvent");
manager.notifyEvent(notify);
}
} catch (SEPAProcessingException e) {
SPUManagerBeans.postProcessingException();
logger.error(e.getMessage());
if (logger.isTraceEnabled())
e.printStackTrace();
}
}
}
// End of processing
logger.log(Level.getLevel("spu"), "Send EOP");
manager.endOfProcessing(this);
}
}
Aggregations