MotechEvent

public class MotechEvent implements Serializable

Motech Scheduled Event data carrier class. It contains a subject, to which listeners can subscribe and a payload in the form of a map of parameters. Instance of this class with event specific data will be sent by Motech Scheduler when a scheduled event is fired.

This class is immutable

Constructors

MotechEvent

public MotechEvent()

MotechEvent

public MotechEvent(String subject)

Constructs a MotechEvent with the given subject.

Parameters:
  • subject – the subject of the event
Throws:
  • IllegalArgumentException – if the subject is null or contains '*', '..'

MotechEvent

public MotechEvent(String subject, Map<String, Object> parameters)

Constructs a MotechEvent with the given subject and parameters.

Parameters:
  • subject – the subject of the event
  • parameters – the map of additional parameters
Throws:
  • IllegalArgumentException – if the subject is null or contains '*', '..'

MotechEvent

public MotechEvent(String subject, Map<String, Object> parameters, String callbackName)

Constructs a MotechEvent with the given subject, parameters and the callback name.

Parameters:
  • subject – the subject of the event
  • parameters – the map of additional parameters
  • callbackName – the name of the callback
Throws:
  • IllegalArgumentException – if the subject is null or contains '*', '..'

MotechEvent

public MotechEvent(String subject, Map<String, Object> parameters, String callbackName, Map<String, Object> metadata)

Constructs a MotechEvent with the given subject, parameters and the callback name.

Parameters:
  • subject – the subject of the event
  • parameters – the map of additional parameters
  • callbackName – the name of the callback
  • metadata – the map of event metadata
Throws:
  • IllegalArgumentException – if the subject is null or contains '*', '..'

Methods

equals

public boolean equals(Object o)

getCallbackName

public String getCallbackName()

Returns the name of the callback to invoke after this event is handled

Returns:callback name

getId

public UUID getId()

Returns the universally unique identifier

Returns:the id

getMessageDestination

public String getMessageDestination()

Returns the id of the Motech listener that this event is meant for

Returns:message destination

getMessageRedeliveryCount

public int getMessageRedeliveryCount()

Returns the redeliveryCount. This is incremented by the event system if the delivery fails, so it is equal to the number of failed deliveries. Any exception from the handler is counted as failure in this context. It cannot be larger than org.motechproject.event.messaging.MotechEventConfig.messageMaxRedeliveryCount

Returns:the number of message redeliveries

getMetadata

public Map<String, Object> getMetadata()

Returns the metadata of this MotechEvent. It can store any additional data, that is not meant to be the event’s payload. If null, returns empty HashMap.

Returns:the map of metadata

getParameters

public Map<String, Object> getParameters()

Returns the parameters, if null returns empty HashMap.

Returns:the map of the parameters

getSubject

public String getSubject()

Returns the name of the subject.

Returns:the subject

hashCode

public int hashCode()

incrementMessageRedeliveryCount

public void incrementMessageRedeliveryCount()

Increments the redeliveryCount. It is invoked by the event system if the delivery fails. If it is null, sets the value to 0.

isBroadcast

public boolean isBroadcast()

Returns whether event is a broadcast event

Returns:broadcast

isDiscarded

public boolean isDiscarded()

Returns whether event is discarded

Returns:event discarded

isInvalid

public boolean isInvalid()

Returns whether event is invalid

Returns:event invalid

setBroadcast

public void setBroadcast(boolean value)

Sets event as a broadcast event

Parameters:
  • value

setCallbackName

public void setCallbackName(String callbackName)

Sets the name of the callback to invoke after this event is handled

Parameters:
  • callbackName

setDiscarded

public void setDiscarded(boolean value)

Sets event as discarded

Parameters:
  • value

setId

public void setId(UUID id)

Sets the id.

Parameters:
  • id – the universally unique identifier

setInvalid

public void setInvalid(boolean value)

Sets event as a invalid

Parameters:
  • value

setMessageDestination

public void setMessageDestination(String value)

Sets the id of the Motech listener that this event is meant for

Parameters:
  • value

setMessageRedeliveryCount

public void setMessageRedeliveryCount(int value)

setMetadata

public void setMetadata(Map<String, Object> metadata)

Sets the metadata of this MotechEvent. It can store any additional data, that is not meant to be the event’s payload.

Parameters:
  • metadata – the metadata map

toString

public String toString()