Search in sources :

Example 1 with AtmosphereMessagingModule

use of io.joynr.messaging.AtmosphereMessagingModule in project joynr by bmwcarit.

the class MyGpsProviderApplication method main.

public static void main(String[] args) throws Exception {
    // Get the provider domain from the command line
    if (args.length != 1 && args.length != 2) {
        LOG.error("\n\nUSAGE: java {} <local-domain> [websocket] \n\n NOTE: Providers are registered on the local domain.", MyGpsProviderApplication.class.getName());
        return;
    }
    String localDomain = args[0];
    LOG.debug("Registering provider on domain \"{}\"", localDomain);
    // joynr config properties are used to set joynr configuration at
    // compile time. They are set on the
    // JoynrInjectorFactory.
    Properties joynrConfig = new Properties();
    // Set a custom static persistence file (default is joynr.properties in
    // the working dir) to store
    // joynr configuration. It allows for changing the joynr configuration
    // at runtime. Custom persistence
    // files support running the consumer and provider applications from
    // within the same directory.
    joynrConfig.setProperty(MessagingPropertyKeys.PERSISTENCE_FILE, STATIC_PERSISTENCE_FILE);
    // How to use custom infrastructure elements:
    // 1) Set them programmatically at compile time using the joynr
    // configuration properties at the
    // JoynInjectorFactory. E.g. uncomment the following lines to set a
    // certain joynr server
    // instance.
    // joynrConfig.setProperty(MessagingPropertyKeys.BOUNCE_PROXY_URL,
    // "http://localhost:8080/bounceproxy/");
    // joynrConfig.setProperty(MessagingPropertyKeys.DISCOVERYDIRECTORYURL,
    // "http://localhost:8080/discovery/channels/discoverydirectory_channelid/");
    // Each joynr instance has a local domain. It identifies the execution
    // device/platform, e.g. the
    // vehicle. Normally, providers on that instance are registered for the
    // local domain.
    joynrConfig.setProperty(PROPERTY_JOYNR_DOMAIN_LOCAL, localDomain);
    // NOTE: When running this application to test the android-location-provider, you must use
    // the concrete hostname (and _not_ localhost) in the bounceproxy URL, since this URL
    // is registered in the global discovery directory and must be resolvable by the Android
    // device.
    joynrConfig.setProperty(MessagingPropertyKeys.BOUNCE_PROXY_URL, "http://<concrete host>:8080/bounceproxy/");
    // 2) Or set them in the static persistence file (default:
    // joynr.properties in working dir) at
    // runtime. If not available in the working dir, it will be created
    // during the first launch
    // of the application. Copy the following lines to the custom
    // persistence file to set a
    // certain joynr server instance.
    // NOTE: This application uses a custom static persistence file
    // provider-joynr.properties.
    // Copy the following lines to the custom persistence file to set a
    // certain joynr server
    // instance.
    // joynr.messaging.bounceproxyurl=http://localhost:8080/bounceproxy/
    // joynr.messaging.discoverydirectoryurl=http://localhost:8080/discovery/channels/discoverydirectory_channelid/
    // 3) Or set them in Java System properties.
    // -Djoynr.messaging.bounceProxyUrl=http://localhost:8080/bounceproxy/
    // -Djoynr.messaging.capabilitiesDirectoryUrl=http://localhost:8080/discovery/channels/discoverydirectory_channelid/
    // NOTE:
    // Programmatically set configuration properties override properties set
    // in the static persistence file.
    // Java system properties override both
    // Application-specific configuration properties are injected to the
    // application by setting
    // them on the JoynApplicationModule.
    Properties appConfig = new Properties();
    provisionAccessControl(joynrConfig, localDomain);
    Module runtimeModule = null;
    if (args.length == 2 && args[1].equalsIgnoreCase("websocket")) {
        joynrConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_HOST, "localhost");
        joynrConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_PORT, "4242");
        joynrConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_PROTOCOL, "ws");
        joynrConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_PATH, "");
        runtimeModule = new LibjoynrWebSocketRuntimeModule();
    } else {
        runtimeModule = Modules.override(new CCInProcessRuntimeModule()).with(new AtmosphereMessagingModule());
    }
    LOG.debug("Using the following runtime module: " + runtimeModule.getClass().getSimpleName());
    JoynrApplication joynrApplication = new JoynrInjectorFactory(joynrConfig, new StaticDomainAccessControlProvisioningModule(), runtimeModule).createApplication(new JoynrApplicationModule(MyGpsProviderApplication.class, appConfig));
    joynrApplication.run();
    joynrApplication.shutdown();
}
Also used : LibjoynrWebSocketRuntimeModule(io.joynr.runtime.LibjoynrWebSocketRuntimeModule) CCInProcessRuntimeModule(io.joynr.runtime.CCInProcessRuntimeModule) Properties(java.util.Properties) Module(com.google.inject.Module) LibjoynrWebSocketRuntimeModule(io.joynr.runtime.LibjoynrWebSocketRuntimeModule) StaticDomainAccessControlProvisioningModule(io.joynr.accesscontrol.StaticDomainAccessControlProvisioningModule) AtmosphereMessagingModule(io.joynr.messaging.AtmosphereMessagingModule) CCInProcessRuntimeModule(io.joynr.runtime.CCInProcessRuntimeModule) JoynrApplicationModule(io.joynr.runtime.JoynrApplicationModule) WebsocketModule(io.joynr.messaging.websocket.WebsocketModule) StaticDomainAccessControlProvisioningModule(io.joynr.accesscontrol.StaticDomainAccessControlProvisioningModule) JoynrApplicationModule(io.joynr.runtime.JoynrApplicationModule) AtmosphereMessagingModule(io.joynr.messaging.AtmosphereMessagingModule) JoynrApplication(io.joynr.runtime.JoynrApplication) AbstractJoynrApplication(io.joynr.runtime.AbstractJoynrApplication) JoynrInjectorFactory(io.joynr.runtime.JoynrInjectorFactory)

Example 2 with AtmosphereMessagingModule

use of io.joynr.messaging.AtmosphereMessagingModule 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 3 with AtmosphereMessagingModule

use of io.joynr.messaging.AtmosphereMessagingModule in project joynr by bmwcarit.

the class BroadcastEnd2EndTest method getRuntime.

@Override
protected JoynrRuntime getRuntime(Properties joynrConfig, Module... modules) {
    Module runtimeModule = Modules.override(new CCInProcessRuntimeModule()).with(new AtmosphereMessagingModule());
    Module modulesWithRuntime = Modules.override(modules).with(runtimeModule);
    DummyJoynrApplication application = (DummyJoynrApplication) new JoynrInjectorFactory(joynrConfig, modulesWithRuntime).createApplication(DummyJoynrApplication.class);
    dummyApplications.add(application);
    return application.getRuntime();
}
Also used : DummyJoynrApplication(io.joynr.integration.util.DummyJoynrApplication) CCInProcessRuntimeModule(io.joynr.runtime.CCInProcessRuntimeModule) Module(com.google.inject.Module) AtmosphereMessagingModule(io.joynr.messaging.AtmosphereMessagingModule) CCInProcessRuntimeModule(io.joynr.runtime.CCInProcessRuntimeModule) AtmosphereMessagingModule(io.joynr.messaging.AtmosphereMessagingModule) JoynrInjectorFactory(io.joynr.runtime.JoynrInjectorFactory)

Example 4 with AtmosphereMessagingModule

use of io.joynr.messaging.AtmosphereMessagingModule 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 5 with AtmosphereMessagingModule

use of io.joynr.messaging.AtmosphereMessagingModule in project joynr by bmwcarit.

the class SubscriptionEnd2EndTest method getRuntime.

@Override
protected JoynrRuntime getRuntime(Properties joynrConfig, Module... modules) {
    Module runtimeModule = Modules.override(new CCInProcessRuntimeModule()).with(new AtmosphereMessagingModule());
    Module modulesWithRuntime = Modules.override(modules).with(runtimeModule);
    DummyJoynrApplication application = (DummyJoynrApplication) new JoynrInjectorFactory(joynrConfig, modulesWithRuntime).createApplication(DummyJoynrApplication.class);
    dummyApplications.add(application);
    return application.getRuntime();
}
Also used : DummyJoynrApplication(io.joynr.integration.util.DummyJoynrApplication) CCInProcessRuntimeModule(io.joynr.runtime.CCInProcessRuntimeModule) Module(com.google.inject.Module) AtmosphereMessagingModule(io.joynr.messaging.AtmosphereMessagingModule) CCInProcessRuntimeModule(io.joynr.runtime.CCInProcessRuntimeModule) AtmosphereMessagingModule(io.joynr.messaging.AtmosphereMessagingModule) JoynrInjectorFactory(io.joynr.runtime.JoynrInjectorFactory)

Aggregations

AtmosphereMessagingModule (io.joynr.messaging.AtmosphereMessagingModule)13 Module (com.google.inject.Module)10 CCInProcessRuntimeModule (io.joynr.runtime.CCInProcessRuntimeModule)10 WebsocketModule (io.joynr.messaging.websocket.WebsocketModule)7 MqttPahoModule (io.joynr.messaging.mqtt.paho.client.MqttPahoModule)6 JoynrApplicationModule (io.joynr.runtime.JoynrApplicationModule)6 LibjoynrWebSocketRuntimeModule (io.joynr.runtime.LibjoynrWebSocketRuntimeModule)6 JoynrInjectorFactory (io.joynr.runtime.JoynrInjectorFactory)5 Properties (java.util.Properties)5 StaticDomainAccessControlProvisioningModule (io.joynr.accesscontrol.StaticDomainAccessControlProvisioningModule)4 Injector (com.google.inject.Injector)3 DummyJoynrApplication (io.joynr.integration.util.DummyJoynrApplication)3 AbstractModule (com.google.inject.AbstractModule)2 Singleton (com.google.inject.Singleton)2 TypeLiteral (com.google.inject.TypeLiteral)2 JoynrPropertiesModule (io.joynr.common.JoynrPropertiesModule)2 MessagingTestModule (io.joynr.messaging.MessagingTestModule)2 AbstractJoynrApplication (io.joynr.runtime.AbstractJoynrApplication)2 CCWebSocketRuntimeModule (io.joynr.runtime.CCWebSocketRuntimeModule)2 JoynrApplication (io.joynr.runtime.JoynrApplication)2