Search in sources :

Example 16 with Bindings

use of it.unibo.arces.wot.sepa.commons.sparql.Bindings in project SEPA by arces-wot.

the class MessageReceiver method joinChat.

public boolean joinChat() {
    if (joined)
        return true;
    Response ret = subscribe(message);
    joined = !ret.isError();
    if (joined) {
        for (Bindings bindings : ((SubscribeResponse) ret).getBindingsResults().getBindings()) {
            listener.onMessageReceived(new Message(bindings.getBindingValue("sender"), message.getBindingValue("receiver"), bindings.getBindingValue("text"), bindings.getBindingValue("time")));
        }
    }
    return joined;
}
Also used : SubscribeResponse(it.unibo.arces.wot.sepa.commons.response.SubscribeResponse) Response(it.unibo.arces.wot.sepa.commons.response.Response) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse) Bindings(it.unibo.arces.wot.sepa.commons.sparql.Bindings)

Example 17 with Bindings

use of it.unibo.arces.wot.sepa.commons.sparql.Bindings in project SEPA by arces-wot.

the class MessageSender method joinChat.

public boolean joinChat() {
    if (joined)
        return true;
    Response ret = subscribe(message);
    joined = !ret.isError();
    if (joined) {
        for (Bindings bindings : ((SubscribeResponse) ret).getBindingsResults().getBindings()) {
            listener.onMessageSent(new Message(message.getBindingValue("sender"), bindings.getBindingValue("receiver"), bindings.getBindingValue("text"), bindings.getBindingValue("time")));
        }
    }
    return joined;
}
Also used : SubscribeResponse(it.unibo.arces.wot.sepa.commons.response.SubscribeResponse) Response(it.unibo.arces.wot.sepa.commons.response.Response) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse) Bindings(it.unibo.arces.wot.sepa.commons.sparql.Bindings)

Example 18 with Bindings

use of it.unibo.arces.wot.sepa.commons.sparql.Bindings 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;
}
Also used : Response(it.unibo.arces.wot.sepa.commons.response.Response) UpdateResponse(it.unibo.arces.wot.sepa.commons.response.UpdateResponse) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse) 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) Bindings(it.unibo.arces.wot.sepa.commons.sparql.Bindings) Notification(it.unibo.arces.wot.sepa.commons.response.Notification) SEPAProtocolException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse)

Example 19 with Bindings

use of it.unibo.arces.wot.sepa.commons.sparql.Bindings in project SEPA by arces-wot.

the class SmartLightingBenchmark method populate.

private int populate(int nRoad, int nPost, int firstRoadIndex) throws SEPAProtocolException, SEPASecurityException {
    Producer road = new Producer(appProfile, "INSERT_ROAD");
    Producer addPost2Road = new Producer(appProfile, "ADD_POST");
    Producer sensor = new Producer(appProfile, "INSERT_SENSOR");
    Producer post = new Producer(appProfile, "INSERT_POST");
    Producer lamp = new Producer(appProfile, "INSERT_LAMP");
    Producer addSensor2post = new Producer(appProfile, "ADD_SENSOR");
    Producer addLamp2post = new Producer(appProfile, "ADD_LAMP");
    logger.debug("Number of roads: " + nRoad + " Posts/road: " + nPost + " First road index: " + firstRoadIndex);
    Bindings bindings = new Bindings();
    for (int roadIndex = firstRoadIndex; roadIndex < firstRoadIndex + nRoad; roadIndex++) {
        // while (nRoad>0) {
        String roadURI = "bench:Road_" + roadIndex;
        bindings.addBinding("road", new RDFTermURI(roadURI));
        long startTime = System.nanoTime();
        Response ret = road.update(bindings);
        long stopTime = System.nanoTime();
        logger.info("INSERT ROAD " + roadURI + " " + (stopTime - startTime) + " 1");
        if (!ret.getClass().equals(UpdateResponse.class))
            return firstRoadIndex;
        for (int postIndex = 1; postIndex < nPost + 1; postIndex++) {
            // while(postNumber>0) {
            // URI
            String postURI = "bench:Post_" + roadIndex + "_" + postIndex;
            String lampURI = "bench:Lamp_" + roadIndex + "_" + postIndex;
            String temparatureURI = "bench:Temperature_" + roadIndex + "_" + postIndex;
            String presenceURI = "bench:Presence_" + roadIndex + "_" + postIndex;
            bindings.addBinding("post", new RDFTermURI(postURI));
            bindings.addBinding("lamp", new RDFTermURI(lampURI));
            // New post
            startTime = System.nanoTime();
            ret = post.update(bindings);
            stopTime = System.nanoTime();
            logger.info("INSERT POST " + postURI + " " + (stopTime - startTime) + " 3");
            if (!ret.getClass().equals(UpdateResponse.class))
                return firstRoadIndex;
            // Add post to road
            startTime = System.nanoTime();
            ret = addPost2Road.update(bindings);
            stopTime = System.nanoTime();
            logger.info("INSERT POST2ROAD " + postURI + " " + (stopTime - startTime) + " 1");
            if (!ret.getClass().equals(UpdateResponse.class))
                return firstRoadIndex;
            // New lamp
            startTime = System.nanoTime();
            ret = lamp.update(bindings);
            stopTime = System.nanoTime();
            logger.info("INSERT LAMP " + lampURI + " " + (stopTime - startTime) + " 4");
            if (!ret.getClass().equals(UpdateResponse.class))
                return firstRoadIndex;
            // Add lamp to post
            startTime = System.nanoTime();
            ret = addLamp2post.update(bindings);
            stopTime = System.nanoTime();
            logger.info("INSERT LAMP2POST " + lampURI + " " + (stopTime - startTime) + " 1");
            if (!ret.getClass().equals(UpdateResponse.class))
                return firstRoadIndex;
            // New temperature sensor
            bindings.addBinding("sensor", new RDFTermURI(temparatureURI));
            bindings.addBinding("type", new RDFTermURI("bench:TEMPERATURE"));
            bindings.addBinding("unit", new RDFTermURI("bench:CELSIUS"));
            bindings.addBinding("value", new RDFTermLiteral("0"));
            startTime = System.nanoTime();
            ret = sensor.update(bindings);
            stopTime = System.nanoTime();
            logger.info("INSERT SENSOR " + temparatureURI + " " + (stopTime - startTime) + " 5");
            if (!ret.getClass().equals(UpdateResponse.class))
                return firstRoadIndex;
            startTime = System.nanoTime();
            ret = addSensor2post.update(bindings);
            stopTime = System.nanoTime();
            logger.info("INSERT SENSOR2POST " + temparatureURI + " " + (stopTime - startTime) + " 1");
            if (!ret.getClass().equals(UpdateResponse.class))
                return firstRoadIndex;
            // New presence sensor
            bindings.addBinding("sensor", new RDFTermURI(presenceURI));
            bindings.addBinding("type", new RDFTermURI("bench:PRESENCE"));
            bindings.addBinding("unit", new RDFTermURI("bench:BOOLEAN"));
            bindings.addBinding("value", new RDFTermLiteral("false"));
            startTime = System.nanoTime();
            ret = sensor.update(bindings);
            stopTime = System.nanoTime();
            logger.info("INSERT SENSOR " + presenceURI + " " + (stopTime - startTime) + " 5");
            if (!ret.getClass().equals(UpdateResponse.class))
                return firstRoadIndex;
            startTime = System.nanoTime();
            ret = addSensor2post.update(bindings);
            stopTime = System.nanoTime();
            logger.info("INSERT SENSOR2POST " + presenceURI + " " + (stopTime - startTime) + " 1");
            if (!ret.getClass().equals(UpdateResponse.class))
                return firstRoadIndex;
        }
    }
    return firstRoadIndex + nRoad;
}
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) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse) UpdateResponse(it.unibo.arces.wot.sepa.commons.response.UpdateResponse) Producer(it.unibo.arces.wot.sepa.pattern.Producer) RDFTermURI(it.unibo.arces.wot.sepa.commons.sparql.RDFTermURI) Bindings(it.unibo.arces.wot.sepa.commons.sparql.Bindings) RDFTermLiteral(it.unibo.arces.wot.sepa.commons.sparql.RDFTermLiteral)

Example 20 with Bindings

use of it.unibo.arces.wot.sepa.commons.sparql.Bindings in project SEPA by arces-wot.

the class SmartLightingBenchmark method updateRoad.

protected boolean updateRoad(int nRoad, Integer dimming) {
    String roadURI = "bench:Road_" + nRoad;
    Bindings bindings = new Bindings();
    bindings.addBinding("?road", new RDFTermURI(roadURI));
    bindings.addBinding("?dimming", new RDFTermLiteral(dimming.toString()));
    long startTime = System.nanoTime();
    Response ret = roadUpdater.update(bindings);
    long stopTime = System.nanoTime();
    logger.info("UPDATE ROAD " + roadURI + " " + (stopTime - startTime));
    return ret.getClass().equals(UpdateResponse.class);
}
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) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse) RDFTermURI(it.unibo.arces.wot.sepa.commons.sparql.RDFTermURI) Bindings(it.unibo.arces.wot.sepa.commons.sparql.Bindings) RDFTermLiteral(it.unibo.arces.wot.sepa.commons.sparql.RDFTermLiteral)

Aggregations

Bindings (it.unibo.arces.wot.sepa.commons.sparql.Bindings)34 RDFTermURI (it.unibo.arces.wot.sepa.commons.sparql.RDFTermURI)21 RDFTermLiteral (it.unibo.arces.wot.sepa.commons.sparql.RDFTermLiteral)19 Response (it.unibo.arces.wot.sepa.commons.response.Response)12 ErrorResponse (it.unibo.arces.wot.sepa.commons.response.ErrorResponse)11 SubscribeResponse (it.unibo.arces.wot.sepa.commons.response.SubscribeResponse)9 QueryResponse (it.unibo.arces.wot.sepa.commons.response.QueryResponse)4 UpdateResponse (it.unibo.arces.wot.sepa.commons.response.UpdateResponse)4 JsonElement (com.google.gson.JsonElement)2 JsonObject (com.google.gson.JsonObject)2 SEPAProtocolException (it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException)2 ARBindingsResults (it.unibo.arces.wot.sepa.commons.sparql.ARBindingsResults)2 BindingsResults (it.unibo.arces.wot.sepa.commons.sparql.BindingsResults)2 RDFTerm (it.unibo.arces.wot.sepa.commons.sparql.RDFTerm)2 Producer (it.unibo.arces.wot.sepa.pattern.Producer)2 SEPAPropertiesException (it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException)1 SEPASecurityException (it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException)1 QueryRequest (it.unibo.arces.wot.sepa.commons.request.QueryRequest)1 Notification (it.unibo.arces.wot.sepa.commons.response.Notification)1 ApplicationProfile (it.unibo.arces.wot.sepa.pattern.ApplicationProfile)1