Search in sources :

Example 1 with MqttPahoModule

use of io.joynr.messaging.mqtt.paho.client.MqttPahoModule in project joynr by bmwcarit.

the class MyRadioProviderApplication method getRuntimeModule.

private static Module getRuntimeModule(String transport, String host, int port, Properties joynrConfig) {
    Module runtimeModule;
    if (transport != null) {
        if (transport.contains("websocketcc")) {
            configureWebSocket(host, port, joynrConfig);
            runtimeModule = new CCWebSocketRuntimeModule();
        } else if (transport.contains("websocket")) {
            configureWebSocket(host, port, joynrConfig);
            runtimeModule = new LibjoynrWebSocketRuntimeModule();
        } else {
            runtimeModule = new CCInProcessRuntimeModule();
        }
        Module backendTransportModules = Modules.EMPTY_MODULE;
        if (transport.contains("http")) {
            backendTransportModules = Modules.combine(backendTransportModules, new AtmosphereMessagingModule());
        }
        if (transport.contains("mqtt")) {
            configureMqtt(joynrConfig);
            backendTransportModules = Modules.combine(backendTransportModules, new MqttPahoModule());
        }
        return Modules.override(runtimeModule).with(backendTransportModules);
    }
    return Modules.override(new CCInProcessRuntimeModule()).with(new MqttPahoModule());
}
Also used : LibjoynrWebSocketRuntimeModule(io.joynr.runtime.LibjoynrWebSocketRuntimeModule) MqttPahoModule(io.joynr.messaging.mqtt.paho.client.MqttPahoModule) CCInProcessRuntimeModule(io.joynr.runtime.CCInProcessRuntimeModule) CCWebSocketRuntimeModule(io.joynr.runtime.CCWebSocketRuntimeModule) Module(com.google.inject.Module) CCWebSocketRuntimeModule(io.joynr.runtime.CCWebSocketRuntimeModule) LibjoynrWebSocketRuntimeModule(io.joynr.runtime.LibjoynrWebSocketRuntimeModule) StaticDomainAccessControlProvisioningModule(io.joynr.accesscontrol.StaticDomainAccessControlProvisioningModule) AtmosphereMessagingModule(io.joynr.messaging.AtmosphereMessagingModule) MqttPahoModule(io.joynr.messaging.mqtt.paho.client.MqttPahoModule) CCInProcessRuntimeModule(io.joynr.runtime.CCInProcessRuntimeModule) JoynrApplicationModule(io.joynr.runtime.JoynrApplicationModule) WebsocketModule(io.joynr.messaging.websocket.WebsocketModule) AtmosphereMessagingModule(io.joynr.messaging.AtmosphereMessagingModule)

Example 2 with MqttPahoModule

use of io.joynr.messaging.mqtt.paho.client.MqttPahoModule in project joynr by bmwcarit.

the class ClusterController method main.

public static void main(String[] args) {
    int port = 4242;
    String host = "localhost";
    String transport = null;
    String brokerUri = null;
    Options options = new Options();
    Options helpOptions = new Options();
    setupOptions(options, helpOptions);
    CommandLine line;
    CommandLineParser parser = new DefaultParser();
    // to just get help / usage info.
    try {
        line = parser.parse(helpOptions, args);
        if (line.hasOption('h')) {
            HelpFormatter formatter = new HelpFormatter();
            // use 'options' here to print help about all possible parameters
            formatter.printHelp(ClusterController.class.getName(), options, true);
            System.exit(0);
        }
    } catch (ParseException e) {
    // ignore, since any option except '-h' will cause this exception
    }
    try {
        line = parser.parse(options, args);
        if (line.hasOption('p')) {
            port = Integer.parseInt(line.getOptionValue('p'));
            LOG.info("found port = " + port);
        }
        if (line.hasOption('H')) {
            host = line.getOptionValue('H');
            LOG.info("found host = " + host);
        }
        if (line.hasOption('t')) {
            transport = line.getOptionValue('t').toLowerCase();
            LOG.info("found transport = " + transport);
        }
        if (line.hasOption('b')) {
            brokerUri = line.getOptionValue('b');
            LOG.info("found brokerUri = " + brokerUri);
        }
    } catch (ParseException e) {
        LOG.error("failed to parse command line: " + e);
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(ClusterController.class.getName(), options, true);
        System.exit(1);
    }
    webSocketConfig = new Properties();
    webSocketConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_HOST, host);
    webSocketConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_PORT, "" + port);
    webSocketConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_PROTOCOL, "ws");
    webSocketConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_PATH, "");
    Properties ccConfig = new Properties();
    ccConfig.putAll(webSocketConfig);
    ccConfig.setProperty(ConfigurableMessagingSettings.PROPERTY_CC_CONNECTION_TYPE, "WEBSOCKET");
    Module runtimeModule = new CCWebSocketRuntimeModule();
    if (transport != null) {
        Module backendTransportModules = Modules.EMPTY_MODULE;
        if (transport.contains("atmosphere") || transport.contains("http")) {
            backendTransportModules = Modules.combine(backendTransportModules, new AtmosphereMessagingModule());
        }
        if (transport.contains("mqtt")) {
            if (brokerUri != null) {
                try {
                    URI uri = new URI(brokerUri);
                    if (uri.getAuthority() == null || uri.getHost() == null || uri.getPort() < 0) {
                        throw new URISyntaxException(brokerUri, "host, authority or port was not set");
                    }
                } catch (URISyntaxException e) {
                    System.err.println(brokerUri + " is not a valid URI for the MQTT broker. Expecting for example: tcp://localhost:1883 Error: " + e.getMessage());
                    System.exit(1);
                }
                ccConfig.put("joynr.messaging.mqtt.brokerUri", brokerUri);
                ccConfig.put("joynr.messaging.primaryglobaltransport", "mqtt");
            }
            backendTransportModules = Modules.combine(backendTransportModules, new MqttPahoModule());
        }
        runtimeModule = Modules.override(runtimeModule).with(backendTransportModules);
    }
    Injector injectorCC = new JoynrInjectorFactory(ccConfig, runtimeModule).getInjector();
    runtime = injectorCC.getInstance(JoynrRuntime.class);
    LocalCapabilitiesDirectory capabilitiesDirectory = injectorCC.getInstance(LocalCapabilitiesDirectory.class);
    Thread shutdownHook = new Thread() {

        @Override
        public void run() {
            LOG.info("executing shutdown hook");
            synchronized (this) {
                LOG.info("notifying any waiting thread from shutdown hook");
                notifyAll();
            }
            LOG.info("shutting down");
            runtime.shutdown(false);
            LOG.info("shutdown completed");
        }
    };
    LOG.info("adding shutdown hook");
    Runtime.getRuntime().addShutdownHook(shutdownHook);
    if (System.console() != null) {
        ConsoleReader console;
        try {
            console = new ConsoleReader();
            String command = "";
            while (!command.equals("q")) {
                command = console.readLine();
                if (command.equals("caps")) {
                    Set<DiscoveryEntry> allLocalDiscoveryEntries = capabilitiesDirectory.listLocalCapabilities();
                    StringBuffer discoveryEntriesAsText = new StringBuffer();
                    for (DiscoveryEntry capability : allLocalDiscoveryEntries) {
                        discoveryEntriesAsText.append(capability.toString()).append('\n');
                    }
                    LOG.info(discoveryEntriesAsText.toString());
                } else {
                    LOG.info("\n\nUSAGE press\n" + " q\tto quit\n caps\tto list registered providers\n");
                }
            }
        } catch (IOException e) {
            LOG.error("error reading input from console", e);
        }
    } else {
        LOG.info("\n\nNon-interactive mode detected.\n" + "This cluster controller will continue to run until its JVM gets terminated\n" + "by the operating system. This can be triggered by sending a SIGTERM signal\n" + "to the process running the JVM.");
        synchronized (shutdownHook) {
            LOG.info("waiting on shutdown hook");
            try {
                shutdownHook.wait();
            } catch (InterruptedException e) {
            // ignore
            }
        }
    }
    System.exit(0);
}
Also used : Options(org.apache.commons.cli.Options) URISyntaxException(java.net.URISyntaxException) Properties(java.util.Properties) URI(java.net.URI) HelpFormatter(org.apache.commons.cli.HelpFormatter) Injector(com.google.inject.Injector) LocalCapabilitiesDirectory(io.joynr.capabilities.LocalCapabilitiesDirectory) CommandLineParser(org.apache.commons.cli.CommandLineParser) DefaultParser(org.apache.commons.cli.DefaultParser) DiscoveryEntry(joynr.types.DiscoveryEntry) MqttPahoModule(io.joynr.messaging.mqtt.paho.client.MqttPahoModule) ConsoleReader(jline.console.ConsoleReader) IOException(java.io.IOException) CommandLine(org.apache.commons.cli.CommandLine) ParseException(org.apache.commons.cli.ParseException) Module(com.google.inject.Module) AtmosphereMessagingModule(io.joynr.messaging.AtmosphereMessagingModule) MqttPahoModule(io.joynr.messaging.mqtt.paho.client.MqttPahoModule) WebsocketModule(io.joynr.messaging.websocket.WebsocketModule) AtmosphereMessagingModule(io.joynr.messaging.AtmosphereMessagingModule)

Example 3 with MqttPahoModule

use of io.joynr.messaging.mqtt.paho.client.MqttPahoModule in project joynr by bmwcarit.

the class MqttProviderProxyEnd2EndTest method getRuntime.

@Override
protected JoynrRuntime getRuntime(Properties joynrConfig, Module... modules) {
    mqttConfig = new Properties();
    mqttConfig.put(MqttModule.PROPERTY_KEY_MQTT_BROKER_URI, "tcp://localhost:" + mqttBrokerPort);
    // test is using 2 global address typs, so need to set one of them as primary
    mqttConfig.put(MessagingPropertyKeys.PROPERTY_MESSAGING_PRIMARYGLOBALTRANSPORT, "mqtt");
    mqttConfig.put(MessagingPropertyKeys.DISCOVERYDIRECTORYURL, "tcp://localhost:" + mqttBrokerPort);
    mqttConfig.put(MessagingPropertyKeys.DOMAINACCESSCONTROLLERURL, "tcp://localhost:" + mqttBrokerPort);
    mqttConfig.put(MessagingPropertyKeys.MQTT_TOPIC_PREFIX_MULTICAST, "");
    mqttConfig.put(MessagingPropertyKeys.MQTT_TOPIC_PREFIX_REPLYTO, "replyto/");
    mqttConfig.put(MessagingPropertyKeys.MQTT_TOPIC_PREFIX_UNICAST, "");
    joynrConfig.putAll(mqttConfig);
    joynrConfig.putAll(baseTestConfig);
    Module runtimeModule = Modules.override(new CCInProcessRuntimeModule()).with(modules);
    Module modulesWithRuntime = Modules.override(runtimeModule).with(new MqttPahoModule(), new AbstractModule() {

        @Override
        protected void configure() {
            bind(RawMessagingPreprocessor.class).toInstance(new RawMessagingPreprocessor() {

                @Override
                public byte[] process(byte[] rawMessage, Map<String, Serializable> context) {
                    return rawMessage;
                }
            });
        }
    });
    DummyJoynrApplication application = (DummyJoynrApplication) new JoynrInjectorFactory(joynrConfig, modulesWithRuntime).createApplication(DummyJoynrApplication.class);
    return application.getRuntime();
}
Also used : DummyJoynrApplication(io.joynr.integration.util.DummyJoynrApplication) MqttPahoModule(io.joynr.messaging.mqtt.paho.client.MqttPahoModule) CCInProcessRuntimeModule(io.joynr.runtime.CCInProcessRuntimeModule) Properties(java.util.Properties) Module(com.google.inject.Module) MqttModule(io.joynr.messaging.mqtt.MqttModule) MqttPahoModule(io.joynr.messaging.mqtt.paho.client.MqttPahoModule) CCInProcessRuntimeModule(io.joynr.runtime.CCInProcessRuntimeModule) AbstractModule(com.google.inject.AbstractModule) RawMessagingPreprocessor(io.joynr.messaging.RawMessagingPreprocessor) Map(java.util.Map) AbstractModule(com.google.inject.AbstractModule) JoynrInjectorFactory(io.joynr.runtime.JoynrInjectorFactory)

Example 4 with MqttPahoModule

use of io.joynr.messaging.mqtt.paho.client.MqttPahoModule in project joynr by bmwcarit.

the class RoutingTableOverwriteEnd2EndTest method createRuntime.

protected JoynrRuntime createRuntime(String runtimeId, Properties additionalProperties) {
    Properties properties = new Properties();
    properties.put(MqttModule.PROPERTY_KEY_MQTT_BROKER_URI, "tcp://localhost:" + mqttBrokerPort);
    properties.put(MessagingPropertyKeys.PROPERTY_MESSAGING_PRIMARYGLOBALTRANSPORT, "mqtt");
    properties.put(MessagingPropertyKeys.DISCOVERYDIRECTORYURL, "tcp://localhost:" + mqttBrokerPort);
    properties.put(MessagingPropertyKeys.CHANNELID, runtimeId);
    properties.put(MqttModule.PROPERTY_KEY_MQTT_CLIENT_ID_PREFIX, runtimeId);
    if (additionalProperties != null) {
        properties.putAll(additionalProperties);
    }
    Module module = Modules.override(new CCInProcessRuntimeModule()).with(new MqttPahoModule());
    DummyJoynrApplication application = (DummyJoynrApplication) new JoynrInjectorFactory(properties, module).createApplication(DummyJoynrApplication.class);
    return application.getRuntime();
}
Also used : DummyJoynrApplication(io.joynr.integration.util.DummyJoynrApplication) MqttPahoModule(io.joynr.messaging.mqtt.paho.client.MqttPahoModule) CCInProcessRuntimeModule(io.joynr.runtime.CCInProcessRuntimeModule) Properties(java.util.Properties) Module(com.google.inject.Module) MqttModule(io.joynr.messaging.mqtt.MqttModule) MqttPahoModule(io.joynr.messaging.mqtt.paho.client.MqttPahoModule) CCInProcessRuntimeModule(io.joynr.runtime.CCInProcessRuntimeModule) JoynrInjectorFactory(io.joynr.runtime.JoynrInjectorFactory)

Example 5 with MqttPahoModule

use of io.joynr.messaging.mqtt.paho.client.MqttPahoModule in project joynr by bmwcarit.

the class WebSocketProviderProxyEnd2EndTest method createClusterController.

private JoynrRuntime createClusterController(Properties webSocketConfig) {
    Properties ccConfig = new Properties();
    ccConfig.putAll(webSocketConfig);
    ccConfig.putAll(baseTestConfig);
    ccConfig.setProperty(ConfigurableMessagingSettings.PROPERTY_CC_CONNECTION_TYPE, "WEBSOCKET");
    injectorCC = new JoynrInjectorFactory(ccConfig, Modules.override(new CCWebSocketRuntimeModule()).with(new MqttPahoModule(), new AbstractModule() {

        @Override
        protected void configure() {
            bind(Boolean.class).annotatedWith(Names.named(WebSocketMessagingSkeleton.WEBSOCKET_IS_MAIN_TRANSPORT)).toInstance(Boolean.TRUE);
        }
    })).getInjector();
    return injectorCC.getInstance(JoynrRuntime.class);
}
Also used : MqttPahoModule(io.joynr.messaging.mqtt.paho.client.MqttPahoModule) CCWebSocketRuntimeModule(io.joynr.runtime.CCWebSocketRuntimeModule) Properties(java.util.Properties) JoynrInjectorFactory(io.joynr.runtime.JoynrInjectorFactory) AbstractModule(com.google.inject.AbstractModule)

Aggregations

MqttPahoModule (io.joynr.messaging.mqtt.paho.client.MqttPahoModule)12 Module (com.google.inject.Module)11 CCInProcessRuntimeModule (io.joynr.runtime.CCInProcessRuntimeModule)8 Properties (java.util.Properties)7 AtmosphereMessagingModule (io.joynr.messaging.AtmosphereMessagingModule)6 WebsocketModule (io.joynr.messaging.websocket.WebsocketModule)6 AbstractModule (com.google.inject.AbstractModule)5 LibjoynrWebSocketRuntimeModule (io.joynr.runtime.LibjoynrWebSocketRuntimeModule)5 JoynrApplicationModule (io.joynr.runtime.JoynrApplicationModule)4 JoynrInjectorFactory (io.joynr.runtime.JoynrInjectorFactory)4 Injector (com.google.inject.Injector)3 StaticDomainAccessControlProvisioningModule (io.joynr.accesscontrol.StaticDomainAccessControlProvisioningModule)3 DummyJoynrApplication (io.joynr.integration.util.DummyJoynrApplication)3 MqttModule (io.joynr.messaging.mqtt.MqttModule)3 CCWebSocketRuntimeModule (io.joynr.runtime.CCWebSocketRuntimeModule)3 JoynrPropertiesModule (io.joynr.common.JoynrPropertiesModule)2 JoynrMessageProcessor (io.joynr.messaging.JoynrMessageProcessor)2 NoOpRawMessagingPreprocessor (io.joynr.messaging.NoOpRawMessagingPreprocessor)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 Before (org.junit.Before)2