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 [4/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/...
Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/handler/ReplicationServerProtocolHandler.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/handler/ReplicationServerProtocolHandler.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/handler/ReplicationServerProtocolHandler.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/handler/ReplicationServerProtocolHandler.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,32 @@
+/*
+ * 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.service.protocol.handler;
+
+import org.apache.directory.mitosis.service.ReplicationService;
+import org.apache.directory.mitosis.service.protocol.codec.ReplicationClientProtocolCodecFactory;
+
+public class ReplicationServerProtocolHandler extends
+ ReplicationProtocolHandler
+{
+ public ReplicationServerProtocolHandler( ReplicationService service )
+ {
+ super( service, new ReplicationClientContextHandler(), new ReplicationClientProtocolCodecFactory() );
+ }
+}
Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/BaseMessage.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/BaseMessage.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/BaseMessage.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/BaseMessage.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,64 @@
+/*
+ * 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.service.protocol.message;
+
+import org.apache.directory.shared.ldap.util.EqualsBuilder;
+import org.apache.directory.shared.ldap.util.HashCodeBuilder;
+
+public abstract class BaseMessage {
+
+ private final int sequence;
+
+ protected BaseMessage( int sequence )
+ {
+ this.sequence = sequence;
+ }
+
+ public abstract int getType();
+
+ public int getSequence()
+ {
+ return sequence;
+ }
+
+ public boolean equals(Object object)
+ {
+ if (!(object instanceof BaseMessage))
+ {
+ return false;
+ }
+
+ BaseMessage rhs = (BaseMessage) object;
+
+ return new EqualsBuilder().append(
+ this.sequence, rhs.sequence).isEquals();
+ }
+
+ public int hashCode()
+ {
+ return new HashCodeBuilder(-1364566505, -1158072471).append(
+ this.sequence).toHashCode();
+ }
+
+ public String toString()
+ {
+ return String.valueOf( sequence );
+ }
+}
Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/BeginLogEntriesAckMessage.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/BeginLogEntriesAckMessage.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/BeginLogEntriesAckMessage.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/BeginLogEntriesAckMessage.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,102 @@
+/*
+ * 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.service.protocol.message;
+
+import org.apache.directory.shared.ldap.util.EqualsBuilder;
+import org.apache.directory.shared.ldap.util.HashCodeBuilder;
+import org.apache.directory.mitosis.common.CSNVector;
+import org.apache.directory.mitosis.service.protocol.Constants;
+
+public class BeginLogEntriesAckMessage extends ResponseMessage
+{
+ private final CSNVector purgeVector;
+ private final CSNVector updateVector;
+
+ public BeginLogEntriesAckMessage( int sequence, int responseCode,
+ CSNVector purgeVector,
+ CSNVector updateVector )
+ {
+ super( sequence, responseCode );
+
+ if( responseCode == Constants.OK )
+ {
+ assert purgeVector != null;
+ assert updateVector != null;
+
+ this.purgeVector = purgeVector;
+ this.updateVector = updateVector;
+ }
+ else
+ {
+ this.purgeVector = null;
+ this.updateVector = null;
+ }
+ }
+
+ public int getType()
+ {
+ return Constants.GET_UPDATE_VECTOR_ACK;
+ }
+
+ public CSNVector getPurgeVector()
+ {
+ return purgeVector;
+ }
+
+ public CSNVector getUpdateVector()
+ {
+ return updateVector;
+ }
+
+ /**
+ * @see java.lang.Object#equals(Object)
+ */
+ public boolean equals(Object object)
+ {
+ if (object == this) {
+ return true;
+ }
+
+ if (!(object instanceof BeginLogEntriesAckMessage))
+ {
+ return false;
+ }
+
+ BeginLogEntriesAckMessage rhs = (BeginLogEntriesAckMessage) object;
+
+ return new EqualsBuilder().appendSuper(super.equals(object)).append(
+ this.purgeVector, rhs.purgeVector).append(
+ this.updateVector, rhs.updateVector).isEquals();
+ }
+
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode()
+ {
+ return new HashCodeBuilder(537917217, 1652875233).appendSuper(
+ super.hashCode()).append(this.purgeVector).append(this.updateVector).toHashCode();
+ }
+
+ public String toString()
+ {
+ return "[BeginLogEntriesAck] " + super.toString() + ", PV: " + purgeVector + ", UV: " + updateVector;
+ }
+}
Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/BeginLogEntriesMessage.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/BeginLogEntriesMessage.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/BeginLogEntriesMessage.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/BeginLogEntriesMessage.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,59 @@
+/*
+ * 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.service.protocol.message;
+
+import org.apache.directory.mitosis.service.protocol.Constants;
+import org.apache.directory.shared.ldap.util.EqualsBuilder;
+import org.apache.directory.shared.ldap.util.HashCodeBuilder;
+
+public class BeginLogEntriesMessage extends BaseMessage
+{
+
+ public BeginLogEntriesMessage( int sequence )
+ {
+ super( sequence );
+ }
+
+ public int getType()
+ {
+ return Constants.BEGIN_LOG_ENTRIES;
+ }
+
+ public boolean equals( final Object other )
+ {
+ if( !( other instanceof BeginLogEntriesMessage ) )
+ {
+ return false;
+ }
+
+ return new EqualsBuilder().isEquals();
+ }
+
+ public int hashCode()
+ {
+ return new HashCodeBuilder( -1480829129, 951761287 ).appendSuper(
+ super.hashCode() ).toHashCode();
+ }
+
+ public String toString()
+ {
+ return "[BeginLogEntries] " + super.toString();
+ }
+}
Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/EndLogEntriesAckMessage.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/EndLogEntriesAckMessage.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/EndLogEntriesAckMessage.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/EndLogEntriesAckMessage.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,60 @@
+/*
+ * 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.service.protocol.message;
+
+import org.apache.directory.mitosis.service.protocol.Constants;
+import org.apache.directory.shared.ldap.util.EqualsBuilder;
+import org.apache.directory.shared.ldap.util.HashCodeBuilder;
+
+public class EndLogEntriesAckMessage extends ResponseMessage
+{
+
+ public EndLogEntriesAckMessage( int sequence, int responseCode )
+ {
+ super( sequence, responseCode );
+ }
+
+ public int getType()
+ {
+ return Constants.END_LOG_ENTRIES_ACK;
+ }
+
+ public boolean equals( Object object )
+ {
+ if( !( object instanceof EndLogEntriesAckMessage ) )
+ {
+ return false;
+ }
+
+ return new EqualsBuilder().appendSuper( super.equals( object ) )
+ .isEquals();
+ }
+
+ public int hashCode()
+ {
+ return new HashCodeBuilder( 247639103, -470023671 ).appendSuper(
+ super.hashCode() ).toHashCode();
+ }
+
+ public String toString()
+ {
+ return "[EndLogEntriesAck] " + super.toString();
+ }
+}
Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/EndLogEntriesMessage.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/EndLogEntriesMessage.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/EndLogEntriesMessage.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/EndLogEntriesMessage.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,59 @@
+/*
+ * 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.service.protocol.message;
+
+import org.apache.directory.mitosis.service.protocol.Constants;
+import org.apache.directory.shared.ldap.util.EqualsBuilder;
+import org.apache.directory.shared.ldap.util.HashCodeBuilder;
+
+public class EndLogEntriesMessage extends BaseMessage
+{
+
+ public EndLogEntriesMessage( int sequence )
+ {
+ super( sequence );
+ }
+
+ public int getType()
+ {
+ return Constants.END_LOG_ENTRIES;
+ }
+
+ public boolean equals( final Object other )
+ {
+ if( !( other instanceof EndLogEntriesMessage ) )
+ {
+ return false;
+ }
+
+ return new EqualsBuilder().isEquals();
+ }
+
+ public int hashCode()
+ {
+ return new HashCodeBuilder( 1892305163, -1367551105 ).appendSuper(
+ super.hashCode() ).toHashCode();
+ }
+
+ public String toString()
+ {
+ return "[EndLogEntries] " + super.toString();
+ }
+}
Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/LogEntryAckMessage.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/LogEntryAckMessage.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/LogEntryAckMessage.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/LogEntryAckMessage.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,69 @@
+/*
+ * 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.service.protocol.message;
+
+import org.apache.directory.mitosis.service.protocol.Constants;
+import org.apache.directory.shared.ldap.util.EqualsBuilder;
+import org.apache.directory.shared.ldap.util.HashCodeBuilder;
+
+public class LogEntryAckMessage extends ResponseMessage
+{
+ public LogEntryAckMessage( int sequence, int responseCode )
+ {
+ super(sequence, responseCode);
+ }
+
+ public int getType()
+ {
+ return Constants.LOG_ENTRY_ACK;
+ }
+
+ /**
+ * @see java.lang.Object#equals(Object)
+ */
+ public boolean equals(Object object)
+ {
+ if (object == this)
+ {
+ return true;
+ }
+
+ if (!(object instanceof LogEntryAckMessage))
+ {
+ return false;
+ }
+
+ return new EqualsBuilder().appendSuper(super.equals(object)).isEquals();
+ }
+
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode()
+ {
+ return new HashCodeBuilder(-873557437, -1464393829).appendSuper(
+ super.hashCode()).toHashCode();
+ }
+
+ public String toString()
+ {
+ return "[LogEntryAck] " + super.toString();
+ }
+}
Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/LogEntryMessage.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/LogEntryMessage.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/LogEntryMessage.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/LogEntryMessage.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,81 @@
+/*
+ * 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.service.protocol.message;
+
+import org.apache.directory.mitosis.operation.Operation;
+import org.apache.directory.mitosis.service.protocol.Constants;
+import org.apache.directory.shared.ldap.util.EqualsBuilder;
+import org.apache.directory.shared.ldap.util.HashCodeBuilder;
+
+public class LogEntryMessage extends BaseMessage
+{
+ private final Operation operation;
+
+ public LogEntryMessage( int sequence, Operation operation )
+ {
+ super(sequence);
+ this.operation = operation;
+ }
+
+ public int getType()
+ {
+ return Constants.LOG_ENTRY;
+ }
+
+ public Operation getOperation()
+ {
+ return operation;
+ }
+
+ /**
+ * @see java.lang.Object#equals(Object)
+ */
+ public boolean equals(Object object)
+ {
+ if (object == this) {
+ return true;
+ }
+
+ if (!(object instanceof LogEntryMessage))
+ {
+ return false;
+ }
+
+ LogEntryMessage rhs = (LogEntryMessage) object;
+
+ return new EqualsBuilder().appendSuper(super.equals(object)).append(
+ this.operation, rhs.operation).isEquals();
+ }
+
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode()
+ {
+ return new HashCodeBuilder(633013569, -1063609843).appendSuper(
+ super.hashCode()).append(this.operation)
+ .toHashCode();
+ }
+
+ public String toString()
+ {
+ return "[LogEntry] " + super.toString() + ", " + operation;
+ }
+}
Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/LoginAckMessage.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/LoginAckMessage.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/LoginAckMessage.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/LoginAckMessage.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,81 @@
+/*
+ * 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.service.protocol.message;
+
+import org.apache.directory.shared.ldap.util.EqualsBuilder;
+import org.apache.directory.shared.ldap.util.HashCodeBuilder;
+import org.apache.directory.mitosis.common.ReplicaId;
+import org.apache.directory.mitosis.service.protocol.Constants;
+
+public class LoginAckMessage extends ResponseMessage
+{
+ private ReplicaId replicaId;
+
+ public LoginAckMessage( int sequence, int responseCode, ReplicaId replicaId )
+ {
+ super(sequence, responseCode);
+ this.replicaId = replicaId;
+ }
+
+ public int getType()
+ {
+ return Constants.LOGIN_ACK;
+ }
+
+ public ReplicaId getReplicaId()
+ {
+ return replicaId;
+ }
+
+ /**
+ * @see java.lang.Object#equals(Object)
+ */
+ public boolean equals(Object object)
+ {
+ if (object == this)
+ {
+ return true;
+ }
+
+ if (!(object instanceof LoginAckMessage))
+ {
+ return false;
+ }
+
+ LoginAckMessage rhs = (LoginAckMessage) object;
+
+ return new EqualsBuilder().appendSuper(super.equals(object)).
+ append(this.replicaId, rhs.replicaId).isEquals();
+ }
+
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode()
+ {
+ return new HashCodeBuilder(-280394717, -328404193).appendSuper(
+ super.hashCode()).append(this.replicaId).toHashCode();
+ }
+
+ public String toString()
+ {
+ return "[LoginAck] " + super.toString() + ", " + replicaId;
+ }
+}
Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/LoginMessage.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/LoginMessage.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/LoginMessage.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/LoginMessage.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,77 @@
+/*
+ * 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.service.protocol.message;
+
+import org.apache.directory.shared.ldap.util.EqualsBuilder;
+import org.apache.directory.shared.ldap.util.HashCodeBuilder;
+import org.apache.directory.mitosis.common.ReplicaId;
+import org.apache.directory.mitosis.service.protocol.Constants;
+
+public class LoginMessage extends BaseMessage
+{
+ private final ReplicaId replicaId;
+
+ public LoginMessage( int sequence, ReplicaId replicaId )
+ {
+ super( sequence );
+
+ this.replicaId = replicaId;
+ }
+
+ public int getType()
+ {
+ return Constants.LOGIN;
+ }
+
+ public ReplicaId getReplicaId()
+ {
+ return replicaId;
+ }
+
+ /**
+ * @see java.lang.Object#equals(Object)
+ */
+ public boolean equals(Object object)
+ {
+ if (!(object instanceof LoginMessage))
+ {
+ return false;
+ }
+
+ LoginMessage rhs = (LoginMessage) object;
+
+ return new EqualsBuilder().appendSuper(super.equals(object)).append(
+ this.replicaId, rhs.replicaId).isEquals();
+ }
+
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode()
+ {
+ return new HashCodeBuilder(1520317245, 1630850531).appendSuper(
+ super.hashCode()).append(this.replicaId).toHashCode();
+ }
+
+ public String toString()
+ {
+ return "[Login] " + super.toString() + ", " + replicaId;
+ }
+}
Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/ResponseMessage.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/ResponseMessage.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/ResponseMessage.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/message/ResponseMessage.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,75 @@
+/*
+ * 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.service.protocol.message;
+
+import org.apache.directory.shared.ldap.util.EqualsBuilder;
+import org.apache.directory.shared.ldap.util.HashCodeBuilder;
+
+public abstract class ResponseMessage extends BaseMessage
+{
+ private final int responseCode;
+
+ public ResponseMessage( int sequence, int responseCode )
+ {
+ super(sequence);
+
+ this.responseCode = responseCode;
+ }
+
+ public int getResponseCode()
+ {
+ return responseCode;
+ }
+
+ /**
+ * @see java.lang.Object#equals(Object)
+ */
+ public boolean equals(Object object)
+ {
+ if (object == this)
+ {
+ return true;
+ }
+
+ if (!(object instanceof ResponseMessage))
+ {
+ return false;
+ }
+
+ ResponseMessage rhs = (ResponseMessage) object;
+
+ return new EqualsBuilder().appendSuper(super.equals(object)).append(
+ this.responseCode, rhs.responseCode).isEquals();
+ }
+
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode()
+ {
+ return new HashCodeBuilder(-710373179, 1116475565).appendSuper(
+ super.hashCode()).append(this.responseCode).toHashCode();
+ }
+
+ public String toString()
+ {
+ return super.toString() + ": " + responseCode;
+ }
+}
Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/ReplicationLogIterator.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/ReplicationLogIterator.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/ReplicationLogIterator.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/ReplicationLogIterator.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,28 @@
+/*
+ * 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.store;
+
+import org.apache.directory.mitosis.operation.Operation;
+
+public interface ReplicationLogIterator {
+ boolean next();
+ void close();
+ Operation getOperation();
+}
Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/ReplicationStore.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/ReplicationStore.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/ReplicationStore.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/ReplicationStore.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,69 @@
+/*
+ * 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.store;
+
+import java.util.Set;
+
+import javax.naming.Name;
+
+import org.apache.directory.server.core.DirectoryServiceConfiguration;
+import org.apache.directory.mitosis.common.CSN;
+import org.apache.directory.mitosis.common.CSNVector;
+import org.apache.directory.mitosis.common.ReplicaId;
+import org.apache.directory.mitosis.common.UUID;
+import org.apache.directory.mitosis.configuration.ReplicationConfiguration;
+import org.apache.directory.mitosis.operation.Operation;
+
+public interface ReplicationStore {
+
+ void open( DirectoryServiceConfiguration serviceCfg, ReplicationConfiguration cfg );
+
+ void close();
+
+ ReplicaId getReplicaId();
+
+ Set getKnownReplicaIds();
+
+ // UUID to DN table operations
+
+ Name getDN( UUID uuid );
+
+ boolean putUUID( UUID uuid, Name dn );
+
+ boolean removeUUID( UUID uuid );
+
+ // Log entry operations
+
+ void putLog( Operation operation );
+
+ ReplicationLogIterator getLogs( CSN fromCSN, boolean inclusive );
+
+ ReplicationLogIterator getLogs( CSNVector updateVector, boolean inclusive );
+
+ int removeLogs( CSN toCSN, boolean inclusive );
+
+ int getLogSize();
+
+ int getLogSize( ReplicaId replicaId );
+
+ CSNVector getUpdateVector();
+
+ CSNVector getPurgeVector();
+}
Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/ReplicationStoreException.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/ReplicationStoreException.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/ReplicationStoreException.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/ReplicationStoreException.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,41 @@
+/*
+ * 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.store;
+
+public class ReplicationStoreException extends RuntimeException {
+
+ private static final long serialVersionUID = 3257289127798913336L;
+
+ public ReplicationStoreException() {
+ super();
+ }
+
+ public ReplicationStoreException(String message) {
+ super(message);
+ }
+
+ public ReplicationStoreException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ReplicationStoreException(Throwable cause) {
+ super(cause);
+ }
+}
Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/derby/DerbyReplicationLogIterator.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/derby/DerbyReplicationLogIterator.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/derby/DerbyReplicationLogIterator.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/derby/DerbyReplicationLogIterator.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.store.derby;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.apache.directory.mitosis.common.CSN;
+import org.apache.directory.mitosis.common.ReplicaId;
+import org.apache.directory.mitosis.common.SimpleCSN;
+import org.apache.directory.mitosis.operation.Operation;
+import org.apache.directory.mitosis.operation.OperationCodec;
+import org.apache.directory.mitosis.store.ReplicationLogIterator;
+import org.apache.directory.mitosis.store.ReplicationStoreException;
+
+class DerbyReplicationLogIterator implements ReplicationLogIterator
+{
+ private final OperationCodec codec;
+ private final Connection con;
+ private final Statement stmt;
+ private final ResultSet rs;
+
+ DerbyReplicationLogIterator( OperationCodec codec,
+ Connection con, Statement stmt, ResultSet rs )
+ {
+ this.codec = codec;
+ this.con = con;
+ this.stmt = stmt;
+ this.rs = rs;
+ }
+
+ public boolean next() {
+ try
+ {
+ return rs.next();
+ }
+ catch( SQLException e )
+ {
+ throw new ReplicationStoreException( e );
+ }
+ }
+
+ public void close() {
+ SQLUtil.cleanup( con, stmt, rs );
+ }
+
+ public CSN getCSN()
+ {
+ try
+ {
+ ReplicaId replicaId = new ReplicaId( rs.getString( 1 ) );
+ long timestamp = rs.getLong( 2 );
+ int operationSequence = rs.getInt( 3 );
+ return new SimpleCSN( timestamp, replicaId, operationSequence );
+ }
+ catch( Exception e )
+ {
+ throw new ReplicationStoreException( e );
+ }
+ }
+
+ public Operation getOperation()
+ {
+ try
+ {
+ return codec.decode( rs.getBytes( 4 ) );
+ }
+ catch( Exception e )
+ {
+ throw new ReplicationStoreException( e );
+ }
+ }
+}
Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/derby/DerbyReplicationStore.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/derby/DerbyReplicationStore.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/derby/DerbyReplicationStore.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/derby/DerbyReplicationStore.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,719 @@
+/*
+ * 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.store.derby;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.naming.Name;
+import javax.naming.ldap.LdapName;
+
+import org.apache.commons.dbcp.BasicDataSource;
+import org.apache.directory.server.core.DirectoryServiceConfiguration;
+import org.apache.directory.mitosis.common.CSN;
+import org.apache.directory.mitosis.common.CSNVector;
+import org.apache.directory.mitosis.common.ReplicaId;
+import org.apache.directory.mitosis.common.SimpleCSN;
+import org.apache.directory.mitosis.common.UUID;
+import org.apache.directory.mitosis.configuration.ReplicationConfiguration;
+import org.apache.directory.mitosis.operation.Operation;
+import org.apache.directory.mitosis.operation.OperationCodec;
+import org.apache.directory.mitosis.store.ReplicationLogIterator;
+import org.apache.directory.mitosis.store.ReplicationStore;
+import org.apache.directory.mitosis.store.ReplicationStoreException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DerbyReplicationStore implements ReplicationStore
+{
+ private static final Logger log = LoggerFactory.getLogger( DerbyReplicationStore.class );
+
+ private static final String DEFAULT_TABLE_PREFIX = "REPLICATION_";
+ private static final String KEY_REPLICA_ID = "replicaId";
+
+ private static final String DRIVER_NAME = "org.apache.derby.jdbc.EmbeddedDriver";
+ private static final String DB_URI_PREFIX = "jdbc:derby:";
+
+ private String dbURI;
+ private BasicDataSource dataSource;
+ private ReplicaId replicaId;
+ private String tablePrefix = DEFAULT_TABLE_PREFIX;
+ private String metadataTableName;
+ private String uuidTableName;
+ private String logTableName;
+ private Set knownReplicaIds;
+ private final Object knownReplicaIdsLock = new Object();
+ private final OperationCodec operationCodec = new OperationCodec();
+
+
+ public String getTablePrefix()
+ {
+ return tablePrefix;
+ }
+
+ public void setTablePrefix( String tablePrefix )
+ {
+ if( tablePrefix == null )
+ {
+ tablePrefix = DEFAULT_TABLE_PREFIX;
+ }
+
+ tablePrefix = tablePrefix.trim();
+ if( tablePrefix.length() == 0 )
+ {
+ tablePrefix = DEFAULT_TABLE_PREFIX;
+ }
+
+ this.tablePrefix = tablePrefix;
+ }
+
+ public void open( DirectoryServiceConfiguration serviceCfg, ReplicationConfiguration cfg )
+ {
+ replicaId = cfg.getReplicaId();
+
+ // Calculate DB URI
+ dbURI = DB_URI_PREFIX + serviceCfg.getStartupConfiguration().getWorkingDirectory().getPath() + File.separator + "replication";
+
+ // Create database if not exists.
+ try
+ {
+ Class.forName( DRIVER_NAME );
+ Connection con = DriverManager.getConnection( dbURI + ";create=true" );
+ con.close();
+ }
+ catch( Exception e )
+ {
+ throw new ReplicationStoreException( "Failed to initialize Derby database.", e );
+ }
+
+ // Initialize DataSource
+ BasicDataSource dataSource = new BasicDataSource();
+ dataSource.setDriverClassName( DRIVER_NAME );
+ dataSource.setUrl( dbURI );
+ dataSource.setUsername( "sa" );
+ dataSource.setPassword( "" );
+ this.dataSource = dataSource;
+
+ // Pre-calculate table names
+ metadataTableName = tablePrefix + "METADATA";
+ uuidTableName = tablePrefix + "UUID";
+ logTableName = tablePrefix + "LOG";
+
+ initSchema();
+ loadMetadata();
+ }
+
+ private void initSchema()
+ {
+ Connection con = null;
+ Statement stmt = null;
+ ResultSet rs = null;
+
+ try
+ {
+ con = dataSource.getConnection();
+ con.setAutoCommit( true );
+
+ stmt = con.createStatement();
+
+ try
+ {
+ rs = stmt.executeQuery( "SELECT M_KEY FROM " + metadataTableName + " WHERE M_KEY IS NULL" );
+ rs.close();
+ rs = null;
+ }
+ catch( SQLException e )
+ {
+ stmt.executeUpdate( "CREATE TABLE " + metadataTableName + " (" +
+ " M_KEY VARCHAR(30) NOT NULL PRIMARY KEY," +
+ " M_VALUE VARCHAR(100) NOT NULL )" );
+ }
+
+ try
+ {
+ rs = stmt.executeQuery( "SELECT UUID FROM " + uuidTableName + " WHERE UUID IS NULL" );
+ rs.close();
+ rs = null;
+ }
+ catch( SQLException e )
+ {
+ stmt.executeUpdate( "CREATE TABLE " + uuidTableName + " (" +
+ " UUID CHAR(32) NOT NULL PRIMARY KEY," +
+ " DN CLOB NOT NULL" +
+ ")" );
+ }
+
+ try
+ {
+ rs = stmt.executeQuery( "SELECT CSN_REPLICA_ID FROM " + logTableName + " WHERE CSN_REPLICA_ID IS NULL" );
+ rs.close();
+ rs = null;
+ }
+ catch( SQLException e )
+ {
+ stmt.executeUpdate( "CREATE TABLE " + logTableName + " (" +
+ " CSN_REPLICA_ID VARCHAR(16) NOT NULL," +
+ " CSN_TIMESTAMP BIGINT NOT NULL," +
+ " CSN_OP_SEQ INTEGER NOT NULL," +
+ " OPERATION BLOB NOT NULL," +
+ "CONSTRAINT " + logTableName + "_PK PRIMARY KEY (" +
+ " CSN_REPLICA_ID," +
+ " CSN_TIMESTAMP," +
+ " CSN_OP_SEQ)" +
+ ")");
+ }
+ }
+ catch( SQLException e )
+ {
+ throw new ReplicationStoreException( "Failed to initialize DB schema.", e );
+ }
+ finally
+ {
+ SQLUtil.cleanup( con, stmt, rs );
+ }
+ }
+
+ private void loadMetadata()
+ {
+ Connection con = null;
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+
+ try
+ {
+ con = dataSource.getConnection();
+ con.setAutoCommit( true );
+ con.setTransactionIsolation( Connection.TRANSACTION_REPEATABLE_READ );
+ con.setReadOnly( true );
+
+ // Check if replicaId is already registered
+ ps = con.prepareStatement( "SELECT M_VALUE FROM " + metadataTableName + " WHERE M_KEY=?" );
+ ps.setString( 1, KEY_REPLICA_ID );
+ rs = ps.executeQuery();
+ if( rs.next() )
+ {
+ // If already registered, match it with what user specified.
+ String actualReplicaId = rs.getString( 1 );
+ if( !replicaId.getId().equalsIgnoreCase( actualReplicaId ) )
+ {
+ throw new ReplicationStoreException(
+ "Replica ID mismatches: " + actualReplicaId +
+ " (expected: " + replicaId + ")" );
+ }
+ }
+ else
+ {
+ rs.close();
+ rs = null;
+ ps.close();
+ ps = null;
+
+ con.setReadOnly( false );
+ // If not registered yet, register with what user specified.
+ ps = con.prepareStatement( "INSERT INTO " + metadataTableName + " (M_KEY, M_VALUE) VALUES (?,?)" );
+ ps.setString( 1, KEY_REPLICA_ID );
+ ps.setString( 2, replicaId.getId() );
+ ps.executeUpdate();
+ }
+
+ if( rs != null )
+ {
+ rs.close();
+ rs = null;
+ }
+ ps.close();
+ ps = null;
+
+ // Get known replica IDs.
+ ps = con.prepareStatement( "SELECT DISTINCT CSN_REPLICA_ID FROM " + logTableName );
+ rs = ps.executeQuery();
+ knownReplicaIds = new HashSet();
+ while( rs.next() )
+ {
+ knownReplicaIds.add( new ReplicaId( rs.getString( 1 ) ) );
+ }
+ }
+ catch( Exception e )
+ {
+ if( e instanceof ReplicationStoreException )
+ {
+ throw ( ReplicationStoreException ) e;
+ }
+ throw new ReplicationStoreException( e );
+ }
+ finally
+ {
+ SQLUtil.cleanup( con, ps, rs );
+ }
+ }
+
+ public void close()
+ {
+ try
+ {
+ dataSource.close();
+ }
+ catch( SQLException e )
+ {
+ log.warn( "Failed to close the dataSource.", e );
+ }
+ dataSource = null;
+ replicaId = null;
+
+ try
+ {
+ DriverManager.getConnection( dbURI + ";shutdown=true" );
+ }
+ catch( Exception e )
+ {
+ // An exception is thrown always.
+ }
+ }
+
+ public ReplicaId getReplicaId()
+ {
+ return replicaId;
+ }
+
+ public Set getKnownReplicaIds()
+ {
+ return new HashSet( knownReplicaIds );
+ }
+
+ public Name getDN( UUID uuid )
+ {
+ Connection con = null;
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+
+ try
+ {
+ con = dataSource.getConnection();
+ con.setTransactionIsolation( Connection.TRANSACTION_READ_COMMITTED );
+ con.setReadOnly( true );
+ ps = con.prepareStatement( "SELECT DN FROM " + uuidTableName + " WHERE UUID=?" );
+ ps.setString( 1, uuid.toOctetString() );
+ rs = ps.executeQuery();
+ if( rs.next() )
+ {
+ return new LdapName( rs.getString( 1 ) );
+ }
+ else
+ {
+ return null;
+ }
+ }
+ catch( Exception e )
+ {
+ throw new ReplicationStoreException( e );
+ }
+ finally
+ {
+ SQLUtil.cleanup( con, ps, rs );
+ }
+ }
+
+ public boolean putUUID( UUID uuid, Name dn )
+ {
+ String uuidString = uuid.toOctetString();
+ Connection con = null;
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+
+ try
+ {
+ con = dataSource.getConnection();
+ con.setAutoCommit( false );
+ con.setTransactionIsolation( Connection.TRANSACTION_REPEATABLE_READ );
+ con.setReadOnly( true );
+
+ // Check if the specified uuid already exists
+ ps = con.prepareStatement( "SELECT UUID FROM " + uuidTableName + " WHERE UUID=?" );
+ ps.setString( 1, uuidString );
+ rs = ps.executeQuery();
+ if( rs.next() )
+ {
+ return false;
+ }
+
+ rs.close();
+ rs = null;
+
+ // insert
+ con.setReadOnly( false );
+ ps = con.prepareStatement( "INSERT INTO " + uuidTableName + " (UUID, DN) VALUES(?,?)" );
+ ps.setString( 1, uuidString );
+ ps.setString( 2, dn.toString() );
+
+ int updateCnt = ps.executeUpdate();
+ con.commit();
+ return updateCnt == 1;
+ }
+ catch( Exception e )
+ {
+ try
+ {
+ con.rollback();
+ } catch (SQLException e1) {
+ }
+
+ throw new ReplicationStoreException( e );
+ }
+ finally
+ {
+ SQLUtil.cleanup( con, ps, rs );
+ }
+ }
+
+ public boolean removeUUID( UUID uuid )
+ {
+ String uuidString = uuid.toOctetString();
+ Connection con = null;
+ PreparedStatement ps = null;
+
+ try
+ {
+ con = dataSource.getConnection();
+ con.setAutoCommit( true );
+ con.setTransactionIsolation( Connection.TRANSACTION_READ_UNCOMMITTED );
+ con.setReadOnly( false );
+
+ // Check if the specified uuid already exists
+ ps = con.prepareStatement( "DELETE FROM " + uuidTableName + " WHERE UUID=?" );
+ ps.setString( 1, uuidString );
+ return ps.executeUpdate() == 1;
+ }
+ catch( Exception e )
+ {
+ throw new ReplicationStoreException( e );
+ }
+ finally
+ {
+ SQLUtil.cleanup( con, ps, null );
+ }
+ }
+
+ public void putLog( Operation op )
+ {
+ CSN csn = op.getCSN();
+ byte[] encodedOp = operationCodec.encode( op );
+ Connection con = null;
+ PreparedStatement ps = null;
+
+ try
+ {
+ con = dataSource.getConnection();
+ con.setAutoCommit( true );
+ con.setTransactionIsolation( Connection.TRANSACTION_READ_UNCOMMITTED );
+ con.setReadOnly( false );
+
+ // Check if the specified uuid already exists
+ ps = con.prepareStatement( "INSERT INTO " + logTableName + " (CSN_REPLICA_ID, CSN_TIMESTAMP, CSN_OP_SEQ, OPERATION) VALUES(?,?,?,?)" );
+ ps.setString( 1, csn.getReplicaId().getId() );
+ ps.setLong( 2, csn.getTimestamp() );
+ ps.setInt( 3, csn.getOperationSequence() );
+ ps.setBytes( 4, encodedOp );
+ if( ps.executeUpdate() != 1 )
+ {
+ throw new ReplicationStoreException( "Failed to insert a row." );
+ }
+ }
+ catch( Exception e )
+ {
+ if( e instanceof ReplicationStoreException )
+ {
+ throw ( ReplicationStoreException ) e;
+ }
+
+ throw new ReplicationStoreException( e );
+ }
+ finally
+ {
+ SQLUtil.cleanup( con, ps, null );
+ }
+
+ if( !knownReplicaIds.contains( csn.getReplicaId() ) )
+ {
+ synchronized( knownReplicaIdsLock )
+ {
+ Set newKnownReplicaIds = new HashSet( knownReplicaIds );
+ newKnownReplicaIds.add( csn.getReplicaId() );
+ knownReplicaIds = newKnownReplicaIds;
+ }
+ }
+ }
+
+ public ReplicationLogIterator getLogs( CSNVector updateVector, boolean inclusive )
+ {
+ Connection con = null;
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+
+ updateVector = getNormalizedUpdateVector( updateVector );
+
+ StringBuffer buf = new StringBuffer(
+ "SELECT CSN_REPLICA_ID, CSN_TIMESTAMP, CSN_OP_SEQ, OPERATION FROM " +
+ logTableName + " " );
+
+ if( updateVector.size() > 0 )
+ {
+ buf.append( "WHERE " );
+ for( int i = updateVector.size();; )
+ {
+ buf.append( "( CSN_REPLICA_ID = ? AND (CSN_TIMESTAMP = ? AND CSN_OP_SEQ >" + (inclusive? "=" : "" ) + " ? OR CSN_TIMESTAMP > ?) ) " );
+ i --;
+ if( i == 0 )
+ {
+ break;
+ }
+ else
+ {
+ buf.append( "OR " );
+ }
+
+ }
+ }
+ buf.append( "ORDER BY CSN_TIMESTAMP ASC, CSN_OP_SEQ ASC" );
+
+ String query = buf.toString();
+
+ try
+ {
+ con = dataSource.getConnection();
+ con.setAutoCommit( true );
+ con.setTransactionIsolation( Connection.TRANSACTION_READ_UNCOMMITTED );
+ con.setReadOnly( true );
+
+ // Check if the specified uuid already exists
+ ps = con.prepareStatement( query );
+
+ Iterator i = updateVector.getReplicaIds().iterator();
+ int paramIdx = 1;
+ while( i.hasNext() )
+ {
+ ReplicaId replicaId = ( ReplicaId ) i.next();
+ CSN csn = updateVector.getCSN( replicaId );
+ ps.setString( paramIdx++, replicaId.getId() );
+ ps.setLong( paramIdx++, csn.getTimestamp() );
+ ps.setInt( paramIdx++, csn.getOperationSequence() );
+ ps.setLong( paramIdx++, csn.getTimestamp() );
+ }
+ rs = ps.executeQuery();
+
+ return new DerbyReplicationLogIterator( operationCodec, con, ps, rs );
+ }
+ catch( Exception e )
+ {
+ throw new ReplicationStoreException( e );
+ }
+ }
+
+ private CSNVector getNormalizedUpdateVector( CSNVector updateVector )
+ {
+ CSNVector newUV = new CSNVector();
+ synchronized( knownReplicaIds )
+ {
+ Iterator i = knownReplicaIds.iterator();
+ while( i.hasNext() )
+ {
+ newUV.setCSN( new SimpleCSN( 0, ( ReplicaId ) i.next(), 0 ) );
+ }
+ }
+
+ newUV.setAllCSN( updateVector );
+ return newUV;
+ }
+
+ public ReplicationLogIterator getLogs( CSN fromCSN, boolean inclusive )
+ {
+ Connection con = null;
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+
+ try
+ {
+ con = dataSource.getConnection();
+ con.setAutoCommit( true );
+ con.setTransactionIsolation( Connection.TRANSACTION_READ_UNCOMMITTED );
+ con.setReadOnly( true );
+
+ // Check if the specified uuid already exists
+ ps = con.prepareStatement( "SELECT CSN_REPLICA_ID, CSN_TIMESTAMP, CSN_OP_SEQ, OPERATION FROM " + logTableName + " " +
+ "WHERE CSN_REPLICA_ID = ? AND (CSN_TIMESTAMP = ? AND CSN_OP_SEQ >" + (inclusive? "=" : "" ) + " ? OR CSN_TIMESTAMP > ?) " +
+ "ORDER BY CSN_TIMESTAMP ASC, CSN_OP_SEQ ASC");
+ ps.setString( 1, fromCSN.getReplicaId().getId() );
+ ps.setLong( 2, fromCSN.getTimestamp() );
+ ps.setInt( 3, fromCSN.getOperationSequence() );
+ ps.setLong( 4, fromCSN.getTimestamp() );
+ rs = ps.executeQuery();
+
+ return new DerbyReplicationLogIterator( operationCodec, con, ps, rs );
+ }
+ catch( Exception e )
+ {
+ throw new ReplicationStoreException( e );
+ }
+ }
+
+ public int removeLogs( CSN toCSN, boolean inclusive )
+ {
+ Connection con = null;
+ PreparedStatement ps = null;
+
+ try
+ {
+ con = dataSource.getConnection();
+ con.setAutoCommit( true );
+ con.setTransactionIsolation( Connection.TRANSACTION_READ_UNCOMMITTED );
+ con.setReadOnly( false );
+
+ // Check if the specified uuid already exists
+ ps = con.prepareStatement( "DELETE FROM " + logTableName + " WHERE " +
+ "CSN_REPLICA_ID = ? AND (CSN_TIMESTAMP = ? AND CSN_OP_SEQ <" + (inclusive? "=" : "" ) + " ? OR CSN_TIMESTAMP < ?)" );
+ ps.setString( 1, toCSN.getReplicaId().getId() );
+ ps.setLong( 2, toCSN.getTimestamp() );
+ ps.setInt( 3, toCSN.getOperationSequence() );
+ ps.setLong( 4, toCSN.getTimestamp() );
+ return ps.executeUpdate();
+ }
+ catch( Exception e )
+ {
+ throw new ReplicationStoreException( e );
+ }
+ finally
+ {
+ SQLUtil.cleanup( con, ps, null );
+ }
+ }
+
+ public int getLogSize()
+ {
+ Connection con = null;
+ Statement stmt = null;
+ ResultSet rs = null;
+
+ try
+ {
+ con = dataSource.getConnection();
+ con.setTransactionIsolation( Connection.TRANSACTION_READ_COMMITTED );
+ con.setReadOnly( true );
+ stmt = con.createStatement();
+ rs = stmt.executeQuery( "SELECT COUNT(*) FROM " + logTableName );
+ rs.next();
+ return rs.getInt( 1 );
+ }
+ catch( Exception e )
+ {
+ throw new ReplicationStoreException( e );
+ }
+ finally
+ {
+ SQLUtil.cleanup( con, stmt, rs );
+ }
+ }
+
+ public int getLogSize( ReplicaId replicaId )
+ {
+ Connection con = null;
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+
+ try
+ {
+ con = dataSource.getConnection();
+ con.setTransactionIsolation( Connection.TRANSACTION_READ_COMMITTED );
+ con.setReadOnly( true );
+ ps = con.prepareStatement( "SELECT COUNT(*) FROM " + logTableName + " WHERE CSN_REPLICA_ID=?");
+ ps.setString( 1, replicaId.getId() );
+ rs = ps.executeQuery();
+ rs.next();
+ return rs.getInt( 1 );
+ }
+ catch( Exception e )
+ {
+ throw new ReplicationStoreException( e );
+ }
+ finally
+ {
+ SQLUtil.cleanup( con, ps, rs );
+ }
+ }
+
+ public CSNVector getUpdateVector()
+ {
+ return getVector( false );
+ }
+
+ public CSNVector getPurgeVector()
+ {
+ return getVector( true );
+ }
+
+ private CSNVector getVector( boolean min )
+ {
+ final String ORDER = min ? "ASC" : "DESC";
+
+ Connection con = null;
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+ CSNVector result = new CSNVector();
+
+ try
+ {
+ con = dataSource.getConnection();
+ con.setTransactionIsolation( Connection.TRANSACTION_READ_COMMITTED );
+ con.setReadOnly( true );
+ ps = con.prepareStatement( "SELECT CSN_TIMESTAMP, CSN_OP_SEQ FROM " + logTableName + " WHERE CSN_REPLICA_ID=? ORDER BY CSN_TIMESTAMP " + ORDER + ", CSN_OP_SEQ " + ORDER );
+
+ Iterator it = knownReplicaIds.iterator();
+ while( it.hasNext() )
+ {
+ ReplicaId replicaId = ( ReplicaId ) it.next();
+ ps.setString( 1, replicaId.getId() );
+ rs = ps.executeQuery();
+ if( rs.next() )
+ {
+ result.setCSN( new SimpleCSN( rs.getLong( 1 ), replicaId, rs.getInt( 2 ) ) );
+ }
+ rs.close();
+ rs = null;
+ ps.clearParameters();
+ }
+
+ return result;
+ }
+ catch( Exception e )
+ {
+ throw new ReplicationStoreException( e );
+ }
+ finally
+ {
+ SQLUtil.cleanup( con, ps, rs );
+ }
+ }
+}
Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/derby/SQLUtil.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/derby/SQLUtil.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/derby/SQLUtil.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/store/derby/SQLUtil.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.store.derby;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+class SQLUtil {
+
+ static void cleanup( Connection con, Statement stmt, ResultSet rs )
+ {
+ if( rs != null )
+ {
+ try
+ {
+ rs.close();
+ }
+ catch( SQLException e )
+ {
+ }
+ }
+ if( stmt != null )
+ {
+ try
+ {
+ stmt.close();
+ }
+ catch( SQLException e )
+ {
+ }
+ }
+ if( con != null )
+ {
+ try
+ {
+ con.close();
+ }
+ catch( SQLException e )
+ {
+ }
+ }
+ }
+}
Added: directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/util/OctetString.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/util/OctetString.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/util/OctetString.java (added)
+++ directory/trunks/apacheds/mitosis/src/main/java/org/apache/directory/mitosis/util/OctetString.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.util;
+
+/**
+ * A utuility class that generates octet strings from numbers.
+ *
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev: 118 $, $Date: 2006-09-18 13:48:47Z $
+ */
+public class OctetString
+{
+ private static final char[] highDigits;
+ private static final char[] lowDigits;
+
+ static
+ {
+ final char[] digits =
+ { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
+
+ int i;
+ char[] high = new char[256];
+ char[] low = new char[256];
+
+ for( i = 0; i < 256; i++ )
+ {
+ high[i] = digits[ i >>> 4 ];
+ low[i] = digits[ i & 0x0F ];
+ }
+
+ highDigits = high;
+ lowDigits = low;
+ }
+
+ public static void append( StringBuffer dst, long value )
+ {
+ int v;
+ v = (int) ( value >>> 56 );
+ dst.append( highDigits[ v ] );
+ dst.append( lowDigits[ v ] );
+
+ v = (int) ( value >>> 48 ) & 0xff;
+ dst.append( highDigits[ v ] );
+ dst.append( lowDigits[ v ] );
+
+ v = (int) ( value >>> 40 ) & 0xff;
+ dst.append( highDigits[ v ] );
+ dst.append( lowDigits[ v ] );
+
+ v = (int) ( value >>> 32 ) & 0xff;
+ dst.append( highDigits[ v ] );
+ dst.append( lowDigits[ v ] );
+
+ v = (int) ( value >>> 24 ) & 0xff;
+ dst.append( highDigits[ v ] );
+ dst.append( lowDigits[ v ] );
+
+ v = (int) ( value >>> 16 ) & 0xff;
+ dst.append( highDigits[ v ] );
+ dst.append( lowDigits[ v ] );
+
+ v = (int) ( value >>> 8 ) & 0xff;
+ dst.append( highDigits[ v ] );
+ dst.append( lowDigits[ v ] );
+
+ v = (int) value & 0xff;
+ dst.append( highDigits[ v ] );
+ dst.append( lowDigits[ v ] );
+ }
+
+ public static void append( StringBuffer dst, int value )
+ {
+ int v;
+ v = ( value >>> 24 ) & 0xff;
+ dst.append( highDigits[ v ] );
+ dst.append( lowDigits[ v ] );
+
+ v = ( value >>> 16 ) & 0xff;
+ dst.append( highDigits[ v ] );
+ dst.append( lowDigits[ v ] );
+
+ v = ( value >>> 8 ) & 0xff;
+ dst.append( highDigits[ v ] );
+ dst.append( lowDigits[ v ] );
+
+ v = value & 0xff;
+ dst.append( highDigits[ v ] );
+ dst.append( lowDigits[ v ] );
+ }
+
+ public static String toString( byte[] src )
+ {
+ final int end = src.length;
+ StringBuffer dst = new StringBuffer( src.length << 1 );
+ for( int i = 0; i < end; i++ )
+ {
+ dst.append( highDigits[ src[ i ] & 0xff ] );
+ dst.append( lowDigits[ src[ i ] & 0xff ] );
+ }
+
+ return dst.toString();
+ }
+
+ public static String toString( long value )
+ {
+ StringBuffer dst = new StringBuffer( 16 );
+ append( dst, value );
+ return dst.toString();
+ }
+
+ public static String toString( int value )
+ {
+ StringBuffer dst = new StringBuffer( 8 );
+ append( dst, value );
+ return dst.toString();
+ }
+
+ public static int parseInt( String value )
+ {
+ return Integer.parseInt( value, 16 );
+ }
+
+ public static long parseLong( String value )
+ {
+ return Long.parseLong( value, 16 );
+ }
+
+ private OctetString()
+ {
+ }
+}
Added: directory/trunks/apacheds/mitosis/src/main/schema/mitosis.schema
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/main/schema/mitosis.schema?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/main/schema/mitosis.schema (added)
+++ directory/trunks/apacheds/mitosis/src/main/schema/mitosis.schema Thu Oct 12 11:33:14 2006
@@ -0,0 +1,23 @@
+# -----------------------------------------------------------------------------
+# LCUP/LDUP Schema
+# -----------------------------------------------------------------------------
+
+attributetype ( 1.3.6.1.4.1.4203.666.1.6
+ NAME 'entryUUID'
+ DESC 'LCUP/LDUP: UUID of the entry'
+ EQUALITY octetStringMatch
+ SYNTAX 1.3.6.1.4.1.1466.115.121.1.40{64}
+ SINGLE-VALUE
+ NO-USER-MODIFICATION
+ USAGE directoryOperation )
+
+attributetype ( 1.3.6.1.4.1.4203.666.1.7
+ NAME 'entryCSN'
+ DESC 'LCUP/LDUP: change sequence number of the entry'
+ EQUALITY octetStringMatch
+ ORDERING octetStringOrderingMatch
+ SYNTAX 1.3.6.1.4.1.1466.115.121.1.40{64}
+ SINGLE-VALUE
+ NO-USER-MODIFICATION
+ USAGE directoryOperation )
+
Added: directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/common/SimpleCSNTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/common/SimpleCSNTest.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/common/SimpleCSNTest.java (added)
+++ directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/common/SimpleCSNTest.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,185 @@
+/*
+ * 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 junit.framework.TestCase;
+
+/**
+ *
+ * Test for the SimpleCSN class
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SimpleCSNTest extends TestCase
+{
+
+ public void testCSN()
+ {
+ long ts = System.currentTimeMillis();
+
+ CSN csn = new SimpleCSN( Long.toString( ts, 16 ) + ":abcdefghi0123:" + 1 );
+
+ assertEquals( ts, csn.getTimestamp() );
+ assertEquals( 1, csn.getOperationSequence() );
+ assertEquals( "abcdefghi0123", csn.getReplicaId().toString() );
+ }
+
+ public void testCSNEmpty()
+ {
+ try
+ {
+ new SimpleCSN( "" );
+ fail();
+ }
+ catch ( InvalidCSNException ice )
+ {
+ assertTrue( true );
+ }
+ }
+
+ public void testCSNTSOnly()
+ {
+ try
+ {
+ new SimpleCSN( "123" );
+ fail();
+ }
+ catch ( InvalidCSNException ice )
+ {
+ assertTrue( true );
+ }
+ }
+
+ public void testCSNInvalidTS()
+ {
+ try
+ {
+ new SimpleCSN( "zzz:abc:1" );
+ fail();
+ }
+ catch ( InvalidCSNException ice )
+ {
+ assertTrue( true );
+ }
+ }
+
+ public void testCSNNoTS()
+ {
+ try
+ {
+ new SimpleCSN( ":abc:1" );
+ fail();
+ }
+ catch ( InvalidCSNException ice )
+ {
+ assertTrue( true );
+ }
+ }
+
+ public void testCSNInavlidReplica()
+ {
+ try
+ {
+ new SimpleCSN( "123:*:1" );
+ fail();
+ }
+ catch ( InvalidCSNException ice )
+ {
+ assertTrue( true );
+ }
+ }
+
+ public void testCSNNoReplica()
+ {
+ try
+ {
+ new SimpleCSN( "123::1" );
+ fail();
+ }
+ catch ( InvalidCSNException ice )
+ {
+ assertTrue( true );
+ }
+ }
+
+ public void testCSNInavlidOpSeq()
+ {
+ try
+ {
+ new SimpleCSN( "123:abc:zzz" );
+ fail();
+ }
+ catch ( InvalidCSNException ice )
+ {
+ assertTrue( true );
+ }
+ }
+
+ public void testCSNEmptyOpSeq()
+ {
+ try
+ {
+ new SimpleCSN( "123:abc:" );
+ fail();
+ }
+ catch ( InvalidCSNException ice )
+ {
+ assertTrue( true );
+ }
+ }
+
+ public void testCSNNoOpSeq()
+ {
+ try
+ {
+ new SimpleCSN( "123:abc" );
+ fail();
+ }
+ catch ( InvalidCSNException ice )
+ {
+ assertTrue( true );
+ }
+ }
+
+ public void testCSNToBytes()
+ {
+ CSN csn = new SimpleCSN( "0123456789abcdef:test:5678cdef" );
+
+ byte[] bytes = csn.toBytes();
+
+ assertEquals( 0x01, bytes[0] );
+ assertEquals( 0x23, bytes[1] );
+ assertEquals( 0x45, bytes[2] );
+ assertEquals( 0x67, bytes[3] );
+ assertEquals( (byte)0x89, bytes[4] );
+ assertEquals( (byte)0xAB, bytes[5] );
+ assertEquals( (byte)0xCD, bytes[6] );
+ assertEquals( (byte)0xEF, bytes[7] );
+ assertEquals( 0x56, bytes[8] );
+ assertEquals( 0x78, bytes[9] );
+ assertEquals( (byte)0xCD, bytes[10] );
+ assertEquals( (byte)0xEF, bytes[11] );
+
+ assertEquals( "test", new String( bytes, 12, bytes.length - 12 ) );
+
+ CSN deserializedCSN = new SimpleCSN( bytes );
+ assertEquals( csn, deserializedCSN );
+ }
+}
Added: directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/AbstractMessageCodecTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/AbstractMessageCodecTest.java?view=auto&rev=463366
==============================================================================
--- directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/AbstractMessageCodecTest.java (added)
+++ directory/trunks/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/service/protocol/codec/AbstractMessageCodecTest.java Thu Oct 12 11:33:14 2006
@@ -0,0 +1,89 @@
+/*
+ * 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.service.protocol.codec;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.directory.mitosis.service.protocol.message.BaseMessage;
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.WriteFuture;
+import org.apache.mina.filter.codec.demux.MessageDecoder;
+import org.apache.mina.filter.codec.demux.MessageEncoder;
+import org.apache.mina.filter.codec.support.SimpleProtocolDecoderOutput;
+import org.apache.mina.filter.codec.support.SimpleProtocolEncoderOutput;
+
+public abstract class AbstractMessageCodecTest extends TestCase
+{
+ private final BaseMessage message;
+ private final MessageEncoder encoder;
+ private final MessageDecoder decoder;
+
+ protected AbstractMessageCodecTest( BaseMessage message,
+ MessageEncoder encoder,
+ MessageDecoder decoder )
+ {
+ if( message == null )
+ {
+ throw new NullPointerException( "message" );
+ }
+ if( encoder == null )
+ {
+ throw new NullPointerException( "encoder" );
+ }
+ if( decoder == null )
+ {
+ throw new NullPointerException( "decoder" );
+ }
+
+ this.message = message;
+ this.encoder = encoder;
+ this.decoder = decoder;
+ }
+
+ public void testMessageCodec() throws Exception
+ {
+ SimpleProtocolEncoderOutput encoderOut = new SimpleProtocolEncoderOutput()
+ {
+ protected WriteFuture doFlush( ByteBuffer buf )
+ {
+ return null;
+ }
+
+ };
+ encoder.encode( null, message, encoderOut );
+ ByteBuffer buf = ( ByteBuffer ) encoderOut.getBufferQueue().pop();
+
+ buf.mark();
+ Assert.assertTrue( decoder.decodable( null, buf ) == MessageDecoder.OK );
+ buf.reset();
+
+ SimpleProtocolDecoderOutput decoderOut = new SimpleProtocolDecoderOutput();
+ decoder.decode( null, buf, decoderOut );
+
+ Assert.assertTrue( compare( message,
+ ( BaseMessage ) decoderOut.getMessageQueue().pop() ) );
+ }
+
+ protected boolean compare( BaseMessage expected, BaseMessage actual )
+ {
+ return expected.equals( actual );
+ }
+}