Search in sources :

Example 26 with JoynrInjectorFactory

use of io.joynr.runtime.JoynrInjectorFactory in project joynr by bmwcarit.

the class HelloWorldJava method main.

public static final void main(String... args) throws InterruptedException {
    JoynrInjectorFactory joynrInjectorFactory = new JoynrInjectorFactory(new CCInProcessRuntimeModule());
    JoynrApplication helloWorldApplication = joynrInjectorFactory.createApplication(HelloWorldApplication.class);
    helloWorldApplication.run();
    // Wait for the application to finish, shutdown and exit
    executionSemaphore.acquire();
    helloWorldApplication.shutdown();
    logger.info("Done.");
}
Also used : CCInProcessRuntimeModule(io.joynr.runtime.CCInProcessRuntimeModule) JoynrInjectorFactory(io.joynr.runtime.JoynrInjectorFactory) JoynrApplication(io.joynr.runtime.JoynrApplication) AbstractJoynrApplication(io.joynr.runtime.AbstractJoynrApplication)

Example 27 with JoynrInjectorFactory

use of io.joynr.runtime.JoynrInjectorFactory in project joynr by bmwcarit.

the class GpsConsumerApplication method main.

/**
 * Main method. This method is responsible for: 1. Instantiating the consumer application. 2. Injecting the instance
 * with Guice bindings 3. Starting the application. 4. Ending the application so that the necessary clean up calls
 * are made.
 *
 * @param args arguments give when calling the main method
 */
public static void main(String[] args) {
    // mvn exec:java -Dexec.classpathScope="test" -Dexec.mainClass="io.joynr.public_examples.android_location_provider.GpsConsumerApplication" -Dexec.args="<provider-domain>"
    if (args.length != 1) {
        LOG.error("USAGE: java {} <provider-domain>", GpsConsumerApplication.class.getName());
        return;
    }
    String providerDomain = args[0];
    LOG.debug("Searching for providers on domain \"{}\"", providerDomain);
    // joynr config properties are used to set joynr configuration at compile time. They are set on the
    // JoynInjectorFactory.
    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/");
    joynrConfig.setProperty(PROPERTY_JOYNR_DOMAIN_LOCAL, "test_consumer_local_domain");
    // 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 consumer-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();
    appConfig.setProperty(APP_CONFIG_PROVIDER_DOMAIN, providerDomain);
    JoynrApplication gpsConsumerApp = new JoynrInjectorFactory(joynrConfig, Modules.override(new CCInProcessRuntimeModule()).with(new AtmosphereMessagingModule())).createApplication(new JoynrApplicationModule(GpsConsumerApplication.class, appConfig));
    gpsConsumerApp.run();
    pressQEnterToContinue();
    gpsConsumerApp.shutdown();
}
Also used : CCInProcessRuntimeModule(io.joynr.runtime.CCInProcessRuntimeModule) Properties(java.util.Properties) 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 28 with JoynrInjectorFactory

use of io.joynr.runtime.JoynrInjectorFactory in project joynr by bmwcarit.

the class MyRadioConsumerApplication method main.

/**
 * Main method. This method is responsible for: 1. Instantiating the consumer application. 2. Injecting the instance
 * with Guice bindings 3. Starting the application. 4. Ending the application so that the necessary clean up calls
 * are made.
 *
 * @param args arguments give when calling the main method
 */
public static void main(String[] args) {
    // run application from cmd line using Maven:
    // mvn exec:java -Dexec.mainClass="io.joynr.demo.MyRadioConsumerApplication" -Dexec.args="<arguments>"
    DiscoveryScope tmpDiscoveryScope = DiscoveryScope.LOCAL_AND_GLOBAL;
    String host = "localhost";
    int port = 4242;
    String providerDomain = "domain";
    String transport = null;
    CommandLine line;
    Options options = new Options();
    Options helpOptions = new Options();
    setupOptions(options, helpOptions);
    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(MyRadioConsumerApplication.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('d')) {
            providerDomain = line.getOptionValue('d');
            LOG.info("found domain = " + providerDomain);
        }
        if (line.hasOption('H')) {
            host = line.getOptionValue('H');
            LOG.info("found host = " + host);
        }
        if (line.hasOption('l')) {
            tmpDiscoveryScope = DiscoveryScope.LOCAL_ONLY;
            LOG.info("found scope local");
        }
        if (line.hasOption('p')) {
            port = Integer.parseInt(line.getOptionValue('p'));
            LOG.info("found port = " + port);
        }
        if (line.hasOption('t')) {
            transport = line.getOptionValue('t').toLowerCase();
            LOG.info("found transport = " + transport);
        }
    } catch (ParseException e) {
        LOG.error("failed to parse command line: " + e);
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(MyRadioConsumerApplication.class.getName(), options, true);
        System.exit(1);
    }
    // joynr config properties are used to set joynr configuration at compile time. They are set on the
    // JoynInjectorFactory.
    Properties joynrConfig = new Properties();
    Module runtimeModule = getRuntimeModule(transport, host, port, joynrConfig);
    LOG.debug("Using the following runtime module: " + runtimeModule.getClass().getSimpleName());
    LOG.debug("Searching for providers on domain \"{}\"", providerDomain);
    // 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/");
    joynrConfig.setProperty(PROPERTY_JOYNR_DOMAIN_LOCAL, "radioapp_consumer_local_domain");
    // 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 consumer-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();
    appConfig.setProperty(APP_CONFIG_PROVIDER_DOMAIN, providerDomain);
    final DiscoveryScope discoveryScope = tmpDiscoveryScope;
    JoynrApplication myRadioConsumerApp = new JoynrInjectorFactory(joynrConfig, runtimeModule).createApplication(new JoynrApplicationModule(MyRadioConsumerApplication.class, appConfig) {

        @Override
        protected void configure() {
            super.configure();
            bind(DiscoveryScope.class).toInstance(discoveryScope);
        }
    });
    myRadioConsumerApp.run();
    myRadioConsumerApp.shutdown();
}
Also used : Options(org.apache.commons.cli.Options) DiscoveryScope(io.joynr.arbitration.DiscoveryScope) Properties(java.util.Properties) AbstractJoynrApplication(io.joynr.runtime.AbstractJoynrApplication) JoynrApplication(io.joynr.runtime.JoynrApplication) JoynrInjectorFactory(io.joynr.runtime.JoynrInjectorFactory) HelpFormatter(org.apache.commons.cli.HelpFormatter) CommandLine(org.apache.commons.cli.CommandLine) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) Module(com.google.inject.Module) AtmosphereMessagingModule(io.joynr.messaging.AtmosphereMessagingModule) MqttPahoModule(io.joynr.messaging.mqtt.paho.client.MqttPahoModule) LibjoynrWebSocketRuntimeModule(io.joynr.runtime.LibjoynrWebSocketRuntimeModule) CCInProcessRuntimeModule(io.joynr.runtime.CCInProcessRuntimeModule) JoynrApplicationModule(io.joynr.runtime.JoynrApplicationModule) WebsocketModule(io.joynr.messaging.websocket.WebsocketModule) JoynrApplicationModule(io.joynr.runtime.JoynrApplicationModule) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 29 with JoynrInjectorFactory

use of io.joynr.runtime.JoynrInjectorFactory in project joynr by bmwcarit.

the class MyRadioProviderApplication method main.

public static void main(String[] args) throws Exception {
    // run application from cmd line using Maven:
    // mvn exec:java -Dexec.mainClass="io.joynr.demo.MyRadioProviderApplication" -Dexec.args="<arguments>"
    // where arguments provided as
    // -d provider-domain [-h websocket-host] [-p websocket-port] [-t [(websocket | websocketCC):[http]:[mqtt]] [-l]
    ProviderScope tmpProviderScope = ProviderScope.GLOBAL;
    String host = "localhost";
    int port = 4242;
    String localDomain = "domain";
    String transport = null;
    CommandLine line;
    Options options = new Options();
    Options helpOptions = new Options();
    setupOptions(options, helpOptions);
    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(MyRadioProviderApplication.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('d')) {
            localDomain = line.getOptionValue('d');
            LOG.info("found domain = " + localDomain);
        }
        if (line.hasOption('H')) {
            host = line.getOptionValue('H');
            LOG.info("found host = " + host);
        }
        if (line.hasOption('l')) {
            tmpProviderScope = ProviderScope.LOCAL;
            LOG.info("found scope local");
        }
        if (line.hasOption('p')) {
            port = Integer.parseInt(line.getOptionValue('p'));
            LOG.info("found port = " + port);
        }
        if (line.hasOption('t')) {
            transport = line.getOptionValue('t').toLowerCase();
            LOG.info("found transport = " + transport);
        }
    } catch (ParseException e) {
        LOG.error("failed to parse command line: " + e);
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(MyRadioProviderApplication.class.getName(), options, true);
        System.exit(1);
    }
    Properties joynrConfig = new Properties();
    Module runtimeModule = getRuntimeModule(transport, host, port, joynrConfig);
    final ProviderScope providerScope = tmpProviderScope;
    LOG.info("Using the following runtime module: " + runtimeModule.getClass().getSimpleName());
    LOG.info("Registering provider with the following scope: " + providerScope.name());
    LOG.info("Registering provider on domain \"{}\"", localDomain);
    // joynr config properties are used to set joynr configuration at
    // compile time. They are set on the
    // JoynrInjectorFactory.
    // 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);
    // 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();
    // Use injected static provisioning of access control entries to allow access to anyone to this interface
    provisionAccessControl(joynrConfig, localDomain);
    JoynrApplication joynrApplication = new JoynrInjectorFactory(joynrConfig, runtimeModule, new StaticDomainAccessControlProvisioningModule()).createApplication(new JoynrApplicationModule(MyRadioProviderApplication.class, appConfig) {

        @Override
        protected void configure() {
            super.configure();
            bind(ProviderScope.class).toInstance(providerScope);
        }
    });
    joynrApplication.run();
    joynrApplication.shutdown();
}
Also used : Options(org.apache.commons.cli.Options) Properties(java.util.Properties) StaticDomainAccessControlProvisioningModule(io.joynr.accesscontrol.StaticDomainAccessControlProvisioningModule) JoynrApplication(io.joynr.runtime.JoynrApplication) AbstractJoynrApplication(io.joynr.runtime.AbstractJoynrApplication) JoynrInjectorFactory(io.joynr.runtime.JoynrInjectorFactory) HelpFormatter(org.apache.commons.cli.HelpFormatter) CommandLine(org.apache.commons.cli.CommandLine) ProviderScope(joynr.types.ProviderScope) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) 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) JoynrApplicationModule(io.joynr.runtime.JoynrApplicationModule) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 30 with JoynrInjectorFactory

use of io.joynr.runtime.JoynrInjectorFactory in project joynr by bmwcarit.

the class InitRuntimeTask method doInBackground.

@Override
protected JoynrRuntime doInBackground(Object... params) {
    try {
        Log.d("JAS", "starting joynr runtime");
        publishProgress("Starting joynr runtime...\n");
        // create/make persistence file absolute
        File appWorkingDir = applicationContext.getFilesDir();
        String persistenceFileName = appWorkingDir.getPath() + File.separator + joynrConfig.getProperty(MessagingPropertyKeys.PERSISTENCE_FILE, MessagingPropertyKeys.DEFAULT_PERSISTENCE_FILE);
        joynrConfig.setProperty(MessagingPropertyKeys.PERSISTENCE_FILE, persistenceFileName);
        // create/make participant ID persistence file absolute
        String participantIdPersistenceFileName = appWorkingDir.getPath() + File.separator + joynrConfig.getProperty(ConfigurableMessagingSettings.PROPERTY_PARTICIPANTIDS_PERSISISTENCE_FILE, ConfigurableMessagingSettings.DEFAULT_PARTICIPANTIDS_PERSISTENCE_FILE);
        joynrConfig.setProperty(ConfigurableMessagingSettings.PROPERTY_PARTICIPANTIDS_PERSISISTENCE_FILE, participantIdPersistenceFileName);
        publishProgress("Properties loaded\n");
        // Create an injector with all the required custom modules.
        // CCInProcessRuntimeModule is used by default but can be overwritten by custom modules
        Module combinedModules = Modules.override(new LibjoynrWebSocketRuntimeModule()).with(modules);
        Injector injectorA = new JoynrInjectorFactory(joynrConfig, combinedModules).createChildInjector();
        JoynrRuntime runtime = injectorA.getInstance(JoynrRuntime.class);
        if (runtime != null) {
            Log.d("JAS", "joynr runtime started");
        } else {
            Log.e("JAS", "joynr runtime not started");
        }
        publishProgress("joynr runtime started.\n");
        return runtime;
    } catch (Exception e) {
        Log.e("JAS", "joynr runtime not started", e);
        publishProgress(e.getMessage());
    }
    return null;
}
Also used : LibjoynrWebSocketRuntimeModule(io.joynr.runtime.LibjoynrWebSocketRuntimeModule) JoynrRuntime(io.joynr.runtime.JoynrRuntime) Injector(com.google.inject.Injector) Module(com.google.inject.Module) LibjoynrWebSocketRuntimeModule(io.joynr.runtime.LibjoynrWebSocketRuntimeModule) File(java.io.File) JoynrInjectorFactory(io.joynr.runtime.JoynrInjectorFactory)

Aggregations

JoynrInjectorFactory (io.joynr.runtime.JoynrInjectorFactory)31 Module (com.google.inject.Module)22 CCInProcessRuntimeModule (io.joynr.runtime.CCInProcessRuntimeModule)21 Properties (java.util.Properties)20 MqttPahoModule (io.joynr.messaging.mqtt.paho.client.MqttPahoModule)11 AbstractJoynrApplication (io.joynr.runtime.AbstractJoynrApplication)11 JoynrApplication (io.joynr.runtime.JoynrApplication)11 JoynrApplicationModule (io.joynr.runtime.JoynrApplicationModule)11 DummyJoynrApplication (io.joynr.integration.util.DummyJoynrApplication)10 AtmosphereMessagingModule (io.joynr.messaging.AtmosphereMessagingModule)10 LibjoynrWebSocketRuntimeModule (io.joynr.runtime.LibjoynrWebSocketRuntimeModule)10 WebsocketModule (io.joynr.messaging.websocket.WebsocketModule)9 AbstractModule (com.google.inject.AbstractModule)7 StaticDomainAccessControlProvisioningModule (io.joynr.accesscontrol.StaticDomainAccessControlProvisioningModule)7 CCWebSocketRuntimeModule (io.joynr.runtime.CCWebSocketRuntimeModule)7 Injector (com.google.inject.Injector)5 TestGlobalAddressModule (io.joynr.messaging.routing.TestGlobalAddressModule)5 JoynrRuntime (io.joynr.runtime.JoynrRuntime)5 MqttModule (io.joynr.messaging.mqtt.MqttModule)3 ClusterControllerRuntime (io.joynr.runtime.ClusterControllerRuntime)3