use of com.robo4j.configuration.ConfigurationBuilder 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();
}
use of com.robo4j.configuration.ConfigurationBuilder 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();
}
use of com.robo4j.configuration.ConfigurationBuilder 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());
}
use of com.robo4j.configuration.ConfigurationBuilder 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();
}
use of com.robo4j.configuration.ConfigurationBuilder 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();
}
Aggregations