On Mon, Nov 26, 2012 at 11:58 PM, <[email protected]> wrote:
> Author: elecharny
> Date: Mon Nov 26 18:28:34 2012
> New Revision: 1413771
>
> URL: http://svn.apache.org/viewvc?rev=1413771&view=rev
> Log:
> Improved the serialization
>
> Modified:
>
> directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaEventMessage.java
>
> directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaEventMessageSerializer.java
>
> Modified:
> directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaEventMessage.java
> URL:
> http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaEventMessage.java?rev=1413771&r1=1413770&r2=1413771&view=diff
>
> ==============================================================================
> ---
> directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaEventMessage.java
> (original)
> +++
> directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaEventMessage.java
> Mon Nov 26 18:28:34 2012
> @@ -78,11 +78,11 @@ public class ReplicaEventMessage
> */
> public boolean isEventOlderThan( String csn ) throws Exception
> {
> - if( csn == null )
> - {
> - return false;
> - }
> -
> + if ( csn == null )
> + {
> + return false;
> + }
> +
> String entryCsn = entry.get( SchemaConstants.ENTRY_CSN_AT
> ).getString();
>
> int i = entryCsn.compareTo( csn );
>
> Modified:
> directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaEventMessageSerializer.java
> URL:
> http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaEventMessageSerializer.java?rev=1413771&r1=1413770&r2=1413771&view=diff
>
> ==============================================================================
> ---
> directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaEventMessageSerializer.java
> (original)
> +++
> directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/replication/ReplicaEventMessageSerializer.java
> Mon Nov 26 18:28:34 2012
> @@ -29,9 +29,7 @@ import java.io.ObjectOutputStream;
>
> import jdbm.helper.Serializer;
>
> -import
> org.apache.directory.server.core.partition.impl.btree.jdbm.EntrySerializer;
> -import org.apache.directory.shared.ldap.codec.api.LdapApiService;
> -import org.apache.directory.shared.ldap.codec.api.LdapApiServiceFactory;
> +import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
> import org.apache.directory.shared.ldap.model.entry.Entry;
> import org.apache.directory.shared.ldap.model.message.controls.ChangeType;
> import org.apache.directory.shared.ldap.model.name.Dn;
> @@ -39,11 +37,12 @@ import org.apache.directory.shared.ldap.
>
>
> /**
> - * A Modification serializer/deserializer.
> + * A ReplicaEventMessage serializer/deserializer.
> + *
> * A modification is serialized following this format : <br/>
> * <ul>
> * <li>byte : EventType</li>
> - * <li>int : entry's length in bytes</li>
> + * <li>byte[] : the serialized DN</li>
> * <li>byte[] : the serialized entry</li>
> * </ul>
> *
> @@ -54,12 +53,7 @@ public class ReplicaEventMessageSerializ
> /** The serialVersionUID */
> private static final long serialVersionUID = 1L;
>
> - /** The internal entry serializer */
> - private transient EntrySerializer entrySerializer;
> -
> - /** The LDAP codec used to serialize the entries */
> - private transient LdapApiService codec =
> LdapApiServiceFactory.getSingleton();
> -
> + /** The schemaManager */
> private transient SchemaManager schemaManager;
>
>
> @@ -71,7 +65,6 @@ public class ReplicaEventMessageSerializ
> public ReplicaEventMessageSerializer( SchemaManager schemaManager )
> {
> this.schemaManager = schemaManager;
> - entrySerializer = new EntrySerializer( schemaManager );
> }
>
>
> @@ -88,20 +81,14 @@ public class ReplicaEventMessageSerializ
> ByteArrayOutputStream baos = new ByteArrayOutputStream();
> ObjectOutput out = new ObjectOutputStream( baos );
>
> + // The change type first
> + out.writeByte( changeType.getValue() );
> +
> // The entry DN
> entry.getDn().writeExternal( out );
>
> // The entry
> - byte[] data = entrySerializer.serialize( entry );
> -
>
the reason we have the above code is that we store ClonedServerEntry
instances [1] into the replica log
instead of DefaultEntry objects, so we need to use the EntrySerializer.
[1] ClonedServerEntry objects hold the appropriate content to be send out
to clients (after filtering attributes etc..)
> - // Entry's length
> - out.writeInt( data.length );
> -
> - // Entry's data
> - out.write( data );
> -
> - // The change type
> - out.writeByte( changeType.getValue() );
> + entry.writeExternal( out );
>
> out.flush();
>
> @@ -124,25 +111,19 @@ public class ReplicaEventMessageSerializ
>
> try
> {
> + // The changeType
> + byte type = in.readByte();
> + ChangeType changeType = ChangeType.getChangeType( type );
> +
> // The Entry's DN
> Dn entryDn = new Dn( schemaManager );
> entryDn.readExternal( in );
>
> - // The Entry's length
> - int length = in.readInt();
> -
> - byte[] data = new byte[length];
> -
> - // The entry itself
> - in.readFully( data );
> -
> - Entry entry = ( Entry ) entrySerializer.deserialize( data );
> + // The Entry
> + Entry entry = new DefaultEntry( schemaManager );
> + entry.readExternal( in );
> entry.setDn( entryDn );
>
> - // Read the changeType
> - byte type = in.readByte();
> - ChangeType changeType = ChangeType.getChangeType( type );
> -
> // And create a ReplicaEventMessage
> replicaEventMessage = new ReplicaEventMessage( changeType,
> entry );
> }
>
>
>
--
Kiran Ayyagari
http://keydap.com