public class BufferedConnection extends Object implements Connection
Events from a Buffer.
This exists as a Connection implementation because the existing API (and the Java 7
standard library) has no simple way of knowing whether an asynchronous request succeeded
or failed. The wrapConnectionWithBufferWriter(io.sentry.connection.Connection) method is used to wrap an existing
Connection in a small anonymous Connection implementation that will always synchronously
write the sent Event to a Buffer and then pass it to the underlying Connection (often an
AsyncConnection in practice). Then, an instance of the BufferedConnection is used
to wrap the "real" Connection ("under" the AsyncConnection) so that it remove Events from
the Buffer if and only if the underlying send(Event) call doesn't throw an exception.
Note: In the future, if we are able to migrate to Java 8 at a minimum, we would probably make use
of CompletableFutures, though that would require changing the existing API regardless.| Constructor and Description |
|---|
BufferedConnection(Connection actualConnection,
Buffer buffer,
long flushtime,
boolean gracefulShutdown,
long shutdownTimeout)
Construct a BufferedConnection that will store events that failed to send to the provided
Buffer and attempt to flush them to the underlying connection later. |
| Modifier and Type | Method and Description |
|---|---|
void |
addEventSendCallback(EventSendCallback eventSendCallback)
Add a callback that is called when an exception occurs while attempting to
send events to the Sentry server.
|
void |
close() |
void |
send(Event event)
Sends an event to the Sentry server.
|
Connection |
wrapConnectionWithBufferWriter(Connection connectionToWrap)
Wrap a connection so that
Events are buffered before being passed on to
the underlying connection. |
public BufferedConnection(Connection actualConnection, Buffer buffer, long flushtime, boolean gracefulShutdown, long shutdownTimeout)
Buffer and attempt to flush them to the underlying connection later.actualConnection - Connection to wrap.buffer - Buffer to be used when Connection.send(Event)s fail.flushtime - Time to wait between flush attempts, in milliseconds.gracefulShutdown - Indicates whether or not the shutdown operation should be managed by a ShutdownHook.shutdownTimeout - Timeout for graceful shutdown of the executor, in milliseconds.public void send(Event event)
Connectionsend in interface Connectionevent - captured event to add in Sentry.public void addEventSendCallback(EventSendCallback eventSendCallback)
ConnectionaddEventSendCallback in interface ConnectioneventSendCallback - callback instancepublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic Connection wrapConnectionWithBufferWriter(Connection connectionToWrap)
Events are buffered before being passed on to
the underlying connection.
This is important to ensure buffering happens synchronously with Event creation,
before they are passed on to the (optional) asynchronous connection so that Events will
be stored even if the application is about to exit due to a crash.connectionToWrap - Connection to wrap with buffering logic.Events to a buffer before passing along to
a wrapped Connection.Copyright © 2012–2017. All rights reserved.