Search in sources :

Example 1 with SEPAProcessingException

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;
}
Also used : Response(it.unibo.arces.wot.sepa.commons.response.Response) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse) SEPASparqlParsingException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASparqlParsingException) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException) SPARQL11ProtocolException(it.unibo.arces.wot.sepa.engine.protocol.sparql11.SPARQL11ProtocolException) IOException(java.io.IOException) InternalUpdateRequest(it.unibo.arces.wot.sepa.engine.scheduling.InternalUpdateRequest) SEPAProcessingException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAProcessingException) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse)

Example 2 with SEPAProcessingException

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;
}
Also used : Response(it.unibo.arces.wot.sepa.commons.response.Response) SubscribeResponse(it.unibo.arces.wot.sepa.commons.response.SubscribeResponse) UpdateResponse(it.unibo.arces.wot.sepa.commons.response.UpdateResponse) QueryResponse(it.unibo.arces.wot.sepa.commons.response.QueryResponse) ARBindingsResults(it.unibo.arces.wot.sepa.commons.sparql.ARBindingsResults) BindingsResults(it.unibo.arces.wot.sepa.commons.sparql.BindingsResults) ARBindingsResults(it.unibo.arces.wot.sepa.commons.sparql.ARBindingsResults) QueryResponse(it.unibo.arces.wot.sepa.commons.response.QueryResponse) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException) IOException(java.io.IOException) Bindings(it.unibo.arces.wot.sepa.commons.sparql.Bindings) SEPAProcessingException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAProcessingException) Notification(it.unibo.arces.wot.sepa.commons.response.Notification)

Example 3 with SEPAProcessingException

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);
    }
}
Also used : SEPAProcessingException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAProcessingException) Notification(it.unibo.arces.wot.sepa.commons.response.Notification)

Aggregations

SEPAProcessingException (it.unibo.arces.wot.sepa.commons.exceptions.SEPAProcessingException)3 SEPASecurityException (it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException)2 Notification (it.unibo.arces.wot.sepa.commons.response.Notification)2 Response (it.unibo.arces.wot.sepa.commons.response.Response)2 IOException (java.io.IOException)2 SEPASparqlParsingException (it.unibo.arces.wot.sepa.commons.exceptions.SEPASparqlParsingException)1 ErrorResponse (it.unibo.arces.wot.sepa.commons.response.ErrorResponse)1 QueryResponse (it.unibo.arces.wot.sepa.commons.response.QueryResponse)1 SubscribeResponse (it.unibo.arces.wot.sepa.commons.response.SubscribeResponse)1 UpdateResponse (it.unibo.arces.wot.sepa.commons.response.UpdateResponse)1 ARBindingsResults (it.unibo.arces.wot.sepa.commons.sparql.ARBindingsResults)1 Bindings (it.unibo.arces.wot.sepa.commons.sparql.Bindings)1 BindingsResults (it.unibo.arces.wot.sepa.commons.sparql.BindingsResults)1 SPARQL11ProtocolException (it.unibo.arces.wot.sepa.engine.protocol.sparql11.SPARQL11ProtocolException)1 InternalUpdateRequest (it.unibo.arces.wot.sepa.engine.scheduling.InternalUpdateRequest)1