Class VertxSink

java.lang.Object
com.arpnetworking.tsdcore.sinks.BaseSink
com.arpnetworking.tsdcore.sinks.VertxSink
All Implemented Interfaces:
Sink
Direct Known Subclasses:
AggregationServerSink

public abstract class VertxSink extends BaseSink
Abstract publisher to send data to a server via Vertx NetSocket. This class is best described as 3 separate parts:
  • The public interface
  • The connect loop
  • The send loop

The job of the public interface is to isolate the vertx event loop that sits at the heart of the sink. The public interface, therefore provides the thread safety to the other two components. Notably, the main way it interacts with the vertx event loop is by dispatching runnables to it.

The connect loop runs on the vertx event loop and is tasked with maintaining the connection to the upstream server. This is done by calling connectToServer. When an error is detected on the socket, the callback fires and again calls connectToServer. If the connection fails, connectToServer is called in a vertx setTimer call, thus making it a loop.

The send loop also runs on the vertx event loop and is tasked with sending the queued data to the connected socket. If a connected socket does not exist, the loop will "sleep" by re-scheduling itself with the vertx setTimer call. The main function for this loop is consumeLoop.

Author:
Brandon Arp (brandon dot arp at inscopemetrics dot io)
  • Constructor Details

  • Method Details

    • close

      public void close()
      Description copied from interface: Sink
      Called to allow the publisher to clean-up. No further calls to recordAggregation will be made after a call to close.
    • toLogValue

      public Object toLogValue()
      Description copied from class: BaseSink
      Generate a Steno log compatible representation.
      Overrides:
      toLogValue in class BaseSink
      Returns:
      Steno log compatible representation.
    • onConnect

      protected void onConnect(io.vertx.core.net.NetSocket socket)
      Perform tasks when the connection is first established. This method is invoked while holding a lock on the socket.
      Parameters:
      socket - The NetSocket instance that was connected.
    • enqueueData

      protected void enqueueData(io.vertx.core.buffer.Buffer data)
      Adds a Buffer of data to the pending data queue.
      Parameters:
      data - The data to add to the queue.
    • sendRawData

      protected void sendRawData(io.vertx.core.buffer.Buffer data)
      Sends a Buffer of bytes to the socket if the client is connected.
      Parameters:
      data - the data to send
    • getVertx

      protected final io.vertx.core.Vertx getVertx()
      Accessor for Vertx instance.
      Returns:
      The Vertx instance.