Class Beacon
- java.lang.Object
-
- com.dynatrace.openkit.protocol.Beacon
-
public class Beacon extends java.lang.ObjectThe Beacon class holds all the beacon data and the beacon protocol implementation.
-
-
Constructor Summary
Constructors Constructor Description Beacon(BeaconInitializer initializer, BeaconConfiguration configuration)Creates a new beacon instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAction(BaseActionImpl action)AddBaseActionImplto Beacon.voidaddWebRequest(int parentActionID, WebRequestTracerBaseImpl webRequestTracer)Add web request to Beacon.voidclearData()Clears all previously collected data for this Beacon.intcreateID()Create a unique identifier.intcreateSequenceNumber()Create a unique sequence number.java.lang.StringcreateTag(int parentActionID, int tracerSeqNo)Create a web request tag.voiddisableCapture()Disables capturing for this sessionvoidenableCapture()Enables capturing for this beacon.protected byte[]encodeBeaconChunk(java.lang.String chunkToEncode)Encodes the given chunk to anCHARSETbyte array.voidendSession()AddSessionImplto Beacon when session is ended.longgetCurrentTimestamp()Get the current timestamp in milliseconds by delegating to TimingProviderlonggetDeviceID()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 usedintgetSessionNumber()Get a session ID for the current data collection levelintgetSessionSequenceNumber()Returns sequence number of the session.longgetSessionStartTime()Returns the time when the session was started (in milliseconds).voididentifyUser(java.lang.String userTag)Add user identification to Beacon.voidinitializeServerConfiguration(ServerConfiguration serverConfiguration)Initializes the beacon with the givenServerConfiguration.booleanisActionReportingAllowedByPrivacySettings()Get a boolean, indicating if action reporting is enabled by the privacy configurationbooleanisCrashCapturingEnabled()Indicates whether crash capturing for this beacon is currently enabled or not.booleanisDataCapturingEnabled()Indicates whether data capturing for this beacon is currently enabled or not.booleanisEmpty()Tests if the Beacon is empty.booleanisErrorCapturingEnabled()Indicates whether error capturing for this beacon is currently enabled or not.booleanisServerConfigurationSet()Indicates whether a server configuration is set on this beacon's configuration or not.voidreportCrash(java.lang.String errorName, java.lang.String reason, java.lang.String stacktrace)Add crash to Beacon.voidreportCrash(java.lang.Throwable throwable)Add crash to Beacon.voidreportError(int parentActionID, java.lang.String errorName, int errorCode)Add error to Beacon.voidreportError(int parentActionID, java.lang.String errorName, java.lang.String causeName, java.lang.String causeDescription, java.lang.String causeStackTrace)voidreportError(int parentActionID, java.lang.String errorName, java.lang.Throwable throwable)voidreportEvent(int parentActionID, java.lang.String eventName)Add event (aka.voidreportValue(int parentActionID, java.lang.String valueName, double value)Add key-value-pair to Beacon.voidreportValue(int parentActionID, java.lang.String valueName, int value)Add key-value-pair to Beacon.voidreportValue(int parentActionID, java.lang.String valueName, long value)Add key-value-pair to Beacon.voidreportValue(int parentActionID, java.lang.String valueName, java.lang.String value)Add key-value-pair to Beacon.StatusResponsesend(HTTPClientProvider provider, AdditionalQueryParameters additionalParameters)Send current state of Beacon.voidsendBizEvent(java.lang.String type, java.util.Map<java.lang.String,JSONValue> attributes)voidsendEvent(java.lang.String name, java.util.Map<java.lang.String,JSONValue> attributes)voidsetServerConfigurationUpdateCallback(ServerConfigurationUpdateCallback callback)Sets the callback when a server configuration is updated.voidstartSession()Add start session event to Beacon.voidupdateServerConfiguration(ServerConfiguration serverConfiguration)Updates this beacon with the givenServerConfiguration
-
-
-
Constructor Detail
-
Beacon
public Beacon(BeaconInitializer initializer, BeaconConfiguration configuration)
Creates a new beacon instance- Parameters:
initializer- provider of relevant parameters to initialize / create the beaconconfiguration- OpenKit related configuration.
-
-
Method Detail
-
createID
public int createID()
Create a unique identifier.The identifier returned is only unique per Beacon. Calling this method on two different Beacon instances, might give the same result.
- Returns:
- A unique identifier.
-
getCurrentTimestamp
public long getCurrentTimestamp()
Get the current timestamp in milliseconds by delegating to TimingProvider- Returns:
- Current timestamp in milliseconds.
-
createSequenceNumber
public int createSequenceNumber()
Create a unique sequence number.The sequence number returned is only unique per Beacon. Calling this method on two different Beacon instances, might give the same result.
- Returns:
- A unique sequence number.
-
getSessionStartTime
public long getSessionStartTime()
Returns the time when the session was started (in milliseconds).
-
createTag
public java.lang.String createTag(int parentActionID, int tracerSeqNo)Create a web request tag.Web request tags can be attached as HTTP header for web request tracing. If
PrivacyConfiguration.isWebRequestTracingAllowed()yieldsfalsean empty tag is returned.- Parameters:
parentActionID- The ID of theActionfor which to create a web request tag or0if no parent action exists.tracerSeqNo- Sequence number of theWebRequestTracer.- Returns:
- A web request tracer tag.
-
addAction
public void addAction(BaseActionImpl action)
AddBaseActionImplto Beacon.The serialized data is added to
BeaconCache.- Parameters:
action- The action to add.
-
startSession
public void startSession()
Add start session event to Beacon.The serialized data is added to
BeaconCache.
-
endSession
public void endSession()
AddSessionImplto Beacon when session is ended.The serialized data is added to
BeaconCache.
-
reportValue
public void reportValue(int parentActionID, java.lang.String valueName, int value)Add key-value-pair to Beacon.The serialized data is added to
BeaconCache.- Parameters:
parentActionID- The ID of theActionon which this value was reported.valueName- Value's name.value- Actual value to report.
-
reportValue
public void reportValue(int parentActionID, java.lang.String valueName, long value)Add key-value-pair to Beacon.The serialized data is added to
BeaconCache.- Parameters:
parentActionID- The ID of theActionon which this value was reported.valueName- Value's name.value- Actual value to report.
-
reportValue
public void reportValue(int parentActionID, java.lang.String valueName, double value)Add key-value-pair to Beacon.The serialized data is added to
BeaconCache.- Parameters:
parentActionID- The ID of theActionon which this value was reported.valueName- Value's name.value- Actual value to report.
-
reportValue
public void reportValue(int parentActionID, java.lang.String valueName, java.lang.String value)Add key-value-pair to Beacon.The serialized data is added to
BeaconCache.- Parameters:
parentActionID- The ID of theActionon which this value was reported.valueName- Value's name.value- Actual value to report.
-
reportEvent
public void reportEvent(int parentActionID, java.lang.String eventName)Add event (aka. named event) to Beacon.The serialized data is added to
BeaconCache.- Parameters:
parentActionID- The ID of theActionon which this event was reported.eventName- Event's name.
-
reportError
public void reportError(int parentActionID, java.lang.String errorName, int errorCode)Add error to Beacon.The serialized data is added to
BeaconCache.- Parameters:
parentActionID- The ID of theActionon which this error was reported.errorName- Error's name.errorCode- Some error code.
-
reportError
public void reportError(int parentActionID, java.lang.String errorName, java.lang.String causeName, java.lang.String causeDescription, java.lang.String causeStackTrace)
-
reportError
public void reportError(int parentActionID, java.lang.String errorName, java.lang.Throwable throwable)
-
reportCrash
public void reportCrash(java.lang.String errorName, java.lang.String reason, java.lang.String stacktrace)Add crash to Beacon.The serialized data is added to
BeaconCache.- Parameters:
errorName- Error's name.reason- Reason for that error.stacktrace- Crash stacktrace.
-
reportCrash
public void reportCrash(java.lang.Throwable throwable)
Add crash to Beacon.The serialized data is added to
BeaconCache.- Parameters:
throwable-Throwableto report.
-
addWebRequest
public void addWebRequest(int parentActionID, WebRequestTracerBaseImpl webRequestTracer)Add web request to Beacon.The serialized data is added to
BeaconCache.- Parameters:
parentActionID- The id of the parentActionon which this web request was reported.webRequestTracer- Web request tracer to serialize.
-
identifyUser
public void identifyUser(java.lang.String userTag)
Add user identification to Beacon.The serialized data is added to
BeaconCache.- Parameters:
userTag- User tag containing data to serialize. TheuserTagis the only name-beacon data that can be null/empty.
-
send
public StatusResponse send(HTTPClientProvider provider, AdditionalQueryParameters additionalParameters)
Send current state of Beacon.This method tries to send all so far collected and serialized data.
- Parameters:
provider- Provider for getting anHTTPClientrequired to send the data.additionalParameters- additional parameters that will be send with the beacon request (can benull).- Returns:
- Returns the last status response retrieved from the server side, or
nullif an error occurred.
-
sendBizEvent
public void sendBizEvent(java.lang.String type, java.util.Map<java.lang.String,JSONValue> attributes)
-
sendEvent
public void sendEvent(java.lang.String name, java.util.Map<java.lang.String,JSONValue> attributes)
-
encodeBeaconChunk
protected byte[] encodeBeaconChunk(java.lang.String chunkToEncode) throws java.io.UnsupportedEncodingExceptionEncodes the given chunk to anCHARSETbyte array.This method should only be used by tests.
- Parameters:
chunkToEncode- the beacon chunk to encode- Returns:
- the encoded beacon chunk
- Throws:
java.io.UnsupportedEncodingException
-
clearData
public void clearData()
Clears all previously collected data for this Beacon.This only affects the so far serialized data, which gets removed from the cache.
-
getDeviceID
public 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- Returns:
- The device identifier, which is truncated to 250 characters if level 2 (USER_BEHAVIOR) is used.
-
getSessionNumber
public int getSessionNumber()
Get a session ID for the current data collection levelIf session number reporting is allowed (see also
PrivacyConfiguration.isSessionNumberReportingAllowed(), then the real session number is returned, otherwise1is returned.- Returns:
- Pre calculated session number or
1if session number reporting is not allowed.
-
getSessionSequenceNumber
public int getSessionSequenceNumber()
Returns sequence number of the session.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.
-
isEmpty
public boolean isEmpty()
Tests if the Beacon is empty.A beacon is considered to be empty, if it does not contain any action or event data.
- Returns:
trueif the beacon is empty,falseotherwise.
-
initializeServerConfiguration
public void initializeServerConfiguration(ServerConfiguration serverConfiguration)
Initializes the beacon with the givenServerConfiguration.- Parameters:
serverConfiguration- the server configuration which will be used for initialization.
-
updateServerConfiguration
public void updateServerConfiguration(ServerConfiguration serverConfiguration)
Updates this beacon with the givenServerConfiguration- Parameters:
serverConfiguration- the server configuration which will be used to update this beacon.
-
isServerConfigurationSet
public boolean isServerConfigurationSet()
Indicates whether a server configuration is set on this beacon's configuration or not.
-
setServerConfigurationUpdateCallback
public void setServerConfigurationUpdateCallback(ServerConfigurationUpdateCallback callback)
Sets the callback when a server configuration is updated.- Parameters:
callback- the callback to be notified when the server configuration is updated.
-
isDataCapturingEnabled
public boolean isDataCapturingEnabled()
Indicates whether data capturing for this beacon is currently enabled or not.
-
isErrorCapturingEnabled
public boolean isErrorCapturingEnabled()
Indicates whether error capturing for this beacon is currently enabled or not.
-
isCrashCapturingEnabled
public boolean isCrashCapturingEnabled()
Indicates whether crash capturing for this beacon is currently enabled or not.
-
enableCapture
public void enableCapture()
Enables capturing for this beacon.This will implicitly cause
isServerConfigurationSet()to returntrue.
-
disableCapture
public void disableCapture()
Disables capturing for this sessionThis will implicitly cause
isServerConfigurationSet()to returntrue.
-
isActionReportingAllowedByPrivacySettings
public boolean isActionReportingAllowedByPrivacySettings()
Get a boolean, indicating if action reporting is enabled by the privacy configuration- Returns:
trueif action reporting is enabled by privacy configuration,falseotherwise.
-
-