directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r576193 [2/6] - in /directory/apacheds/trunk/mitosis/src: main/java/org/apache/directory/mitosis/common/ main/java/org/apache/directory/mitosis/configuration/ main/java/org/apache/directory/mitosis/service/ main/java/org/apache/directory/mi...
Date Sun, 16 Sep 2007 22:12:09 GMT
Modified: directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/ReplicationService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/ReplicationService.java?rev=576193&r1=576192&r2=576193&view=diff
==============================================================================
--- directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/ReplicationService.java (original)
+++ directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/ReplicationService.java Sun Sep 16 15:12:06 2007
@@ -1,551 +1,551 @@
-/*
- *  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;
-
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.SearchControls;
-import javax.naming.directory.SearchResult;
-
-import org.apache.directory.mitosis.common.CSN;
-import org.apache.directory.mitosis.common.Constants;
-import org.apache.directory.mitosis.common.DefaultCSN;
-import org.apache.directory.mitosis.common.Replica;
-import org.apache.directory.mitosis.common.ReplicaId;
-import org.apache.directory.mitosis.configuration.ReplicationConfiguration;
-import org.apache.directory.mitosis.configuration.ReplicationInterceptorConfiguration;
-import org.apache.directory.mitosis.operation.Operation;
-import org.apache.directory.mitosis.operation.OperationFactory;
-import org.apache.directory.mitosis.service.protocol.codec.ReplicationServerProtocolCodecFactory;
-import org.apache.directory.mitosis.service.protocol.handler.ReplicationClientContextHandler;
-import org.apache.directory.mitosis.service.protocol.handler.ReplicationServerContextHandler;
-import org.apache.directory.mitosis.service.protocol.handler.ReplicationServerProtocolHandler;
-import org.apache.directory.mitosis.store.ReplicationStore;
-import org.apache.directory.server.core.DirectoryServiceConfiguration;
-import org.apache.directory.server.core.configuration.InterceptorConfiguration;
-import org.apache.directory.server.core.enumeration.SearchResultFilteringEnumeration;
-import org.apache.directory.server.core.interceptor.BaseInterceptor;
-import org.apache.directory.server.core.interceptor.Interceptor;
-import org.apache.directory.server.core.interceptor.NextInterceptor;
-import org.apache.directory.server.core.interceptor.context.AddOperationContext;
-import org.apache.directory.server.core.interceptor.context.DeleteOperationContext;
-import org.apache.directory.server.core.interceptor.context.EntryOperationContext;
-import org.apache.directory.server.core.interceptor.context.GetMatchedNameOperationContext;
-import org.apache.directory.server.core.interceptor.context.ListOperationContext;
-import org.apache.directory.server.core.interceptor.context.LookupOperationContext;
-import org.apache.directory.server.core.interceptor.context.ModifyOperationContext;
-import org.apache.directory.server.core.interceptor.context.MoveAndRenameOperationContext;
-import org.apache.directory.server.core.interceptor.context.MoveOperationContext;
-import org.apache.directory.server.core.interceptor.context.RenameOperationContext;
-import org.apache.directory.server.core.interceptor.context.SearchOperationContext;
-import org.apache.directory.server.core.invocation.InvocationStack;
-import org.apache.directory.server.core.partition.PartitionNexus;
-import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
-import org.apache.directory.shared.ldap.constants.SchemaConstants;
-import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
-import org.apache.directory.shared.ldap.filter.ExprNode;
-import org.apache.directory.shared.ldap.filter.FilterParser;
-import org.apache.directory.shared.ldap.filter.FilterParserImpl;
-import org.apache.directory.shared.ldap.filter.PresenceNode;
-import org.apache.directory.shared.ldap.name.LdapDN;
-import org.apache.mina.common.IoAcceptor;
-import org.apache.mina.filter.LoggingFilter;
-import org.apache.mina.filter.codec.ProtocolCodecFilter;
-import org.apache.mina.transport.socket.nio.SocketAcceptor;
-import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * An {@link Interceptor} that intercepts LDAP operations and propagates the
- * changes occurred by the operations into other {@link Replica}s so the DIT
- * of each {@link Replica} in the cluster has the same content without any
- * conflict.
- * <p>
- * Once an operation is invoked, this interceptor transforms it into one or
- * more operations that makes the requested operation more proper and robust
- * for replication.  The transformation process is actually just calling a
- * respective factory method in {@link OperationFactory}.  The methods in 
- * {@link OperationFactory} returns a new {@link Operation} instance.
- * <p>
- * The newly created {@link Operation} is used for three purposes.
- * <ul>
- * <li>To perform the requested operation to the local {@link PartitionNexus}
- * <li>To store the created {@link Operation} itself to
- *     {@link ReplicationStore} so that it can be retrieved later by
- *     {@link ReplicationLogCleanJob} and {@link ReplicationClientContextHandler}
- * <li>To transfer itself to other {@link Replica}s via TCP/IP communication
- *     between {@link ReplicationClientContextHandler} and
- *     {@link ReplicationServerContextHandler}
- * </ul>
- * The first two actions (modifying the local DIT and storing the
- * {@link Operation} to {@link ReplicationStore}) are performed automatically
- * when
- * {@link Operation#execute(PartitionNexus, ReplicationStore, AttributeTypeRegistry)}
- * method is invoked.  {@link ReplicationService} always call it instead of
- * forwarding the requested operation to the next {@link Interceptor}.
- * <p>
- * The last action takes place by {@link ReplicationClientContextHandler},
- * which handles TCP/IP connection managed by {@link ClientConnectionManager}.
- * <p>
- * There are two special attributes in the entries to be replicated:
- * <ul>
- * <li><tt>entryCSN</tt> - stores {@link CSN} of the entry.  This attribute is
- *     used to compare the incoming operation from other replica is still
- *     valid.  If the local <tt>entryCSN</tt> value is bigger then that of the
- *     incoming operation, it means conflict, and therefore an appropriate
- *     conflict resolution mechanism should get engaged.</li>
- * <li><tt>entryDeleted</tt> - is <tt>TRUE</tt> if and only if the entry is
- *     deleted.  The entry is not deleted immediately by a delete operation
- *     because <tt>entryCSN</tt> attribute should be retained for certain
- *     amount of time to determine whether the incoming change log, which
- *     affects an entry with the same DN, is a conflict (modification on a
- *     deleted entry) or not (creation of a new entry). You can purge old
- *     deleted entries and related change logs in {@link ReplicationStore} by
- *     calling {@link #purgeAgedData()}, or they will be purged automatically
- *     by periodic manner as you configured with {@link ReplicationConfiguration}.
- *     by calling {@link ReplicationConfiguration#setLogMaxAge(int)}.
- *     Because of this attribute, <tt>lookup</tt> and <tt>search</tt>
- *     operations are overrided to ignore entries with <tt>entryDeleted</tt>
- *     set to <tt>TRUE</tt>.</li>
- * </ul>
- * 
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev$, $Date$
- */
-public class ReplicationService extends BaseInterceptor
-{
-    private static final Logger log = LoggerFactory.getLogger( ReplicationService.class );
-    
-    /** The service name */
-    public static final String NAME = "replicationService";
-    
-
-    private static final String ENTRY_CSN_OID = "1.3.6.1.4.1.18060.0.4.1.2.30";
-    private static final String ENTRY_DELETED_OID = "1.3.6.1.4.1.18060.0.4.1.2.31";
-
-    private DirectoryServiceConfiguration directoryServiceConfiguration;
-    private ReplicationConfiguration configuration;
-    private PartitionNexus nexus;
-    private OperationFactory operationFactory;
-    private ReplicationStore store;
-    private IoAcceptor registry;
-    private final ClientConnectionManager clientConnectionManager = new ClientConnectionManager( this );
-    private AttributeTypeRegistry attrRegistry;
-
-
-    public ReplicationService()
-    {
-    }
-
-
-    public ReplicationConfiguration getConfiguration()
-    {
-        return configuration;
-    }
-
-
-    public DirectoryServiceConfiguration getFactoryConfiguration()
-    {
-        return directoryServiceConfiguration;
-    }
-
-
-    public void init( DirectoryServiceConfiguration serviceCfg, InterceptorConfiguration cfg ) throws NamingException
-    {
-        ReplicationInterceptorConfiguration replicationCfg = ( ReplicationInterceptorConfiguration ) cfg;
-        configuration = replicationCfg.getReplicationConfiguration();
-        configuration.validate();
-        // and then preserve frequently used ones
-        directoryServiceConfiguration = serviceCfg;
-        nexus = serviceCfg.getPartitionNexus();
-        store = configuration.getStore();
-        operationFactory = new OperationFactory( serviceCfg, configuration );
-        attrRegistry = serviceCfg.getRegistries().getAttributeTypeRegistry();
-
-        // Initialize store and service
-        store.open( serviceCfg, configuration );
-        boolean serviceStarted = false;
-        try
-        {
-            startNetworking();
-            serviceStarted = true;
-        }
-        catch ( Exception e )
-        {
-            throw new ReplicationServiceException( "Failed to initialize MINA ServiceRegistry.", e );
-        }
-        finally
-        {
-            if ( !serviceStarted )
-            {
-                // roll back
-                store.close();
-            }
-        }
-
-        purgeAgedData();
-    }
-
-
-    private void startNetworking() throws Exception
-    {
-        registry = new SocketAcceptor();
-        SocketAcceptorConfig config = new SocketAcceptorConfig();
-        config.setReuseAddress( true );
-
-        config.getFilterChain().addLast( "protocol",
-            new ProtocolCodecFilter( new ReplicationServerProtocolCodecFactory() ) );
-
-        config.getFilterChain().addLast( "logger", new LoggingFilter() );
-
-        // bind server protocol provider
-        registry.bind( new InetSocketAddress( configuration.getServerPort() ), new ReplicationServerProtocolHandler(
-            this ), config );
-
-        clientConnectionManager.start( configuration );
-    }
-
-
-    public void destroy()
-    {
-        stopNetworking();
-        store.close();
-    }
-
-
-    private void stopNetworking()
-    {
-        // close all open connections, deactivate all filters and service registry
-        try
-        {
-            clientConnectionManager.stop();
-        }
-        catch ( Exception e )
-        {
-            log.warn( "Failed to stop the client connection manager.", e );
-        }
-        registry.unbindAll();
-    }
-    
-    
-    /**
-     * Forces this context to send replication data to the peer replica immediately.
-     */
-    public void replicate()
-    {
-        log.info( "Forcing replication..." );
-        this.clientConnectionManager.replicate();
-    }
-
-    /**
-     * Wake the sleeping (unconnected) replicas.
-     */
-    public void interruptConnectors()
-    {
-        log.info( "Waking sleeping replicas..." );
-        this.clientConnectionManager.interruptConnectors();
-    }
-
-
-    /**
-     * Purges old replication logs and the old entries marked as 'deleted'
-     * (i.e. {@link Constants#ENTRY_DELETED} is <tt>TRUE</tt>).  This method
-     * should be called periodically to make sure the size of the DIT and
-     * {@link ReplicationStore} increase limitlessly.
-     * 
-     * @see ReplicationConfiguration#setLogMaxAge(int)
-     * @see ReplicationLogCleanJob
-     */
-    public void purgeAgedData() throws NamingException
-    {
-        Attributes rootDSE = nexus.getRootDSE( null );
-        Attribute namingContextsAttr = rootDSE.get( "namingContexts" );
-        if ( namingContextsAttr == null || namingContextsAttr.size() == 0 )
-        {
-            throw new NamingException( "No namingContexts attributes in rootDSE." );
-        }
-
-        CSN purgeCSN = new DefaultCSN( System.currentTimeMillis() - configuration.getLogMaxAge() * 1000L * 60L * 60L
-            * 24L, // convert days to millis
-            new ReplicaId( "ZZZZZZZZZZZZZZZZ" ), Integer.MAX_VALUE );
-        FilterParser parser = new FilterParserImpl();
-        ExprNode filter;
-
-        try
-        {
-            filter = parser.parse( "(& (" + ENTRY_CSN_OID + "<=" + purgeCSN.toOctetString() + ") (" + ENTRY_DELETED_OID
-                + "=TRUE))" );
-        }
-        catch ( IOException e )
-        {
-            throw ( NamingException ) new NamingException().initCause( e );
-        }
-        catch ( ParseException e )
-        {
-            throw ( NamingException ) new NamingException().initCause( e );
-        }
-
-        // Iterate all context partitions to send all entries of them.
-        NamingEnumeration e = namingContextsAttr.getAll();
-        while ( e.hasMore() )
-        {
-            Object value = e.next();
-            // Convert attribute value to JNDI name.
-            LdapDN contextName;
-            if ( value instanceof LdapDN )
-            {
-                contextName = ( LdapDN ) value;
-            }
-            else
-            {
-                contextName = new LdapDN( String.valueOf( value ) );
-            }
-
-            contextName.normalize( attrRegistry.getNormalizerMapping() );
-            log.info( "Purging aged data under '" + contextName + '"' );
-            purgeAgedData( contextName, filter );
-        }
-
-        store.removeLogs( purgeCSN, false );
-    }
-
-
-    private void purgeAgedData( LdapDN contextName, ExprNode filter ) throws NamingException
-    {
-        SearchControls ctrl = new SearchControls();
-        ctrl.setSearchScope( SearchControls.SUBTREE_SCOPE );
-        ctrl.setReturningAttributes( new String[] { "entryCSN", "entryDeleted" } );
-
-        NamingEnumeration<SearchResult> e = nexus.search( 
-            new SearchOperationContext( contextName, directoryServiceConfiguration.getEnvironment(), filter, ctrl ) );
-
-        List<LdapDN> names = new ArrayList<LdapDN>();
-        try
-        {
-            while ( e.hasMore() )
-            {
-                SearchResult sr = e.next();
-                LdapDN name = new LdapDN( sr.getName() );
-                if ( name.size() > contextName.size() )
-                {
-                    names.add( new LdapDN( sr.getName() ) );
-                }
-            }
-        }
-        finally
-        {
-            e.close();
-        }
-
-        for ( LdapDN name : names )
-        {
-            try
-            {
-                name.normalize( attrRegistry.getNormalizerMapping() );
-                Attributes entry = nexus.lookup( new LookupOperationContext( name ) );
-                log.info( "Purge: " + name + " (" + entry + ')' );
-                nexus.delete( new DeleteOperationContext( name ) );
-            }
-            catch ( NamingException ex )
-            {
-                log.warn( "Failed to fetch/delete: " + name, ex );
-            }
-        }
-    }
-
-
-    public void add( NextInterceptor nextInterceptor, AddOperationContext addContext ) throws NamingException
-    {
-        Operation op = operationFactory.newAdd( addContext.getDn(), addContext.getEntry() );
-        op.execute( nexus, store, attrRegistry );
-    }
-
-
-    @Override
-    public void delete( NextInterceptor next, DeleteOperationContext opContext ) throws NamingException
-    {
-        Operation op = operationFactory.newDelete( opContext.getDn() );
-        op.execute( nexus, store, attrRegistry );
-    }
-
-
-    public void modify( NextInterceptor next, ModifyOperationContext modifyContext ) throws NamingException
-    {
-        Operation op = operationFactory.newModify( modifyContext );
-        op.execute( nexus, store, attrRegistry );
-    }
-    
-    
-    @Override
-    public void move( NextInterceptor next, MoveOperationContext opContext ) throws NamingException
-    {
-        MoveOperationContext moveOpContext = opContext;
-        Operation op = operationFactory.newMove( moveOpContext.getDn(), moveOpContext.getParent() );
-        op.execute( nexus, store, attrRegistry );
-    }
-    
-    
-    @Override
-    public void moveAndRename( NextInterceptor next, MoveAndRenameOperationContext opContext ) throws NamingException
-    {
-        MoveAndRenameOperationContext moveAndRenameOpContext = opContext;
-        Operation op = operationFactory.newMove( moveAndRenameOpContext.getDn(), moveAndRenameOpContext.getParent(), moveAndRenameOpContext.getNewRdn(), moveAndRenameOpContext.getDelOldDn() );
-        op.execute( nexus, store, attrRegistry );
-    }
-    
-    
-    @Override
-    public void rename( NextInterceptor next, RenameOperationContext renameOpContext ) throws NamingException
-    {
-        Operation op = operationFactory.newModifyRn( renameOpContext.getDn(), renameOpContext.getNewRdn(), renameOpContext.getDelOldDn() );
-        op.execute( nexus, store, attrRegistry );
-    }
-
-
-    public boolean hasEntry( NextInterceptor nextInterceptor, EntryOperationContext entryContext ) throws NamingException
-    {
-        // Ask others first.
-        boolean hasEntry = nextInterceptor.hasEntry( entryContext );
-
-        // If the entry exists,
-        if ( hasEntry )
-        {
-            // Check DELETED attribute.
-            try
-            {
-                Attributes entry = nextInterceptor.lookup( new LookupOperationContext( entryContext.getDn() ) );
-                hasEntry = !isDeleted( entry );
-            }
-            catch ( NameNotFoundException e )
-            {
-                System.out.println( e.toString( true ) );
-                hasEntry = false;
-            }
-        }
-
-        return hasEntry;
-    }
-
-
-    public Attributes lookup( NextInterceptor nextInterceptor, LookupOperationContext lookupContext ) throws NamingException
-    {
-        if ( lookupContext.getAttrsId() != null )
-        {
-            boolean found = false;
-            
-            String[] attrIds = lookupContext.getAttrsIdArray();
-            
-            // Look for 'entryDeleted' attribute is in attrIds.
-            for ( String attrId:attrIds )
-            {
-                if ( Constants.ENTRY_DELETED.equals( attrId ) )
-                {
-                    found = true;
-                    break;
-                }
-            }
-    
-            // If not exists, add one.
-            if ( !found )
-            {
-                String[] newAttrIds = new String[attrIds.length + 1];
-                System.arraycopy( attrIds, 0, newAttrIds, 0, attrIds.length );
-                newAttrIds[attrIds.length] = Constants.ENTRY_DELETED;
-                lookupContext.setAttrsId( newAttrIds );
-            }
-        }
-        
-        Attributes result = nextInterceptor.lookup( lookupContext );
-        ensureNotDeleted( lookupContext.getDn(), result );
-        return result;
-    }
-
-
-    @Override
-    public NamingEnumeration<SearchResult> list( NextInterceptor nextInterceptor, ListOperationContext opContext ) throws NamingException
-    {
-        DirContext ctx = ( DirContext ) InvocationStack.getInstance().peek().getCaller();
-
-    	NamingEnumeration<SearchResult> result = nextInterceptor.search(
-	            new SearchOperationContext( 
-	                opContext.getDn(), ctx.getEnvironment(),
-	                new PresenceNode( SchemaConstants.OBJECT_CLASS_AT_OID ),
-	                new SearchControls() ) );
-
-        return new SearchResultFilteringEnumeration( result, new SearchControls(), InvocationStack.getInstance().peek(),
-            Constants.DELETED_ENTRIES_FILTER, "List replication filter" );
-    }
-
-
-    @Override
-    public NamingEnumeration<SearchResult> search( NextInterceptor nextInterceptor, SearchOperationContext opContext ) throws NamingException
-    {
-        SearchControls searchControls = opContext.getSearchControls();
-        
-        if ( searchControls.getReturningAttributes() != null )
-        {
-            String[] oldAttrIds = searchControls.getReturningAttributes();
-            String[] newAttrIds = new String[oldAttrIds.length + 1];
-            System.arraycopy( oldAttrIds, 0, newAttrIds, 0, oldAttrIds.length );
-            newAttrIds[oldAttrIds.length] = Constants.ENTRY_DELETED.toLowerCase();
-            searchControls.setReturningAttributes( newAttrIds );
-        }
-        
-    	NamingEnumeration<SearchResult> result = nextInterceptor.search( 
-            new SearchOperationContext( opContext.getDn(), opContext.getEnv(), opContext.getFilter(), searchControls ) );
-        return new SearchResultFilteringEnumeration( result, searchControls, InvocationStack.getInstance().peek(),
-            Constants.DELETED_ENTRIES_FILTER, "Search Replication filter" );
-    }
-
-
-    private void ensureNotDeleted( LdapDN name, Attributes entry ) throws NamingException, LdapNameNotFoundException
-    {
-        if ( isDeleted( entry ) )
-        {
-            LdapNameNotFoundException e = new LdapNameNotFoundException( "Deleted entry: " + name.getUpName() );
-            e.setResolvedName( nexus.getMatchedName( new GetMatchedNameOperationContext( name ) ) );
-            throw e;
-        }
-    }
-
-
-    private boolean isDeleted( Attributes entry ) throws NamingException
-    {
-        if ( entry == null )
-        {
-            return true;
-        }
-
-        Attribute deleted = entry.get( Constants.ENTRY_DELETED );
-        return ( deleted != null && "TRUE".equalsIgnoreCase( deleted.get().toString() ) );
-    }
-}
+/*
+ *  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;
+
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+import org.apache.directory.mitosis.common.CSN;
+import org.apache.directory.mitosis.common.Constants;
+import org.apache.directory.mitosis.common.DefaultCSN;
+import org.apache.directory.mitosis.common.Replica;
+import org.apache.directory.mitosis.common.ReplicaId;
+import org.apache.directory.mitosis.configuration.ReplicationConfiguration;
+import org.apache.directory.mitosis.configuration.ReplicationInterceptorConfiguration;
+import org.apache.directory.mitosis.operation.Operation;
+import org.apache.directory.mitosis.operation.OperationFactory;
+import org.apache.directory.mitosis.service.protocol.codec.ReplicationServerProtocolCodecFactory;
+import org.apache.directory.mitosis.service.protocol.handler.ReplicationClientContextHandler;
+import org.apache.directory.mitosis.service.protocol.handler.ReplicationServerContextHandler;
+import org.apache.directory.mitosis.service.protocol.handler.ReplicationServerProtocolHandler;
+import org.apache.directory.mitosis.store.ReplicationStore;
+import org.apache.directory.server.core.DirectoryServiceConfiguration;
+import org.apache.directory.server.core.configuration.InterceptorConfiguration;
+import org.apache.directory.server.core.enumeration.SearchResultFilteringEnumeration;
+import org.apache.directory.server.core.interceptor.BaseInterceptor;
+import org.apache.directory.server.core.interceptor.Interceptor;
+import org.apache.directory.server.core.interceptor.NextInterceptor;
+import org.apache.directory.server.core.interceptor.context.AddOperationContext;
+import org.apache.directory.server.core.interceptor.context.DeleteOperationContext;
+import org.apache.directory.server.core.interceptor.context.EntryOperationContext;
+import org.apache.directory.server.core.interceptor.context.GetMatchedNameOperationContext;
+import org.apache.directory.server.core.interceptor.context.ListOperationContext;
+import org.apache.directory.server.core.interceptor.context.LookupOperationContext;
+import org.apache.directory.server.core.interceptor.context.ModifyOperationContext;
+import org.apache.directory.server.core.interceptor.context.MoveAndRenameOperationContext;
+import org.apache.directory.server.core.interceptor.context.MoveOperationContext;
+import org.apache.directory.server.core.interceptor.context.RenameOperationContext;
+import org.apache.directory.server.core.interceptor.context.SearchOperationContext;
+import org.apache.directory.server.core.invocation.InvocationStack;
+import org.apache.directory.server.core.partition.PartitionNexus;
+import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
+import org.apache.directory.shared.ldap.filter.ExprNode;
+import org.apache.directory.shared.ldap.filter.FilterParser;
+import org.apache.directory.shared.ldap.filter.FilterParserImpl;
+import org.apache.directory.shared.ldap.filter.PresenceNode;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.filter.LoggingFilter;
+import org.apache.mina.filter.codec.ProtocolCodecFilter;
+import org.apache.mina.transport.socket.nio.SocketAcceptor;
+import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * An {@link Interceptor} that intercepts LDAP operations and propagates the
+ * changes occurred by the operations into other {@link Replica}s so the DIT
+ * of each {@link Replica} in the cluster has the same content without any
+ * conflict.
+ * <p>
+ * Once an operation is invoked, this interceptor transforms it into one or
+ * more operations that makes the requested operation more proper and robust
+ * for replication.  The transformation process is actually just calling a
+ * respective factory method in {@link OperationFactory}.  The methods in 
+ * {@link OperationFactory} returns a new {@link Operation} instance.
+ * <p>
+ * The newly created {@link Operation} is used for three purposes.
+ * <ul>
+ * <li>To perform the requested operation to the local {@link PartitionNexus}
+ * <li>To store the created {@link Operation} itself to
+ *     {@link ReplicationStore} so that it can be retrieved later by
+ *     {@link ReplicationLogCleanJob} and {@link ReplicationClientContextHandler}
+ * <li>To transfer itself to other {@link Replica}s via TCP/IP communication
+ *     between {@link ReplicationClientContextHandler} and
+ *     {@link ReplicationServerContextHandler}
+ * </ul>
+ * The first two actions (modifying the local DIT and storing the
+ * {@link Operation} to {@link ReplicationStore}) are performed automatically
+ * when
+ * {@link Operation#execute(PartitionNexus, ReplicationStore, AttributeTypeRegistry)}
+ * method is invoked.  {@link ReplicationService} always call it instead of
+ * forwarding the requested operation to the next {@link Interceptor}.
+ * <p>
+ * The last action takes place by {@link ReplicationClientContextHandler},
+ * which handles TCP/IP connection managed by {@link ClientConnectionManager}.
+ * <p>
+ * There are two special attributes in the entries to be replicated:
+ * <ul>
+ * <li><tt>entryCSN</tt> - stores {@link CSN} of the entry.  This attribute is
+ *     used to compare the incoming operation from other replica is still
+ *     valid.  If the local <tt>entryCSN</tt> value is bigger then that of the
+ *     incoming operation, it means conflict, and therefore an appropriate
+ *     conflict resolution mechanism should get engaged.</li>
+ * <li><tt>entryDeleted</tt> - is <tt>TRUE</tt> if and only if the entry is
+ *     deleted.  The entry is not deleted immediately by a delete operation
+ *     because <tt>entryCSN</tt> attribute should be retained for certain
+ *     amount of time to determine whether the incoming change log, which
+ *     affects an entry with the same DN, is a conflict (modification on a
+ *     deleted entry) or not (creation of a new entry). You can purge old
+ *     deleted entries and related change logs in {@link ReplicationStore} by
+ *     calling {@link #purgeAgedData()}, or they will be purged automatically
+ *     by periodic manner as you configured with {@link ReplicationConfiguration}.
+ *     by calling {@link ReplicationConfiguration#setLogMaxAge(int)}.
+ *     Because of this attribute, <tt>lookup</tt> and <tt>search</tt>
+ *     operations are overrided to ignore entries with <tt>entryDeleted</tt>
+ *     set to <tt>TRUE</tt>.</li>
+ * </ul>
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class ReplicationService extends BaseInterceptor
+{
+    private static final Logger log = LoggerFactory.getLogger( ReplicationService.class );
+    
+    /** The service name */
+    public static final String NAME = "replicationService";
+    
+
+    private static final String ENTRY_CSN_OID = "1.3.6.1.4.1.18060.0.4.1.2.30";
+    private static final String ENTRY_DELETED_OID = "1.3.6.1.4.1.18060.0.4.1.2.31";
+
+    private DirectoryServiceConfiguration directoryServiceConfiguration;
+    private ReplicationConfiguration configuration;
+    private PartitionNexus nexus;
+    private OperationFactory operationFactory;
+    private ReplicationStore store;
+    private IoAcceptor registry;
+    private final ClientConnectionManager clientConnectionManager = new ClientConnectionManager( this );
+    private AttributeTypeRegistry attrRegistry;
+
+
+    public ReplicationService()
+    {
+    }
+
+
+    public ReplicationConfiguration getConfiguration()
+    {
+        return configuration;
+    }
+
+
+    public DirectoryServiceConfiguration getFactoryConfiguration()
+    {
+        return directoryServiceConfiguration;
+    }
+
+
+    public void init( DirectoryServiceConfiguration serviceCfg, InterceptorConfiguration cfg ) throws NamingException
+    {
+        ReplicationInterceptorConfiguration replicationCfg = ( ReplicationInterceptorConfiguration ) cfg;
+        configuration = replicationCfg.getReplicationConfiguration();
+        configuration.validate();
+        // and then preserve frequently used ones
+        directoryServiceConfiguration = serviceCfg;
+        nexus = serviceCfg.getPartitionNexus();
+        store = configuration.getStore();
+        operationFactory = new OperationFactory( serviceCfg, configuration );
+        attrRegistry = serviceCfg.getRegistries().getAttributeTypeRegistry();
+
+        // Initialize store and service
+        store.open( serviceCfg, configuration );
+        boolean serviceStarted = false;
+        try
+        {
+            startNetworking();
+            serviceStarted = true;
+        }
+        catch ( Exception e )
+        {
+            throw new ReplicationServiceException( "Failed to initialize MINA ServiceRegistry.", e );
+        }
+        finally
+        {
+            if ( !serviceStarted )
+            {
+                // roll back
+                store.close();
+            }
+        }
+
+        purgeAgedData();
+    }
+
+
+    private void startNetworking() throws Exception
+    {
+        registry = new SocketAcceptor();
+        SocketAcceptorConfig config = new SocketAcceptorConfig();
+        config.setReuseAddress( true );
+
+        config.getFilterChain().addLast( "protocol",
+            new ProtocolCodecFilter( new ReplicationServerProtocolCodecFactory() ) );
+
+        config.getFilterChain().addLast( "logger", new LoggingFilter() );
+
+        // bind server protocol provider
+        registry.bind( new InetSocketAddress( configuration.getServerPort() ), new ReplicationServerProtocolHandler(
+            this ), config );
+
+        clientConnectionManager.start( configuration );
+    }
+
+
+    public void destroy()
+    {
+        stopNetworking();
+        store.close();
+    }
+
+
+    private void stopNetworking()
+    {
+        // close all open connections, deactivate all filters and service registry
+        try
+        {
+            clientConnectionManager.stop();
+        }
+        catch ( Exception e )
+        {
+            log.warn( "Failed to stop the client connection manager.", e );
+        }
+        registry.unbindAll();
+    }
+    
+    
+    /**
+     * Forces this context to send replication data to the peer replica immediately.
+     */
+    public void replicate()
+    {
+        log.info( "Forcing replication..." );
+        this.clientConnectionManager.replicate();
+    }
+
+    /**
+     * Wake the sleeping (unconnected) replicas.
+     */
+    public void interruptConnectors()
+    {
+        log.info( "Waking sleeping replicas..." );
+        this.clientConnectionManager.interruptConnectors();
+    }
+
+
+    /**
+     * Purges old replication logs and the old entries marked as 'deleted'
+     * (i.e. {@link Constants#ENTRY_DELETED} is <tt>TRUE</tt>).  This method
+     * should be called periodically to make sure the size of the DIT and
+     * {@link ReplicationStore} increase limitlessly.
+     * 
+     * @see ReplicationConfiguration#setLogMaxAge(int)
+     * @see ReplicationLogCleanJob
+     */
+    public void purgeAgedData() throws NamingException
+    {
+        Attributes rootDSE = nexus.getRootDSE( null );
+        Attribute namingContextsAttr = rootDSE.get( "namingContexts" );
+        if ( namingContextsAttr == null || namingContextsAttr.size() == 0 )
+        {
+            throw new NamingException( "No namingContexts attributes in rootDSE." );
+        }
+
+        CSN purgeCSN = new DefaultCSN( System.currentTimeMillis() - configuration.getLogMaxAge() * 1000L * 60L * 60L
+            * 24L, // convert days to millis
+            new ReplicaId( "ZZZZZZZZZZZZZZZZ" ), Integer.MAX_VALUE );
+        FilterParser parser = new FilterParserImpl();
+        ExprNode filter;
+
+        try
+        {
+            filter = parser.parse( "(& (" + ENTRY_CSN_OID + "<=" + purgeCSN.toOctetString() + ") (" + ENTRY_DELETED_OID
+                + "=TRUE))" );
+        }
+        catch ( IOException e )
+        {
+            throw ( NamingException ) new NamingException().initCause( e );
+        }
+        catch ( ParseException e )
+        {
+            throw ( NamingException ) new NamingException().initCause( e );
+        }
+
+        // Iterate all context partitions to send all entries of them.
+        NamingEnumeration e = namingContextsAttr.getAll();
+        while ( e.hasMore() )
+        {
+            Object value = e.next();
+            // Convert attribute value to JNDI name.
+            LdapDN contextName;
+            if ( value instanceof LdapDN )
+            {
+                contextName = ( LdapDN ) value;
+            }
+            else
+            {
+                contextName = new LdapDN( String.valueOf( value ) );
+            }
+
+            contextName.normalize( attrRegistry.getNormalizerMapping() );
+            log.info( "Purging aged data under '" + contextName + '"' );
+            purgeAgedData( contextName, filter );
+        }
+
+        store.removeLogs( purgeCSN, false );
+    }
+
+
+    private void purgeAgedData( LdapDN contextName, ExprNode filter ) throws NamingException
+    {
+        SearchControls ctrl = new SearchControls();
+        ctrl.setSearchScope( SearchControls.SUBTREE_SCOPE );
+        ctrl.setReturningAttributes( new String[] { "entryCSN", "entryDeleted" } );
+
+        NamingEnumeration<SearchResult> e = nexus.search( 
+            new SearchOperationContext( contextName, directoryServiceConfiguration.getEnvironment(), filter, ctrl ) );
+
+        List<LdapDN> names = new ArrayList<LdapDN>();
+        try
+        {
+            while ( e.hasMore() )
+            {
+                SearchResult sr = e.next();
+                LdapDN name = new LdapDN( sr.getName() );
+                if ( name.size() > contextName.size() )
+                {
+                    names.add( new LdapDN( sr.getName() ) );
+                }
+            }
+        }
+        finally
+        {
+            e.close();
+        }
+
+        for ( LdapDN name : names )
+        {
+            try
+            {
+                name.normalize( attrRegistry.getNormalizerMapping() );
+                Attributes entry = nexus.lookup( new LookupOperationContext( name ) );
+                log.info( "Purge: " + name + " (" + entry + ')' );
+                nexus.delete( new DeleteOperationContext( name ) );
+            }
+            catch ( NamingException ex )
+            {
+                log.warn( "Failed to fetch/delete: " + name, ex );
+            }
+        }
+    }
+
+
+    public void add( NextInterceptor nextInterceptor, AddOperationContext addContext ) throws NamingException
+    {
+        Operation op = operationFactory.newAdd( addContext.getDn(), addContext.getEntry() );
+        op.execute( nexus, store, attrRegistry );
+    }
+
+
+    @Override
+    public void delete( NextInterceptor next, DeleteOperationContext opContext ) throws NamingException
+    {
+        Operation op = operationFactory.newDelete( opContext.getDn() );
+        op.execute( nexus, store, attrRegistry );
+    }
+
+
+    public void modify( NextInterceptor next, ModifyOperationContext modifyContext ) throws NamingException
+    {
+        Operation op = operationFactory.newModify( modifyContext );
+        op.execute( nexus, store, attrRegistry );
+    }
+    
+    
+    @Override
+    public void move( NextInterceptor next, MoveOperationContext opContext ) throws NamingException
+    {
+        MoveOperationContext moveOpContext = opContext;
+        Operation op = operationFactory.newMove( moveOpContext.getDn(), moveOpContext.getParent() );
+        op.execute( nexus, store, attrRegistry );
+    }
+    
+    
+    @Override
+    public void moveAndRename( NextInterceptor next, MoveAndRenameOperationContext opContext ) throws NamingException
+    {
+        MoveAndRenameOperationContext moveAndRenameOpContext = opContext;
+        Operation op = operationFactory.newMove( moveAndRenameOpContext.getDn(), moveAndRenameOpContext.getParent(), moveAndRenameOpContext.getNewRdn(), moveAndRenameOpContext.getDelOldDn() );
+        op.execute( nexus, store, attrRegistry );
+    }
+    
+    
+    @Override
+    public void rename( NextInterceptor next, RenameOperationContext renameOpContext ) throws NamingException
+    {
+        Operation op = operationFactory.newModifyRn( renameOpContext.getDn(), renameOpContext.getNewRdn(), renameOpContext.getDelOldDn() );
+        op.execute( nexus, store, attrRegistry );
+    }
+
+
+    public boolean hasEntry( NextInterceptor nextInterceptor, EntryOperationContext entryContext ) throws NamingException
+    {
+        // Ask others first.
+        boolean hasEntry = nextInterceptor.hasEntry( entryContext );
+
+        // If the entry exists,
+        if ( hasEntry )
+        {
+            // Check DELETED attribute.
+            try
+            {
+                Attributes entry = nextInterceptor.lookup( new LookupOperationContext( entryContext.getDn() ) );
+                hasEntry = !isDeleted( entry );
+            }
+            catch ( NameNotFoundException e )
+            {
+                System.out.println( e.toString( true ) );
+                hasEntry = false;
+            }
+        }
+
+        return hasEntry;
+    }
+
+
+    public Attributes lookup( NextInterceptor nextInterceptor, LookupOperationContext lookupContext ) throws NamingException
+    {
+        if ( lookupContext.getAttrsId() != null )
+        {
+            boolean found = false;
+            
+            String[] attrIds = lookupContext.getAttrsIdArray();
+            
+            // Look for 'entryDeleted' attribute is in attrIds.
+            for ( String attrId:attrIds )
+            {
+                if ( Constants.ENTRY_DELETED.equals( attrId ) )
+                {
+                    found = true;
+                    break;
+                }
+            }
+    
+            // If not exists, add one.
+            if ( !found )
+            {
+                String[] newAttrIds = new String[attrIds.length + 1];
+                System.arraycopy( attrIds, 0, newAttrIds, 0, attrIds.length );
+                newAttrIds[attrIds.length] = Constants.ENTRY_DELETED;
+                lookupContext.setAttrsId( newAttrIds );
+            }
+        }
+        
+        Attributes result = nextInterceptor.lookup( lookupContext );
+        ensureNotDeleted( lookupContext.getDn(), result );
+        return result;
+    }
+
+
+    @Override
+    public NamingEnumeration<SearchResult> list( NextInterceptor nextInterceptor, ListOperationContext opContext ) throws NamingException
+    {
+        DirContext ctx = ( DirContext ) InvocationStack.getInstance().peek().getCaller();
+
+    	NamingEnumeration<SearchResult> result = nextInterceptor.search(
+	            new SearchOperationContext( 
+	                opContext.getDn(), ctx.getEnvironment(),
+	                new PresenceNode( SchemaConstants.OBJECT_CLASS_AT_OID ),
+	                new SearchControls() ) );
+
+        return new SearchResultFilteringEnumeration( result, new SearchControls(), InvocationStack.getInstance().peek(),
+            Constants.DELETED_ENTRIES_FILTER, "List replication filter" );
+    }
+
+
+    @Override
+    public NamingEnumeration<SearchResult> search( NextInterceptor nextInterceptor, SearchOperationContext opContext ) throws NamingException
+    {
+        SearchControls searchControls = opContext.getSearchControls();
+        
+        if ( searchControls.getReturningAttributes() != null )
+        {
+            String[] oldAttrIds = searchControls.getReturningAttributes();
+            String[] newAttrIds = new String[oldAttrIds.length + 1];
+            System.arraycopy( oldAttrIds, 0, newAttrIds, 0, oldAttrIds.length );
+            newAttrIds[oldAttrIds.length] = Constants.ENTRY_DELETED.toLowerCase();
+            searchControls.setReturningAttributes( newAttrIds );
+        }
+        
+    	NamingEnumeration<SearchResult> result = nextInterceptor.search( 
+            new SearchOperationContext( opContext.getDn(), opContext.getEnv(), opContext.getFilter(), searchControls ) );
+        return new SearchResultFilteringEnumeration( result, searchControls, InvocationStack.getInstance().peek(),
+            Constants.DELETED_ENTRIES_FILTER, "Search Replication filter" );
+    }
+
+
+    private void ensureNotDeleted( LdapDN name, Attributes entry ) throws NamingException, LdapNameNotFoundException
+    {
+        if ( isDeleted( entry ) )
+        {
+            LdapNameNotFoundException e = new LdapNameNotFoundException( "Deleted entry: " + name.getUpName() );
+            e.setResolvedName( nexus.getMatchedName( new GetMatchedNameOperationContext( name ) ) );
+            throw e;
+        }
+    }
+
+
+    private boolean isDeleted( Attributes entry ) throws NamingException
+    {
+        if ( entry == null )
+        {
+            return true;
+        }
+
+        Attribute deleted = entry.get( Constants.ENTRY_DELETED );
+        return ( deleted != null && "TRUE".equalsIgnoreCase( deleted.get().toString() ) );
+    }
+}

Modified: directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/ReplicationServiceException.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/ReplicationServiceException.java?rev=576193&r1=576192&r2=576193&view=diff
==============================================================================
--- directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/ReplicationServiceException.java (original)
+++ directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/ReplicationServiceException.java Sun Sep 16 15:12:06 2007
@@ -1,53 +1,53 @@
-/*
- *  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;
-
-
-import org.apache.directory.mitosis.common.ReplicationException;
-
-
-public class ReplicationServiceException extends ReplicationException
-{
-    private static final long serialVersionUID = 3906090070204430386L;
-
-
-    public ReplicationServiceException()
-    {
-        super();
-    }
-
-
-    public ReplicationServiceException( String message, Throwable cause )
-    {
-        super( message, cause );
-    }
-
-
-    public ReplicationServiceException( String message )
-    {
-        super( message );
-    }
-
-
-    public ReplicationServiceException( Throwable cause )
-    {
-        super( cause );
-    }
-}
+/*
+ *  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;
+
+
+import org.apache.directory.mitosis.common.ReplicationException;
+
+
+public class ReplicationServiceException extends ReplicationException
+{
+    private static final long serialVersionUID = 3906090070204430386L;
+
+
+    public ReplicationServiceException()
+    {
+        super();
+    }
+
+
+    public ReplicationServiceException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+
+
+    public ReplicationServiceException( String message )
+    {
+        super( message );
+    }
+
+
+    public ReplicationServiceException( Throwable cause )
+    {
+        super( cause );
+    }
+}

Modified: directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/Constants.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/Constants.java?rev=576193&r1=576192&r2=576193&view=diff
==============================================================================
--- directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/Constants.java (original)
+++ directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/Constants.java Sun Sep 16 15:12:06 2007
@@ -1,43 +1,43 @@
-/*
- *  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;
-
-
-public class Constants
-{
-    public static final int LOGIN = 0x00;
-    public static final int LOGIN_ACK = 0x01;
-    public static final int GET_UPDATE_VECTOR = 0x02;
-    public static final int GET_UPDATE_VECTOR_ACK = 0x03;
-    public static final int LOG_ENTRY = 0x04;
-    public static final int LOG_ENTRY_ACK = 0x05;
-    public static final int BEGIN_LOG_ENTRIES = 0x06;
-    public static final int BEGIN_LOG_ENTRIES_ACK = 0x07;
-    public static final int END_LOG_ENTRIES = 0x08;
-    public static final int END_LOG_ENTRIES_ACK = 0x09;
-
-    public static final int OK = 0;
-    public static final int NOT_OK = -1;
-
-
-    private Constants()
-    {
-    }
-}
+/*
+ *  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;
+
+
+public class Constants
+{
+    public static final int LOGIN = 0x00;
+    public static final int LOGIN_ACK = 0x01;
+    public static final int GET_UPDATE_VECTOR = 0x02;
+    public static final int GET_UPDATE_VECTOR_ACK = 0x03;
+    public static final int LOG_ENTRY = 0x04;
+    public static final int LOG_ENTRY_ACK = 0x05;
+    public static final int BEGIN_LOG_ENTRIES = 0x06;
+    public static final int BEGIN_LOG_ENTRIES_ACK = 0x07;
+    public static final int END_LOG_ENTRIES = 0x08;
+    public static final int END_LOG_ENTRIES_ACK = 0x09;
+
+    public static final int OK = 0;
+    public static final int NOT_OK = -1;
+
+
+    private Constants()
+    {
+    }
+}

Modified: directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/BaseMessageDecoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/BaseMessageDecoder.java?rev=576193&r1=576192&r2=576193&view=diff
==============================================================================
--- directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/BaseMessageDecoder.java (original)
+++ directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/BaseMessageDecoder.java Sun Sep 16 15:12:06 2007
@@ -1,105 +1,105 @@
-/*
- *  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 org.apache.directory.mitosis.service.protocol.message.BaseMessage;
-import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.common.IoSession;
-import org.apache.mina.filter.codec.ProtocolDecoderException;
-import org.apache.mina.filter.codec.ProtocolDecoderOutput;
-import org.apache.mina.filter.codec.demux.MessageDecoder;
-import org.apache.mina.filter.codec.demux.MessageDecoderResult;
-
-
-public abstract class BaseMessageDecoder implements MessageDecoder
-{
-    private final int type;
-    private final int minBodyLength;
-    private final int maxBodyLength;
-    private boolean readHeader;
-    private int sequence;
-    private int bodyLength;
-
-
-    protected BaseMessageDecoder( int type, int minBodyLength, int maxBodyLength )
-    {
-        this.type = type;
-        this.minBodyLength = minBodyLength;
-        this.maxBodyLength = maxBodyLength;
-    }
-
-
-    public final MessageDecoderResult decodable( IoSession session, ByteBuffer buf )
-    {
-        return type == buf.get() ? OK : NOT_OK;
-    }
-
-
-    public final MessageDecoderResult decode( IoSession session, ByteBuffer in, ProtocolDecoderOutput out )
-        throws Exception
-    {
-        if ( !readHeader )
-        {
-            if ( in.remaining() < 9 )
-            {
-                return NEED_DATA;
-            }
-
-            in.get(); // skip type field
-            sequence = in.getInt();
-            bodyLength = in.getInt();
-
-            if ( bodyLength < minBodyLength || bodyLength > maxBodyLength )
-            {
-                throw new ProtocolDecoderException( "Wrong bodyLength: " + bodyLength );
-            }
-
-            readHeader = true;
-        }
-
-        if ( readHeader )
-        {
-            if ( in.remaining() < bodyLength )
-            {
-                return NEED_DATA;
-            }
-
-            int oldLimit = in.limit();
-
-            try
-            {
-                in.limit( in.position() + bodyLength );
-                out.write( decodeBody( sequence, bodyLength, in ) );
-                return OK;
-            }
-            finally
-            {
-                readHeader = false;
-                in.limit( oldLimit );
-            }
-        }
-
-        throw new InternalError();
-    }
-
-
-    protected abstract BaseMessage decodeBody( int sequence, int bodyLength, ByteBuffer in ) throws Exception;
-}
+/*
+ *  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 org.apache.directory.mitosis.service.protocol.message.BaseMessage;
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderException;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+import org.apache.mina.filter.codec.demux.MessageDecoder;
+import org.apache.mina.filter.codec.demux.MessageDecoderResult;
+
+
+public abstract class BaseMessageDecoder implements MessageDecoder
+{
+    private final int type;
+    private final int minBodyLength;
+    private final int maxBodyLength;
+    private boolean readHeader;
+    private int sequence;
+    private int bodyLength;
+
+
+    protected BaseMessageDecoder( int type, int minBodyLength, int maxBodyLength )
+    {
+        this.type = type;
+        this.minBodyLength = minBodyLength;
+        this.maxBodyLength = maxBodyLength;
+    }
+
+
+    public final MessageDecoderResult decodable( IoSession session, ByteBuffer buf )
+    {
+        return type == buf.get() ? OK : NOT_OK;
+    }
+
+
+    public final MessageDecoderResult decode( IoSession session, ByteBuffer in, ProtocolDecoderOutput out )
+        throws Exception
+    {
+        if ( !readHeader )
+        {
+            if ( in.remaining() < 9 )
+            {
+                return NEED_DATA;
+            }
+
+            in.get(); // skip type field
+            sequence = in.getInt();
+            bodyLength = in.getInt();
+
+            if ( bodyLength < minBodyLength || bodyLength > maxBodyLength )
+            {
+                throw new ProtocolDecoderException( "Wrong bodyLength: " + bodyLength );
+            }
+
+            readHeader = true;
+        }
+
+        if ( readHeader )
+        {
+            if ( in.remaining() < bodyLength )
+            {
+                return NEED_DATA;
+            }
+
+            int oldLimit = in.limit();
+
+            try
+            {
+                in.limit( in.position() + bodyLength );
+                out.write( decodeBody( sequence, bodyLength, in ) );
+                return OK;
+            }
+            finally
+            {
+                readHeader = false;
+                in.limit( oldLimit );
+            }
+        }
+
+        throw new InternalError();
+    }
+
+
+    protected abstract BaseMessage decodeBody( int sequence, int bodyLength, ByteBuffer in ) throws Exception;
+}

Modified: directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/BaseMessageEncoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/BaseMessageEncoder.java?rev=576193&r1=576192&r2=576193&view=diff
==============================================================================
--- directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/BaseMessageEncoder.java (original)
+++ directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/BaseMessageEncoder.java Sun Sep 16 15:12:06 2007
@@ -1,62 +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.service.protocol.codec;
-
-
-import org.apache.directory.mitosis.service.protocol.message.BaseMessage;
-import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.common.IoSession;
-import org.apache.mina.filter.codec.ProtocolEncoderOutput;
-import org.apache.mina.filter.codec.demux.MessageEncoder;
-
-
-public abstract class BaseMessageEncoder implements MessageEncoder
-{
-    public BaseMessageEncoder()
-    {
-    }
-
-
-    public final void encode( IoSession session, Object in, ProtocolEncoderOutput out ) throws Exception
-    {
-        BaseMessage m = ( BaseMessage ) in;
-        ByteBuffer buf = ByteBuffer.allocate( 16 );
-        buf.setAutoExpand( true );
-        buf.put( ( byte ) m.getType() );
-        buf.putInt( m.getSequence() );
-        buf.putInt( 0 ); // placeholder for body length field
-
-        final int bodyStartPos = buf.position();
-        encodeBody( m, buf );
-        final int bodyEndPos = buf.position();
-        final int bodyLength = bodyEndPos - bodyStartPos;
-
-        // fill bodyLength
-        buf.position( bodyStartPos - 4 );
-        buf.putInt( bodyLength );
-        buf.position( bodyEndPos );
-
-        buf.flip();
-        out.write( buf );
-    }
-
-
-    protected abstract void encodeBody( BaseMessage in, ByteBuffer out ) throws Exception;
-}
+/*
+ *  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 org.apache.directory.mitosis.service.protocol.message.BaseMessage;
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+import org.apache.mina.filter.codec.demux.MessageEncoder;
+
+
+public abstract class BaseMessageEncoder implements MessageEncoder
+{
+    public BaseMessageEncoder()
+    {
+    }
+
+
+    public final void encode( IoSession session, Object in, ProtocolEncoderOutput out ) throws Exception
+    {
+        BaseMessage m = ( BaseMessage ) in;
+        ByteBuffer buf = ByteBuffer.allocate( 16 );
+        buf.setAutoExpand( true );
+        buf.put( ( byte ) m.getType() );
+        buf.putInt( m.getSequence() );
+        buf.putInt( 0 ); // placeholder for body length field
+
+        final int bodyStartPos = buf.position();
+        encodeBody( m, buf );
+        final int bodyEndPos = buf.position();
+        final int bodyLength = bodyEndPos - bodyStartPos;
+
+        // fill bodyLength
+        buf.position( bodyStartPos - 4 );
+        buf.putInt( bodyLength );
+        buf.position( bodyEndPos );
+
+        buf.flip();
+        out.write( buf );
+    }
+
+
+    protected abstract void encodeBody( BaseMessage in, ByteBuffer out ) throws Exception;
+}

Modified: directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesAckMessageDecoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesAckMessageDecoder.java?rev=576193&r1=576192&r2=576193&view=diff
==============================================================================
--- directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesAckMessageDecoder.java (original)
+++ directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesAckMessageDecoder.java Sun Sep 16 15:12:06 2007
@@ -1,96 +1,96 @@
-/*
- *  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 java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-
-import org.apache.directory.mitosis.common.CSNVector;
-import org.apache.directory.mitosis.common.ReplicaId;
-import org.apache.directory.mitosis.common.DefaultCSN;
-import org.apache.directory.mitosis.service.protocol.Constants;
-import org.apache.directory.mitosis.service.protocol.message.BaseMessage;
-import org.apache.directory.mitosis.service.protocol.message.BeginLogEntriesAckMessage;
-import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.common.IoSession;
-import org.apache.mina.filter.codec.ProtocolDecoderException;
-import org.apache.mina.filter.codec.ProtocolDecoderOutput;
-
-
-public class BeginLogEntriesAckMessageDecoder extends ResponseMessageDecoder
-{
-    private final CharsetDecoder utf8decoder;
-
-
-    public BeginLogEntriesAckMessageDecoder()
-    {
-        super( Constants.GET_UPDATE_VECTOR_ACK, 0, 3072 );
-        utf8decoder = Charset.forName( "UTF-8" ).newDecoder();
-    }
-
-
-    protected BaseMessage decodeBody( int sequence, int bodyLength, int responseCode, ByteBuffer in ) throws Exception
-    {
-        if ( responseCode != Constants.OK )
-        {
-            return new BeginLogEntriesAckMessage( sequence, responseCode, null, null );
-        }
-
-        CSNVector purgeVector = new CSNVector();
-        CSNVector updateVector = new CSNVector();
-        BeginLogEntriesAckMessage m = new BeginLogEntriesAckMessage( sequence, responseCode, purgeVector, updateVector );
-        readCSNVector( in, purgeVector );
-        readCSNVector( in, updateVector );
-
-        return m;
-    }
-
-
-    private void readCSNVector( ByteBuffer in, CSNVector updateVector ) throws Exception
-    {
-        int nReplicas = in.getInt();
-        if ( nReplicas < 0 )
-        {
-            throw new ProtocolDecoderException( "Wrong nReplicas: " + nReplicas );
-        }
-
-        for ( ; nReplicas > 0; nReplicas-- )
-        {
-            ReplicaId replicaId;
-            try
-            {
-                replicaId = new ReplicaId( in.getString( utf8decoder ) );
-            }
-            catch ( CharacterCodingException e )
-            {
-                throw new ProtocolDecoderException( "Invalid replicaId", e );
-            }
-
-            updateVector.setCSN( new DefaultCSN( in.getLong(), replicaId, in.getInt() ) );
-        }
-    }
-
-
-    public void finishDecode( IoSession session, ProtocolDecoderOutput out ) throws Exception
-    {
-    }
-}
+/*
+ *  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 java.nio.charset.CharacterCodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+
+import org.apache.directory.mitosis.common.CSNVector;
+import org.apache.directory.mitosis.common.ReplicaId;
+import org.apache.directory.mitosis.common.DefaultCSN;
+import org.apache.directory.mitosis.service.protocol.Constants;
+import org.apache.directory.mitosis.service.protocol.message.BaseMessage;
+import org.apache.directory.mitosis.service.protocol.message.BeginLogEntriesAckMessage;
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderException;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+
+
+public class BeginLogEntriesAckMessageDecoder extends ResponseMessageDecoder
+{
+    private final CharsetDecoder utf8decoder;
+
+
+    public BeginLogEntriesAckMessageDecoder()
+    {
+        super( Constants.GET_UPDATE_VECTOR_ACK, 0, 3072 );
+        utf8decoder = Charset.forName( "UTF-8" ).newDecoder();
+    }
+
+
+    protected BaseMessage decodeBody( int sequence, int bodyLength, int responseCode, ByteBuffer in ) throws Exception
+    {
+        if ( responseCode != Constants.OK )
+        {
+            return new BeginLogEntriesAckMessage( sequence, responseCode, null, null );
+        }
+
+        CSNVector purgeVector = new CSNVector();
+        CSNVector updateVector = new CSNVector();
+        BeginLogEntriesAckMessage m = new BeginLogEntriesAckMessage( sequence, responseCode, purgeVector, updateVector );
+        readCSNVector( in, purgeVector );
+        readCSNVector( in, updateVector );
+
+        return m;
+    }
+
+
+    private void readCSNVector( ByteBuffer in, CSNVector updateVector ) throws Exception
+    {
+        int nReplicas = in.getInt();
+        if ( nReplicas < 0 )
+        {
+            throw new ProtocolDecoderException( "Wrong nReplicas: " + nReplicas );
+        }
+
+        for ( ; nReplicas > 0; nReplicas-- )
+        {
+            ReplicaId replicaId;
+            try
+            {
+                replicaId = new ReplicaId( in.getString( utf8decoder ) );
+            }
+            catch ( CharacterCodingException e )
+            {
+                throw new ProtocolDecoderException( "Invalid replicaId", e );
+            }
+
+            updateVector.setCSN( new DefaultCSN( in.getLong(), replicaId, in.getInt() ) );
+        }
+    }
+
+
+    public void finishDecode( IoSession session, ProtocolDecoderOutput out ) throws Exception
+    {
+    }
+}

Modified: directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesAckMessageEncoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesAckMessageEncoder.java?rev=576193&r1=576192&r2=576193&view=diff
==============================================================================
--- directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesAckMessageEncoder.java (original)
+++ directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesAckMessageEncoder.java Sun Sep 16 15:12:06 2007
@@ -1,99 +1,99 @@
-/*
- *  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 java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetEncoder;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.apache.mina.common.ByteBuffer;
-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.service.protocol.Constants;
-import org.apache.directory.mitosis.service.protocol.message.BaseMessage;
-import org.apache.directory.mitosis.service.protocol.message.BeginLogEntriesAckMessage;
-
-
-public class BeginLogEntriesAckMessageEncoder extends ResponseMessageEncoder
-{
-    private final CharsetEncoder utf8encoder;
-
-
-    public BeginLogEntriesAckMessageEncoder()
-    {
-        utf8encoder = Charset.forName( "UTF-8" ).newEncoder();
-    }
-
-
-    protected void encodeBody( BaseMessage in, ByteBuffer out ) throws Exception
-    {
-        // write out response code
-        super.encodeBody( in, out );
-
-        BeginLogEntriesAckMessage m = ( BeginLogEntriesAckMessage ) in;
-        if ( m.getResponseCode() != Constants.OK )
-        {
-            return;
-        }
-
-        writeCSNVector( out, m.getPurgeVector() );
-        writeCSNVector( out, m.getUpdateVector() );
-    }
-
-
-    private void writeCSNVector( ByteBuffer out, CSNVector csns )
-    {
-        Set replicaIds = csns.getReplicaIds();
-
-        int nReplicas = replicaIds.size();
-        out.putInt( nReplicas );
-        Iterator it = replicaIds.iterator();
-        while ( it.hasNext() )
-        {
-            ReplicaId replicaId = ( ReplicaId ) it.next();
-            CSN csn = csns.getCSN( replicaId );
-            try
-            {
-                out.putString( replicaId.getId(), utf8encoder );
-                out.put( ( byte ) 0x00 );
-                out.putLong( csn.getTimestamp() );
-                out.putInt( csn.getOperationSequence() );
-            }
-            catch ( CharacterCodingException e )
-            {
-                throw new RuntimeException( e );
-            }
-        }
-    }
-
-
-    public Set getMessageTypes()
-    {
-        Set<Class> set = new HashSet<Class>();
-        set.add( BeginLogEntriesAckMessage.class );
-        return set;
-    }
-
-}
+/*
+ *  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 java.nio.charset.CharacterCodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetEncoder;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.mina.common.ByteBuffer;
+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.service.protocol.Constants;
+import org.apache.directory.mitosis.service.protocol.message.BaseMessage;
+import org.apache.directory.mitosis.service.protocol.message.BeginLogEntriesAckMessage;
+
+
+public class BeginLogEntriesAckMessageEncoder extends ResponseMessageEncoder
+{
+    private final CharsetEncoder utf8encoder;
+
+
+    public BeginLogEntriesAckMessageEncoder()
+    {
+        utf8encoder = Charset.forName( "UTF-8" ).newEncoder();
+    }
+
+
+    protected void encodeBody( BaseMessage in, ByteBuffer out ) throws Exception
+    {
+        // write out response code
+        super.encodeBody( in, out );
+
+        BeginLogEntriesAckMessage m = ( BeginLogEntriesAckMessage ) in;
+        if ( m.getResponseCode() != Constants.OK )
+        {
+            return;
+        }
+
+        writeCSNVector( out, m.getPurgeVector() );
+        writeCSNVector( out, m.getUpdateVector() );
+    }
+
+
+    private void writeCSNVector( ByteBuffer out, CSNVector csns )
+    {
+        Set replicaIds = csns.getReplicaIds();
+
+        int nReplicas = replicaIds.size();
+        out.putInt( nReplicas );
+        Iterator it = replicaIds.iterator();
+        while ( it.hasNext() )
+        {
+            ReplicaId replicaId = ( ReplicaId ) it.next();
+            CSN csn = csns.getCSN( replicaId );
+            try
+            {
+                out.putString( replicaId.getId(), utf8encoder );
+                out.put( ( byte ) 0x00 );
+                out.putLong( csn.getTimestamp() );
+                out.putInt( csn.getOperationSequence() );
+            }
+            catch ( CharacterCodingException e )
+            {
+                throw new RuntimeException( e );
+            }
+        }
+    }
+
+
+    public Set getMessageTypes()
+    {
+        Set<Class> set = new HashSet<Class>();
+        set.add( BeginLogEntriesAckMessage.class );
+        return set;
+    }
+
+}

Modified: directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesMessageDecoder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesMessageDecoder.java?rev=576193&r1=576192&r2=576193&view=diff
==============================================================================
--- directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesMessageDecoder.java (original)
+++ directory/apacheds/trunk/mitosis/src/main/java/org/apache/directory/mitosis/service/protocol/codec/BeginLogEntriesMessageDecoder.java Sun Sep 16 15:12:06 2007
@@ -1,49 +1,49 @@
-/*
- *  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 org.apache.directory.mitosis.service.protocol.Constants;
-import org.apache.directory.mitosis.service.protocol.message.BaseMessage;
-import org.apache.directory.mitosis.service.protocol.message.BeginLogEntriesMessage;
-import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.common.IoSession;
-import org.apache.mina.filter.codec.ProtocolDecoderOutput;
-
-
-public class BeginLogEntriesMessageDecoder extends BaseMessageDecoder
-{
-
-    public BeginLogEntriesMessageDecoder()
-    {
-        super( Constants.BEGIN_LOG_ENTRIES, 0, 0 );
-    }
-
-
-    protected BaseMessage decodeBody( int sequence, int bodyLength, ByteBuffer in ) throws Exception
-    {
-        return new BeginLogEntriesMessage( sequence );
-    }
-
-
-    public void finishDecode( IoSession session, ProtocolDecoderOutput out ) throws Exception
-    {
-    }
-}
+/*
+ *  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 org.apache.directory.mitosis.service.protocol.Constants;
+import org.apache.directory.mitosis.service.protocol.message.BaseMessage;
+import org.apache.directory.mitosis.service.protocol.message.BeginLogEntriesMessage;
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+
+
+public class BeginLogEntriesMessageDecoder extends BaseMessageDecoder
+{
+
+    public BeginLogEntriesMessageDecoder()
+    {
+        super( Constants.BEGIN_LOG_ENTRIES, 0, 0 );
+    }
+
+
+    protected BaseMessage decodeBody( int sequence, int bodyLength, ByteBuffer in ) throws Exception
+    {
+        return new BeginLogEntriesMessage( sequence );
+    }
+
+
+    public void finishDecode( IoSession session, ProtocolDecoderOutput out ) throws Exception
+    {
+    }
+}



Mime
View raw message