Class VertxSink
- All Implemented Interfaces:
Sink
- Direct Known Subclasses:
AggregationServerSink
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)
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
VertxSink.Builder<B extends BaseSink.Builder<B,
S>, S extends Sink> Implementation of base builder pattern forVertxSink
. -
Constructor Summary
ModifierConstructorDescriptionprotected
VertxSink
(VertxSink.Builder<?, ?> builder) Protected constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Called to allow the publisher to clean-up.protected void
enqueueData
(io.vertx.core.buffer.Buffer data) Adds aBuffer
of data to the pending data queue.protected final io.vertx.core.Vertx
getVertx()
Accessor forVertx
instance.protected void
onConnect
(io.vertx.core.net.NetSocket socket) Perform tasks when the connection is first established.protected void
sendRawData
(io.vertx.core.buffer.Buffer data) Sends aBuffer
of bytes to the socket if the client is connected.Generate a Steno log compatible representation.Methods inherited from class com.arpnetworking.tsdcore.sinks.BaseSink
getMetricSafeName, getName, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.arpnetworking.tsdcore.sinks.Sink
recordAggregateData
-
Constructor Details
-
VertxSink
Protected constructor.- Parameters:
builder
- Instance ofVertxSink.Builder
.
-
-
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
Description copied from class:BaseSink
Generate a Steno log compatible representation.- Overrides:
toLogValue
in classBaseSink
- 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
- TheNetSocket
instance that was connected.
-
enqueueData
protected void enqueueData(io.vertx.core.buffer.Buffer data) Adds aBuffer
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 aBuffer
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 forVertx
instance.- Returns:
- The
Vertx
instance.
-