org.axonframework.domain
Class ApplicationEvent

java.lang.Object
  extended by org.axonframework.domain.EventBase
      extended by org.axonframework.domain.ApplicationEvent
All Implemented Interfaces:
Serializable, Event
Direct Known Subclasses:
ScheduledEvent, SystemEvent

public abstract class ApplicationEvent
extends EventBase

Represents an event that does not represent a state change of an application but does have functional meaning to the application.

This implementation will maintain a loose reference to the source of the event. However, this source will not be serialized with the event. This means the source will not be available after deserialization. Instead, you can access the source type and source description.

Note: Do not confuse the type of reference used by this class with Java's weak reference. The reference maintained by this event will prevent the garbage collector from cleaning up the source instance. However, the reference will not survive serialization of the event.

Design consideration: Be cautious when using application events. Make sure you did not overlook an opportunity to use a domain event.

Since:
0.4
Author:
Allard Buijze
See Also:
DomainEvent, Serialized Form

Constructor Summary
protected ApplicationEvent(Object source)
          Initialize an application event with the given source.
 
Method Summary
 Object getSource()
          Returns the instance that reported this event.
 String getSourceDescription()
          Returns the description of the instance that reported this event.
 Class getSourceType()
          Returns the type of the instance that reported this event.
 
Methods inherited from class org.axonframework.domain.EventBase
addMetaData, equals, getEventIdentifier, getEventRevision, getMetaData, getMetaDataValue, getTimestamp, hashCode, setEventRevision
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ApplicationEvent

protected ApplicationEvent(Object source)
Initialize an application event with the given source. Source may be null. In that case, the source type and source description will be set to Object.class and [unknown source] respectively.

Parameters:
source - the instance that reported this event. If any.
Method Detail

getSource

public Object getSource()
Returns the instance that reported this event. Will return null if no source was specified or if this event has been serialized.

Returns:
the source of the event, if available.

getSourceType

public Class getSourceType()
Returns the type of the instance that reported this event. Unlike the source, this value will survive serialization. If the source was null, this method will return Object.class.

Returns:
the type of the instance that reported this event

getSourceDescription

public String getSourceDescription()
Returns the description of the instance that reported this event. The description is set to the value returned by source.toString(). Unlike the source itself, this value will survive serialization. If the source was null, this method will return [unknown source].

Returns:
the description of the instance that reported this event


Copyright © 2011. All Rights Reserved.