Search in sources :

Example 1 with ApplicationProfile

use of it.unibo.arces.wot.sepa.pattern.ApplicationProfile 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 2 with ApplicationProfile

use of it.unibo.arces.wot.sepa.pattern.ApplicationProfile in project SEPA by arces-wot.

the class RealTimeIoTResourceUpdate method main.

public static void main(String[] args) throws SEPAPropertiesException, SEPAProtocolException, SEPASecurityException {
    ApplicationProfile app = null;
    app = new ApplicationProfile("sapexamples/GatewayProfile.jsap");
    for (int i = 0; i < nThreads; i++) {
        producers.execute(new RealTimeIoTResourceUpdate().new ProducerThread(app, "UPDATE_RESOURCE"));
    }
    try {
        producers.awaitTermination(60, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        logger.warn(e.getMessage());
    }
}
Also used : ApplicationProfile(it.unibo.arces.wot.sepa.pattern.ApplicationProfile)

Example 3 with ApplicationProfile

use of it.unibo.arces.wot.sepa.pattern.ApplicationProfile 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);
}
Also used : Producer(it.unibo.arces.wot.sepa.pattern.Producer) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) ApplicationProfile(it.unibo.arces.wot.sepa.pattern.ApplicationProfile)

Example 4 with ApplicationProfile

use of it.unibo.arces.wot.sepa.pattern.ApplicationProfile in project SEPA by arces-wot.

the class Dashboard method loadSAP.

private boolean loadSAP(String file) {
    if (file == null) {
        FileInputStream in = null;
        try {
            in = new FileInputStream("dashboard.properties");
        } catch (FileNotFoundException e) {
            logger.warn(e.getMessage());
            lblInfo.setText("Error: " + e.getMessage());
            lblInfo.setToolTipText("Error: " + e.getMessage());
            frmSepaDashboard.setTitle(versionLabel + " - " + e.getMessage());
            return false;
        }
        // Properties sapFile = new Properties();
        try {
            appProperties.load(in);
        } catch (IOException e) {
            logger.error(e.getMessage());
            lblInfo.setText("Error: " + e.getMessage());
            lblInfo.setToolTipText("Error: " + e.getMessage());
            frmSepaDashboard.setTitle(versionLabel + " - " + e.getMessage());
            return false;
        }
        String path = appProperties.getProperty("appProfile");
        if (path == null) {
            lblInfo.setText("Error: path in dashboard.properties is null");
            lblInfo.setToolTipText("Error: path in dashboard.properties is null");
            frmSepaDashboard.setTitle(versionLabel + " - " + "path in dashboard.properties is null");
            return false;
        }
        file = path;
    }
    labelUrl.setText("---");
    labelHttpPort.setText("---");
    labelHttpsPort.setText("---");
    labelWsPort.setText("---");
    labelWssPort.setText("---");
    labelUpdatePath.setText("---");
    labelQueryPath.setText("---");
    labelSubscribePath.setText("---");
    labelSecurePath.setText("---");
    SPARQLSubscribe.setText("");
    SPARQLUpdate.setText("");
    namespacesDM.getDataVector().clear();
    updateListDM.clear();
    subscribeListDM.clear();
    updateForcedBindingsDM.clearBindings();
    subscribeForcedBindingsDM.clearBindings();
    updatesList.clearSelection();
    subscribesList.clearSelection();
    try {
        appProfile = new ApplicationProfile(file);
    } catch (SEPAPropertiesException e) {
        logger.error(e.getMessage());
        lblInfo.setText("Error: " + e.getMessage());
        lblInfo.setToolTipText("Error: " + e.getMessage());
        frmSepaDashboard.setTitle(versionLabel + " - " + e.getMessage());
        return false;
    }
    try {
        sepaClient = new SEPADashbooard(appProfile);
    } catch (SEPAProtocolException | SEPASecurityException e) {
        logger.error(e.getMessage());
        lblInfo.setText("Error: " + e.getMessage());
        lblInfo.setToolTipText("Error: " + e.getMessage());
        frmSepaDashboard.setTitle(versionLabel + " - " + e.getMessage());
        return false;
    }
    frmSepaDashboard.setTitle(versionLabel + " - " + file);
    // Loading namespaces
    for (String prefix : appProfile.getPrefixes()) {
        Vector<String> row = new Vector<String>();
        row.add(prefix);
        row.addElement(appProfile.getNamespaceURI(prefix));
        namespacesDM.addRow(row);
    }
    // Loading updates
    for (String update : appProfile.getUpdateIds()) {
        // updateListDM.addElement(update);
        updateListDM.add(update);
    }
    // Loading subscribes
    for (String subscribe : appProfile.getSubscribeIds()) {
        // subscribeListDM.addElement(subscribe);
        subscribeListDM.add(subscribe);
    }
    // Enable all the buttons
    btnUpdate.setEnabled(true);
    btnSubscribe.setEnabled(true);
    btnQuery.setEnabled(true);
    labelUrl.setText(appProfile.getHost());
    labelHttpPort.setText(String.format("%d", appProfile.getHttpPort()));
    labelHttpsPort.setText(String.format("%d", appProfile.getHttpsPort()));
    labelWsPort.setText(String.format("%d", appProfile.getWsPort()));
    labelWssPort.setText(String.format("%d", appProfile.getWssPort()));
    labelUpdatePath.setText(appProfile.getUpdatePath());
    labelQueryPath.setText(appProfile.getQueryPath());
    labelSubscribePath.setText(appProfile.getSubscribePath());
    labelSecurePath.setText(appProfile.getSecurePath());
    lblInfo.setText("JSAP loaded");
    lblInfo.setToolTipText("JSAP loaded");
    return true;
}
Also used : SEPAProtocolException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException) SEPAPropertiesException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException) FileNotFoundException(java.io.FileNotFoundException) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException) IOException(java.io.IOException) ApplicationProfile(it.unibo.arces.wot.sepa.pattern.ApplicationProfile) Vector(java.util.Vector) FileInputStream(java.io.FileInputStream)

Example 5 with ApplicationProfile

use of it.unibo.arces.wot.sepa.pattern.ApplicationProfile in project SEPA by arces-wot.

the class LCDProducer method main.

public static void main(String[] args) throws SEPAProtocolException, SEPASecurityException, SEPAPropertiesException {
    ApplicationProfile appProfile = new ApplicationProfile("wot-plugfest.jsap");
    LCDProducer client = new LCDProducer(appProfile, "LCD");
    superCar(client);
    justText(client);
}
Also used : ApplicationProfile(it.unibo.arces.wot.sepa.pattern.ApplicationProfile)

Aggregations

ApplicationProfile (it.unibo.arces.wot.sepa.pattern.ApplicationProfile)8 Producer (it.unibo.arces.wot.sepa.pattern.Producer)2 IOException (java.io.IOException)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 SEPAPropertiesException (it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException)1 SEPAProtocolException (it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException)1 SEPASecurityException (it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException)1 Bindings (it.unibo.arces.wot.sepa.commons.sparql.Bindings)1 RDFTermLiteral (it.unibo.arces.wot.sepa.commons.sparql.RDFTermLiteral)1 RDFTermURI (it.unibo.arces.wot.sepa.commons.sparql.RDFTermURI)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 Vector (java.util.Vector)1