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();
}
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);
}
}
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;
}
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();
}
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();
}
}
}
}
Aggregations