Search in sources :

Example 26 with RoboContext

use of com.robo4j.RoboContext in project robo4j by Robo4J.

the class RoboHttpDynamicTests method getClientRoboSystem.

private RoboContext getClientRoboSystem() throws Exception {
    /* system which is testing main system */
    RoboBuilder builder = getHttpClientRobotBuilder(HOST_SYSTEM, PORT);
    Configuration config = new ConfigurationBuilder().addString(PROPERTY_TARGET, ID_CLIENT_UNIT).addString(PROPERTY_UNIT_PATHS_CONFIG, "[{\"roboUnit\":\"" + ID_TARGET_UNIT + "\",\"method\":\"POST\"}]").addString("message", JSON_STRING).build();
    builder.add(SocketMessageDecoratedProducerUnit.class, config, DECORATED_PRODUCER);
    RoboContext result = builder.build();
    result.start();
    return result;
}
Also used : ConfigurationBuilder(com.robo4j.configuration.ConfigurationBuilder) Configuration(com.robo4j.configuration.Configuration) RoboBuilder(com.robo4j.RoboBuilder) RoboContext(com.robo4j.RoboContext)

Example 27 with RoboContext

use of com.robo4j.RoboContext in project robo4j by Robo4J.

the class RoboHttpUnitGetTestApp method twoKnownAttributesTest.

/**
 * Run the system with known attributes
 *
 * @throws Exception
 *             exception
 */
public void twoKnownAttributesTest() throws Exception {
    RoboContext systemGetProvider = twoAttributesSystem();
    RoboContext systemGetAccessor = attributeRequestSystem();
    systemGetProvider.start();
    System.out.println("systemGetProvider: State after start:");
    System.out.println(SystemUtil.printStateReport(systemGetProvider));
    systemGetAccessor.start();
    System.out.println("systemGetAccessor: State after start:");
    System.out.println(SystemUtil.printStateReport(systemGetAccessor));
    RoboReference<HttpDecoratedRequest> httpClient = systemGetAccessor.getReference(UNIT_ID_HTTP_CLIENT);
    HttpRequestDenominator denominator = new HttpRequestDenominator(HttpMethod.GET, "/units/controller?attributes=number", HttpVersion.HTTP_1_1);
    HttpDecoratedRequest request = new HttpDecoratedRequest(denominator);
    request.addCallback(StringConsumer.NAME);
    httpClient.sendMessage(request);
    System.out.println("Press <Enter>...");
    System.in.read();
    systemGetProvider.shutdown();
}
Also used : HttpDecoratedRequest(com.robo4j.socket.http.message.HttpDecoratedRequest) RoboContext(com.robo4j.RoboContext) HttpRequestDenominator(com.robo4j.socket.http.message.HttpRequestDenominator)

Example 28 with RoboContext

use of com.robo4j.RoboContext in project robo4j by Robo4J.

the class RoboHttpUnitGetTestApp method oneKnownAttributeTest.

/**
 * Run the system with known attributes
 *
 * @throws Exception
 *             exception
 */
public void oneKnownAttributeTest() throws Exception {
    final HttpPathConfigJsonBuilder pathBuilder = HttpPathConfigJsonBuilder.Builder().addPath("controller", HttpMethod.GET);
    // @formatter:off
    Configuration systemConfiguration = new ConfigurationBuilder().addInteger("poolSizeScheduler", 4).addInteger("poolSizeWorker", 2).addInteger("poolSizeBlocking", 3).build();
    RoboBuilder builder = new RoboBuilder("roboSystem1", systemConfiguration);
    // @formatter:on
    // @formatter:off
    Configuration config = new ConfigurationBuilder().addInteger(PROPERTY_SOCKET_PORT, SERVER_PORT).addString("packages", PACKAGE_CODECS).addString(PROPERTY_UNIT_PATHS_CONFIG, pathBuilder.build()).build();
    // @formatter:on
    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(HttpOneAttributeGetController.class, config, "controller");
    RoboContext system = builder.build();
    system.start();
    System.out.println("systemPong: State after start:");
    System.out.println(SystemUtil.printStateReport(system));
    System.out.println("Press <Enter>...");
    System.in.read();
    system.shutdown();
}
Also used : ConfigurationBuilder(com.robo4j.configuration.ConfigurationBuilder) Configuration(com.robo4j.configuration.Configuration) HttpPathConfigJsonBuilder(com.robo4j.socket.http.util.HttpPathConfigJsonBuilder) RoboBuilder(com.robo4j.RoboBuilder) RoboContext(com.robo4j.RoboContext)

Example 29 with RoboContext

use of com.robo4j.RoboContext in project robo4j by Robo4J.

the class DatagramPathUtils method updateDatagramServerContextPaths.

public static void updateDatagramServerContextPaths(final RoboContext context, final ServerContext serverContext, final Collection<HttpPathMethodDTO> paths) {
    final Map<PathHttpMethod, ServerPathConfig> resultPaths = paths.stream().map(e -> {
        RoboReference<Object> reference = context.getReference(e.getRoboUnit());
        return new ServerPathConfig(toPath(SystemPath.UNITS.getPath(), e.getRoboUnit()), reference, e.getMethod(), e.getCallbacks());
    }).collect(Collectors.toMap(e -> new PathHttpMethod(e.getPath(), null), e -> e));
    serverContext.addPaths(resultPaths);
}
Also used : ClientContext(com.robo4j.socket.http.units.ClientContext) Collection(java.util.Collection) ServerPathConfig(com.robo4j.socket.http.units.ServerPathConfig) HttpPathUtils.toPath(com.robo4j.socket.http.util.HttpPathUtils.toPath) PathHttpMethod(com.robo4j.socket.http.units.PathHttpMethod) Collectors(java.util.stream.Collectors) ServerContext(com.robo4j.socket.http.units.ServerContext) HttpPathMethodDTO(com.robo4j.socket.http.dto.HttpPathMethodDTO) Map(java.util.Map) RoboContext(com.robo4j.RoboContext) ClientPathConfig(com.robo4j.socket.http.units.ClientPathConfig) SystemPath(com.robo4j.socket.http.enums.SystemPath) RoboReference(com.robo4j.RoboReference) RoboReference(com.robo4j.RoboReference) ServerPathConfig(com.robo4j.socket.http.units.ServerPathConfig) PathHttpMethod(com.robo4j.socket.http.units.PathHttpMethod)

Example 30 with RoboContext

use of com.robo4j.RoboContext in project robo4j by Robo4J.

the class HttpPathUtils method updateHttpServerContextPaths.

public static void updateHttpServerContextPaths(final RoboContext context, final ServerContext serverContext, final Collection<HttpPathMethodDTO> paths) {
    final Map<PathHttpMethod, ServerPathConfig> resultPaths = paths.stream().map(e -> {
        RoboReference<Object> reference = context.getReference(e.getRoboUnit());
        return HttpPathUtils.toHttpPathConfig(e, reference);
    }).collect(Collectors.toMap(e -> new PathHttpMethod(e.getPath(), e.getMethod()), e -> e));
    resultPaths.put(new PathHttpMethod(Utf8Constant.UTF8_SOLIDUS, HttpMethod.GET), new ServerPathConfig(Utf8Constant.UTF8_SOLIDUS, null, HttpMethod.GET));
    serverContext.addPaths(resultPaths);
}
Also used : StringConstants(com.robo4j.util.StringConstants) JsonReader(com.robo4j.socket.http.json.JsonReader) ClientContext(com.robo4j.socket.http.units.ClientContext) Collection(java.util.Collection) ServerPathConfig(com.robo4j.socket.http.units.ServerPathConfig) Set(java.util.Set) PathHttpMethod(com.robo4j.socket.http.units.PathHttpMethod) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ServerContext(com.robo4j.socket.http.units.ServerContext) List(java.util.List) HttpPathMethodDTO(com.robo4j.socket.http.dto.HttpPathMethodDTO) Stream(java.util.stream.Stream) Map(java.util.Map) HttpMethod(com.robo4j.socket.http.HttpMethod) RoboContext(com.robo4j.RoboContext) ClientPathConfig(com.robo4j.socket.http.units.ClientPathConfig) SystemPath(com.robo4j.socket.http.enums.SystemPath) Utf8Constant(com.robo4j.util.Utf8Constant) JsonDocument(com.robo4j.socket.http.json.JsonDocument) Collections(java.util.Collections) RoboReference(com.robo4j.RoboReference) RoboReference(com.robo4j.RoboReference) ServerPathConfig(com.robo4j.socket.http.units.ServerPathConfig) PathHttpMethod(com.robo4j.socket.http.units.PathHttpMethod)

Aggregations

RoboContext (com.robo4j.RoboContext)50 RoboBuilder (com.robo4j.RoboBuilder)33 Test (org.junit.jupiter.api.Test)20 InputStream (java.io.InputStream)17 Configuration (com.robo4j.configuration.Configuration)10 ConfigurationBuilder (com.robo4j.configuration.ConfigurationBuilder)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 FileInputStream (java.io.FileInputStream)5 RoboReference (com.robo4j.RoboReference)4 RoboBuilderException (com.robo4j.RoboBuilderException)3 ServerPathConfig (com.robo4j.socket.http.units.ServerPathConfig)3 List (java.util.List)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 StringConsumer (com.robo4j.StringConsumer)2 BiColor (com.robo4j.hw.rpi.i2c.adafruitbackpack.BiColor)2 DataEvent3f (com.robo4j.hw.rpi.imu.bno.DataEvent3f)2 HttpMethod (com.robo4j.socket.http.HttpMethod)2 CameraMessage (com.robo4j.socket.http.codec.CameraMessage)2 HttpPathMethodDTO (com.robo4j.socket.http.dto.HttpPathMethodDTO)2