Class SCMEvent<P>
- java.lang.Object
-
- jenkins.scm.api.SCMEvent<P>
-
- Type Parameters:
P
- the type of (provider specific) payload.
- Direct Known Subclasses:
SCMHeadEvent
,SCMNavigatorEvent
,SCMSourceEvent
public abstract class SCMEvent<P> extends Object
Base class for all events from a SCM system.NOTE: Not every SCM system will be able to support all possible events. Not every plugin building on top of the SCM API will be able to respond to every event.
Information for SCM API consumers
Consumers of events should assume that the data from an event is unverified / untrusted. Events should be used to scope queries against the
SCMNavigator
/SCMSource
to which they relate. In all other respects, consumers should treat the event payload and information derived from the payload as being just a rumour.NOTE: Implementations may retain their own internal tracking of portions of the event payload that are verified / trusted and use such internal information to assist in optimization of the processing of scoped queried, but at this time we are not exposing such partial trust information to consumers until we have established some patterns.
The priority for consumers of the SCM API, in other words, implementations of
SCMNavigatorOwner
andSCMSourceOwner
, is to avoid full rescans as a means of detecting:- Creation of new
SCMSource
instances within aSCMNavigator
, i.e. aSCMNavigatorOwner
implementation should make best effort to handle aSCMSourceEvent
ofSCMEvent.Type.CREATED
without resorting toSCMNavigator.visitSources(SCMSourceObserver)
- Creation of new
SCMHead
instances within aSCMSource
, i.e. aSCMSourceOwner
implementation should make best effort to handle aSCMHeadEvent
ofSCMEvent.Type.CREATED
without resorting toSCMSource.fetch(SCMHeadObserver, TaskListener)
orSCMSource.fetch(SCMSourceCriteria, SCMHeadObserver, TaskListener)
- The update of a
SCMHead
instance to point to a newSCMRevision
, i.e. aSCMHeadEvent
ofSCMEvent.Type.UPDATED
. NOTE: typically existing legacy SCM implementations will handle this out-of-band, but it would be nice if the notification could be consolidated.
Information for SCM API providers
The priority for implementers of the SCM API, in other words, implementations of
SCMNavigator
andSCMSource
, is to ensure that consumers do not have to trigger full rescans.Where implementers can obtain some form of trust / verification about event payloads, please share your patterns with the maintainers of this API so that a generic set of patterns can be abstracted for exposure to consumers.
- Since:
- 2.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
SCMEvent.Dispatcher<E extends SCMEvent<?>>
static class
SCMEvent.EventQueueMetrics
static class
SCMEvent.Type
The type of event.
-
Field Summary
Fields Modifier and Type Field Description static String
ORIGIN_UNKNOWN
An unknown origin.
-
Constructor Summary
Constructors Modifier Constructor Description SCMEvent(SCMEvent.Type type, long timestamp, P payload)
Deprecated.SCMEvent(SCMEvent.Type type, long timestamp, P payload, String origin)
Constructor to use when the timestamp is available from the external SCM.SCMEvent(SCMEvent.Type type, P payload)
Deprecated.SCMEvent(SCMEvent.Type type, P payload, String origin)
Constructor to use when the timestamp is not available from the external SCM.protected
SCMEvent(SCMEvent<P> copy)
Copy constructor which may be required in cases where sub-classes need to implementreadResolve
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Cause[]
asCauses()
If this event is being used to trigger a build, what - if any - Causes should be added to the triggered build.static void
closeExecutorService()
Shutdown the timer and throw it away.String
description()
Return a description of the event.boolean
equals(Object o)
protected static ScheduledExecutorService
executorService()
TheScheduledExecutorService
that events should be fired on.Date
getDate()
Gets the timestamp of the event as aDate
.static SCMEvent.EventQueueMetrics
getEventProcessingMetrics()
String
getOrigin()
Gets the origin of the event, e.g.P
getPayload()
Gets the provider specific event payload.long
getTimestamp()
Gets the timestamp of the event (seeSystem.currentTimeMillis()
for start and units).SCMEvent.Type
getType()
Gets the type of event.int
hashCode()
static String
originOf(javax.servlet.http.HttpServletRequest req)
Helper method to get the origin of an event from aHttpServletRequest
.String
toString()
-
-
-
Field Detail
-
ORIGIN_UNKNOWN
public static final String ORIGIN_UNKNOWN
An unknown origin.- Since:
- 2.0.3
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SCMEvent
@Deprecated public SCMEvent(@NonNull SCMEvent.Type type, long timestamp, @NonNull P payload)
Deprecated.Constructor to use when the timestamp is available from the external SCM.- Parameters:
type
- the type of event.timestamp
- the timestamp from the external SCM (seeSystem.currentTimeMillis()
for start and units)payload
- the original provider specific payload.
-
SCMEvent
public SCMEvent(@NonNull SCMEvent.Type type, long timestamp, @NonNull P payload, @CheckForNull String origin)
Constructor to use when the timestamp is available from the external SCM.- Parameters:
type
- the type of event.timestamp
- the timestamp from the external SCM (seeSystem.currentTimeMillis()
for start and units)payload
- the original provider specific payload.origin
- the (optional) origin of the event, e.g. a hostname, etc. It is recommended to useoriginOf(HttpServletRequest)
where the event originates from aHttpServletRequest
and the request is available when the event is being created.- Since:
- 2.0.3
-
SCMEvent
@Deprecated public SCMEvent(@NonNull SCMEvent.Type type, @NonNull P payload)
Deprecated.Constructor to use when the timestamp is not available from the external SCM. The timestamp will be set usingSystem.currentTimeMillis()
- Parameters:
type
- the type of event.payload
- the original provider specific payload.
-
SCMEvent
public SCMEvent(@NonNull SCMEvent.Type type, @NonNull P payload, @CheckForNull String origin)
Constructor to use when the timestamp is not available from the external SCM. The timestamp will be set usingSystem.currentTimeMillis()
- Parameters:
type
- the type of event.payload
- the original provider specific payload.origin
- the (optional) origin of the event, e.g. a hostname, etc- Since:
- 2.0.3
-
-
Method Detail
-
executorService
@NonNull protected static ScheduledExecutorService executorService()
TheScheduledExecutorService
that events should be fired on.- Returns:
- a
ScheduledExecutorService
.
-
getEventProcessingMetrics
public static SCMEvent.EventQueueMetrics getEventProcessingMetrics()
-
closeExecutorService
@Terminator public static void closeExecutorService()
Shutdown the timer and throw it away.
-
getType
@NonNull public SCMEvent.Type getType()
Gets the type of event.- Returns:
- the type of event.
-
getTimestamp
public long getTimestamp()
Gets the timestamp of the event (seeSystem.currentTimeMillis()
for start and units).- Returns:
- the timestamp of the event.
-
getDate
@NonNull public Date getDate()
Gets the timestamp of the event as aDate
.- Returns:
- the timestamp of the event.
-
getPayload
@NonNull public P getPayload()
Gets the provider specific event payload.- Returns:
- the provider specific event payload.
-
getOrigin
@NonNull public String getOrigin()
Gets the origin of the event, e.g. a hostname, etc.- Returns:
- the origin of the event (or
ORIGIN_UNKNOWN
if the origin is unknown) - Since:
- 2.0.3
-
description
@CheckForNull public String description()
Return a description of the event.- Returns:
- the description or
null
if no description can be provided. - Since:
- 2.1.1
-
asCauses
@NonNull public Cause[] asCauses()
If this event is being used to trigger a build, what - if any - Causes should be added to the triggered build. TheCause
instances should probably be new instances each time, seeCause.onAddedTo(Run)
.- Returns:
- the
Cause
instances to add to any builds triggered by this event.
-
originOf
@CheckForNull public static String originOf(@CheckForNull javax.servlet.http.HttpServletRequest req)
Helper method to get the origin of an event from aHttpServletRequest
. The current format is the list of hostname / ip addresses from the request (parsingX-Forwarded-For
headers) separated by→
followed by a⇒
and finally the requested URL (omitting the query portion of the URL).- Parameters:
req
- theHttpServletRequest
ornull
(this is to allow passingStapler.getCurrentRequest()
without having to check fornull
)- Returns:
- the origin of the event or
null
if theHttpServletRequest
is null. - Since:
- 2.0.3
-
-