Search in sources :

Example 1 with DiscoveryScope

use of io.joynr.arbitration.DiscoveryScope in project joynr by bmwcarit.

the class ConsumerInvocationParameters method parseCommandLineArgs.

private CommandLine parseCommandLineArgs(String[] args) throws ParseException {
    Options options = new Options();
    options.addOption(Option.builder("s").longOpt(CMDLINE_OPTIONNAME_SYNCMODE).required(true).hasArg().argName("mode").type(COMMUNICATIONMODE.class).desc("Determines how the test methods are called. Can be either SYNC or ASYNC.").build());
    options.addOption(Option.builder("t").longOpt(CMDLINE_OPTIONNAME_TESTCASE).required(true).hasArg().argName("testname").type(TESTCASE.class).desc("Determines which test is performed. Can be either SEND_STRING, SEND_STRUCT or SEND_BYTEARRAY.").build());
    options.addOption(Option.builder("d").longOpt(CMDLINE_OPTIONNAME_DOMAINNAME).required(true).hasArg().argName("domainName").type(String.class).desc("Provider domain").build());
    options.addOption(Option.builder("w").longOpt(CMDLINE_OPTIONNAME_WARMUPS).required(true).hasArg().argName("numWarmups").type(Number.class).desc("Number of warmup runs").build());
    options.addOption(Option.builder("r").longOpt(CMDLINE_OPTIONNAME_NUMRUNS).required(true).hasArg().argName("numRuns").type(Number.class).desc("Number of test runs").build());
    options.addOption(Option.builder("sl").longOpt(CMDLINE_OPTIONNAME_STRINGDATALENGTH).required(false).hasArg().argName("numChars").type(Number.class).desc("Length of strings which are transmitted during the test").build());
    options.addOption(Option.builder("bs").longOpt(CMDLINE_OPTIONNAME_BYTEARRAYSIZE).required(false).hasArg().argName("numBytes").type(Number.class).desc("Size of byte arrays which are transmitted during the test").build());
    options.addOption(Option.builder("ds").longOpt(CMDLINE_OPTIONNAME_DISCOVERYSCOPE).required(false).hasArg().argName("discoveryscope").type(DiscoveryScope.class).desc("Determines the discovery scope. Can be GLOBAL_ONLY, LOCAL_AND_GLOBAL, " + "LOCAL_ONLY or LOCAL_THEN_GLOBAL. Default is LOCAL_ONLY.").build());
    options.addOption(Option.builder("runtime").longOpt(CMDLINE_OPTIONNAME_RUNTIMECFG).required(false).hasArg().argName("runtime").type(RuntimeConfig.class).desc("Runtime module configuration. " + "Default is " + runtimeConfig.toString()).build());
    options.addOption(Option.builder("backend").longOpt(CMDLINE_OPTIONNAME_BACKENDCFG).required(false).hasArg().argName("backend").type(BackendConfig.class).desc("Backend configuration. At the moment only MQTT is supported. Default is " + backendConfig.toString()).build());
    options.addOption(Option.builder("mbu").longOpt(CMDLINE_OPTIONNAME_MQTTBROKERURI).required(false).hasArg().argName("uri").type(String.class).desc("MQTT broker URI. Default is " + mqttBrokerUri).build());
    options.addOption(Option.builder("ch").longOpt(CMDLINE_OPTIONNAME_CC_HOST).required(false).hasArg().argName("cluster-controller host").type(String.class).desc("Host of the cluster-controller for websocket connections. Default is " + ccHost).build());
    options.addOption(Option.builder("cp").longOpt(CMDLINE_OPTIONNAME_CC_PORT).required(false).hasArg().argName("cluster-controller port").type(String.class).desc("Port of the cluster-controller for websocket connections. Default is " + ccPort).build());
    CommandLineParser parser = new DefaultParser();
    try {
        return parser.parse(options, args);
    } catch (ParseException exception) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("PerformanceTestConsumerApplication", "", options, "", true);
        throw exception;
    }
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Options(org.apache.commons.cli.Options) DiscoveryScope(io.joynr.arbitration.DiscoveryScope) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 2 with DiscoveryScope

use of io.joynr.arbitration.DiscoveryScope in project joynr by bmwcarit.

the class DummyCapabilitiesDirectory method lookup.

@Override
public Promise<Lookup1Deferred> lookup(String[] domains, String interfaceName, joynr.types.DiscoveryQos discoveryQos) {
    final Lookup1Deferred deferred = new Lookup1Deferred();
    CapabilitiesCallback callback = new CapabilitiesCallback() {

        @Override
        public void processCapabilitiesReceived(@CheckForNull Collection<DiscoveryEntryWithMetaInfo> capabilities) {
            if (capabilities != null) {
                deferred.resolve(capabilities.toArray(new DiscoveryEntryWithMetaInfo[0]));
            } else {
                deferred.reject(new ProviderRuntimeException("Received capabilities list was null"));
            }
        }

        @Override
        public void onError(Throwable e) {
            deferred.reject(new ProviderRuntimeException(e.toString()));
        }
    };
    DiscoveryScope discoveryScope = DiscoveryScope.valueOf(discoveryQos.getDiscoveryScope().name());
    lookup(domains, interfaceName, new DiscoveryQos(30000, ArbitrationStrategy.NotSet, discoveryQos.getCacheMaxAge(), discoveryScope), callback);
    return new Promise<Lookup1Deferred>(deferred);
}
Also used : Promise(io.joynr.provider.Promise) DiscoveryScope(io.joynr.arbitration.DiscoveryScope) CheckForNull(javax.annotation.CheckForNull) Collection(java.util.Collection) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) DiscoveryQos(io.joynr.arbitration.DiscoveryQos)

Example 3 with DiscoveryScope

use of io.joynr.arbitration.DiscoveryScope 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 4 with DiscoveryScope

use of io.joynr.arbitration.DiscoveryScope in project joynr by bmwcarit.

the class LocalCapabilitiesDirectoryImpl method lookup.

@Override
public Promise<Lookup1Deferred> lookup(String[] domains, String interfaceName, joynr.types.DiscoveryQos discoveryQos) {
    final Lookup1Deferred deferred = new Lookup1Deferred();
    CapabilitiesCallback callback = new CapabilitiesCallback() {

        @Override
        public void processCapabilitiesReceived(@CheckForNull Collection<DiscoveryEntryWithMetaInfo> capabilities) {
            if (capabilities == null) {
                deferred.reject(new ProviderRuntimeException("Received capablities collection was null"));
            } else {
                deferred.resolve(capabilities.toArray(new DiscoveryEntryWithMetaInfo[capabilities.size()]));
            }
        }

        @Override
        public void onError(Throwable e) {
            deferred.reject(new ProviderRuntimeException(e.toString()));
        }
    };
    DiscoveryScope discoveryScope = DiscoveryScope.valueOf(discoveryQos.getDiscoveryScope().name());
    lookup(domains, interfaceName, new DiscoveryQos(discoveryQos.getDiscoveryTimeout(), defaultDiscoveryRetryInterval, ArbitrationStrategy.NotSet, discoveryQos.getCacheMaxAge(), discoveryScope), callback);
    return new Promise<>(deferred);
}
Also used : Promise(io.joynr.provider.Promise) DiscoveryScope(io.joynr.arbitration.DiscoveryScope) CheckForNull(javax.annotation.CheckForNull) Collection(java.util.Collection) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) DiscoveryQos(io.joynr.arbitration.DiscoveryQos)

Example 5 with DiscoveryScope

use of io.joynr.arbitration.DiscoveryScope in project joynr by bmwcarit.

the class LocalCapabilitiesDirectoryImpl method lookup.

@Override
public void lookup(final String[] domains, final String interfaceName, final DiscoveryQos discoveryQos, final CapabilitiesCallback capabilitiesCallback) {
    DiscoveryScope discoveryScope = discoveryQos.getDiscoveryScope();
    Set<DiscoveryEntry> localDiscoveryEntries = getLocalEntriesIfRequired(discoveryScope, domains, interfaceName);
    Set<DiscoveryEntryWithMetaInfo> globalDiscoveryEntries = getGloballyCachedEntriesIfRequired(discoveryScope, domains, interfaceName, discoveryQos.getCacheMaxAgeMs());
    switch(discoveryScope) {
        case LOCAL_ONLY:
            capabilitiesCallback.processCapabilitiesReceived(CapabilityUtils.convertToDiscoveryEntryWithMetaInfoSet(true, localDiscoveryEntries));
            break;
        case LOCAL_THEN_GLOBAL:
            handleLocalThenGlobal(domains, interfaceName, discoveryQos, capabilitiesCallback, CapabilityUtils.convertToDiscoveryEntryWithMetaInfoSet(true, localDiscoveryEntries), globalDiscoveryEntries);
            break;
        case GLOBAL_ONLY:
            handleGlobalOnly(domains, interfaceName, discoveryQos, capabilitiesCallback, globalDiscoveryEntries);
            break;
        case LOCAL_AND_GLOBAL:
            handleLocalAndGlobal(domains, interfaceName, discoveryQos, capabilitiesCallback, CapabilityUtils.convertToDiscoveryEntryWithMetaInfoSet(true, localDiscoveryEntries), globalDiscoveryEntries);
            break;
        default:
            throw new IllegalStateException("Unknown or illegal DiscoveryScope value: " + discoveryScope);
    }
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) DiscoveryScope(io.joynr.arbitration.DiscoveryScope) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo)

Aggregations

DiscoveryScope (io.joynr.arbitration.DiscoveryScope)6 CheckForNull (javax.annotation.CheckForNull)3 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)3 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)2 Promise (io.joynr.provider.Promise)2 Collection (java.util.Collection)2 ProviderRuntimeException (joynr.exceptions.ProviderRuntimeException)2 DiscoveryEntry (joynr.types.DiscoveryEntry)2 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)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 Module (com.google.inject.Module)1 AtmosphereMessagingModule (io.joynr.messaging.AtmosphereMessagingModule)1 MqttPahoModule (io.joynr.messaging.mqtt.paho.client.MqttPahoModule)1 WebsocketModule (io.joynr.messaging.websocket.WebsocketModule)1 AbstractJoynrApplication (io.joynr.runtime.AbstractJoynrApplication)1 CCInProcessRuntimeModule (io.joynr.runtime.CCInProcessRuntimeModule)1