Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 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.eventsourcing;
 
 
Abstract implementation of the Snapshotter that uses a task executor to creates snapshots. Actual snapshot creation logic should be provided by a subclass.

By default, this implementations uses a org.axonframework.util.DirectExecutor to process snapshot taking tasks. In production environments, it is recommended to use asynchronous executors instead.

Author(s):
Allard Buijze
Since:
0.6
 
 public abstract class AbstractSnapshotter implements Snapshotter {
 
     private SnapshotEventStore eventStore;
     private Executor executor = .;
 
     @Override
     public void scheduleSnapshot(String typeIdentifierAggregateIdentifier aggregateIdentifier) {
         .execute(createSnapshotterTask(typeIdentifieraggregateIdentifier));
     }

    
Creates an instance of a task that contains the actual snapshot creation logic.

Parameters:
typeIdentifier The type of the aggregate to create a snapshot for
aggregateIdentifier The identifier of the aggregate to create a snapshot for
Returns:
the task containing snapshot creation logic
 
     protected Runnable createSnapshotterTask(String typeIdentifierAggregateIdentifier aggregateIdentifier) {
         return new CreateSnapshotTask(typeIdentifieraggregateIdentifier);
     }

    
Creates a snapshot event for an aggregate of the given typeIdentifier of which passed events are available in the given eventStream. May return null to indicate a snapshot event is not necessary or appropriate for the given event stream.

Parameters:
typeIdentifier The aggregate's type identifier
eventStream The event stream containing the aggregate's past events
Returns:
the snapshot event for the given events, or null if none should be stored.
 
     protected abstract DomainEvent createSnapshot(String typeIdentifierDomainEventStream eventStream);
 
     private final class CreateSnapshotTask implements Runnable {
 
         private final String typeIdentifier;
         private final AggregateIdentifier aggregateIdentifier;
 
         private CreateSnapshotTask(String typeIdentifierAggregateIdentifier aggregateIdentifier) {
             this. = typeIdentifier;
             this. = aggregateIdentifier;
         }
 
         @Override
         public void run() {
             DomainEventStream eventStream = .readEvents();
             DomainEvent snapshotEvent = createSnapshot(eventStream);
             if (snapshotEvent != null) {
                 .appendSnapshotEvent(snapshotEvent);
             }
         }
     }

    
Sets the event store where the snapshotter can load domain events and store its snapshot events.

Parameters:
eventStore the event store to use
 
     @Resource
     public void setEventStore(SnapshotEventStore eventStore) {
         this. = eventStore;
     }

    
Sets the executor that should process actual snapshot taking. Defaults to a single threaded (asynchronous) executor.

Parameters:
executor the executor to execute snapshotting tasks
    @Resource
    public void setExecutor(Executor executor) {
        this. = executor;
    }

    
Returns the event store this snapshotter uses to load domain events and store snapshot events.

Returns:
the event store this snapshotter uses to load domain events and store snapshot events.
    protected SnapshotEventStore getEventStore() {
        return ;
    }

    
Returns the executor that executes snapshot taking tasks.

Returns:
the executor that executes snapshot taking tasks.
    protected Executor getExecutor() {
        return ;
    }
New to GrepCode? Check out our FAQ X