Search in sources :

Example 1 with JoynrApplicationModule

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

the class JoynrApplicationLauncher method init.

public void init(Properties properties, Set<Class<? extends JoynrApplication>> joynrApplicationsClasses, AbstractJoynrInjectorFactory injectorFactory, Module... modules) {
    ThreadFactory threadFactory = new ThreadFactory() {

        @Override
        public Thread newThread(Runnable r) {
            return new Thread(r, r.getClass().getSimpleName());
        }
    };
    executionQueue = Executors.newCachedThreadPool(threadFactory);
    try {
        // updateInjectorModule must be called before getInjector can be called.
        // for this reason the injector has to be created here, and not by the creator of the injectorFactory
        injectorFactory.updateInjectorModule(properties, modules);
        joynrInjector = injectorFactory.getInjector();
        for (Class<? extends JoynrApplication> appClass : joynrApplicationsClasses) {
            if (Modifier.isAbstract(appClass.getModifiers())) {
                continue;
            }
            AcceptsMessageReceiver acceptsMessageReceiverAnnotation = appClass.getAnnotation(AcceptsMessageReceiver.class);
            // TODO why not reuse the previously requested value for
            // AcceptsMessageReceiver?
            MessageReceiverType messageReceiverType = acceptsMessageReceiverAnnotation == null ? MessageReceiverType.ANY : appClass.getAnnotation(AcceptsMessageReceiver.class).value();
            if (messageReceiverType.equals(MessageReceiverType.SERVLET)) {
                continue;
            }
            logger.info("Running app: " + appClass.getName());
            final JoynrApplication app = injectorFactory.createApplication(new JoynrApplicationModule(appClass));
            apps.add(app);
            executionQueue.submit(app);
        }
    } catch (RuntimeException e) {
        logger.error("ERROR", e);
        throw e;
    }
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) AcceptsMessageReceiver(io.joynr.runtime.AcceptsMessageReceiver) JoynrApplicationModule(io.joynr.runtime.JoynrApplicationModule) MessageReceiverType(io.joynr.runtime.MessageReceiverType) JoynrApplication(io.joynr.runtime.JoynrApplication)

Example 2 with JoynrApplicationModule

use of io.joynr.runtime.JoynrApplicationModule 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 3 with JoynrApplicationModule

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

the class CapabilitiesDirectoryLauncher method start.

public static void start(Properties joynrConfig) {
    // LongPollingMessagingModule is only added in main(), since the servletMessagingModule will be used otherwise
    JoynrInjectorFactory injectorFactory = new JoynrInjectorFactory(joynrConfig, Modules.override(new JpaPersistModule("CapabilitiesDirectory"), new CCInProcessRuntimeModule()).with(new TestGlobalAddressModule(), new CapabilitiesDirectoryModule()));
    capabilitiesDirectoryLauncher = injectorFactory.createApplication(new JoynrApplicationModule("capabilitiesDirectoryLauncher", CapabilitiesDirectoryLauncher.class));
    capabilitiesDirectoryLauncher.run();
    capabilitiesDirectory = injectorFactory.getInjector().getInstance(CapabilitiesDirectoryImpl.class);
}
Also used : TestGlobalAddressModule(io.joynr.messaging.routing.TestGlobalAddressModule) CCInProcessRuntimeModule(io.joynr.runtime.CCInProcessRuntimeModule) JoynrApplicationModule(io.joynr.runtime.JoynrApplicationModule) JpaPersistModule(com.google.inject.persist.jpa.JpaPersistModule) JoynrInjectorFactory(io.joynr.runtime.JoynrInjectorFactory)

Example 4 with JoynrApplicationModule

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

the class GlobalDomainAccessControllerLauncher method start.

public static GlobalDomainAccessControllerLauncher start(Properties joynrConfig) {
    JoynrInjectorFactory injectorFactory = new JoynrInjectorFactory(joynrConfig, new GlobalDomainAccessControllerModule());
    JoynrApplication domainAccessControllerLauncherApp = injectorFactory.createApplication(new JoynrApplicationModule(APP_ID, GlobalDomainAccessControllerLauncher.class));
    domainAccessControllerLauncherApp.run();
    return (GlobalDomainAccessControllerLauncher) domainAccessControllerLauncherApp;
}
Also used : JoynrApplicationModule(io.joynr.runtime.JoynrApplicationModule) JoynrInjectorFactory(io.joynr.runtime.JoynrInjectorFactory) JoynrApplication(io.joynr.runtime.JoynrApplication) AbstractJoynrApplication(io.joynr.runtime.AbstractJoynrApplication)

Example 5 with JoynrApplicationModule

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

the class ConsumerApplication method createJoynrApplication.

private static JoynrApplication createJoynrApplication() throws Exception {
    Properties joynrConfig = createJoynrConfig();
    Module runtimeModule = getRuntimeModule(joynrConfig);
    Properties appConfig = new Properties();
    JoynrInjectorFactory injectorFactory = new JoynrInjectorFactory(joynrConfig, runtimeModule, new StaticDomainAccessControlProvisioningModule());
    JoynrApplication joynrApplication = injectorFactory.createApplication(new JoynrApplicationModule(ConsumerApplication.class, appConfig));
    return joynrApplication;
}
Also used : Properties(java.util.Properties) Module(com.google.inject.Module) 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) StaticDomainAccessControlProvisioningModule(io.joynr.accesscontrol.StaticDomainAccessControlProvisioningModule) JoynrApplicationModule(io.joynr.runtime.JoynrApplicationModule) JoynrInjectorFactory(io.joynr.runtime.JoynrInjectorFactory) JoynrApplication(io.joynr.runtime.JoynrApplication) AbstractJoynrApplication(io.joynr.runtime.AbstractJoynrApplication)

Aggregations

JoynrApplicationModule (io.joynr.runtime.JoynrApplicationModule)12 JoynrApplication (io.joynr.runtime.JoynrApplication)11 JoynrInjectorFactory (io.joynr.runtime.JoynrInjectorFactory)11 AbstractJoynrApplication (io.joynr.runtime.AbstractJoynrApplication)10 Properties (java.util.Properties)9 Module (com.google.inject.Module)8 CCInProcessRuntimeModule (io.joynr.runtime.CCInProcessRuntimeModule)8 WebsocketModule (io.joynr.messaging.websocket.WebsocketModule)7 LibjoynrWebSocketRuntimeModule (io.joynr.runtime.LibjoynrWebSocketRuntimeModule)7 StaticDomainAccessControlProvisioningModule (io.joynr.accesscontrol.StaticDomainAccessControlProvisioningModule)6 AtmosphereMessagingModule (io.joynr.messaging.AtmosphereMessagingModule)6 MqttPahoModule (io.joynr.messaging.mqtt.paho.client.MqttPahoModule)5 CCWebSocketRuntimeModule (io.joynr.runtime.CCWebSocketRuntimeModule)2 CommandLine (org.apache.commons.cli.CommandLine)2 CommandLineParser (org.apache.commons.cli.CommandLineParser)2 DefaultParser (org.apache.commons.cli.DefaultParser)2 HelpFormatter (org.apache.commons.cli.HelpFormatter)2 Options (org.apache.commons.cli.Options)2 ParseException (org.apache.commons.cli.ParseException)2 JpaPersistModule (com.google.inject.persist.jpa.JpaPersistModule)1