use of com.robo4j.socket.http.message.DatagramDecoratedRequest 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);
}
use of com.robo4j.socket.http.message.DatagramDecoratedRequest 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);
}
use of com.robo4j.socket.http.message.DatagramDecoratedRequest 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;
}
Aggregations