[dna-commits] DNA SVN: r348 - in trunk/dna-repository/src: main/java/org/jboss/dna/repository/federation/merge and 2 other directories.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Wed Jul 9 11:04:15 EDT 2008


Author: rhauch
Date: 2008-07-09 11:04:15 -0400 (Wed, 09 Jul 2008)
New Revision: 348

Added:
   trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/
   trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/AbstractContribution.java
   trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/BasicFederatedNode.java
   trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/Contribution.java
   trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/EmptyContribution.java
   trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/FederatedNode.java
   trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/MergePlan.java
   trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/MergeProcessor.java
   trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/NodeContribution.java
   trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/PropertyContribution.java
   trunk/dna-repository/src/test/java/org/jboss/dna/repository/federation/impl/
   trunk/dna-repository/src/test/java/org/jboss/dna/repository/federation/impl/BasicFederatedNodeTest.java
Log:
DNA-115 - Create federation service 
http://jira.jboss.com/jira/browse/DNA-115

Added MergePlan (including the Cntribution interface and various implementation classes) and MergeProcessor framework.

Added: trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/AbstractContribution.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/AbstractContribution.java	                        (rev 0)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/AbstractContribution.java	2008-07-09 15:04:15 UTC (rev 348)
@@ -0,0 +1,121 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.repository.federation.merge;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import org.jboss.dna.spi.graph.DateTime;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.Path.Segment;
+
+/**
+ * @author Randall Hauch
+ */
+public abstract class AbstractContribution implements Contribution {
+
+    /**
+     * This is the first version of this class. See the documentation of MergePlan.serialVersionUID.
+     */
+    private static final long serialVersionUID = 1L;
+
+    protected static final List<Segment> EMPTY_CHILDREN = Collections.emptyList();
+    protected static final Map<Name, Property> EMPTY_PROPERTIES = Collections.emptyMap();
+
+    private final String sourceName;
+    private DateTime expirationTimeInUtc;
+
+    /**
+     * Create a contribution for the source with the supplied name.
+     * 
+     * @param sourceName the name of the source, which may not be null or blank
+     */
+    protected AbstractContribution( String sourceName ) {
+        assert sourceName != null && sourceName.trim().length() != 0;
+        this.sourceName = sourceName;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getSourceName() {
+        return this.sourceName;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public List<Segment> getChildren() {
+        return EMPTY_CHILDREN;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Map<Name, Property> getProperties() {
+        return EMPTY_PROPERTIES;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public DateTime getExpirationTimeInUtc() {
+        return this.expirationTimeInUtc;
+    }
+
+    /**
+     * @param expirationTimeInUtc Sets expirationTimeInUtc to the specified value.
+     */
+    public void setExpirationTimeInUtc( DateTime expirationTimeInUtc ) {
+        this.expirationTimeInUtc = expirationTimeInUtc;
+    }
+
+    /**
+     * {@inheritDoc}
+     * <p>
+     * This implementation returns the hash code of the {@link #getSourceName() source name}, and is compatible with the
+     * implementation of {@link #equals(Object)}.
+     * </p>
+     */
+    @Override
+    public int hashCode() {
+        return this.sourceName.hashCode();
+    }
+
+    /**
+     * {@inheritDoc}
+     * <p>
+     * This implementation only compares the {@link #getSourceName() source name}.
+     * </p>
+     */
+    @Override
+    public boolean equals( Object obj ) {
+        if (obj == this) return true;
+        if (obj instanceof AbstractContribution) {
+            AbstractContribution that = (AbstractContribution)obj;
+            return this.getSourceName().equals(that.getSourceName());
+        }
+        return false;
+    }
+
+}


Property changes on: trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/AbstractContribution.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/BasicFederatedNode.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/BasicFederatedNode.java	                        (rev 0)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/BasicFederatedNode.java	2008-07-09 15:04:15 UTC (rev 348)
@@ -0,0 +1,148 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.repository.federation.merge;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Property;
+
+/**
+ * @author Randall Hauch
+ */
+ at ThreadSafe
+public class BasicFederatedNode implements FederatedNode {
+
+    private final UUID uuid;
+
+    // private Name name;
+
+    /**
+     * Create a new federated node instance.
+     * 
+     * @param uuid the UUID; may not be null
+     */
+    public BasicFederatedNode( UUID uuid ) {
+        assert uuid != null;
+        this.uuid = uuid;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public UUID getUuid() {
+        return uuid;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Name getName() {
+        return null;
+    }
+
+    /**
+     * @param name Sets name to the specified value; may not be null
+     */
+    public void setName( Name name ) {
+        assert name != null;
+        // this.name = name;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Set<String> getContributingSources() {
+        Set<String> names = new HashSet<String>();
+        return names;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Iterator<Property> getProperties() {
+        // Compute merged properties ...
+        return null;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Property getProperty( Name propertyName ) {
+        return null;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getPropertyCount() {
+        return 0;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Iterator<Name> getPropertyNames() {
+        return null;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void removeAllProperties() {
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setAllProperties( Property... properties ) {
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setAllProperties( Iterable<Property> properties ) {
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setProperties( Property... properties ) {
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setProperties( Iterable<Property> properties ) {
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Property setPropertyIfAbsent( Property property ) {
+        return null;
+    }
+
+}


Property changes on: trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/BasicFederatedNode.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/Contribution.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/Contribution.java	                        (rev 0)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/Contribution.java	2008-07-09 15:04:15 UTC (rev 348)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.repository.federation.merge;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.graph.DateTime;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.Path.Segment;
+
+/**
+ * The contribution of a source to the information for a single federated node. Users of this interface should treat contributions
+ * as generally being immutable, since some implementation will be immutable and will return immutable
+ * {@link #getProperties() properties} and {@link #getChildren() children} containers. Thus, rather than make changes to an
+ * existing contribution, a new contribution is created to replace the previous contribution.
+ * 
+ * @author Randall Hauch
+ */
+ at NotThreadSafe
+public interface Contribution extends Serializable {
+
+    /**
+     * Get the name of the source that made this contribution.
+     * 
+     * @return the name of the contributing source
+     */
+    public String getSourceName();
+
+    /**
+     * Get the expiration time, already in UTC.
+     * 
+     * @return the expiration time in UTC
+     */
+    public DateTime getExpirationTimeInUtc();
+
+    /**
+     * Get the properties that make up this contribution. This map is immutable.
+     * 
+     * @return the map of properties; never null
+     */
+    public Map<Name, Property> getProperties();
+
+    /**
+     * Get the children that make up this contribution. This list is immutable.
+     * 
+     * @return the list of children; never null
+     */
+    public List<Segment> getChildren();
+}


Property changes on: trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/Contribution.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/EmptyContribution.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/EmptyContribution.java	                        (rev 0)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/EmptyContribution.java	2008-07-09 15:04:15 UTC (rev 348)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.repository.federation.merge;
+
+/**
+ * A source contribution that is empty. In other words, the source has no contribution to make.
+ * <p>
+ * Note that this is different than an unknown contribution, which may occur when a source is added to a federated repository
+ * after the contributions have already been determined for nodes. In this case, the new source's contribution for a node is not
+ * known and must be determined.
+ * </p>
+ * 
+ * @author Randall Hauch
+ */
+public class EmptyContribution extends AbstractContribution {
+
+    /**
+     * This is the first version of this class. See the documentation of MergePlan.serialVersionUID.
+     */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * Create a contribution for the source with the supplied name.
+     * 
+     * @param sourceName the name of the source, which may not be null or blank
+     */
+    public EmptyContribution( String sourceName ) {
+        super(sourceName);
+    }
+
+}


Property changes on: trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/EmptyContribution.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Copied: trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/FederatedNode.java (from rev 321, trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederatedNode.java)
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/FederatedNode.java	                        (rev 0)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/FederatedNode.java	2008-07-09 15:04:15 UTC (rev 348)
@@ -0,0 +1,140 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.repository.federation.merge;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Property;
+
+/**
+ * @author Randall Hauch
+ */
+ at ThreadSafe
+public interface FederatedNode {
+    /**
+     * Get the unique identifier for this federated node.
+     * 
+     * @return the UUID; never null
+     */
+    UUID getUuid();
+
+    /**
+     * Get the name of this node.
+     * 
+     * @return the node name; never null
+     */
+    Name getName();
+
+    /**
+     * Get the property with the given name.
+     * 
+     * @param propertyName the property name
+     * @return the property, or null if the property does not exist
+     * @throws IllegalArgumentException if the name is null
+     */
+    Property getProperty( Name propertyName );
+
+    /**
+     * Get the number of properties on this node. This value is technically an estimate, as it may not exactly match the number of
+     * properties returned by {@link #getProperties()} or {@link #getPropertyNames()}.
+     * 
+     * @return the approximate number of properties.
+     */
+    int getPropertyCount();
+
+    /**
+     * Get the properties. This method returns a consistent set of properties at the moment this method is called, and is not
+     * affected by additions or change to the properties. In other words, it is safe for concurrent operations and is not a
+     * fail-fast iterator.
+     * 
+     * @return the properties on this node via an immutable iterator
+     */
+    Iterator<Property> getProperties();
+
+    /**
+     * Get the names of the properties for this node. This method returns a consistent set of names at the moment this method is
+     * called, and is not affected by additions or change to the properties. In other words, it is safe for concurrent operations
+     * and is not a fail-fast iterator.
+     * 
+     * @return the property names via an immutable iterator
+     */
+    Iterator<Name> getPropertyNames();
+
+    /**
+     * Set the property if it is not already set.
+     * 
+     * @param property the property
+     * @return the existing property, or null if there was no property and the supplied property was set
+     * @throws IllegalArgumentException if the property is null
+     */
+    Property setPropertyIfAbsent( Property property );
+
+    /**
+     * Set the supplied properties. This method will overwrite any existing properties with the new properties if they have the
+     * same {@link Property#getName() property name}. This method ignores any null property references, and does nothing if there
+     * are no properties supplied.
+     * 
+     * @param properties the properties that should be set
+     */
+    void setProperties( Property... properties );
+
+    /**
+     * Set the supplied properties. This method will overwrite any existing properties with the new properties if they have the
+     * same {@link Property#getName() property name}. This method ignores any null property references, and does nothing if there
+     * are no properties supplied.
+     * 
+     * @param properties the properties that should be set
+     */
+    void setProperties( Iterable<Property> properties );
+
+    /**
+     * Replace all existing properties with the supplied properties. This method ignores any null property references, and does
+     * nothing if there are no properties supplied.
+     * 
+     * @param properties the properties that should be set
+     */
+    void setAllProperties( Property... properties );
+
+    /**
+     * Replace all existing properties with the supplied properties. This method ignores any null property references, and does
+     * nothing if there are no properties supplied.
+     * 
+     * @param properties the properties that should replace the existing properties
+     */
+    void setAllProperties( Iterable<Property> properties );
+
+    /**
+     * Remove all properties, except for the {@link #getName() name} and {@link #getUuid() identifier}.
+     */
+    void removeAllProperties();
+
+    /**
+     * Get the sources that have contributed information to this node.
+     * 
+     * @return the names of the sources that have contributed content to this node.
+     */
+    Set<String> getContributingSources();
+
+}

Added: trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/MergePlan.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/MergePlan.java	                        (rev 0)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/MergePlan.java	2008-07-09 15:04:15 UTC (rev 348)
@@ -0,0 +1,168 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.repository.federation.merge;
+
+import java.io.InvalidClassException;
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.graph.DateTime;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Property;
+
+/**
+ * This class represents the details about how information from different sources are merged into a single federated node.
+ * <p>
+ * A merge plan basically consists of the individual contribution from each source and the information about how these
+ * contributions were merged into the single federated node.
+ * </p>
+ * <p>
+ * Merge plans are designed to be {@link Serializable serializable}, as they are persisted on the federated node and deserialized
+ * to assist in the management of the federated node.
+ * </p>
+ * 
+ * @author Randall Hauch
+ */
+ at NotThreadSafe
+public class MergePlan implements Serializable {
+
+    /**
+     * Define the earliest version of this class that is supported. The Java runtime, upon deserialization, compares the
+     * serialized object's version to this, and if less than this version will throw a {@link InvalidClassException}. If, however,
+     * the serialized object's version is compatible with this class, it will be deserialized successfully.
+     * <p>
+     * <a href="http://java.sun.com/j2se/1.5.0/docs/guide/serialization/spec/version.html#6678">Sun's documentation</a> describes
+     * the following changes can be made without negatively affecting the deserialization of older versions:
+     * <ul>
+     * <li>Adding fields - When the class being reconstituted has a field that does not occur in the stream, that field in the
+     * object will be initialized to the default value for its type. If class-specific initialization is needed, the class may
+     * provide a readObject method that can initialize the field to nondefault values.</i>
+     * <li>Adding classes - The stream will contain the type hierarchy of each object in the stream. Comparing this hierarchy in
+     * the stream with the current class can detect additional classes. Since there is no information in the stream from which to
+     * initialize the object, the class's fields will be initialized to the default values.</i>
+     * <li>Removing classes - Comparing the class hierarchy in the stream with that of the current class can detect that a class
+     * has been deleted. In this case, the fields and objects corresponding to that class are read from the stream. Primitive
+     * fields are discarded, but the objects referenced by the deleted class are created, since they may be referred to later in
+     * the stream. They will be garbage-collected when the stream is garbage-collected or reset.</i>
+     * <li>Adding writeObject/readObject methods - If the version reading the stream has these methods then readObject is
+     * expected, as usual, to read the required data written to the stream by the default serialization. It should call
+     * defaultReadObject first before reading any optional data. The writeObject method is expected as usual to call
+     * defaultWriteObject to write the required data and then may write optional data.</i>
+     * <li>Removing writeObject/readObject methods - If the class reading the stream does not have these methods, the required
+     * data will be read by default serialization, and the optional data will be discarded.</i>
+     * <li>Adding java.io.Serializable - This is equivalent to adding types. There will be no values in the stream for this class
+     * so its fields will be initialized to default values. The support for subclassing nonserializable classes requires that the
+     * class's supertype have a no-arg constructor and the class itself will be initialized to default values. If the no-arg
+     * constructor is not available, the InvalidClassException is thrown.</i>
+     * <li>Changing the access to a field - The access modifiers public, package, protected, and private have no effect on the
+     * ability of serialization to assign values to the fields.</i>
+     * <li>Changing a field from static to nonstatic or transient to nontransient - When relying on default serialization to
+     * compute the serializable fields, this change is equivalent to adding a field to the class. The new field will be written to
+     * the stream but earlier classes will ignore the value since serialization will not assign values to static or transient
+     * fields.</i>
+     * </ul>
+     * All other kinds of modifications should be avoided.
+     * </p>
+     */
+    private static final long serialVersionUID = 1L;
+
+    private final Map<String, Contribution> contributions = new HashMap<String, Contribution>();
+    private Map<Name, Property> annotations = null;
+    private DateTime expirationTimeInUtc;
+
+    /**
+     * Create this version
+     */
+    public MergePlan() {
+    }
+
+    /**
+     * Get the expiration time, already in UTC.
+     * 
+     * @return the expiration time in UTC, or null if there is no known expiration time
+     */
+    public DateTime getExpirationTimeInUtc() {
+        return expirationTimeInUtc;
+    }
+
+    /**
+     * Get the contribution from the source with the supplied name. Note that contributions always include sources that contribute
+     * information and sources that contribute no information. If a source is not included in this list, its contributions are
+     * <i>unknown</i>; that is, it is unknown whether that source does or does not contribute to the node.
+     * 
+     * @param sourceName the name of the source
+     * @return the contribution, or null if the contribution of the source is unknown
+     */
+    public Contribution getContributionFrom( String sourceName ) {
+        return contributions.get(sourceName);
+    }
+
+    /**
+     * Add the supplied contribution, replacing and returning any previous contribution for the same source.
+     * 
+     * @param contribution the new contribution
+     * @return the previous contribution for the source, or null if there was no previous contribution.
+     */
+    public Contribution addContribution( Contribution contribution ) {
+        assert contribution != null;
+        Contribution previous = contributions.put(contribution.getSourceName(), contribution);
+        DateTime contributionExpirationInUtc = contribution.getExpirationTimeInUtc();
+        if (expirationTimeInUtc == null || contributionExpirationInUtc.isBefore(expirationTimeInUtc)) {
+            expirationTimeInUtc = contributionExpirationInUtc;
+        }
+        return previous;
+    }
+
+    /**
+     * Get the plan annotation property with the given name. Plan annotations are custom properties that may be set by
+     * {@link MergeProcessor} implementations to store custom properties on the plan. This method does nothing if the supplied
+     * name is null
+     * 
+     * @param name the name of the annotation
+     * @return the existing annotation, or null if there is no annotation with the supplied name
+     * @see #setAnnotation(Property)
+     */
+    public Property getAnnotation( Name name ) {
+        if (name == null) return null;
+        if (this.annotations == null) return null;
+        return this.annotations.get(name);
+    }
+
+    /**
+     * Set the plan annotation property. This method replaces and returns any existing annotation property with the same name.
+     * This method also returns immediately if the supplied annotation is null.
+     * 
+     * @param annotation the new annotation
+     * @return the previous annotation property with the same name, or null if there was no previous annotation property for the
+     *         name
+     * @see #getAnnotation(Name)
+     */
+    public Property setAnnotation( Property annotation ) {
+        if (annotation == null) return null;
+        if (this.annotations == null) {
+            this.annotations = new HashMap<Name, Property>();
+        }
+        return this.annotations.put(annotation.getName(), annotation);
+    }
+
+}


Property changes on: trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/MergePlan.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/MergeProcessor.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/MergeProcessor.java	                        (rev 0)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/MergeProcessor.java	2008-07-09 15:04:15 UTC (rev 348)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.repository.federation.merge;
+
+import org.jboss.dna.repository.util.ExecutionContext;
+
+/**
+ * @author Randall Hauch
+ */
+public interface MergeProcessor {
+
+    /**
+     * Merge the supplied contributions into a single federated node instance.
+     * 
+     * @param context the context in which this processor is running; never null
+     * @param federatedNode the federated node into which should be place all of the merged properties and child references; never
+     *        null
+     * @param previousMergePlan the merge plan generated from the most recent previous merge; may be null if the node has not yet
+     *        been merged
+     * @param newMergePlan the new merge plan that contains the contributions from each of the sources and which may be consulted
+     *        (and annotated) to should be filled out by this method implementation; never null
+     */
+    void merge( ExecutionContext context,
+                FederatedNode federatedNode,
+                MergePlan previousMergePlan,
+                MergePlan newMergePlan );
+
+}


Property changes on: trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/MergeProcessor.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/NodeContribution.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/NodeContribution.java	                        (rev 0)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/NodeContribution.java	2008-07-09 15:04:15 UTC (rev 348)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.repository.federation.merge;
+
+import java.util.ArrayList;
+import java.util.List;
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.Path.Segment;
+
+/**
+ * The contribution of a source to the information for a single federated node.
+ * <p>
+ * This class does return a mutable list of {@link #getChildren() children} and mutable map of {@link #getProperties() properties}.
+ * </p>
+ * 
+ * @author Randall Hauch
+ */
+ at NotThreadSafe
+public class NodeContribution extends PropertyContribution {
+
+    /**
+     * This is the first version of this class. See the documentation of MergePlan.serialVersionUID.
+     */
+    private static final long serialVersionUID = 1L;
+
+    private List<Segment> children;
+
+    /**
+     * Create a contribution of node properties and children from the source with the supplied name.
+     * 
+     * @param sourceName the name of the source, which may not be null or blank
+     * @param properties the properties from the source; may not be null
+     * @param children the children from the source; may not be null or empty
+     */
+    public NodeContribution( String sourceName,
+                             Iterable<Property> properties,
+                             Iterable<Segment> children ) {
+        super(sourceName, properties);
+        this.children = new ArrayList<Segment>(1);
+        for (Segment child : children) {
+            this.children.add(child);
+        }
+    }
+
+    /**
+     * Get the children that make up this contribution. This list is immutable.
+     * 
+     * @return the list of children; never null
+     */
+    @Override
+    public List<Segment> getChildren() {
+        return this.children;
+    }
+}


Property changes on: trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/NodeContribution.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/PropertyContribution.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/PropertyContribution.java	                        (rev 0)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/PropertyContribution.java	2008-07-09 15:04:15 UTC (rev 348)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.repository.federation.merge;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Property;
+
+/**
+ * The record of a source contributing only properties to a node.
+ * <p>
+ * This class does return a mutable mutable map of {@link #getProperties() properties}.
+ * </p>
+ * 
+ * @author Randall Hauch
+ */
+public class PropertyContribution extends AbstractContribution {
+
+    /**
+     * This is the first version of this class. See the documentation of MergePlan.serialVersionUID.
+     */
+    private static final long serialVersionUID = 1L;
+
+    private final Map<Name, Property> properties;
+
+    /**
+     * Create a contribution of node properties from the source with the supplied name.
+     * 
+     * @param sourceName the name of the source, which may not be null or blank
+     * @param properties the properties from the source; may not be null
+     */
+    public PropertyContribution( String sourceName,
+                                 Iterable<Property> properties ) {
+        super(sourceName);
+        this.properties = new HashMap<Name, Property>();
+        for (Property property : properties) {
+            this.properties.put(property.getName(), property);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Map<Name, Property> getProperties() {
+        return this.properties;
+    }
+
+}


Property changes on: trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/merge/PropertyContribution.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/dna-repository/src/test/java/org/jboss/dna/repository/federation/impl/BasicFederatedNodeTest.java
===================================================================
--- trunk/dna-repository/src/test/java/org/jboss/dna/repository/federation/impl/BasicFederatedNodeTest.java	                        (rev 0)
+++ trunk/dna-repository/src/test/java/org/jboss/dna/repository/federation/impl/BasicFederatedNodeTest.java	2008-07-09 15:04:15 UTC (rev 348)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.repository.federation.impl;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class BasicFederatedNodeTest {
+
+    @Before
+    public void beforeEach() {
+    }
+
+    @Test
+    public void shouldDoSomething() {
+
+    }
+
+}


Property changes on: trunk/dna-repository/src/test/java/org/jboss/dna/repository/federation/impl/BasicFederatedNodeTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain




More information about the dna-commits mailing list