public class Beacon
extends java.lang.Object
| Constructor and Description |
|---|
Beacon(BeaconInitializer initializer,
BeaconConfiguration configuration)
Creates a new beacon instance
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAction(BaseActionImpl action)
Add
BaseActionImpl to Beacon. |
void |
addWebRequest(int parentActionID,
WebRequestTracerBaseImpl webRequestTracer)
Add web request to Beacon.
|
void |
clearData()
Clears all previously collected data for this Beacon.
|
int |
createID()
Create a unique identifier.
|
int |
createSequenceNumber()
Create a unique sequence number.
|
java.lang.String |
createTag(int parentActionID,
int tracerSeqNo)
Create a web request tag.
|
void |
disableCapture()
Disables capturing for this session
|
void |
enableCapture()
Enables capturing for this beacon.
|
protected byte[] |
encodeBeaconChunk(java.lang.String chunkToEncode)
Encodes the given chunk to an
CHARSET byte array. |
void |
endSession()
Add
SessionImpl to Beacon when session is ended. |
long |
getCurrentTimestamp()
Get the current timestamp in milliseconds by delegating to TimingProvider
|
long |
getDeviceID()
Get a visitor ID for the current data collection level
in case of level 2 (USER_BEHAVIOR) the value from the configuration is used
in case of level 1 (PERFORMANCE) or 0 (OFF) a random number in the positive Long range is used
|
int |
getSessionNumber()
Get a session ID for the current data collection level
|
int |
getSessionSequenceNumber()
Returns sequence number of the session.
|
long |
getSessionStartTime()
Returns the time when the session was started (in milliseconds).
|
void |
identifyUser(java.lang.String userTag)
Add user identification to Beacon.
|
void |
initializeServerConfiguration(ServerConfiguration serverConfiguration)
Initializes the beacon with the given
ServerConfiguration. |
boolean |
isActionReportingAllowedByPrivacySettings()
Get a boolean, indicating if action reporting is enabled by the privacy configuration
|
boolean |
isDataCapturingEnabled()
Indicates whether data capturing for this beacon is currently enabled or not.
|
boolean |
isEmpty()
Tests if the Beacon is empty.
|
boolean |
isServerConfigurationSet()
Indicates whether a server configuration is set on this beacon's configuration or not.
|
void |
reportCrash(java.lang.String errorName,
java.lang.String reason,
java.lang.String stacktrace)
Add crash to Beacon.
|
void |
reportError(int parentActionID,
java.lang.String errorName,
int errorCode,
java.lang.String reason)
Add error to Beacon.
|
void |
reportEvent(int parentActionID,
java.lang.String eventName)
Add event (aka.
|
void |
reportValue(int parentActionID,
java.lang.String valueName,
double value)
Add key-value-pair to Beacon.
|
void |
reportValue(int parentActionID,
java.lang.String valueName,
int value)
Add key-value-pair to Beacon.
|
void |
reportValue(int parentActionID,
java.lang.String valueName,
java.lang.String value)
Add key-value-pair to Beacon.
|
StatusResponse |
send(HTTPClientProvider provider,
AdditionalQueryParameters additionalParameters)
Send current state of Beacon.
|
void |
setServerConfigurationUpdateCallback(ServerConfigurationUpdateCallback callback)
Sets the callback when a server configuration is updated.
|
void |
startSession()
Add start session event to Beacon.
|
void |
updateServerConfiguration(ServerConfiguration serverConfiguration)
Updates this beacon with the given
ServerConfiguration |
public Beacon(BeaconInitializer initializer, BeaconConfiguration configuration)
initializer - provider of relevant parameters to initialize / create the beaconconfiguration - OpenKit related configuration.public int createID()
The identifier returned is only unique per Beacon. Calling this method on two different Beacon instances, might give the same result.
public long getCurrentTimestamp()
public int createSequenceNumber()
The sequence number returned is only unique per Beacon. Calling this method on two different Beacon instances, might give the same result.
public long getSessionStartTime()
public java.lang.String createTag(int parentActionID,
int tracerSeqNo)
Web request tags can be attached as HTTP header for web request tracing.
If PrivacyConfiguration.isWebRequestTracingAllowed() yields false an empty tag is returned.
parentActionID - The ID of the Action for which to create a web request tag
or 0 if no parent action exists.tracerSeqNo - Sequence number of the WebRequestTracer.public void addAction(BaseActionImpl action)
BaseActionImpl to Beacon.
The serialized data is added to BeaconCache.
action - The action to add.public void startSession()
The serialized data is added to BeaconCache.
public void endSession()
SessionImpl to Beacon when session is ended.
The serialized data is added to BeaconCache.
public void reportValue(int parentActionID,
java.lang.String valueName,
int value)
The serialized data is added to BeaconCache.
parentActionID - The ID of the Action on which this value was reported.valueName - Value's name.value - Actual value to report.public void reportValue(int parentActionID,
java.lang.String valueName,
double value)
The serialized data is added to BeaconCache.
parentActionID - The ID of the Action on which this value was reported.valueName - Value's name.value - Actual value to report.public void reportValue(int parentActionID,
java.lang.String valueName,
java.lang.String value)
The serialized data is added to BeaconCache.
parentActionID - The ID of the Action on which this value was reported.valueName - Value's name.value - Actual value to report.public void reportEvent(int parentActionID,
java.lang.String eventName)
The serialized data is added to BeaconCache.
parentActionID - The ID of the Action on which this event was reported.eventName - Event's name.public void reportError(int parentActionID,
java.lang.String errorName,
int errorCode,
java.lang.String reason)
The serialized data is added to BeaconCache.
parentActionID - The ID of the Action on which this error was reported.errorName - Error's name.errorCode - Some error code.reason - Reason for that error.public void reportCrash(java.lang.String errorName,
java.lang.String reason,
java.lang.String stacktrace)
The serialized data is added to BeaconCache.
errorName - Error's name.reason - Reason for that error.stacktrace - Crash stacktrace.public void addWebRequest(int parentActionID,
WebRequestTracerBaseImpl webRequestTracer)
The serialized data is added to BeaconCache.
parentActionID - The id of the parent Action on which this web request was reported.webRequestTracer - Web request tracer to serialize.public void identifyUser(java.lang.String userTag)
The serialized data is added to BeaconCache.
userTag - User tag containing data to serialize.public StatusResponse send(HTTPClientProvider provider, AdditionalQueryParameters additionalParameters)
This method tries to send all so far collected and serialized data.
provider - Provider for getting an HTTPClient required to send the data.additionalParameters - additional parameters that will be send with the beacon request (can be null).null if an error occurred.protected byte[] encodeBeaconChunk(java.lang.String chunkToEncode)
throws java.io.UnsupportedEncodingException
CHARSET byte array.
This method should only be used by tests.
chunkToEncode - the beacon chunk to encodejava.io.UnsupportedEncodingExceptionpublic void clearData()
This only affects the so far serialized data, which gets removed from the cache.
public long getDeviceID()
public int getSessionNumber()
If session number reporting is allowed (see also PrivacyConfiguration.isSessionNumberReportingAllowed(),
then the real session number is returned, otherwise 1 is returned.
1 if session number reporting is not allowed.public int getSessionSequenceNumber()
The session sequence number is a consecutive number which is increased when a session is split due to exceeding the maximum number of allowed events. The split session will then have the same session number but an increased session sequence number.
public boolean isEmpty()
A beacon is considered to be empty, if it does not contain any action or event data.
true if the beacon is empty, false otherwise.public void initializeServerConfiguration(ServerConfiguration serverConfiguration)
ServerConfiguration.serverConfiguration - the server configuration which will be used for initialization.public void updateServerConfiguration(ServerConfiguration serverConfiguration)
ServerConfigurationserverConfiguration - the server configuration which will be used to update this beacon.public boolean isServerConfigurationSet()
public void setServerConfigurationUpdateCallback(ServerConfigurationUpdateCallback callback)
callback - the callback to be notified when the server configuration is updated.public boolean isDataCapturingEnabled()
public void enableCapture()
This will implicitly cause isServerConfigurationSet() to return true.
public void disableCapture()
This will implicitly cause isServerConfigurationSet() to return true.
public boolean isActionReportingAllowedByPrivacySettings()
true if action reporting is enabled by privacy configuration, false otherwise.