Class WebServerSender

java.lang.Object
org.eso.ias.webserversender.WebServerSender
All Implemented Interfaces:
AutoCloseable, SimpleKafkaIasiosConsumer.IasioListener

@WebSocket(maxTextMessageSize=2000000) public class WebServerSender extends Object implements SimpleKafkaIasiosConsumer.IasioListener, AutoCloseable
The WebServerSender gets IASValues from the copre kafka topic and forwards them to the web server through websockets. Received IASValues are cached before being sent at regular time intervals by a dedicated thread or when the max numer of logs to send has been reached, whatever happens first. The limit of the max number of values is not strict. As logs are received in bounces, they are all aded to the cache and the size of the cache checked later. So the promise is to send the values as soon as the zize of the cache is equal or freater than the maximum allowed number of values. Sending values when the max number of items in cache has been reached does not affect the periodic thread that continues running at his schedule. Afetr sending by max number of items, it can happen that the periodic task is executed shortly after.
  • Field Details

    • senderID

      public final String senderID
      The identifier of the sender
    • socketConnected

      public final AtomicBoolean socketConnected
      A flag set to true if the socket is connected
    • STATISTIC_TIME_INTERVAL_PROP_NAME

      public static final String STATISTIC_TIME_INTERVAL_PROP_NAME
      The property to set the time interval for the generation of statistics in minutes
      See Also:
    • DEFAULT_STATS_TIME_INTERVAL

      public static final long DEFAULT_STATS_TIME_INTERVAL
      The defualt interval to publish statistics in minutes
      See Also:
  • Constructor Details

    • WebServerSender

      public WebServerSender(String senderID, String kafkaServers, Properties props, WebServerSender.WebServerSenderListener listener, int hbFrequency, Set<String> acceptedIds, Set<IASTypes> acceptedTypes) throws URISyntaxException
      Constructor
      Parameters:
      senderID - Identifier of the WebServerSender
      kafkaServers - Kafka servers URL
      props - the properties to get kafka servers, topic names and webserver uri
      listener - The listenr of the messages sent to the websocket server i.e. the web server
      hbFrequency - the frequency of the heartbeat (seconds)
      acceptedIds - The IDs of the IASIOs to consume
      acceptedTypes - The IASTypes to consume
      Throws:
      URISyntaxException
  • Method Details

    • onClose

      @OnWebSocketClose public void onClose(int statusCode, String reason)
      Operations performed on connection close
      Parameters:
      statusCode -
      reason -
    • onConnect

      @OnWebSocketConnect public void onConnect(org.eclipse.jetty.websocket.api.Session session)
      Operations performed on connection start
      Parameters:
      session -
    • onMessage

      @OnWebSocketMessage public void onMessage(String message)
      Normally the WebServerSender does not send masseges. The test, WebServerSenderTest sends a message to this WebSocket to confirm the connection: if this method is removed, the tests fails.
      Parameters:
      message - The message received
    • iasiosReceived

      public void iasiosReceived(Collection<IASValue<?>> events)
      This method receives IASValues published in the BSDB. See SimpleKafkaIasiosConsumer.IasioListener.iasiosReceived(Collection)
      Specified by:
      iasiosReceived in interface SimpleKafkaIasiosConsumer.IasioListener
      Parameters:
      events - The IASIOs received in the topic
    • onError

      @OnWebSocketError public void onError(Throwable cause)
    • setUp

      public void setUp() throws Exception
      Initialize the WSS
      Throws:
      Exception - in case of error initializing
    • connect

      public void connect()
      Initializes the WebSocket connection
    • close

      public void close()
      Shutdown the WebSocket client and Kafka consumer
      Specified by:
      close in interface AutoCloseable
    • notifyListener

      protected void notifyListener(String strToNotify)
      Notify the passed string to the listener.
      Parameters:
      strToNotify - The string to notify to the listener
    • setReconnectionInverval

      public void setReconnectionInverval(int interval)
      Set the time to wait before attempt to reconnect
      Parameters:
      interval - time in seconds
    • main

      public static void main(String[] args) throws Exception
      Throws:
      Exception