Search in sources :

Example 1 with DatagramDenominator

use of com.robo4j.socket.http.message.DatagramDenominator in project robo4j by Robo4J.

the class DatagramClientCodecUnit method onMessage.

@Override
public void onMessage(ClientMessageWrapper message) {
    final String encodedMessage = clientContext.getPropertySafe(CodecRegistry.class, PROPERTY_CODEC_REGISTRY).containsEncoder(message.getClazz()) ? processMessage(message.getClazz(), message.getMessage()) : NOT_AVAILABLE;
    final ClientPathConfig pathConfig = clientContext.getPathConfig(new PathHttpMethod(message.getPath(), null));
    final DatagramDenominator denominator = new DatagramDenominator(DatagramBodyType.JSON.getType(), pathConfig.getPath());
    final DatagramDecoratedRequest request = new DatagramDecoratedRequest(denominator);
    request.addMessage(encodedMessage.getBytes());
    getContext().getReference(target).sendMessage(request);
}
Also used : DatagramDenominator(com.robo4j.socket.http.message.DatagramDenominator) DatagramDecoratedRequest(com.robo4j.socket.http.message.DatagramDecoratedRequest)

Example 2 with DatagramDenominator

use of com.robo4j.socket.http.message.DatagramDenominator in project robo4j by Robo4J.

the class RoboDatagramPingPongTest method datagramPingPongTest.

@Test
void datagramPingPongTest() throws Exception {
    RoboContext pongSystem = configurePongSystem(TOTAL_NUMBER);
    RoboContext pingSystem = configurePingSystem();
    pongSystem.start();
    pingSystem.start();
    System.out.println("UDP pongSystem: State after start:");
    System.out.println(SystemUtil.printStateReport(pongSystem));
    System.out.println("UDP pingSystem: State after start:");
    System.out.println(SystemUtil.printStateReport(pingSystem));
    RoboReference<String> pongStringConsumerReference = pongSystem.getReference(StringConsumer.NAME);
    CountDownLatch totalMessageLatch = pongStringConsumerReference.getAttribute(StringConsumer.DESCRIPTOR_MESSAGES_LATCH).get();
    RoboReference<DatagramDecoratedRequest> udpClient = pingSystem.getReference(UDP_CLIENT);
    for (int i = 0; i < TOTAL_NUMBER; i++) {
        DatagramDenominator denominator = new DatagramDenominator(DatagramBodyType.JSON.getType(), "/units/stringConsumer");
        DatagramDecoratedRequest request = new DatagramDecoratedRequest(denominator);
        String message = "{\"message\": \"Hello i:" + i + "\"}";
        request.addMessage(message.getBytes());
        udpClient.sendMessage(request);
    }
    totalMessageLatch.await(TIMEOUT, TIME_UNIT);
    final int pongConsumerTotalNumber = pongStringConsumerReference.getAttribute(StringConsumer.DESCRIPTOR_MESSAGES_TOTAL).get();
    System.out.println("UDP pongSystem: State after shutdown:");
    System.out.println(SystemUtil.printStateReport(pongSystem));
    System.out.println("UDP pingSystem: State after shutdown:");
    System.out.println(SystemUtil.printStateReport(pingSystem));
    pingSystem.shutdown();
    pongSystem.shutdown();
    assertEquals(TOTAL_NUMBER, pongConsumerTotalNumber);
}
Also used : RoboContext(com.robo4j.RoboContext) DatagramDenominator(com.robo4j.socket.http.message.DatagramDenominator) CountDownLatch(java.util.concurrent.CountDownLatch) DatagramDecoratedRequest(com.robo4j.socket.http.message.DatagramDecoratedRequest) Test(org.junit.jupiter.api.Test)

Example 3 with DatagramDenominator

use of com.robo4j.socket.http.message.DatagramDenominator in project robo4j by Robo4J.

the class SocketMessageDecoratedProducerUnit method getDatagramRequest.

private DatagramDecoratedRequest getDatagramRequest(ClientPathConfig pathConfig) {
    final DatagramDenominator denominator = new DatagramDenominator(DatagramBodyType.JSON.getType(), pathConfig.getPath());
    final DatagramDecoratedRequest result = new DatagramDecoratedRequest(denominator);
    result.addMessage(message.getBytes());
    return result;
}
Also used : DatagramDenominator(com.robo4j.socket.http.message.DatagramDenominator) DatagramDecoratedRequest(com.robo4j.socket.http.message.DatagramDecoratedRequest)

Aggregations

DatagramDecoratedRequest (com.robo4j.socket.http.message.DatagramDecoratedRequest)3 DatagramDenominator (com.robo4j.socket.http.message.DatagramDenominator)3 RoboContext (com.robo4j.RoboContext)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.jupiter.api.Test)1