Package org.eso.ias.webserversender
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
The interface of the listener to be notified of Strings received by the WebServer sender. -
Field Summary
Modifier and TypeFieldDescriptionstatic final long
The defualt interval to publish statistics in minutesfinal String
The identifier of the senderfinal AtomicBoolean
A flag set totrue
if the socket is connectedstatic final String
The property to set the time interval for the generation of statistics in minutes -
Constructor Summary
ConstructorDescriptionWebServerSender
(String senderID, String kafkaServers, Properties props, WebServerSender.WebServerSenderListener listener, int hbFrequency, Set<String> acceptedIds, Set<IASTypes> acceptedTypes) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Shutdown the WebSocket client and Kafka consumervoid
connect()
Initializes the WebSocket connectionvoid
iasiosReceived
(Collection<IASValue<?>> events) This method receives IASValues published in the BSDB.static void
protected void
notifyListener
(String strToNotify) Notify the passed string to the listener.void
Operations performed on connection closevoid
onConnect
(org.eclipse.jetty.websocket.api.Session session) Operations performed on connection startvoid
void
Normally the WebServerSender does not send masseges.void
setReconnectionInverval
(int interval) Set the time to wait before attempt to reconnectvoid
setUp()
Initialize the WSS
-
Field Details
-
senderID
The identifier of the sender -
socketConnected
A flag set totrue
if the socket is connected -
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_INTERVALThe 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 WebServerSenderkafkaServers
- Kafka servers URLprops
- the properties to get kafka servers, topic names and webserver urilistener
- The listenr of the messages sent to the websocket server i.e. the web serverhbFrequency
- the frequency of the heartbeat (seconds)acceptedIds
- The IDs of the IASIOs to consumeacceptedTypes
- The IASTypes to consume- Throws:
URISyntaxException
-
-
Method Details
-
onClose
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
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
This method receives IASValues published in the BSDB. SeeSimpleKafkaIasiosConsumer.IasioListener.iasiosReceived(Collection)
- Specified by:
iasiosReceived
in interfaceSimpleKafkaIasiosConsumer.IasioListener
- Parameters:
events
- The IASIOs received in the topic
-
onError
-
setUp
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 interfaceAutoCloseable
-
notifyListener
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
- Throws:
Exception
-