View Javadoc

1   package org.modeshape.repository.sequencer;
2   
3   import net.jcip.annotations.NotThreadSafe;
4   import org.modeshape.graph.ExecutionContext;
5   import org.modeshape.graph.Graph;
6   import org.modeshape.graph.io.Destination;
7   import org.modeshape.graph.io.GraphBatchDestination;
8   import org.modeshape.graph.property.DateTime;
9   
10  /**
11   * The sequencer context represents the complete context of a sequencer invocation, including the execution context (which
12   * contains JAAS credentials, namespace mappings, and value factories) and the I/O environment for writing output.
13   * <p>
14   * This class is not thread safe due to its use of {@link Destination a destination}.
15   * </p>
16   */
17  @NotThreadSafe
18  public class SequencerContext {
19  
20      private final ExecutionContext executionContext;
21      private final Graph sourceGraph;
22      private final Graph destinationGraph;
23      private final Destination destination;
24      private final DateTime timestamp;
25  
26      public SequencerContext( ExecutionContext executionContext,
27                               Graph sourceGraph,
28                               Graph outputGraph,
29                               DateTime timestamp ) {
30          super();
31  
32          assert executionContext != null;
33          assert sourceGraph != null;
34          assert timestamp != null;
35  
36          this.executionContext = executionContext;
37          this.sourceGraph = sourceGraph;
38          this.destinationGraph = outputGraph != null ? outputGraph : sourceGraph;
39          this.destination = new GraphBatchDestination(destinationGraph.batch());
40          this.timestamp = timestamp;
41      }
42  
43      /**
44       * Returns the execution context under which this sequencer context operates
45       * 
46       * @return the execution context under which this sequencer context operates
47       */
48      public ExecutionContext getExecutionContext() {
49          return executionContext;
50      }
51  
52      /**
53       * Get the timestamp of the sequencing. This is always the timestamp of the change event that is being processed.
54       * 
55       * @return timestamp the "current" timestamp; never null
56       */
57      public DateTime getTimestamp() {
58          return timestamp;
59      }
60  
61      /**
62       * Returns the I/O environment in which this sequencer context operates
63       * 
64       * @return the I/O environment in which this sequencer context operates
65       */
66      public Destination getDestination() {
67          return destination;
68      }
69  
70      Graph graph() {
71          return this.sourceGraph;
72      }
73  
74      Graph destinationGraph() {
75          return destinationGraph;
76      }
77  
78  }