You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2006/10/12 20:33:19 UTC

svn commit: r463366 [1/5] - in /directory/trunks/apacheds/mitosis/src: ./ main/ main/java/ main/java/org/ main/java/org/apache/ main/java/org/apache/directory/ main/java/org/apache/directory/mitosis/ main/java/org/apache/directory/mitosis/common/ main/...

Author: elecharny
Date: Thu Oct 12 11:33:14 2006
New Revision: 463366

URL: http://svn.apache.org/viewvc?view=rev&rev=463366
Log:
added mitosis sources

Added:
    directory/trunks/apacheds/mitosis/src/
    directory/trunks/apacheds/mitosis/src/main/
    directory/trunks/apacheds/mitosis/src/main/java/
    directory/trunks/apacheds/mitosis/src/main/java/org/
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/CSN.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/CSNFactory.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/CSNVector.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/Constants.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/InvalidCSNException.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/Replica.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/ReplicaId.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/ReplicationException.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/SimpleCSN.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/SimpleCSNFactory.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/SimpleUUID.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/SimpleUUIDFactory.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/UUID.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/UUIDFactory.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/configuration/
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/configuration/ReplicaIdPropertyEditor.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/configuration/ReplicaPropertyEditor.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/configuration/ReplicationConfiguration.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/configuration/ReplicationConfigurationException.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/AddAttributeOperation.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/AddEntryOperation.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/AttributeOperation.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/CompositeOperation.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/DeleteAttributeOperation.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/Operation.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/OperationCodec.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/OperationFactory.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/ReplaceAttributeOperation.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/support/
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/support/EntryUtil.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/ClientConnectionManager.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/ReplicationContext.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/ReplicationLogCleanJob.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/ReplicationService.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/ReplicationServiceException.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/SimpleReplicationContext.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/Constants.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/BaseMessageDecoder.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/BaseMessageEncoder.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesAckMessageDecoder.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesAckMessageEncoder.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesMessageDecoder.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesMessageEncoder.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/EndLogEntriesAckMessageDecoder.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/EndLogEntriesAckMessageEncoder.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/EndLogEntriesMessageDecoder.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/EndLogEntriesMessageEncoder.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/LogEntryAckMessageDecoder.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/LogEntryAckMessageEncoder.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/LogEntryMessageDecoder.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/LogEntryMessageEncoder.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/LoginAckMessageDecoder.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/LoginAckMessageEncoder.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/LoginMessageDecoder.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/LoginMessageEncoder.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/ReplicationClientProtocolCodecFactory.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/ReplicationServerProtocolCodecFactory.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/ResponseMessageDecoder.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/ResponseMessageEncoder.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/handler/
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/handler/ReplicationClientContextHandler.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/handler/ReplicationClientProtocolHandler.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/handler/ReplicationContextHandler.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/handler/ReplicationProtocolHandler.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/handler/ReplicationServerContextHandler.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/handler/ReplicationServerProtocolHandler.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/BaseMessage.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/BeginLogEntriesAckMessage.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/BeginLogEntriesMessage.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/EndLogEntriesAckMessage.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/EndLogEntriesMessage.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/LogEntryAckMessage.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/LogEntryMessage.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/LoginAckMessage.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/LoginMessage.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/ResponseMessage.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/ReplicationLogIterator.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/ReplicationStore.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/ReplicationStoreException.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/derby/
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/derby/DerbyReplicationLogIterator.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/derby/DerbyReplicationStore.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/derby/SQLUtil.java
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/util/
    directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/util/OctetString.java
    directory/trunks/apacheds/mitosis/src/main/schema/
    directory/trunks/apacheds/mitosis/src/main/schema/mitosis.schema
    directory/trunks/apacheds/mitosis/src/test/
    directory/trunks/apacheds/mitosis/src/test/java/
    directory/trunks/apacheds/mitosis/src/test/java/org/
    directory/trunks/apacheds/mitosis/src/test/java/org/apache/
    directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/
    directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/
    directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/common/
    directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/common/SimpleCSNTest.java
    directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/
    directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/
    directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/
    directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/AbstractMessageCodecTest.java
    directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesAckMessageCodecTest.java
    directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesAckMessageCodecTest2.java
    directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesMessageCodecTest.java
    directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/EndLogEntriesAckMessageCodecTest.java
    directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/EndLogEntriesMessageCodecTest.java
    directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LogEntryAckMessageCodecTest.java
    directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LogEntryMessageCodecTest.java
    directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LoginAckMessageCodecTest.java
    directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/LoginMessageCodecTest.java
    directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/store/
    directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/store/derby/
    directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/store/derby/DerbyReplicationStoreTest.java

Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/CSN.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/CSN.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/CSN.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/CSN.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,62 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.directory.mitosis.common;
+
+import java.io.Serializable;
+
+/**
+ * Represents 'Change Sequence Number' in LDUP specification.
+ * 
+ * A CSN is a composition of a timestamp, a replica ID and a 
+ * operation sequence number.
+ * 
+ * It distinguishes a change made on an object on a server,
+ * and if two operations take place during the same timeStamp,
+ * the operation sequence number makes those operations distinct.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface CSN extends Serializable, Comparable
+{
+    /**
+     * Returns GMT timestamp of modification.
+     */
+    long getTimestamp();
+    
+    /**
+     * Returns replica ID.
+     */
+    ReplicaId getReplicaId();
+    
+    /**
+     * Returns sequence number of modification.
+     */
+    int getOperationSequence();
+    
+    /**
+     * Returns octet-string representation of this CSN. 
+     */
+    String toOctetString();
+    
+    /**
+     * Returns a byte array representing the CSN
+     */
+    byte[] toBytes();
+}

Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/CSNFactory.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/CSNFactory.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/CSNFactory.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/CSNFactory.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,47 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.directory.mitosis.common;
+
+/**
+ * Generates a new {@link CSN}.
+ * 
+ */
+public interface CSNFactory
+{
+    /**
+     * Returns a new {@link CSN}.
+     * Generated CSN can be duplicate if user generates CSNs more than 2G 
+     * times a milliseconds.
+     * 
+     * @param replicaId Replica ID.  ReplicaID must be 1-8 digit alphanumeric
+     *        string.
+     */
+    CSN newInstance( String replicaId );
+    
+    /**
+     * Returns a new {@link CSN}.
+     * Generated CSN can be duplicate if user generates CSNs more than 2G 
+     * times a milliseconds.
+     * 
+     * @param replicaId Replica ID.  ReplicaID must be 1-8 digit alphanumeric
+     *        string.
+     */
+    CSN newInstance( ReplicaId replicaId );
+}

Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/CSNVector.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/CSNVector.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/CSNVector.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/CSNVector.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,115 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.directory.mitosis.common;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.directory.shared.ldap.util.EqualsBuilder;
+import org.apache.directory.shared.ldap.util.HashCodeBuilder;
+
+/**
+ * 
+ * TODO CSNVector.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class CSNVector
+{
+    /**
+     * Declares the Serial Version Uid.
+     *
+     * @see <a
+     *      href="http://c2.com/cgi/wiki?AlwaysDeclareSerialVersionUid">Always
+     *      Declare Serial Version Uid</a>
+     */
+    private static final long serialVersionUID = 1L;
+    
+    private final Map csns = new HashMap();
+    
+    public CSNVector()
+    {
+    }
+    
+    public void setCSN( CSN csn )
+    {
+        csns.put( csn.getReplicaId(), csn );
+    }
+    
+    public void setAllCSN( CSNVector uv )
+    {
+        Iterator i = uv.csns.values().iterator();
+        while( i.hasNext() )
+        {
+            setCSN( ( CSN ) i.next() );
+        }
+    }
+    
+    public CSN  getCSN( ReplicaId replicaId )
+    {
+        return ( CSN ) csns.get( replicaId );
+    }
+    
+    public CSN  removeCSN( ReplicaId replicaId )
+    {
+        return ( CSN ) csns.remove( replicaId );
+    }
+    
+    public Set  getReplicaIds()
+    {
+        return csns.keySet();
+    }
+    
+    public int size()
+    {
+        return csns.size();
+    }
+
+    public boolean equals(Object object) {
+        if (object == this) {
+            return true;
+        }
+        if (!(object instanceof CSNVector)) {
+            return false;
+        }
+        CSNVector rhs = (CSNVector) object;
+        return new EqualsBuilder().append(
+                this.csns, rhs.csns).isEquals();
+    }
+
+    public int hashCode() {
+        return new HashCodeBuilder(-33446267, -459427867).append(
+                this.csns).toHashCode();
+    }
+    
+    public Object clone()
+    {
+        CSNVector result = new CSNVector();
+        result.csns.putAll( this.csns );
+        return result;
+    }
+    
+    public String toString()
+    {
+        return csns.toString();
+    }
+}

Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/Constants.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/Constants.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/Constants.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/Constants.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,63 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.directory.mitosis.common;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+import org.apache.directory.server.core.enumeration.SearchResultFilter;
+import org.apache.directory.server.core.invocation.Invocation;
+
+/**
+ * 
+ * TODO Constants.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class Constants
+{
+    public static final String ENTRY_UUID = "entryUUID";
+    public static final String ENTRY_CSN = "entryCSN";
+    public static final String ENTRY_DELETED = "entryDeleted";
+
+    public static final SearchResultFilter DELETED_ENTRIES_FILTER = new SearchResultFilter()
+    {
+        public boolean accept( Invocation invocation, SearchResult result, SearchControls controls )
+                throws NamingException
+        {
+            if ( controls.getReturningAttributes() == null )
+            {
+                Attributes entry = result.getAttributes();
+                Attribute deleted = entry.get( ENTRY_DELETED );
+                Object value = deleted == null? null : deleted.get();
+                return ( value == null || !"true".equals( value.toString() ) );
+            }
+
+            return true;
+        }
+    };
+
+    private Constants()
+    {
+    }
+}

Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/InvalidCSNException.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/InvalidCSNException.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/InvalidCSNException.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/InvalidCSNException.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,58 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.directory.mitosis.common;
+
+/**
+ * 
+ * InvalidCSNException is thrown when trying to create an invalid CSN.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class InvalidCSNException extends RuntimeException
+{
+    /**
+     * Declares the Serial Version Uid.
+     *
+     * @see <a
+     *      href="http://c2.com/cgi/wiki?AlwaysDeclareSerialVersionUid">Always
+     *      Declare Serial Version Uid</a>
+     */
+    private static final long serialVersionUID = 1L;
+
+    public InvalidCSNException()
+    {
+        super();
+    }
+
+    public InvalidCSNException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+
+    public InvalidCSNException( String message )
+    {
+        super( message );
+    }
+
+    public InvalidCSNException( Throwable cause )
+    {
+        super( cause );
+    }
+}

Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/Replica.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/Replica.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/Replica.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/Replica.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,182 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.directory.mitosis.common;
+
+import java.net.InetSocketAddress;
+
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The class stores a Replica, which is composed of an Id, a server and a port.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class Replica
+{
+    /** The logger */
+    private static Logger log = LoggerFactory.getLogger( Replica.class );
+
+    /** A speedup for logger */
+    private static final boolean IS_DEBUG = log.isDebugEnabled();
+
+    /** The replicaId */
+    private final ReplicaId id;
+    
+    /** The server address */
+    private final InetSocketAddress address;
+    
+    /**
+     * Creates a new instance of Replica, from a String.
+     * 
+     * The String format is the following :
+     * 
+     * <replicaId>@<server>:<port>
+     * 
+     * @param The replica to create
+     */
+    public Replica( String replica )
+    {
+        if ( StringTools.isEmpty( replica ) )
+        {
+            log.error( "Null or empty replica are not allowed" );
+            throw new IllegalArgumentException( "Null or empty Replica " );
+        }
+        
+        replica = replica.trim();
+        
+        int atPos = replica.indexOf( '@' );
+        
+        if ( atPos <= 0 )
+        {
+            log.error( "The ReplicaId '@' element is missing in {}", replica );
+            throw new IllegalArgumentException( "Replica ID not found: " + replica );
+        }
+        
+        int colonPos = replica.indexOf( atPos,  ':' );
+        
+        if ( colonPos < 0 )
+        {
+            log.error( "Replica port not found in {}", replica );
+            throw new IllegalArgumentException( "Port number not found in replica : " + replica );
+        }
+        
+        id = new ReplicaId( replica.substring( 0, atPos ) );
+        String server = replica.substring( atPos + 1, colonPos );
+        int port = -1;
+        
+        try
+        {
+            port = Integer.parseInt( replica.substring( colonPos + 1 ) ) ;
+        }
+        catch ( NumberFormatException nfe )
+        {
+            log.error( "The port value should be a value between 1 and 65535, port  : {}", new Integer( port ) );
+            throw new IllegalArgumentException( "Bad port number : " + port );
+        }
+        
+        try
+        {
+            address = new InetSocketAddress( server, port );
+        }
+        catch ( IllegalArgumentException iae )
+        {
+            log.error(  "The server address/name is invalid ({}) in replica {}", server, replica );
+            throw new IllegalArgumentException( "The server address/name is invalid in replica " + replica 
+                + ", error : " + iae.getMessage() );
+        }
+        
+        if ( IS_DEBUG )
+        {
+            log.debug( "Created a replica {} on server {}", id, server + ':' + port );
+        }
+    }
+
+    /**
+     * Creates a new instance of Replica, from a valid Id and a valid address.
+     *
+     * @param id The Replica Id
+     * @param address The server address.
+     */
+    public Replica( ReplicaId id, InetSocketAddress address )
+    {
+        assert id != null;
+        assert address != null;
+
+        this.id = id;
+        this.address = address;
+    }
+
+    /**
+     * @return the replica address
+     */
+    public InetSocketAddress getAddress()
+    {
+        return address;
+    }
+
+    /**
+     * @return the replica Id
+     */
+    public ReplicaId getId()
+    {
+        return id;
+    }
+    
+    public int hashCode()
+    {
+        return id.hashCode();
+    }
+    
+    public boolean equals( Object o )
+    {
+        if( o == null )
+        {
+            return false;
+        }
+        
+        if( o == this )
+        {
+            return true;
+        }
+        
+        if( o instanceof Replica )
+        {
+            return this.id.equals( ( ( Replica ) o ).id );
+        }
+        else
+        {
+            return false;
+        }
+    }
+    
+    /**
+     * @return The replica. The format is &lt;replica id> '@' &lt;server> ':' &lt;port>
+     */
+    public String toString()
+    {
+        return getId().toString() +
+                '@' +
+                getAddress().getAddress().getHostAddress() +
+                ':' +
+                getAddress().getPort();
+    }
+}

Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/ReplicaId.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/ReplicaId.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/ReplicaId.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/ReplicaId.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,148 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.directory.mitosis.common;
+
+import java.io.Serializable;
+import java.util.regex.Pattern;
+
+import org.apache.directory.shared.ldap.util.StringTools;
+
+/**
+ * Store a replica ID after having normalized it.
+ * 
+ *  The normalization proces checks that the submitted id is valid, ie
+ *  contains only this char set : { '-', '_', 'a..z', 'A..Z', '0..9' }
+ *  and its length is between 1 and 16. 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ReplicaId implements Comparable, Serializable
+{
+    /**
+     * Declares the Serial Version Uid.
+     *
+     * @see <a
+     *      href="http://c2.com/cgi/wiki?AlwaysDeclareSerialVersionUid">Always
+     *      Declare Serial Version Uid</a>
+     */
+    private static final long serialVersionUID = 1L;
+
+    /** The replica pattern. */
+    private static final Pattern REPLICA_ID_PATTERN = Pattern.compile( "[-_A-Z0-9]{1,16}" );
+
+    /** The formated replicaId */
+    private String id;
+
+    /**
+     * Creates a new instance of ReplicaId. The id must be a String 
+     * which respect the pattern :
+     * 
+     * [-_a-zA-Z0-9]*
+     * 
+     * and must be between 1 and 16 chars length
+     *
+     * @param id The replica pattern
+     */
+    public ReplicaId( String id )
+    {
+        if ( StringTools.isEmpty( id ) )
+        {
+            throw new IllegalArgumentException( "Empty ID: " + id );
+        }
+
+        String tmpId = id.trim().toUpperCase();
+        
+        if( !REPLICA_ID_PATTERN.matcher( tmpId ).matches() )
+        {
+            throw new IllegalArgumentException( "Invalid replica ID: " + id );
+        }
+        
+        this.id = id;
+    }
+
+    /**
+     * @return The replicaId
+     */
+    public String getId()
+    {
+        return id;
+    }
+    
+    /**
+     * Returns a hash code value for the object.
+     * 
+     * @return a hash code value for this object.
+     */
+    public int hashCode()
+    {
+        return id.hashCode();
+    }
+    
+    /**
+     * Indicates whether some other object is "equal to" this one
+     * 
+     * @param o the reference object with which to compare.
+     * @return <code>true</code> if this object is the same as the obj argument; 
+     * <code>false</code> otherwise.
+     */
+    public boolean equals( Object o )
+    {
+        if( o == null )
+        {
+            return false;
+        }
+        
+        if( o == this )
+        {
+            return true;
+        }
+        
+        if( o instanceof ReplicaId )
+        {
+            return this.id.equals( ( ( ReplicaId ) o ).id );
+        }
+        else
+        {
+            return false;
+        }
+    }
+    
+    /**
+     * Compares this object with the specified object for order.  Returns a
+     * negative integer, zero, or a positive integer as this object is less
+     * than, equal to, or greater than the specified object.<p>
+     * 
+     * @param   o the Object to be compared.
+     * @return  a negative integer, zero, or a positive integer as this object
+     *      is less than, equal to, or greater than the specified object.
+     */
+    public int compareTo( Object o )
+    {
+        return this.id.compareTo( ( ( ReplicaId ) o ).id );
+    }
+    
+    /**
+     * @return the Replica Id
+     */
+    public String toString()
+    {
+        return id;
+    }
+}

Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/ReplicationException.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/ReplicationException.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/ReplicationException.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/ReplicationException.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,51 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.directory.mitosis.common;
+
+/**
+ * 
+ * TODO ReplicationException.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ReplicationException extends RuntimeException
+{
+    private static final long serialVersionUID = -347196060295426926L;
+
+    public ReplicationException()
+    {
+        super();
+    }
+
+    public ReplicationException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+
+    public ReplicationException( String message )
+    {
+        super( message );
+    }
+
+    public ReplicationException( Throwable cause )
+    {
+        super( cause );
+    }
+}

Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/SimpleCSN.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/SimpleCSN.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/SimpleCSN.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/SimpleCSN.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,333 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.directory.mitosis.common;
+
+import java.io.Serializable;
+
+import org.apache.directory.mitosis.util.OctetString;
+
+/**
+ * Basic implementation of {@link CSN}.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SimpleCSN implements CSN, Serializable, Comparable
+{
+    /**
+     * Declares the Serial Version Uid.
+     *
+     * @see <a
+     *      href="http://c2.com/cgi/wiki?AlwaysDeclareSerialVersionUid">Always
+     *      Declare Serial Version Uid</a>
+     */
+    private static final long serialVersionUID = 1L;
+    
+    /** The timeStamp of this operation */
+    private final long timestamp;
+
+    /** The server identification */
+    private final ReplicaId replicaId;
+    
+    /** The operation number in the same timestamp */
+    private final int operationSequence;
+    
+    /** Stores the String representation of the CSN */
+    private transient String octetString;
+
+    /** Stores the byte array representation of the CSN */
+    private transient byte[] bytes;
+
+    /**
+     * Creates a new instance.
+     * 
+     * @param timestamp GMT timestamp of modification
+     * @param replicaId Replica ID where modification occurred (<tt>[-_A-Za-z0-9]{1,16}</tt>)
+     * @param operationSequence Operation sequence
+     */
+    public SimpleCSN( long timestamp, ReplicaId replicaId, int operationSequence )
+    {
+        this.timestamp = timestamp;
+        this.replicaId = replicaId;
+        this.operationSequence = operationSequence;
+    }
+    
+    /**
+     * Creates a new instance of SimpleCSN from a String.
+     * 
+     * The string format must be :
+     * &lt;timestamp> : &lt;replica ID> : &lt;operation sequence>
+     *
+     * @param value The String containing the CSN
+     */
+    public SimpleCSN( String value ) throws InvalidCSNException
+    {
+        assert value != null;
+        
+        int sepTS = value.indexOf( ':' );
+        
+        assert sepTS > 0;
+        
+        int sepID = value.lastIndexOf( ':' );
+        
+        if ( ( sepID == -1 ) || ( sepID == sepTS ) | ( sepID - sepTS < 2 ) )
+        {
+            throw new InvalidCSNException();
+        }
+        
+        try
+        {
+            timestamp = Long.parseLong( value.substring( 0, sepTS ), 16 );
+        }
+        catch ( NumberFormatException ife )
+        {
+            throw new InvalidCSNException();
+        }
+        
+        try
+        {
+            replicaId = new ReplicaId( value.substring(  sepTS + 1, sepID ) );
+        }
+        catch ( IllegalArgumentException iae )
+        {
+            throw new InvalidCSNException();
+        }
+
+        try
+        {
+            operationSequence = Integer.parseInt( value.substring( sepID + 1 ), 16 );
+        }
+        catch ( NumberFormatException ife )
+        {
+            throw new InvalidCSNException();
+        }
+    }
+
+    /**
+     * Creates a new instance of SimpleCSN from the serialized data
+     *
+     * @param value The byte array which contains the serialized CSN
+     */
+    public SimpleCSN( byte[] value )
+    {
+        timestamp =  ((long)(value[0] & 0x00FF) << 56) |
+                ((long)(value[1] & 0x00FF) << 48) |
+                ((long)(value[2] & 0x00FF) << 40) |
+                ((long)(value[3] & 0x00FF) << 32) |
+                ((long)(value[4] << 24) & 0x00000000FF000000L) |
+                ((long)(value[5] << 16) & 0x0000000000FF0000L) |
+                ((long)(value[6] << 8) & 0x000000000000FF00L) |
+                ((long)value[7] & 0x00000000000000FFL);
+        
+        operationSequence = ((value[8] & 0x00FF) << 24) +
+            ((value[9] & 0x00FF) << 16) +
+            ((value[10] & 0x00FF) << 8) +
+            (value[11] & 0x00FF);
+        
+        char[] chars = new char[value.length - 12];
+                                
+        for ( int i = 12; i < value.length; i++ )
+        {
+            chars[i - 12] = (char)(value[i] & 0x00FF);
+        }
+        
+        replicaId = new ReplicaId( new String( chars ) );
+        bytes = value;
+    }
+
+    /**
+     * Return the CSN as a formated string. The used format is :
+     * &lt;timestamp> ':' &lt;replicaId> ':' &lt;operation sequence>
+     * 
+     * @return The CSN as a String
+     */
+    public String toOctetString()
+    {
+        if( octetString == null )
+        {
+            StringBuffer buf = new StringBuffer( 40 );
+            OctetString.append( buf, timestamp );
+            buf.append( ':' );
+            buf.append( replicaId );
+            buf.append( ':' );
+            OctetString.append( buf, operationSequence );
+            octetString = buf.toString();
+        }
+
+        return octetString;
+    }
+    
+    /**
+     * Get the CSN as a byte array. The data are stored as :
+     * bytes 1 to 8  : timestamp, big-endian
+     * bytes 9 to 12 : operation sequence, big-endian
+     * bytes 13 to ... : ReplicaId 
+     * 
+     * @return A byte array representing theCSN
+     */
+    public byte[] toBytes()
+    {
+        if ( bytes == null )
+        {
+            String id = replicaId.getId();
+            byte[] bb = new byte[8 + id.length() + 4];
+            
+            bb[0] = (byte)(timestamp >> 56 );
+            bb[1] = (byte)(timestamp >> 48 );
+            bb[2] = (byte)(timestamp >> 40 );
+            bb[3] = (byte)(timestamp >> 32 );
+            bb[4] = (byte)(timestamp >> 24 );
+            bb[5] = (byte)(timestamp >> 16 );
+            bb[6] = (byte)(timestamp >> 8 );
+            bb[7] = (byte)timestamp;
+            bb[8] = (byte)((operationSequence >> 24 ) );
+            bb[9] = (byte)((operationSequence >> 16 ) );
+            bb[10] = (byte)((operationSequence >> 8 ) );
+            bb[11] = (byte)(operationSequence );
+            
+            for ( int i = 0; i < id.length(); i++ )
+            {
+                bb[12+i] =(byte)id.charAt( i );
+            }
+            
+            bytes = bb;
+        }
+        
+        return bytes;
+    }
+    
+    /**
+     * @return The timestamp
+     */
+    public long getTimestamp()
+    {
+        return timestamp;
+    }
+    
+    /**
+     * @return The replicaId
+     */
+    public ReplicaId getReplicaId()
+    {
+        return replicaId;
+    }
+
+    /**
+     * @return The operation sequence
+     */
+    public int getOperationSequence()
+    {
+        return operationSequence;
+    }
+
+    /**
+     * @return The CSN as a String
+     */
+    public String toString()
+    {
+        return toOctetString();
+    }
+    
+    /**
+     * Returns a hash code value for the object.
+     * 
+     * @return a hash code value for this object.
+     */
+    public int hashCode()
+    {
+        return replicaId.hashCode() ^ ( int ) timestamp ^ operationSequence;
+    }
+
+    /**
+     * Indicates whether some other object is "equal to" this one
+     * 
+     * @param o the reference object with which to compare.
+     * @return <code>true</code> if this object is the same as the obj argument; 
+     * <code>false</code> otherwise.
+     */
+    public boolean equals( Object o )
+    {
+        if( o == null )
+        {
+            return false;
+        }
+        
+        if( this == o )
+        {
+            return true;
+        }
+        
+        if( !( o instanceof CSN ) )
+        {
+            return false;
+        }
+        
+        CSN that = ( CSN ) o;
+        
+        return timestamp == that.getTimestamp() &&
+               replicaId.equals( that.getReplicaId() ) &&
+               operationSequence == that.getOperationSequence();
+    }
+    
+    /**
+     * Compares this object with the specified object for order.  Returns a
+     * negative integer, zero, or a positive integer as this object is less
+     * than, equal to, or greater than the specified object.<p>
+     * 
+     * @param   o the Object to be compared.
+     * @return  a negative integer, zero, or a positive integer as this object
+     *      is less than, equal to, or greater than the specified object.
+     */
+    public int compareTo( Object o )
+    {
+        CSN that = ( CSN ) o;
+        long thatTimestamp = that.getTimestamp();
+
+        if( this.timestamp < thatTimestamp )
+        {
+            return -1;
+        }
+        else if( this.timestamp > thatTimestamp )
+        {
+            return 1;
+        }
+        
+        int replicaIdCompareResult = this.replicaId.compareTo( that.getReplicaId() );
+        
+        if( replicaIdCompareResult != 0 )
+        {
+            return replicaIdCompareResult;
+        }
+        
+        int thatSequence = that.getOperationSequence();
+
+        if( this.operationSequence < thatSequence )
+        {
+            return -1;
+        }
+        else if( this.operationSequence > thatSequence )
+        {
+            return 1;
+        }
+        else
+        {
+            return 0;
+        }
+    }
+}

Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/SimpleCSNFactory.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/SimpleCSNFactory.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/SimpleCSNFactory.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/SimpleCSNFactory.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,62 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.directory.mitosis.common;
+
+/**
+ * Generates a new {@link CSN}.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SimpleCSNFactory implements CSNFactory
+{
+    private static int operationSequence;
+    private static long lastTimestamp = System.currentTimeMillis();
+
+    public SimpleCSNFactory()
+    {
+    }
+
+    /**
+     * Returns a new {@link CSN}.
+     * Generated CSN can be duplicate if user generates CSNs more than 2G 
+     * times a milliseconds.
+     * 
+     * @param replicaId Replica ID.  ReplicaID must be 1-8 digit alphanumeric
+     *        string.
+     */
+    public CSN newInstance( String replicaId )
+    {
+        return newInstance( new ReplicaId( replicaId ) );
+    }
+
+    public synchronized CSN newInstance( ReplicaId replicaId )
+    {
+        long newTimestamp = System.currentTimeMillis();
+        if( lastTimestamp == newTimestamp )
+        {
+            operationSequence = 0;
+        }
+        
+        CSN newCSN = new SimpleCSN( newTimestamp, replicaId,
+                                    operationSequence ++ );
+        lastTimestamp = newTimestamp;
+        return newCSN;
+    }
+}

Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/SimpleUUID.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/SimpleUUID.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/SimpleUUID.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/SimpleUUID.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,92 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.directory.mitosis.common;
+
+import org.apache.directory.mitosis.util.OctetString;
+
+/**
+ * 
+ * TODO SimpleUUID.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SimpleUUID implements UUID
+{
+    private static final long serialVersionUID = 3256721788405953846L;
+    
+    private final String uuid;
+
+    public SimpleUUID( byte[] uuid )
+    {
+        if( uuid.length != 16 )
+        {
+            throw new IllegalArgumentException( "UUID must be 128-bits long." );
+        }
+        
+        this.uuid = OctetString.toString( uuid );
+    }
+    
+    public SimpleUUID( String uuid )
+    {
+        String newUUID = uuid.replaceAll( "[^0-9A-Za-z]", "" );
+        
+        if( newUUID.length() != 32 )
+        {
+            throw new IllegalArgumentException( "UUID: " + uuid );
+        }
+        
+        this.uuid = newUUID;
+    }
+    
+    public int hashCode()
+    {
+        return uuid.hashCode();
+    }
+    
+    public boolean equals( Object o )
+    {
+        if( o == null )
+        {
+            return false;
+        }
+        
+        if( this == o )
+        {
+            return true;
+        }
+        
+        if( !( o instanceof UUID ) )
+        {
+            return false;
+        }
+        
+        return uuid.equals( ( ( UUID ) o ).toOctetString() );
+    }
+
+    public String toOctetString()
+    {
+        return uuid;
+    }
+
+    public int compareTo( Object o )
+    {
+        return uuid.compareTo( ( ( UUID ) o ).toOctetString() ); 
+    }
+}

Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/SimpleUUIDFactory.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/SimpleUUIDFactory.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/SimpleUUIDFactory.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/SimpleUUIDFactory.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,45 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.directory.mitosis.common;
+
+import org.safehaus.uuid.UUIDGenerator;
+
+/**
+ * Generates {@link UUID}.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SimpleUUIDFactory implements UUIDFactory
+{
+    private static final UUIDGenerator generator = UUIDGenerator.getInstance();
+
+    public SimpleUUIDFactory()
+    {
+    }
+
+    /**
+     * Generates a new type-1 (time-based) {@link UUID}.
+     */
+    public UUID newInstance()
+    {
+        org.safehaus.uuid.UUID uuid = generator.generateTimeBasedUUID();
+        return new SimpleUUID( uuid.asByteArray() );
+    }
+}

Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/UUID.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/UUID.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/UUID.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/UUID.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,35 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.directory.mitosis.common;
+
+import java.io.Serializable;
+
+/**
+ * Represents UUID (Unversally Unique IDentifier).
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface UUID extends Serializable, Comparable
+{
+    /**
+     * Returns octet-string representation of this UUID.
+     */
+    String toOctetString();
+}

Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/UUIDFactory.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/UUIDFactory.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/UUIDFactory.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/common/UUIDFactory.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,36 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.directory.mitosis.common;
+
+/**
+ * Generates {@link UUID}.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface UUIDFactory
+{
+    /**
+     * 
+     * Create a new UUID
+     *
+     * @return The created UUID
+     */
+    UUID newInstance();
+}

Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/configuration/ReplicaIdPropertyEditor.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/configuration/ReplicaIdPropertyEditor.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/configuration/ReplicaIdPropertyEditor.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/configuration/ReplicaIdPropertyEditor.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,71 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.directory.mitosis.configuration;
+
+import java.beans.PropertyEditor;
+import java.beans.PropertyEditorSupport;
+
+import org.apache.directory.mitosis.common.ReplicaId;
+
+/**
+ * A {@link PropertyEditor} that converts strings into {@link ReplicaId}s
+ * and vice versa.
+ *
+ * @author Trustin Lee
+ * @version $Rev: 95 $, $Date: 2006-09-16 13:04:28 +0200 (Sat, 16 Sep 2006) $
+ */
+public class ReplicaIdPropertyEditor extends PropertyEditorSupport
+{
+    public ReplicaIdPropertyEditor()
+    {
+        super();
+    }
+
+    public ReplicaIdPropertyEditor( Object source )
+    {
+        super( source );
+    }
+
+    public String getAsText()
+    {
+        Object val = getValue();
+        if( val == null )
+        {
+            return "";
+        }
+        else
+        {
+            return val.toString();
+        }
+    }
+
+    public void setAsText( String text ) throws IllegalArgumentException
+    {
+        text = text.trim();
+        if( text.length() == 0 )
+        {
+            setValue( null );
+        }
+        else
+        {
+            setValue( new ReplicaId( text ) );
+        }
+    }
+}

Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/configuration/ReplicaPropertyEditor.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/configuration/ReplicaPropertyEditor.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/configuration/ReplicaPropertyEditor.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/configuration/ReplicaPropertyEditor.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,66 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.directory.mitosis.configuration;
+
+import java.beans.PropertyEditor;
+import java.beans.PropertyEditorSupport;
+
+import org.apache.directory.mitosis.common.Replica;
+
+/**
+ * A {@link PropertyEditor} that converts strings into {@link Replica}s
+ * and vice versa.
+ *
+ * @author Trustin Lee
+ * @version $Rev: 95 $, $Date: 2006-09-16 13:04:28 +0200 (Sat, 16 Sep 2006) $
+ */
+public class ReplicaPropertyEditor extends PropertyEditorSupport
+{
+    public ReplicaPropertyEditor()
+    {
+        super();
+    }
+
+    public ReplicaPropertyEditor( Object source )
+    {
+        super( source );
+    }
+
+    public String getAsText()
+    {
+        Object value = getValue();
+        if( value == null )
+        {
+            return "";
+        }
+        
+        Replica replica = ( Replica ) value;
+        return replica.getId().toString() +
+                '@' +
+                replica.getAddress().getAddress().getHostAddress() +
+                ':' +
+                replica.getAddress().getPort();
+    }
+
+    public void setAsText( String text ) throws IllegalArgumentException
+    {
+        setValue( new Replica( text ) );
+    }
+}

Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/configuration/ReplicationConfiguration.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/configuration/ReplicationConfiguration.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/configuration/ReplicationConfiguration.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/configuration/ReplicationConfiguration.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,296 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.directory.mitosis.configuration;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.apache.commons.collections.set.TypedSet;
+import org.apache.directory.mitosis.common.CSNFactory;
+import org.apache.directory.mitosis.common.Replica;
+import org.apache.directory.mitosis.common.ReplicaId;
+import org.apache.directory.mitosis.common.SimpleCSNFactory;
+import org.apache.directory.mitosis.common.SimpleUUIDFactory;
+import org.apache.directory.mitosis.common.UUIDFactory;
+import org.apache.directory.mitosis.store.ReplicationStore;
+import org.apache.directory.mitosis.store.derby.DerbyReplicationStore;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ReplicationConfiguration
+{
+    /** The logger */
+    private static Logger log = LoggerFactory.getLogger( ReplicationConfiguration.class );
+
+    private ReplicaId replicaId;
+    private int serverPort = 7846;
+    private int responseTimeout = 60;
+    private final Set peerReplicas = TypedSet.decorate( new HashSet(), Replica.class );
+    private UUIDFactory uuidFactory = new SimpleUUIDFactory();
+    private CSNFactory csnFactory = new SimpleCSNFactory();
+    private ReplicationStore store = new DerbyReplicationStore();
+    private int logMaxAge = 7; // a week (days)
+
+    public ReplicationConfiguration()
+    {
+    }
+    
+    public int getServerPort()
+    {
+        return serverPort;
+    }
+
+    public void setServerPort( int serverPort )
+    {
+        this.serverPort = serverPort;
+    }
+
+    public int getResponseTimeout()
+    {
+        return responseTimeout;
+    }
+
+    public void setResponseTimeout( int responseTimeout )
+    {
+        this.responseTimeout = responseTimeout;
+    }
+
+    public CSNFactory getCsnFactory()
+    {
+        return csnFactory;
+    }
+    
+    public void setCsnFactory( CSNFactory csnFactory )
+    {
+        this.csnFactory = csnFactory;
+    }
+    
+    public void addPeerReplica( Replica peer )
+    {
+        assert peer != null;
+        peerReplicas.add( peer );
+    }
+    
+    public void removePeerReplica( Replica peer )
+    {
+        assert peer != null;
+        peerReplicas.remove( peer );
+    }
+    
+    public void removeAllPeerReplicas()
+    {
+        peerReplicas.clear();
+    }
+    
+    public Set getPeerReplicas()
+    {
+        Set result = new HashSet();
+        result.addAll( peerReplicas );
+        return result;
+    }
+    
+    public void setPeerReplicas( Set replicas )
+    {
+        assert replicas != null;
+        
+        Set normalizedReplicas = new HashSet();
+        Iterator i = replicas.iterator();
+        while( i.hasNext() )
+        {
+            Object o = i.next();
+            if( o instanceof Replica )
+            {
+                normalizedReplicas.add( o );
+            }
+            else
+            {
+                normalizedReplicas.add( new Replica( o.toString() ) );
+            }
+        }
+        this.peerReplicas.clear();
+        this.peerReplicas.addAll( normalizedReplicas );
+    }
+    
+    public ReplicaId getReplicaId()
+    {
+        return replicaId;
+    }
+    
+    public void setReplicaId( ReplicaId replicaId )
+    {
+        assert replicaId != null;
+        this.replicaId = replicaId;
+    }
+    
+    public ReplicationStore getStore()
+    {
+        return store;
+    }
+    
+    public void setStore( ReplicationStore store )
+    {
+        this.store = store;
+    }
+    
+    public UUIDFactory getUuidFactory()
+    {
+        return uuidFactory;
+    }
+    
+    public void setUuidFactory( UUIDFactory uuidFactory )
+    {
+        this.uuidFactory = uuidFactory;
+    }
+    
+    public int getLogMaxAge()
+    {
+        return logMaxAge;
+    }
+    
+    public void setLogMaxAge( int logMaxAge )
+    {
+        if( logMaxAge <= 0 )
+        {
+            throw new ReplicationConfigurationException( "logMaxAge: " + logMaxAge );
+        }
+        
+        this.logMaxAge = logMaxAge;
+    }
+    
+    /**
+     * Validate Mitosis configuration.
+     * 
+     * We check that the configuration file contains valid
+     * parameters :
+     *  - a replicaId
+     *  - a valid server port (between 0 and 65535)
+     *  - a valid response timeout ( > 0 )
+     *  - a uuidFactory
+     *  - a CSN factory
+     *  - a store (derby)
+     *  - a list of valid replica, none of them being equal
+     *  to the replicaId 
+     *
+     * @throws ReplicationConfigurationException If the configuration file is invalid
+     */
+    public void validate() throws ReplicationConfigurationException
+    {
+        if ( replicaId == null )
+        {
+            log.error( "The replicaId is missing" );
+            throw new ReplicationConfigurationException( "Replica ID is not specified." );
+        }
+        
+        if ( serverPort < 0 || serverPort > 65535 )
+        {
+            log.error( "The replica port is not between 0 and 65535" );
+            throw new ReplicationConfigurationException( "Server port is invalid: " + serverPort );
+        }
+        
+        if ( responseTimeout <= 0 )
+        {
+            log.error( "The replica responsetimeout is negative" );
+            throw new ReplicationConfigurationException( "Invalid response timeout: " + responseTimeout );
+        }
+        
+        if( uuidFactory == null )
+        {
+            log.error( "The UUID factory has not been declared" );
+            throw new ReplicationConfigurationException( "UUID factory is not specified." );
+        }
+        
+        if( csnFactory == null )
+        {
+            log.error( "The CSN factory has not been declared" );
+            throw new ReplicationConfigurationException( "CSN factory is not specified." );
+        }
+        
+        if( store == null )
+        {
+            log.error( "The store has not been declared" );
+            throw new ReplicationConfigurationException( "Replication store is not specified." );
+        }
+        
+        if( peerReplicas.size() == 0 )
+        {
+            log.error( "The replicas peer list is empty" );
+            throw new ReplicationConfigurationException( "No peer replicas" );
+        }
+        
+        // Check the peer replicas.
+        // We should check that no replica has the same Id, and that we don't
+        // have two replicas on the same server with the same port
+        Set ids = new TreeSet();
+        Map servers = new HashMap();  
+        
+        // Initialize the set with this server replicaId
+        ids.add( replicaId.getId() );
+        
+        // And store the local inetadress
+        Integer localPort = new Integer( serverPort );
+        servers.put( "localhost", localPort );
+        servers.put( "127.0.0.1", localPort );
+        
+        try
+        {
+            servers.put( StringTools.lowerCase( InetAddress.getByName( "127.0.0.1" ).getHostName() ) , localPort );
+        }
+        catch ( UnknownHostException uhe )
+        {
+            // Should never occurs with 127.0.0.1
+            throw new ReplicationConfigurationException( "Unknown host name" );
+        }
+        
+        for ( Iterator peer = peerReplicas.iterator(); peer.hasNext(); )
+        {
+            Replica replica = ( Replica ) peer.next();
+            
+            if ( ids.contains( replica.getId() ) ) 
+            {
+                log.error( "Peer replica ID '{}' has already been declared.", replica.getId() );
+                throw new ReplicationConfigurationException( "Peer replica ID '" + replica.getId() + "' has already been declared." );
+            }
+            
+            // Now check that we don't already have a replica on a server with the same port 
+            String replicaServer = StringTools.lowerCase( replica.getAddress().getHostName() );
+            Integer replicaPort = new Integer( replica.getAddress().getPort() );
+            
+            if ( servers.containsKey( replicaServer ) )
+            {
+                Integer peerPort = ((Integer)servers.get( replicaServer ) );
+                
+                if ( replicaPort == peerPort )
+                {
+                    log.error( "The replica in the peer list has already been declared on the server {} with the port {}", replicaServer, peerPort );
+                    throw new ReplicationConfigurationException( "Replication store is not specified." );
+                }
+            }
+            
+            servers.put( replicaServer, replicaPort );
+        }
+    }
+}

Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/configuration/ReplicationConfigurationException.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/configuration/ReplicationConfigurationException.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/configuration/ReplicationConfigurationException.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/configuration/ReplicationConfigurationException.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,54 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.directory.mitosis.configuration;
+
+import org.apache.directory.mitosis.common.ReplicationException;
+
+public class ReplicationConfigurationException extends ReplicationException
+{
+    /**
+     * Declares the Serial Version Uid.
+     *
+     * @see <a
+     *      href="http://c2.com/cgi/wiki?AlwaysDeclareSerialVersionUid">Always
+     *      Declare Serial Version Uid</a>
+     */
+    private static final long serialVersionUID = 1L;
+
+    public ReplicationConfigurationException()
+    {
+        super();
+    }
+
+    public ReplicationConfigurationException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+
+    public ReplicationConfigurationException( String message )
+    {
+        super( message );
+    }
+
+    public ReplicationConfigurationException( Throwable cause )
+    {
+        super( cause );
+    }
+}

Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/AddAttributeOperation.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/AddAttributeOperation.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/AddAttributeOperation.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/AddAttributeOperation.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,63 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.directory.mitosis.operation;
+
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+
+import org.apache.directory.server.core.partition.PartitionNexus;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.mitosis.common.CSN;
+
+/**
+ * An {@link Operation} that adds an attribute to an entry.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AddAttributeOperation extends AttributeOperation
+{
+    private static final long serialVersionUID = 7373124294791982297L;
+
+    /**
+     * Creates a new operation that adds the specified attribute.
+     * 
+     * @param attribute an attribute to add
+     */
+    public AddAttributeOperation( CSN csn, Name name, Attribute attribute )
+    {
+        super( csn, name, attribute );
+    }
+    
+    public String toString()
+    {
+        return super.toString() + ".add( " + getAttribute() + " )";
+    }
+
+    protected void execute1( PartitionNexus nexus ) throws NamingException
+    {
+        Attributes attrs = new BasicAttributes();
+        attrs.put( getAttribute() );
+        nexus.modify( (LdapDN)getName(), DirContext.ADD_ATTRIBUTE, attrs );
+    }
+}

Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/AddEntryOperation.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/AddEntryOperation.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/AddEntryOperation.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/operation/AddEntryOperation.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,125 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.directory.mitosis.operation;
+
+import javax.naming.Name;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+
+import org.apache.directory.server.core.partition.PartitionNexus;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.util.NamespaceTools;
+import org.apache.directory.mitosis.common.CSN;
+import org.apache.directory.mitosis.operation.support.EntryUtil;
+import org.apache.directory.mitosis.store.ReplicationStore;
+
+/**
+ * An {@link Operation} that adds a new entry.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AddEntryOperation extends Operation
+{
+    private static final long serialVersionUID = 2294492811671880570L;
+
+    private final Name normalizedName;
+    private final String userProvidedName;
+    private final Attributes entry;
+
+    /**
+     * Creates a new instance.
+     * 
+     * @param entry an entry
+     */
+    public AddEntryOperation( CSN csn, Name normalizedName, String userProvidedName, Attributes entry )
+    {
+        super( csn );
+
+        assert normalizedName != null;
+        assert userProvidedName != null;
+        assert entry != null;
+        
+        this.normalizedName = normalizedName;
+        this.userProvidedName = userProvidedName;
+        this.entry = ( Attributes ) entry.clone();
+    }
+    
+    public String toString()
+    {
+        return super.toString() + ": [" + normalizedName + "].new( " + entry + " )";
+    }
+
+    protected void execute0( PartitionNexus nexus, ReplicationStore store ) throws NamingException
+    {
+        if( !EntryUtil.isEntryUpdatable( nexus, (LdapDN)normalizedName, getCSN() ) )
+        {
+            return;
+        }
+        EntryUtil.createGlueEntries( nexus, (LdapDN)normalizedName, false );
+        
+        // Replace the entry if an entry with the same name exists.
+        Attributes oldEntry = nexus.lookup( (LdapDN)normalizedName );
+        if( oldEntry != null )
+        {
+            // Find the attributes that new entry doesn't have.
+            Attributes attrsToRemove = ( Attributes ) oldEntry.clone();
+            NamingEnumeration e = oldEntry.getAll();
+            while( e.hasMore() )
+            {
+                Attribute attr = ( Attribute ) e.next();
+                String attrID = attr.getID();
+                if( entry.get( attrID ) != null )
+                {
+                    attrsToRemove.remove( attrID );
+                }
+            }
+            
+            // Don't let RN attribute be removed
+            String rnAttrID = NamespaceTools.getRdnAttribute(
+                    normalizedName.get( normalizedName.size() - 1 ) );
+            attrsToRemove.remove( rnAttrID );
+            
+            // Delete the attributes.
+            nexus.modify( (LdapDN)normalizedName, DirContext.REMOVE_ATTRIBUTE, entry );
+
+            // Remove RN attribute from new entry because it should be the same
+            // with the old one.
+            entry.remove( rnAttrID );
+
+            // Now replace old entries with the new attributes
+            nexus.modify( (LdapDN)normalizedName, DirContext.REPLACE_ATTRIBUTE, entry );
+        }
+        else
+        {
+            String rdn = normalizedName.get( normalizedName.size() - 1 );
+            // Remove the attribute first in case we're using a buggy 
+            // LockableAttributesImpl which doesn't replace old attributes
+            // when we put a new one.
+            entry.remove( NamespaceTools.getRdnAttribute( rdn ) );
+            entry.put(
+                    NamespaceTools.getRdnAttribute( rdn ),
+                    NamespaceTools.getRdnValue( rdn ) );
+            nexus.add( (LdapDN)normalizedName, entry );
+        }
+    }
+}