001 /*
002 * JBoss DNA (http://www.jboss.org/dna)
003 * See the COPYRIGHT.txt file distributed with this work for information
004 * regarding copyright ownership. Some portions may be licensed
005 * to Red Hat, Inc. under one or more contributor license agreements.
006 * See the AUTHORS.txt file in the distribution for a full listing of
007 * individual contributors.
008 *
009 * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
010 * is licensed to you under the terms of the GNU Lesser General Public License as
011 * published by the Free Software Foundation; either version 2.1 of
012 * the License, or (at your option) any later version.
013 *
014 * JBoss DNA is distributed in the hope that it will be useful,
015 * but WITHOUT ANY WARRANTY; without even the implied warranty of
016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017 * Lesser General Public License for more details.
018 *
019 * You should have received a copy of the GNU Lesser General Public
020 * License along with this software; if not, write to the Free
021 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
022 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
023 */
024 package org.jboss.dna.repository.sequencer;
025
026 import java.util.Set;
027 import net.jcip.annotations.ThreadSafe;
028 import org.jboss.dna.common.collection.Problems;
029 import org.jboss.dna.common.component.Component;
030 import org.jboss.dna.graph.Node;
031 import org.jboss.dna.graph.io.Destination;
032 import org.jboss.dna.graph.observe.Observer;
033 import org.jboss.dna.graph.observe.NetChangeObserver.NetChange;
034 import org.jboss.dna.repository.RepositoryLibrary;
035 import org.jboss.dna.repository.util.RepositoryNodePath;
036
037 /**
038 * The interface for a DNA sequencer, which sequences nodes and their content to extract additional information from the
039 * information.
040 * <p>
041 * Implementations must provide a no-argument constructor.
042 * </p>
043 *
044 * @author Randall Hauch
045 * @author John Verhaeg
046 */
047 @ThreadSafe
048 public interface Sequencer extends Component<SequencerConfig> {
049
050 /**
051 * Execute the sequencing operation on the supplied node, which has recently been created or changed. The implementation of
052 * this method is responsible for modifying the appropriate nodes and {@link Destination#submit() saving} any changes made by
053 * this sequencer, and closing any other acquired resources, even in the case of exceptions.
054 * <p>
055 * The {@link SequencingService} determines the sequencers that should be executed by monitoring the changes to one or more
056 * workspaces (it registers an {@link Observer} with the {@link RepositoryLibrary}). Changes in those workspaces are
057 * aggregated for each transaction, and organized into {@link NetChange changes for each node}. The SequencingService then
058 * determines for each {@link NetChange set of changes to a node} the set of full paths to the properties that have changed
059 * and whether those paths {@link SequencerPathExpression#matcher(String) match} the sequencer's
060 * {@link SequencerConfig#getPathExpressions() path expressions}. Each path expression produces the path to the output node,
061 * and these output paths are accumulated and (with the original node that changed, the node change summary, and other
062 * information) supplied to the sequencer via this method.
063 * <p>
064 * It is possible that a sequencer is configured to apply to multiple properties on a node. So, in cases where multiple
065 * properties are changed on a single node (within a single repository transaction), the sequencer will only be executed once.
066 * Also, in such cases the sequencer's configuration may imply multiple output nodes, so it is left to the sequencer to define
067 * the behavior in such cases.
068 * </p>
069 *
070 * @param input the node that has recently been created or changed; never null
071 * @param sequencedPropertyName the name of the property that caused this sequencer to be executed; never null and never empty
072 * @param changes the immutable summary of changes that occurred on the <code>input</code> node within the transaction; never
073 * null
074 * @param outputPaths the paths to the nodes where the sequencing content should be placed; never null and never empty, but
075 * the set may contain paths for non-existent nodes or may reference the <code>input</code> node
076 * @param context the context in which this sequencer is executing; never null
077 * @param problems the interface used for recording problems; never null
078 * @throws SequencerException if there is an error in this sequencer
079 */
080 void execute( Node input,
081 String sequencedPropertyName,
082 NetChange changes,
083 Set<RepositoryNodePath> outputPaths,
084 SequencerContext context,
085 Problems problems ) throws SequencerException;
086
087 }