Search in sources :

Example 11 with Configuration

use of com.robo4j.configuration.Configuration in project robo4j by Robo4J.

the class RoboHttpUnitGetTestApp method twoAttributesSystem.

private RoboContext twoAttributesSystem() throws Exception {
    Configuration systemConfiguration = new ConfigurationBuilder().addInteger("poolSizeScheduler", 4).addInteger("poolSizeWorker", 2).addInteger("poolSizeBlocking", 3).build();
    RoboBuilder builder = new RoboBuilder(systemConfiguration);
    final HttpPathConfigJsonBuilder pathBuilder = HttpPathConfigJsonBuilder.Builder().addPath("controller", HttpMethod.GET);
    Configuration config = new ConfigurationBuilder().addInteger(PROPERTY_SOCKET_PORT, SERVER_PORT).addString("packages", PACKAGE_CODECS).addString(PROPERTY_UNIT_PATHS_CONFIG, pathBuilder.build()).build();
    builder.add(HttpServerUnit.class, config, "http_server");
    config = new ConfigurationBuilder().addInteger(StringConsumer.PROP_TOTAL_NUMBER_MESSAGES, 1).build();
    builder.add(StringConsumer.class, config, "request_consumer");
    config = new ConfigurationBuilder().addString("target", "request_consumer").build();
    builder.add(HttpTwoAttributesGetController.class, config, "controller");
    return builder.build();
}
Also used : ConfigurationBuilder(com.robo4j.configuration.ConfigurationBuilder) Configuration(com.robo4j.configuration.Configuration) HttpPathConfigJsonBuilder(com.robo4j.socket.http.util.HttpPathConfigJsonBuilder) RoboBuilder(com.robo4j.RoboBuilder)

Example 12 with Configuration

use of com.robo4j.configuration.Configuration in project robo4j by Robo4J.

the class RoboHttpPingPongTest method configurePingSystem.

private RoboContext configurePingSystem() throws Exception {
    /* system which is testing main system */
    RoboBuilder builder = new RoboBuilder();
    Configuration config = new ConfigurationBuilder().addString(PROPERTY_HOST, HOST_SYSTEM).addInteger(PROPERTY_SOCKET_PORT, PORT).build();
    builder.add(HttpClientUnit.class, config, ID_HTTP_CLIENT);
    config = new ConfigurationBuilder().addString(PROPERTY_TARGET, ID_HTTP_CLIENT).addString(PROPERTY_UNIT_PATHS_CONFIG, "[{\"roboUnit\":\"" + CONTROLLER_PING_PONG + "\",\"method\":\"POST\"}]").addString("message", RoboHttpDynamicTests.JSON_STRING).build();
    builder.add(SocketMessageDecoratedProducerUnit.class, config, DECORATED_PRODUCER);
    return builder.build();
}
Also used : ConfigurationBuilder(com.robo4j.configuration.ConfigurationBuilder) Configuration(com.robo4j.configuration.Configuration) RoboBuilder(com.robo4j.RoboBuilder)

Example 13 with Configuration

use of com.robo4j.configuration.Configuration in project robo4j by Robo4J.

the class HttpServerUnitTests method httpServerUnitNoPathTest.

@Test
void httpServerUnitNoPathTest() throws Exception {
    RoboBuilder builder = new RoboBuilder();
    Configuration config = new ConfigurationBuilder().addInteger(PROPERTY_SOCKET_PORT, PORT).addString(PROPERTY_CODEC_PACKAGES, PACKAGE_CODECS).build();
    builder.add(HttpServerUnit.class, config, ID_HTTP_SERVER);
    RoboContext system = builder.build();
    system.start();
    System.out.println("system: State after start:");
    System.out.println(SystemUtil.printStateReport(system));
    RoboReference<HttpServerUnit> systemReference = system.getReference(ID_HTTP_SERVER);
    system.shutdown();
    System.out.println("system: State after shutdown:");
    System.out.println(SystemUtil.printStateReport(system));
    assertEquals(LifecycleState.SHUTDOWN, systemReference.getState());
}
Also used : ConfigurationBuilder(com.robo4j.configuration.ConfigurationBuilder) Configuration(com.robo4j.configuration.Configuration) RoboBuilder(com.robo4j.RoboBuilder) RoboContext(com.robo4j.RoboContext) Test(org.junit.jupiter.api.Test)

Example 14 with Configuration

use of com.robo4j.configuration.Configuration in project robo4j by Robo4J.

the class TankExampleTests method legoTankExampleTest.

@Test
@Disabled("rethink and remove dependency")
void legoTankExampleTest() throws Exception {
    RoboBuilder builder = new RoboBuilder();
    Configuration config = new ConfigurationBuilder().addString("target", ID_UNIT_CONTROLLER).addInteger("port", PORT).addString("packages", "com.robo4j.units.lego.example.codec").addString(RoboHttpUtils.PROPERTY_UNIT_PATHS_CONFIG, HttpPathConfigJsonBuilder.Builder().addPath(ID_UNIT_CONTROLLER, HttpMethod.GET).build()).build();
    builder.add(HttpServerUnit.class, config, ID_HTTP);
    builder.add(TankExampleController.class, new ConfigurationBuilder().addString("target", ID_PLATFORM).build(), ID_UNIT_CONTROLLER);
    /* platform is listening to the bus */
    config = new ConfigurationBuilder().addString("leftMotorPort", "B").addCharacter("leftMotorType", 'N').addString("rightMotorPort", "C").addCharacter("rightMotorType", 'N').build();
    builder.add(SimpleTankTestUnit.class, config, ID_PLATFORM);
    /* lcd is listening to the bus */
    builder.add(LcdTestUnit.class, ID_LCD);
    RoboContext context = builder.build();
    context.start();
    context.getReference(ID_LCD).sendMessage("Press <Enter> to quit!");
    System.in.read();
    context.shutdown();
}
Also used : ConfigurationBuilder(com.robo4j.configuration.ConfigurationBuilder) Configuration(com.robo4j.configuration.Configuration) RoboBuilder(com.robo4j.RoboBuilder) RoboContext(com.robo4j.RoboContext) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 15 with Configuration

use of com.robo4j.configuration.Configuration in project robo4j by Robo4J.

the class LaserScannerExample method main.

public static void main(String[] args) throws RoboBuilderException, IOException {
    float startAngle = -45.0f;
    float range = 90.0f;
    float step = 1.0f;
    InputStream settings;
    switch(args.length) {
        case 1:
            settings = Files.newInputStream(Paths.get(args[0]));
            break;
        case 3:
            startAngle = Float.parseFloat(args[0]);
            range = Float.parseFloat(args[1]);
            step = Float.parseFloat(args[2]);
        default:
            settings = ServoUnitExample.class.getClassLoader().getResourceAsStream("lidarexample.xml");
    }
    Configuration controllerConfiguration = new ConfigurationBuilder().addFloat(LaserScannerTestController.CONFIG_KEY_START_ANGLE, startAngle).addFloat(LaserScannerTestController.CONFIG_KEY_RANGE, range).addFloat(LaserScannerTestController.CONFIG_KEY_STEP, step).build();
    System.out.println(String.format("Running scans with startAngle=%2.1f, range=%2.1f and step=%2.1f", startAngle, range, step));
    RoboBuilder builder = new RoboBuilder();
    if (settings == null) {
        System.out.println("Could not find the settings for the LaserScannerExample!");
        System.exit(2);
    }
    builder.add(settings).add(LaserScannerTestController.class, controllerConfiguration, "controller").add(LaserScanProcessor.class, "processor");
    RoboContext ctx = builder.build();
    RoboReference<Float> tiltServo = ctx.getReference("laserscanner.tilt");
    tiltServo.sendMessage(Float.valueOf(0));
    RoboReference<String> reference = ctx.getReference("controller");
    ctx.start();
    System.out.println("Starting scanning for ever\nPress <Enter> to quit");
    reference.sendMessage("scan");
    System.in.read();
}
Also used : ConfigurationBuilder(com.robo4j.configuration.ConfigurationBuilder) Configuration(com.robo4j.configuration.Configuration) InputStream(java.io.InputStream) RoboBuilder(com.robo4j.RoboBuilder) RoboContext(com.robo4j.RoboContext)

Aggregations

Configuration (com.robo4j.configuration.Configuration)23 ConfigurationBuilder (com.robo4j.configuration.ConfigurationBuilder)22 RoboBuilder (com.robo4j.RoboBuilder)18 RoboContext (com.robo4j.RoboContext)10 Test (org.junit.jupiter.api.Test)8 HttpPathConfigJsonBuilder (com.robo4j.socket.http.util.HttpPathConfigJsonBuilder)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 StringConsumer (com.robo4j.StringConsumer)1 LegoPlatformMessage (com.robo4j.units.lego.platform.LegoPlatformMessage)1 InputStream (java.io.InputStream)1 Disabled (org.junit.jupiter.api.Disabled)1