use of joynr.system.RoutingTypes.WebSocketClientAddress in project joynr by bmwcarit.
the class WebSocketJettyServer method writeBytes.
@Override
public synchronized void writeBytes(Address toAddress, byte[] message, long timeout, TimeUnit unit, final SuccessAction successAction, final FailureAction failureAction) {
if (!(toAddress instanceof WebSocketClientAddress)) {
throw new JoynrIllegalStateException("Web Socket Server can only send to WebSocketClientAddresses");
}
WebSocketClientAddress toClientAddress = (WebSocketClientAddress) toAddress;
Session session = sessionMap.get(toClientAddress.getId());
if (session == null) {
// TODO We need a delay with invalidation of the stub
throw new JoynrDelayMessageException("no active session for WebSocketClientAddress: " + toClientAddress.getId());
}
try {
session.getRemote().sendBytes(ByteBuffer.wrap(message), new WriteCallback() {
@Override
public void writeSuccess() {
successAction.execute();
}
@Override
public void writeFailed(Throwable error) {
if (shutdown) {
return;
}
failureAction.execute(error);
}
});
} catch (WebSocketException e) {
// Jetty throws WebSocketException when expecting [OPEN or CONNECTED] but found a different state
// The client must reconnect, but the message can be queued in the mean time.
sessionMap.remove(toClientAddress.getId());
// TODO We need a delay with invalidation of the stub
throw new JoynrDelayMessageException(e.getMessage(), e);
}
}
use of joynr.system.RoutingTypes.WebSocketClientAddress in project joynr by bmwcarit.
the class WebSocketTest method configure.
private void configure(int maxMessageSize, long reconnectDelay, long websocketIdleTimeout, Set<JoynrMessageProcessor> messageProcessor) {
ObjectMapper objectMapper = new ObjectMapper();
WebSocketEndpointFactory webSocketJettyServerFactory = new WebSocketJettyServerFactory(maxMessageSize, objectMapper);
ccWebSocketMessagingSkeleton = new WebSocketMessagingSkeleton(serverAddress, webSocketJettyServerFactory, messageRouterMock, new WebSocketMessagingSkeleton.MainTransportFlagBearer(), messageProcessor);
ownAddress = new WebSocketClientAddress(UUID.randomUUID().toString());
webSocketJettyClientFactory = new WebSocketJettyClientFactory(ownAddress, maxMessageSize, reconnectDelay, websocketIdleTimeout, objectMapper);
webSocketMessagingStub = new WebSocketMessagingStub(serverAddress, webSocketJettyClientFactory.create(serverAddress));
libWebSocketMessagingSkeleton = new WebSocketMessagingSkeleton(serverAddress, webSocketJettyClientFactory, messageRouterMock, new WebSocketMessagingSkeleton.MainTransportFlagBearer(), messageProcessor);
ccWebSocketMessagingSkeleton.init();
libWebSocketMessagingSkeleton.init();
}
Aggregations