public abstract class Message<T extends Message> extends Properties
PubsubBus message instance.
Properties 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.
Strings. 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".
defaults| Modifier and Type | Method and Description |
|---|---|
Message |
clone()
Clone this
Message instance. |
boolean |
containsAll(Properties properties)
Does this message contain all of the properties supplied in the properties
argument.
|
String |
get(Enum name)
Get the named message property value (by enum).
|
String |
get(String name)
Get the named message property value.
|
String |
getChannelName()
Get the channel name for the message.
|
String |
getEventName()
Get the event name for the message.
|
String |
getEventUUID()
Get the event UUID for the message.
|
String |
getJenkinsInstanceId()
Get the Jenkins instance identity of the master from which the event was published.
|
String |
getJenkinsInstanceUrl()
Get the Jenkins instance URL of the master from which the event was published.
|
protected String |
getObjectId()
Get the Jenkins domain model object Id that this message instance is
associated with.
|
protected String |
getObjectName()
Get the Jenkins domain model object name (full name) that this message instance is
associated with.
|
protected String |
getObjectType()
Get the Jenkins domain model object type that this message instance is
associated with.
|
String |
getTimestamp()
Get the event timestamp for the message.
|
Long |
getTimestampMillis()
Get the event timestamp for the message, as a long.
|
T |
set(Enum name,
String value)
Fluent property setter (by enum).
|
T |
set(String name,
String value)
Fluent property setter.
|
T |
setChannelName(String name)
Set the channel name for the message.
|
T |
setEventName(Enum name)
Set the event name for the message.
|
T |
setEventName(String name)
Set the event name for the message.
|
protected T |
setItemProps(hudson.model.Item item)
Set
Item propertis on the message instance. |
T |
setJenkinsInstanceId()
Set the Jenkins instance identity of the master from which the event was published.
|
String |
toJSON()
Write the message properties to JSON.
|
void |
toJSON(Writer writer)
Write the message properties as JSON to a
Writer. |
String |
toString()
Same as
toJSON(). |
getProperty, getProperty, list, list, load, load, loadFromXML, propertyNames, save, setProperty, store, store, storeToXML, storeToXML, stringPropertyNamesclear, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keys, keySet, merge, put, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, size, values@CheckForNull protected String getObjectName()
EventProps.Jenkins.jenkins_object_name@CheckForNull protected String getObjectType()
EventProps.Jenkins.jenkins_object_type@CheckForNull protected String getObjectId()
null if no id was set on this message instance.EventProps.Jenkins.jenkins_object_idpublic T set(String name, String value)
Same as Properties.setProperty(String, String), but returns this.
Also checks for null name and value args.
name - Property name.value - Property value.this message instance.public T set(Enum name, String value)
name - Property name enum.value - Property value.this message instance.public String get(String name)
name - Propery name.null if not defined.public String get(Enum name)
name - Propery name enum.null if not defined.public String getChannelName()
null if none set.public T setChannelName(String name)
name - The channel name for the message.public String getEventName()
null if none set.public T setEventName(String name)
name - The event name for the message.public T setEventName(Enum name)
name - The event name for the message.public String getJenkinsInstanceUrl()
getJenkinsInstanceId()public String getJenkinsInstanceId()
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 MessageEnricher and use it to call
setJenkinsInstanceId().
Maybe getJenkinsInstanceUrl() will do the trick for you
in terms of working out the origin of an event.
getJenkinsInstanceUrl()public T setJenkinsInstanceId()
public String getTimestamp()
null if none set.public Long getTimestampMillis()
null if none set.public String getEventUUID()
null if none set.protected T setItemProps(@Nonnull hudson.model.Item item)
Item propertis on the message instance.item - The Jenkins Item.public Message clone()
Message instance.
Base implementation creates a SimpleMessage instance.
public boolean containsAll(@Nonnull Properties properties)
properties - The properties to check for.true if this message contain all of the properties supplied in the properties
argument, otherwise false.@Nonnull public final String toJSON()
public final void toJSON(@Nonnull Writer writer) throws IOException
Writer.writer - The Writer instance.IOException - Error writing to the Writer.Copyright © 2016–2019. All rights reserved.