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
SCMSourceinstances within aSCMNavigator, i.e. aSCMNavigatorOwnerimplementation should make best effort to handle aSCMSourceEventofSCMEvent.Type.CREATEDwithout resorting toSCMNavigator.visitSources(SCMSourceObserver) - Creation of new
SCMHeadinstances within aSCMSource, i.e. aSCMSourceOwnerimplementation should make best effort to handle aSCMHeadEventofSCMEvent.Type.CREATEDwithout resorting toSCMSource.fetch(SCMHeadObserver, TaskListener)orSCMSource.fetch(SCMSourceCriteria, SCMHeadObserver, TaskListener) - The update of a
SCMHeadinstance to point to a newSCMRevision, i.e. aSCMHeadEventofSCMEvent.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
Nested ClassesModifier and TypeClassDescriptionprotected static classSCMEvent.Dispatcher<E extends SCMEvent<?>>static classstatic enumThe type of event. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionSCMEvent(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.protectedCopy 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 voidShutdown the timer and throw it away.Return a description of the event.booleanprotected static ScheduledExecutorServiceTheScheduledExecutorServicethat events should be fired on.getDate()Gets the timestamp of the event as aDate.static SCMEvent.EventQueueMetricsGets the origin of the event, e.g.Gets the provider specific event payload.longGets the timestamp of the event (seeSystem.currentTimeMillis()for start and units).getType()Gets the type of event.inthashCode()static StringoriginOf(jakarta.servlet.http.HttpServletRequest req) Helper method to get the origin of an event from aHttpServletRequest.static StringoriginOf(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 aHttpServletRequestand 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
TheScheduledExecutorServicethat 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_UNKNOWNif the origin is unknown) - Since:
- 2.0.3
-
description
Return a description of the event.- Returns:
- the description or
nullif 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. TheCauseinstances should probably be new instances each time, seeCause.onAddedTo(Run).- Returns:
- the
Causeinstances 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-Forheaders) separated by→followed by a⇒and finally the requested URL (omitting the query portion of the URL).- Parameters:
req- theHttpServletRequestornull(this is to allow passingStapler.getCurrentRequest2()without having to check fornull)- Returns:
- the origin of the event or
nullif theHttpServletRequestis 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)