Search in sources :

Example 11 with Bindings

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

the class SEPATest method queryTest.

protected static boolean queryTest(String sparql, String utf8, boolean secure) {
    QueryRequest query = new QueryRequest(sparql);
    if (!secure)
        logger.debug(query.toString());
    else
        logger.debug("SECURE " + query.toString());
    Response response;
    if (!secure)
        response = client.query(query);
    else
        response = client.secureQuery(query);
    logger.debug(response.toString());
    if (response.isQueryResponse() && utf8 != null) {
        QueryResponse queryResponse = (QueryResponse) response;
        List<Bindings> results = queryResponse.getBindingsResults().getBindings();
        if (results.size() == 1) {
            Bindings bindings = results.get(0);
            if (bindings.isLiteral("o")) {
                String value = bindings.getBindingValue("o");
                if (value.equals(utf8))
                    return true;
            }
        }
        return false;
    }
    return response.isQueryResponse();
}
Also used : Response(it.unibo.arces.wot.sepa.commons.response.Response) SubscribeResponse(it.unibo.arces.wot.sepa.commons.response.SubscribeResponse) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse) QueryResponse(it.unibo.arces.wot.sepa.commons.response.QueryResponse) QueryRequest(it.unibo.arces.wot.sepa.commons.request.QueryRequest) QueryResponse(it.unibo.arces.wot.sepa.commons.response.QueryResponse) Bindings(it.unibo.arces.wot.sepa.commons.sparql.Bindings)

Example 12 with Bindings

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

the class GarbageCollector method onAddedResults.

@Override
public void onAddedResults(BindingsResults results) {
    numbers = 0;
    for (Bindings binding : results.getBindings()) {
        numbers += Integer.parseInt(binding.getBindingValue("numbers"));
        logger.info("Total numbers: " + numbers + " GC numbers: " + getApplicationProfile().getExtendedData().get("gcnumbers").getAsInt());
    }
    if (numbers >= getApplicationProfile().getExtendedData().get("gcnumbers").getAsInt()) {
        logger.info("Collecting triples...");
        update(null);
    }
}
Also used : Bindings(it.unibo.arces.wot.sepa.commons.sparql.Bindings)

Example 13 with Bindings

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

the class MeanMonitor method subscribe.

public boolean subscribe() {
    Response ret;
    ret = super.subscribe(null);
    if (ret.isError())
        return false;
    SubscribeResponse results = (SubscribeResponse) ret;
    // Previous mean values
    for (Bindings binding : results.getBindingsResults().getBindings()) {
        logger.info(binding.getBindingValue("mean") + " : " + Float.parseFloat(binding.getBindingValue("value").replaceAll(",", ".")) + " (values: " + Integer.parseInt(binding.getBindingValue("counter")) + ")");
    }
    return true;
}
Also used : Response(it.unibo.arces.wot.sepa.commons.response.Response) SubscribeResponse(it.unibo.arces.wot.sepa.commons.response.SubscribeResponse) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse) SubscribeResponse(it.unibo.arces.wot.sepa.commons.response.SubscribeResponse) Bindings(it.unibo.arces.wot.sepa.commons.sparql.Bindings)

Example 14 with Bindings

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

the class HeapBugTest method main.

public static void main(String[] args) throws SEPAProtocolException, SEPASecurityException, SEPAPropertiesException, IOException {
    if (args.length > 1) {
        for (int index = 0; index < args.length; index++) {
            switch(args[index]) {
                case "-pro":
                    index++;
                    if (index < args.length)
                        try {
                            N_OBSERVATIONS = Integer.parseInt(args[index]);
                        } catch (NumberFormatException e) {
                            printUsage();
                        }
                    else
                        printUsage();
                    break;
                case "-con":
                    index++;
                    if (index < args.length)
                        try {
                            N_CONSUMERS = Integer.parseInt(args[index]);
                        } catch (NumberFormatException e) {
                            printUsage();
                        }
                    else
                        printUsage();
                    break;
                case "-min":
                    index++;
                    if (index <= args.length)
                        try {
                            MIN_SLEEP = Integer.parseInt(args[index]);
                        } catch (NumberFormatException e) {
                            printUsage();
                        }
                    else
                        printUsage();
                    break;
                case "-max":
                    index++;
                    if (index <= args.length)
                        try {
                            DELTA_MAX_SLEEP = Integer.parseInt(args[index]);
                        } catch (NumberFormatException e) {
                            printUsage();
                        }
                    else
                        printUsage();
                    break;
            }
        }
    } else if (args.length == 1) {
        if (!args[0].equals("-default"))
            printUsage();
    } else
        printUsage();
    app = new ApplicationProfile("mqttMonitoring.jsap");
    System.out.println("Context creation");
    creator = new Producer(app, "ADD_OBSERVATION");
    System.out.println("Consumers creation");
    for (int i = 0; i < N_CONSUMERS; i++) {
        HeapBugTestConsumer consumer = new HeapBugTest().new HeapBugTestConsumer(app, "OBSERVATIONS", i);
        consumer.subscribe(null);
    }
    Bindings fb = new Bindings();
    fb.addBinding("unit", new RDFTermURI(unit));
    System.out.println("Producers creation");
    for (int i = 0; i < N_OBSERVATIONS; i++) {
        fb.addBinding("observation", new RDFTermURI(observation + i));
        fb.addBinding("comment", new RDFTermLiteral(comment + i));
        fb.addBinding("label", new RDFTermLiteral(label + i));
        fb.addBinding("location", new RDFTermURI(location + i));
        creator.update(fb);
        HeapBugTestProducer th = new HeapBugTest().new HeapBugTestProducer(i);
        threads.add(th);
        th.start();
    }
    System.out.println("Press any key to exit...");
    System.in.read();
    for (HeapBugTestProducer th : threads) th.interrupt();
}
Also used : Producer(it.unibo.arces.wot.sepa.pattern.Producer) RDFTermURI(it.unibo.arces.wot.sepa.commons.sparql.RDFTermURI) ApplicationProfile(it.unibo.arces.wot.sepa.pattern.ApplicationProfile) Bindings(it.unibo.arces.wot.sepa.commons.sparql.Bindings) RDFTermLiteral(it.unibo.arces.wot.sepa.commons.sparql.RDFTermLiteral)

Example 15 with Bindings

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

the class LCDProducer method superCar.

private static void superCar(Producer client) {
    Bindings bind = new Bindings();
    HashMap<Integer, String> graphics = new HashMap<Integer, String>();
    graphics.put(0, "*              *");
    graphics.put(1, "**            **");
    graphics.put(2, "***          ***");
    graphics.put(3, "****        ****");
    graphics.put(4, "*****      *****");
    graphics.put(5, "******    ******");
    graphics.put(6, "*******  *******");
    graphics.put(7, "****************");
    while (true) {
        for (int i = 0; i < 8; i++) {
            bind = new Bindings();
            bind.addBinding("value", new RDFTermLiteral(graphics.get(i)));
            client.update(bind);
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        for (int i = 7; i > 0; i--) {
            bind = new Bindings();
            bind.addBinding("value", new RDFTermLiteral(graphics.get(i)));
            client.update(bind);
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) 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