AutoCloseable
public class HoneyClient extends Object implements AutoCloseable
HoneyClient
instance.
LibHoney
's static methods to construct and configure an instance of HoneyClient
.
send(Map)
method, which will send it with the settings and
fields of the HoneyClient
instance.
However, in many cases an event should be first customised with relevant data from its runtime context.
createEvent()
creates such a customisable Event
, which can then be submitted to the
Honeycomb server via Event.send()
.
Alternatively, an EventFactory
is useful when a grouping of events being sent shares common properties.
This can be created through the buildEventFactory()
method.
EventFactory
inherits the properties from the instance of HoneyClient
that creates it.
An Event
can be created through EventFactory
and HoneyClient
, and will similarly inherit
properties from them.
HoneyClient
,
EventFactory
, or Event
), as long as as the event being sent ultimately contains them.
EventFactory
and Event
instances that have been created with this instance.
The shutdown is best effort, and subject to a timeout, so it does not block indefinitely. This means, events may ultimately be dropped (e.g. if the honeycomb server cannot be reached in time).
Options
. There are 2 types of fields:
globalFields
have fixed keys and values and remain static for the lifetime of the instance.globalDynamicFields
also have fixed keys, but values are dynamic and resolved every time when
Event.send()
is invoked.EventFactory
s and Event
s that are constructed from a given
HoneyClient
instance.
Note that global fields have a lower precedence than fields added via EventFactory
or Event
,
and thus will be overwritten if the keys equal.
However, across the 2 ways to provide global fields, there is no explicit precedence/ordering.
EventPostProcessor
for details.Constructor | Description |
---|---|
HoneyClient(Options options) |
Constructor that assumes that the default transport is being used.
|
HoneyClient(Options options,
Transport transport) |
Constructor that allows the the transport to be overridden.
|
HoneyClient(Options options,
Transport transport,
ClockProvider clock) |
Constructor that allows the the transport and clock to be overridden.
|
HoneyClient(Options options,
TransportOptions transportOptions) |
Constructor offering further configuration options of the transport layer.
|
Modifier and Type | Method | Description |
---|---|---|
void |
addResponseObserver(ResponseObserver observer) |
Add an observer that gets notified about the outcome of every event sent through this client.
|
EventFactory.Builder |
buildEventFactory() |
Returns a builder for constructing an
EventFactory . |
void |
close() |
Method to initiate shutdown of this client and of the transport.
|
void |
closeOnShutdown() |
Can be used to add a JVM shutdown hook that invokes
close() on this client instance. |
Event |
createEvent() |
Returns an
Event with the configuration and fields populated as set during initialisation of this
client instance. |
void |
removeResponseObserver(ResponseObserver observer) |
Remove the given observer, if response notifications are no longer required, or the reference
should be released.
|
void |
send(Map<String,?> fields) |
Provides a shortcut to sending an event by populating it with the settings and fields of this client instance
and adding the provided map of fields.
|
void |
setAsDefault() |
Can be used to set this LibHoney instance as a global default.
|
public HoneyClient(Options options)
options
- Configuration options.public HoneyClient(Options options, TransportOptions transportOptions)
options
- Configuration options.transportOptions
- Advanced configuration options for the transport.public HoneyClient(Options options, Transport transport)
options
- Configuration options.transport
- used to provide alternative transports (including test/mock implementations).public HoneyClient(Options options, Transport transport, ClockProvider clock)
options
- Configuration options.transport
- used to provide alternative transports (including test/mock implementations).clock
- used to override the clock for testingpublic Event createEvent()
Event
with the configuration and fields populated as set during initialisation of this
client instance.public EventFactory.Builder buildEventFactory()
EventFactory
. It is initially populated with the fields and
configuration settings of this client instance, but can be further customised to create a more specialised
factory of Event
s.EventFactory
.public void send(Map<String,?> fields)
fields
- to provide to the event.IllegalArgumentException
- if client-side validation fails, see HoneyClient
's class
documentation for the "Event Validation" rules.public void addResponseObserver(ResponseObserver observer)
observer
- to register.public void removeResponseObserver(ResponseObserver observer)
close()
will have the effect of clearing all observers.observer
- to remove.public void setAsDefault()
LibHoney.getDefault()
.public void closeOnShutdown()
close()
on this client instance.
Shortcut for LibHoney.closeOnShutdown(HoneyClient)
.public void close()
close
in interface AutoCloseable
Copyright © 2018 Honeycomb. All rights reserved.