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
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.
package org.axonframework.eventsourcing;
Implementation of a snapshotter that uses the actual aggregate and its state to create a snapshot event. The motivation is that an aggregate always contains all relevant state. Therefore, storing the aggregate itself inside an event should capture all necessary information.

Allard Buijze
public class AggregateSnapshotter extends AbstractSnapshotter {
    protected DomainEvent createSnapshot(String typeIdentifierDomainEventStream eventStream) {
        AggregateFactory<?> aggregateFactory = .get(typeIdentifier);
        DomainEvent firstEvent = eventStream.peek();
        AggregateIdentifier aggregateIdentifier = firstEvent.getAggregateIdentifier();
        EventSourcedAggregateRoot aggregate;
        if (firstEvent instanceof AggregateSnapshot) {
            aggregate = ((AggregateSnapshotfirstEvent).getAggregate();
        } else {
            aggregate = aggregateFactory.createAggregate(aggregateIdentifierfirstEvent);
        return new AggregateSnapshot<EventSourcedAggregateRoot>(aggregate);

Sets the aggregate factory to use. The aggregate factory is responsible for creating the aggregates that should be stored within the AggegateSnapshots.

aggregateFactories The list of aggregate factories creating the aggregates to store. May not be null or contain any null values.
java.lang.NullPointerException if aggregateFactories is null or if contains any null values.
    public void setAggregateFactories(List<AggregateFactory<?>> aggregateFactories) {
        for (AggregateFactory<?> factory : aggregateFactories) {
            this..put(factory.getTypeIdentifier(), factory);
New to GrepCode? Check out our FAQ X