Search in sources :

Example 1 with RemoteEndpoint

use of it.unibo.arces.wot.sepa.engine.processing.endpoint.RemoteEndpoint in project SEPA by arces-wot.

the class QueryProcessor method process.

public Response process(InternalQueryRequest req) throws SEPASecurityException, IOException {
    // Build the request
    QueryRequest request;
    request = new QueryRequest(properties.getQueryMethod(), properties.getProtocolScheme(), properties.getHost(), properties.getPort(), properties.getQueryPath(), req.getSparql(), req.getDefaultGraphUri(), req.getNamedGraphUri(), req.getBasicAuthorizationHeader(), req.getInternetMediaType(), QueryProcessorBeans.getTimeout(), 0);
    int n = 0;
    Response ret;
    do {
        long start = Timings.getTime();
        SPARQLEndpoint endpoint;
        if (properties.getProtocolScheme().equals("jena-api") && properties.getHost().equals("in-memory"))
            endpoint = new JenaInMemoryEndpoint();
        else
            endpoint = new RemoteEndpoint();
        ret = endpoint.query(request);
        endpoint.close();
        long stop = Timings.getTime();
        UpdateProcessorBeans.timings(start, stop);
        logger.trace("Response: " + ret.toString());
        Timings.log("QUERY_PROCESSING_TIME", start, stop);
        n++;
        if (ret.isTimeoutError()) {
            QueryProcessorBeans.timedOutRequest();
            logger.error("*** TIMEOUT *** (" + n + "/" + QueryProcessorBeans.getTimeoutNRetry() + ") " + req);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                logger.warn("Failed to sleep...");
            }
        }
    } while (ret.isTimeoutError() && n < QueryProcessorBeans.getTimeoutNRetry());
    // Request ABORTED
    if (ret.isTimeoutError()) {
        logger.error("*** REQUEST ABORTED *** " + request);
        QueryProcessorBeans.abortedRequest();
    }
    return ret;
}
Also used : Response(it.unibo.arces.wot.sepa.commons.response.Response) QueryRequest(it.unibo.arces.wot.sepa.commons.request.QueryRequest) InternalQueryRequest(it.unibo.arces.wot.sepa.engine.scheduling.InternalQueryRequest) JenaInMemoryEndpoint(it.unibo.arces.wot.sepa.engine.processing.endpoint.JenaInMemoryEndpoint) RemoteEndpoint(it.unibo.arces.wot.sepa.engine.processing.endpoint.RemoteEndpoint) SPARQLEndpoint(it.unibo.arces.wot.sepa.engine.processing.endpoint.SPARQLEndpoint) JenaInMemoryEndpoint(it.unibo.arces.wot.sepa.engine.processing.endpoint.JenaInMemoryEndpoint) RemoteEndpoint(it.unibo.arces.wot.sepa.engine.processing.endpoint.RemoteEndpoint) SPARQLEndpoint(it.unibo.arces.wot.sepa.engine.processing.endpoint.SPARQLEndpoint)

Example 2 with RemoteEndpoint

use of it.unibo.arces.wot.sepa.engine.processing.endpoint.RemoteEndpoint in project SEPA by arces-wot.

the class UpdateProcessor method process.

public Response process(InternalUpdateRequest req) throws SEPASecurityException, IOException {
    // ENDPOINT UPDATE (set timeout and set retry = 0)
    UpdateRequest request = new UpdateRequest(properties.getUpdateMethod(), properties.getProtocolScheme(), properties.getHost(), properties.getPort(), properties.getUpdatePath(), req.getSparql(), req.getDefaultGraphUri(), req.getNamedGraphUri(), req.getBasicAuthorizationHeader(), UpdateProcessorBeans.getTimeout(), 0);
    logger.trace(request);
    Response ret;
    int n = 0;
    do {
        long start = Timings.getTime();
        SPARQLEndpoint endpoint;
        if (properties.getProtocolScheme().equals("jena-api") && properties.getHost().equals("in-memory"))
            endpoint = new JenaInMemoryEndpoint();
        else
            endpoint = new RemoteEndpoint();
        ret = endpoint.update(request);
        endpoint.close();
        long stop = Timings.getTime();
        UpdateProcessorBeans.timings(start, stop);
        logger.trace("Response: " + ret.toString());
        Timings.log("UPDATE_PROCESSING_TIME", start, stop);
        n++;
        if (ret.isTimeoutError()) {
            UpdateProcessorBeans.timedOutRequest();
            logger.error("*TIMEOUT* (" + n + "/" + UpdateProcessorBeans.getTimeoutNRetry() + ") " + req);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                logger.warn("Failed to sleep...");
            }
        }
    } while (ret.isTimeoutError() && n < UpdateProcessorBeans.getTimeoutNRetry());
    if (ret.isTimeoutError()) {
        logger.error("*** REQUEST ABORTED *** " + request);
        UpdateProcessorBeans.abortedRequest();
    }
    return ret;
}
Also used : Response(it.unibo.arces.wot.sepa.commons.response.Response) UpdateRequest(it.unibo.arces.wot.sepa.commons.request.UpdateRequest) InternalUpdateRequest(it.unibo.arces.wot.sepa.engine.scheduling.InternalUpdateRequest) JenaInMemoryEndpoint(it.unibo.arces.wot.sepa.engine.processing.endpoint.JenaInMemoryEndpoint) RemoteEndpoint(it.unibo.arces.wot.sepa.engine.processing.endpoint.RemoteEndpoint) SPARQLEndpoint(it.unibo.arces.wot.sepa.engine.processing.endpoint.SPARQLEndpoint) JenaInMemoryEndpoint(it.unibo.arces.wot.sepa.engine.processing.endpoint.JenaInMemoryEndpoint) RemoteEndpoint(it.unibo.arces.wot.sepa.engine.processing.endpoint.RemoteEndpoint) SPARQLEndpoint(it.unibo.arces.wot.sepa.engine.processing.endpoint.SPARQLEndpoint)

Aggregations

Response (it.unibo.arces.wot.sepa.commons.response.Response)2 JenaInMemoryEndpoint (it.unibo.arces.wot.sepa.engine.processing.endpoint.JenaInMemoryEndpoint)2 RemoteEndpoint (it.unibo.arces.wot.sepa.engine.processing.endpoint.RemoteEndpoint)2 SPARQLEndpoint (it.unibo.arces.wot.sepa.engine.processing.endpoint.SPARQLEndpoint)2 QueryRequest (it.unibo.arces.wot.sepa.commons.request.QueryRequest)1 UpdateRequest (it.unibo.arces.wot.sepa.commons.request.UpdateRequest)1 InternalQueryRequest (it.unibo.arces.wot.sepa.engine.scheduling.InternalQueryRequest)1 InternalUpdateRequest (it.unibo.arces.wot.sepa.engine.scheduling.InternalUpdateRequest)1