Class Message<T extends Message>
- All Implemented Interfaces:
Serializable,Cloneable,Map<Object,Object>
- Direct Known Subclasses:
EventFilter,JobChannelMessage,SimpleMessage
PubsubBus message instance.
Light-weight messages
We purposely chose a very simpleProperties based extension for the message
type, so as to avoid marshal/unmarshal issues with more complex message type
(the PubsubBus implementation could be distributed). It is also hoped that
this approach will promote the use of very light-weight event messages that contain
"just enough" information as to allow ChannelSubscribers to decide if they
are interested in the event (or not). If they are interested in the event, they can
use standard Jenkins mechanisms to gain access to the full domain model object(s)
relating to the event.
Note that the use of lose typing is very intentional as complex types
are a notorious source of problems in distributed (the
default bus implementation is not distributed, but one could
implement one) asynchronous libraries. Also consider that this should not be a major
inconvenience if you stick with light-weight events i.e. sending complex/bloated events
is already considered as being an anti-pattern here.
Note the AccessControlledMessage subtype.
Event property namespaces
Event property names are opaqueStrings. Any String is valid, but
we do recommend using valid underscores to namespace e.g. "a_b_c".
This will help to avoid name collisions.
NOTE that the "jenkins" namespace prefix of reserved e.g. "jenkins_channel".
- Author:
- tom.fennelly@gmail.com
- See Also:
-
Nested Class Summary
-
Field Summary
Fields inherited from class java.util.Properties
defaults -
Method Summary
Modifier and TypeMethodDescriptionclone()Clone thisMessageinstance.booleancontainsAll(Properties properties) Does this message contain all of the properties supplied in the properties argument.Get the named message property value (by enum).Get the named message property value.Get the channel name for the message.Get the event name for the message.Get the event UUID for the message.Get the Jenkins instance identity of the controller from which the event was published.Get the Jenkins instance URL of the controller from which the event was published.protected StringGet the Jenkins domain model object Id that this message instance is associated with.protected StringGet the Jenkins domain model object name (full name) that this message instance is associated with.protected StringGet the Jenkins domain model object type that this message instance is associated with.Get the event timestamp for the message.Get the event timestamp for the message, as a long.Fluent property setter (by enum).Fluent property setter.setChannelName(String name) Set the channel name for the message.setEventName(Enum name) Set the event name for the message.setEventName(String name) Set the event name for the message.protected TsetItemProps(Item item) SetItempropertis on the message instance.Set the Jenkins instance identity of the controller from which the event was published.final StringtoJSON()Write the message properties to JSON.final voidWrite the message properties as JSON to aWriter.final StringtoString()Same astoJSON().Methods inherited from class java.util.Properties
clear, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, getProperty, getProperty, hashCode, isEmpty, keys, keySet, list, list, load, load, loadFromXML, merge, propertyNames, put, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, save, setProperty, size, store, store, storeToXML, storeToXML, storeToXML, stringPropertyNames, values
-
Method Details
-
getObjectName
Get the Jenkins domain model object name (full name) that this message instance is associated with.- Returns:
- The Jenkins domain model object name (full name) that this message instance is associated with.
- See Also:
-
getObjectType
Get the Jenkins domain model object type that this message instance is associated with.- Returns:
- The Jenkins domain model object type that this message instance is associated with.
- See Also:
-
getObjectId
Get the Jenkins domain model object Id that this message instance is associated with.- Returns:
- The Jenkins domain model object Id that this message instance is
associated with, or
nullif no id was set on this message instance. - See Also:
-
set
Fluent property setter.Same as
Properties.setProperty(String, String), but returnsthis. Also checks fornullname and value args.- Parameters:
name- Property name.value- Property value.- Returns:
thismessage instance.
-
set
Fluent property setter (by enum).- Parameters:
name- Property name enum.value- Property value.- Returns:
thismessage instance.
-
get
Get the named message property value.- Parameters:
name- Propery name.- Returns:
- The property value, or
nullif not defined.
-
get
Get the named message property value (by enum).- Parameters:
name- Propery name enum.- Returns:
- The property value, or
nullif not defined.
-
getChannelName
Get the channel name for the message.- Returns:
- The channel name for the message, or
nullif none set.
-
setChannelName
Set the channel name for the message.- Parameters:
name- The channel name for the message.
-
getEventName
Get the event name for the message.- Returns:
- The event name for the message, or
nullif none set.
-
setEventName
Set the event name for the message.- Parameters:
name- The event name for the message.
-
setEventName
Set the event name for the message.- Parameters:
name- The event name for the message.
-
getJenkinsInstanceUrl
Get the Jenkins instance URL of the controller from which the event was published.- Returns:
- The Jenkins instance identity.
- See Also:
-
getJenkinsInstanceId
Get the Jenkins instance identity of the controller from which the event was published.Note that this is not automatically added to every event since the identity key is quite large, adding a lot of weight to each event. To add the identity to all messages, simply implement a
MessageEnricherand use it to callsetJenkinsInstanceId().Maybe
getJenkinsInstanceUrl()will do the trick for you in terms of working out the origin of an event.- Returns:
- The Jenkins instance identity.
- See Also:
-
setJenkinsInstanceId
Set the Jenkins instance identity of the controller from which the event was published. -
getTimestamp
Get the event timestamp for the message.- Returns:
- The event timestamp for the message, or
nullif none set.
-
getTimestampMillis
Get the event timestamp for the message, as a long.- Returns:
- The event timestamp for the message, or
nullif none set.
-
getEventUUID
Get the event UUID for the message.- Returns:
- The event UUID for the message, or
nullif none set.
-
setItemProps
SetItempropertis on the message instance.- Parameters:
item- The JenkinsItem.
-
clone
Clone thisMessageinstance.Base implementation creates a
SimpleMessageinstance.- Overrides:
clonein classProperties- Returns:
- The clone.
-
containsAll
Does this message contain all of the properties supplied in the properties argument.- Parameters:
properties- The properties to check for.- Returns:
trueif this message contain all of the properties supplied in the properties argument, otherwisefalse.
-
toJSON
Write the message properties to JSON.- Returns:
- The message properties as a String.
-
toJSON
Write the message properties as JSON to aWriter.- Parameters:
writer- TheWriterinstance.- Throws:
IOException- Error writing to theWriter.
-
toString
Same astoJSON().- Overrides:
toStringin classProperties- Returns:
- The message properties as a JSON String.
-