class BasicWebSocketMessageTransmitter implements WebSocketMessageTransmitter {

  @Override
  public synchronized void transmit(String endpointId, String message) {
    Optional<Session> sessionOptional = registry.get(endpointId);

    if (!sessionOptional.isPresent()) {
      sessionOptional = registry.getByPartialMatch(endpointId).stream().findFirst();
    }

    if (!sessionOptional.isPresent() || !sessionOptional.get().isOpen()) {
      LOG.trace("Session is not registered or closed, adding message to pending");

      reSender.add(endpointId, message);
    } else {
      LOG.trace("Session registered and open, sending message");

      try {
        sessionOptional.get().getBasicRemote().sendText(message);
      } catch (IOException e) {
        LOG.error("Error while trying to send a message to a basic websocket remote endpoint", e);
      }
    }
  }

  @Inject public  BasicWebSocketMessageTransmitter(
      WebSocketSessionRegistry registry, MessagesReSender reSender);

}