Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2010-2011. Axon Framework
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.axonframework.domain;
 
Base class for all Domain Events. This class contains the basic behavior expected from any event to be processed by event sourcing engines and aggregates.

Author(s):
Allard Buijze
Since:
0.1
 
 public abstract class DomainEvent extends EventBase {
 
     private static final long serialVersionUID = 8449341313771775173L;
 
     private volatile Long sequenceNumber;
     private volatile AggregateIdentifier aggregateIdentifier;

    
Initialize the domain event. Will set the current time stamp and generate a random event identifier. Use this constructor when using the org.axonframework.eventsourcing.AbstractEventSourcedAggregateRoot.apply(org.axonframework.domain.DomainEvent) method. The sequenceNumber and aggregateIdentifier are automatically set to the correct values for that aggregate.

This constructor sets the event revision to 0. When a structural change is made to an event type, the eventRevision should be changed by invoking the DomainEvent(long).

If you do not use the org.axonframework.eventsourcing.AbstractEventSourcedAggregateRoot.apply(org.axonframework.domain.DomainEvent) method, but need the sequenceNumber and aggregateIdentifier to be set to specific values, use the DomainEvent(long,org.axonframework.domain.AggregateIdentifier) constructor.

 
     protected DomainEvent() {
         super();
     }

    
Initialize the domain event using the given eventRevision. The event revision allows Event Serializers to detect which upcasters it needs to run when deserializing. Each time a structural change is made to an event type, the eventRevision should be changed accordingly.

Will set the current time stamp and generate a random event identifier. Use this constructor when using the org.axonframework.eventsourcing.AbstractEventSourcedAggregateRoot.apply(org.axonframework.domain.DomainEvent) method. The sequenceNumber and aggregateIdentifier are automatically set to the correct values for that aggregate.

If you do not use the org.axonframework.eventsourcing.AbstractEventSourcedAggregateRoot.apply(org.axonframework.domain.DomainEvent) method, but need the sequenceNumber and aggregateIdentifier to be set to specific values, use the DomainEvent(long,org.axonframework.domain.AggregateIdentifier) constructor.

Parameters:
eventRevision The revision number of this event type
 
     protected DomainEvent(long eventRevision) {
         super(eventRevision);
     }

    
Initialize the domain event. Will set the current time stamp and generate a random event identifier. Use this constructor when you need the sequenceNumber and aggregateIdentifier to be set to specific values.

Two use cases for this constructor are

  • the generation of events when not using event sourcing
  • the generation of snapshot events.

When creating a DomainEvent using this constructor, all calls to setAggregateIdentifier(org.axonframework.domain.AggregateIdentifier) and setSequenceNumber(long) will result in an exception.

Parameters:
sequenceNumber The sequence number to assign to this event
aggregateIdentifier The identifier of the aggregate this event applies to
 
     protected DomainEvent(long sequenceNumberAggregateIdentifier aggregateIdentifier) {
         super();
         this. = sequenceNumber;
         this. = aggregateIdentifier;
     }

    
Initialize the domain event using given parameters. This constructor is intended for reconstruction of events (e.g. by deserialization).

Parameters:
eventIdentifier The event's unique identifier
creationTimeStamp The creation timestamp
eventRevision The revision of the event type
sequenceNumber The sequence number
aggregateIdentifier The identifier of the aggregate that generated this event
    protected DomainEvent(String eventIdentifierDateTime creationTimeStamplong eventRevisionlong sequenceNumber,
                          AggregateIdentifier aggregateIdentifier) {
        super(eventIdentifiercreationTimeStampeventRevision);
        this. = sequenceNumber;
        this. = aggregateIdentifier;
    }

    
Returns the sequence number of this event, if available. Will return null if this event has not been added to an EventContainer.

Returns:
the sequence number of this event, or null if unknown.
    public Long getSequenceNumber() {
        return ;
    }

    
Returns the version number of the aggregate generating this event. This method returns the same value as getSequenceNumber() and is solely provided to provide a clear meaning to the returned value.

Returns:
the version number of the aggregate generating this event.
    public Long getAggregateVersion() {
        return getSequenceNumber();
    }

    
Returns the identifier of the aggregate that reported this event.

Returns:
the identifier of the aggregate that reported this event
        return ;
    }

    
Sets the sequence number of this event. May only be set once.

Parameters:
sequenceNumber the sequence number to assign to this event
Throws:
java.lang.IllegalStateException if a sequence number was already assigned
    void setSequenceNumber(long sequenceNumber) {
        if (this. != null) {
            throw new IllegalStateException("Sequence number may not be applied more than once.");
        }
        this. = sequenceNumber;
    }

    
Sets the aggregate identifier. May only be set once.

Parameters:
aggregateIdentifier the aggregate identifier
Throws:
java.lang.IllegalStateException if an aggregate identifier was already assigned
    void setAggregateIdentifier(AggregateIdentifier aggregateIdentifier) {
        if (this. != null) {
            throw new IllegalStateException("An aggregateIdentifier can not be applied more than once.");
        }
        this. = aggregateIdentifier;
    }

    
Checks for equality of two events. Two events are equal when they have the same type, aggregate identifier, time stamp and sequence number. This allows to test for equality after one or more instances have been serialized and deserialized.

Parameters:
o the other DomainEvent
Returns:
true when equals, otherwise false
    @SuppressWarnings({"RedundantIfStatement"})
    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        if (!super.equals(o)) {
            return false;
        }
        DomainEvent that = (DomainEvento;
        if ( != null
                ? !.equals(that.aggregateIdentifier)
                : that.aggregateIdentifier != null) {
            return false;
        }
        if ( != null ? !.equals(that.sequenceNumber) : that.sequenceNumber != null) {
            return false;
        }
        return true;
    }

    
    @Override
    public int hashCode() {
        return getEventIdentifier().hashCode();
    }
New to GrepCode? Check out our FAQ X