use of it.unibo.arces.wot.sepa.pattern.Producer 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.pattern.Producer in project SEPA by arces-wot.
the class MQTTServerMonitoring method main.
public static void main(String[] args) throws SEPAProtocolException, SEPASecurityException, SEPAPropertiesException {
if (args.length != 1) {
logger.error("Please specify the JSAP file (.jsap)");
System.exit(1);
}
logger.info("Create initializer");
mqttInitializer = new Producer(new ApplicationProfile(args[0]), "ADD_OBSERVATION");
// Semantic mappings
logger.info("Parse semantic mappings");
JsonObject mappings = mqttInitializer.getApplicationProfile().getExtendedData().get("semantic-mappings").getAsJsonObject();
logger.info("Add observations");
for (Entry<String, JsonElement> mapping : mappings.entrySet()) addObservation(mapping);
// Create MQTT adapter
logger.info("Create MQTT adapter");
adapter = new MQTTSmartifier(args[0]);
logger.info("Start MQTT adapter");
if (adapter.start(mqttInitializer.getApplicationProfile().getExtendedData().get("simulate").getAsBoolean())) {
logger.info("Press any key to exit...");
try {
System.in.read();
} catch (IOException e) {
logger.warn(e.getMessage());
}
logger.info("Stop MQTT adapter");
adapter.stop();
logger.info("Stopped");
}
System.exit(1);
}
use of it.unibo.arces.wot.sepa.pattern.Producer 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;
}
Aggregations