Class SCMEvent<P>
- Type Parameters:
P
- the type of (provider specific) payload.
- Direct Known Subclasses:
SCMHeadEvent
,SCMNavigatorEvent
,SCMSourceEvent
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
and
SCMSourceOwner
, 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
and
SCMSource
, 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
Modifier and TypeClassDescriptionprotected static class
SCMEvent.Dispatcher<E extends SCMEvent<?>>
static class
static enum
The type of event. -
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionSCMEvent
(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
Copy constructor which may be required in cases where sub-classes need to implementreadResolve
-
Method Summary
Modifier and TypeMethodDescriptionCause[]
asCauses()
If this event is being used to trigger a build, what - if any - Causes should be added to the triggered build.static void
Shutdown the timer and throw it away.Return a description of the event.boolean
protected static ScheduledExecutorService
TheScheduledExecutorService
that events should be fired on.getDate()
Gets the timestamp of the event as aDate
.static SCMEvent.EventQueueMetrics
Gets the origin of the event, e.g.Gets the provider specific event payload.long
Gets the timestamp of the event (seeSystem.currentTimeMillis()
for start and units).getType()
Gets the type of event.int
hashCode()
static String
originOf
(jakarta.servlet.http.HttpServletRequest req) Helper method to get the origin of an event from aHttpServletRequest
.static String
originOf
(javax.servlet.http.HttpServletRequest req) Deprecated.toString()
-
Field Details
-
ORIGIN_UNKNOWN
An unknown origin.- Since:
- 2.0.3
- See Also:
-
-
Constructor Details
-
SCMEvent
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.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
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
-
SCMEvent
Copy constructor which may be required in cases where sub-classes need to implementreadResolve
- Parameters:
copy
- the event to clone.
-
-
Method Details
-
executorService
TheScheduledExecutorService
that events should be fired on.- Returns:
- a
ScheduledExecutorService
.
-
getEventProcessingMetrics
-
closeExecutorService
Shutdown the timer and throw it away. -
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
Gets the timestamp of the event as aDate
.- Returns:
- the timestamp of the event.
-
getPayload
Gets the provider specific event payload.- Returns:
- the provider specific event payload.
-
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
Return a description of the event.- Returns:
- the description or
null
if no description can be provided. - Since:
- 2.1.1
-
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.
-
equals
-
hashCode
public int hashCode() -
toString
-
originOf
@CheckForNull public static String originOf(@CheckForNull jakarta.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.getCurrentRequest2()
without having to check fornull
)- Returns:
- the origin of the event or
null
if theHttpServletRequest
is null. - Since:
- TODO
-
originOf
@CheckForNull @Deprecated public static String originOf(@CheckForNull javax.servlet.http.HttpServletRequest req) Deprecated.- Since:
- 2.0.3
-
SCMEvent(Type, long, Object, String)