Package com.segment.analytics.messages
Class MessageBuilder<T extends Message,V extends MessageBuilder>
- java.lang.Object
-
- com.segment.analytics.messages.MessageBuilder<T,V>
-
- Direct Known Subclasses:
AliasMessage.Builder
,GroupMessage.Builder
,IdentifyMessage.Builder
,PageMessage.Builder
,ScreenMessage.Builder
,TrackMessage.Builder
public abstract class MessageBuilder<T extends Message,V extends MessageBuilder> extends java.lang.Object
Fluent API to construct instances of aMessage
.Note: Although it is not enforced by the compiler, either the
Message.anonymousId()
orMessage.userId()
must be provided before callingbuild()
. Failure to do so will result in aIllegalStateException
at runtime.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description V
anonymousId(java.lang.String anonymousId)
The Anonymous ID is a pseudo-unique substitute for a User ID, for cases when you don’t have an absolutely unique identifier.V
anonymousId(java.util.UUID anonymousId)
Deprecated.UseanonymousId(String)
instead.T
build()
Create aMessage
instance.V
context(java.util.Map<java.lang.String,?> context)
Set a map of information about the state of the device.V
enableIntegration(java.lang.String key, boolean enable)
Set whether this message is sent to the specified integration or not.V
integrationOptions(java.lang.String key, java.util.Map<java.lang.String,?> options)
Pass in some options that will only be used by the target integration.V
messageId(java.lang.String messageId)
The Message ID is a unique identifier for each message.V
messageId(java.util.UUID messageId)
Deprecated.UsemessageId(String)
instead.protected abstract T
realBuild(Message.Type type, java.lang.String messageId, java.util.Date sentAt, java.util.Date timestamp, java.util.Map<java.lang.String,?> context, java.lang.String anonymousId, java.lang.String userId, java.util.Map<java.lang.String,java.lang.Object> integrations)
V
sentAt(java.util.Date sentAt)
Set a sentAt for the event.V
timestamp(java.util.Date timestamp)
Set a timestamp for the event.Message.Type
type()
Returns theMessage.Type
of the message this builder is constructing.V
userId(java.lang.String userId)
The User ID is a persistent unique identifier for a user (such as a database ID).
-
-
-
Method Detail
-
messageId
public V messageId(java.util.UUID messageId)
Deprecated.UsemessageId(String)
instead.The Message ID is a unique identifier for each message. If not provided, one will be generated for you. This ID is typically used for deduping - messages with the same IDs as previous events may be dropped.- See Also:
- Common Fields
-
messageId
public V messageId(java.lang.String messageId)
The Message ID is a unique identifier for each message. If not provided, one will be generated for you. This ID is typically used for deduping - messages with the same IDs as previous events may be dropped.- See Also:
- Common Fields
-
sentAt
public V sentAt(java.util.Date sentAt)
Set a sentAt for the event. By default, the current sentAt is used, but you may override it for historical import.- See Also:
- SentAt
-
timestamp
public V timestamp(java.util.Date timestamp)
Set a timestamp for the event. By default, the current timestamp is used, but you may override it for historical import.- See Also:
- Timestamp
-
context
public V context(java.util.Map<java.lang.String,?> context)
Set a map of information about the state of the device. You can add any custom data to the context dictionary that you'd like to have access to in the raw logs.Some keys in the context dictionary have semantic meaning and will be collected for you automatically, depending on the library you send data from. Some keys, such as location and speed need to be manually entered.
- See Also:
- Context
-
anonymousId
public V anonymousId(java.util.UUID anonymousId)
Deprecated.UseanonymousId(String)
instead.The Anonymous ID is a pseudo-unique substitute for a User ID, for cases when you don’t have an absolutely unique identifier.- See Also:
- Identities, Anonymous ID
-
anonymousId
public V anonymousId(java.lang.String anonymousId)
The Anonymous ID is a pseudo-unique substitute for a User ID, for cases when you don’t have an absolutely unique identifier.- See Also:
- Identities, Anonymous ID
-
userId
public V userId(java.lang.String userId)
The User ID is a persistent unique identifier for a user (such as a database ID).- See Also:
- Identities, User ID
-
enableIntegration
public V enableIntegration(java.lang.String key, boolean enable)
Set whether this message is sent to the specified integration or not. 'All' is a special key that applies when no key for a specific integration is found.- See Also:
- Integrations
-
integrationOptions
public V integrationOptions(java.lang.String key, java.util.Map<java.lang.String,?> options)
Pass in some options that will only be used by the target integration. This will implicitly mark the integration as enabled.- See Also:
- Integrations
-
realBuild
protected abstract T realBuild(Message.Type type, java.lang.String messageId, java.util.Date sentAt, java.util.Date timestamp, java.util.Map<java.lang.String,?> context, java.lang.String anonymousId, java.lang.String userId, java.util.Map<java.lang.String,java.lang.Object> integrations)
-
build
public T build()
Create aMessage
instance.- Throws:
java.lang.IllegalStateException
- if both anonymousId and userId are not provided.
-
type
public Message.Type type()
Returns theMessage.Type
of the message this builder is constructing.
-
-