<commit_before>/*
 * @(#) $Id$
 */
package org.apache.mina.transport.vmpipe.support;

import java.io.IOException;
import java.net.SocketAddress;
import java.util.Set;

import org.apache.mina.common.CloseFuture;
import org.apache.mina.common.ExceptionMonitor;
import org.apache.mina.common.IoFilterChain;
import org.apache.mina.common.IoFilterChainBuilder;
import org.apache.mina.common.IoHandler;
import org.apache.mina.common.IoSession;
import org.apache.mina.common.IoSessionManager;
import org.apache.mina.common.TransportType;
import org.apache.mina.common.IoFilter.WriteRequest;
import org.apache.mina.common.support.BaseIoSession;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolEncoder;
import org.apache.mina.transport.vmpipe.VmPipeSession;
import org.apache.mina.util.ExceptionUtil;
import org.apache.mina.util.Queue;

/**
 * A {@link IoSession} for in-VM transport (VM_PIPE).
 * 
 * @author The Apache Directory Project (<EMAIL>)
 * @version $Rev$, $Date$
 */
public class VmPipeSessionImpl extends BaseIoSession implements VmPipeSession
{
    private final IoSessionManager manager;
    private final SocketAddress localAddress;
    private final SocketAddress remoteAddress;
    private final IoHandler handler;
    private final VmPipeFilterChain filterChain;
    private final Set managedSessions;
    final VmPipeSessionImpl remoteSession;
    final Object lock;
    final Queue pendingDataQueue;

    /**
     * Constructor for client-side session.
     */
    public VmPipeSessionImpl( IoSessionManager manager, Object lock, SocketAddress localAddress,
                   IoHandler handler, IoFilterChainBuilder filterChainBuilder,
                   VmPipe remoteEntry ) throws IOException
    {
        this.manager = manager;
        this.lock = lock;
        this.localAddress = localAddress;
        this.remoteAddress = remoteEntry.getAddress();
        this.handler = handler;
        this.filterChain = new VmPipeFilterChain( this );
        this.pendingDataQueue = new Queue();

        this.managedSessions = remoteEntry.getManagedClientSessions();
        
        remoteSession = new VmPipeSessionImpl( manager, this, remoteEntry );
        
        // initialize remote session
        try
        {
            remoteEntry.getAcceptor().getFilterChainBuilder().buildFilterChain( remoteSession.getFilterChain() );
            remoteEntry.getFilterChainBuilder().buildFilterChain( remoteSession.getFilterChain() );
            ( ( VmPipeFilterChain ) remoteSession.getFilterChain() ).sessionCreated( remoteSession );
        }
        catch( Throwable t )
        {
            ExceptionMonitor.getInstance().exceptionCaught( t );
            IOException e = new IOException( "Failed to initialize remote session." );
            e.initCause( t );
            throw e;
        }
        
        // initialize client session
        try
        {
            manager.getFilterChainBuilder().buildFilterChain( remoteSession.getFilterChain() );
            filterChainBuilder.buildFilterChain( remoteSession.getFilterChain() );
            handler.sessionCreated( this );
        }
        catch( Throwable t )
        {
            ExceptionUtil.throwException( t );
        }

        VmPipeIdleStatusChecker.getInstance().addSession( remoteSession );
        VmPipeIdleStatusChecker.getInstance().addSession( this );
        
        remoteSession.managedSessions.add( remoteSession );
        this.managedSessions.add( this );
        
        ( ( VmPipeFilterChain ) remoteSession.getFilterChain() ).sessionOpened( remoteSession );
        filterChain.sessionOpened( this );
    }

    /**
     * Constructor for server-side session.
     */
    private VmPipeSessionImpl( IoSessionManager manager, VmPipeSessionImpl remoteSession, VmPipe entry )
    {
        this.manager = manager;
        this.lock = remoteSession.lock;<commit_msg>The filters for the client-side session was added to the server-side session's filter chain. Changed so that they are added to the client-side session's chain as expected.<commit_after>/*
 * @(#) $Id$
 */
package org.apache.mina.transport.vmpipe.support;

import java.io.IOException;
import java.net.SocketAddress;
import java.util.Set;

import org.apache.mina.common.CloseFuture;
import org.apache.mina.common.ExceptionMonitor;
import org.apache.mina.common.IoFilterChain;
import org.apache.mina.common.IoFilterChainBuilder;
import org.apache.mina.common.IoHandler;
import org.apache.mina.common.IoSession;
import org.apache.mina.common.IoSessionManager;
import org.apache.mina.common.TransportType;
import org.apache.mina.common.IoFilter.WriteRequest;
import org.apache.mina.common.support.BaseIoSession;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolEncoder;
import org.apache.mina.transport.vmpipe.VmPipeSession;
import org.apache.mina.util.ExceptionUtil;
import org.apache.mina.util.Queue;

/**
 * A {@link IoSession} for in-VM transport (VM_PIPE).
 * 
 * @author The Apache Directory Project (<EMAIL>)
 * @version $Rev$, $Date$
 */
public class VmPipeSessionImpl extends BaseIoSession implements VmPipeSession
{
    private final IoSessionManager manager;
    private final SocketAddress localAddress;
    private final SocketAddress remoteAddress;
    private final IoHandler handler;
    private final VmPipeFilterChain filterChain;
    private final Set managedSessions;
    final VmPipeSessionImpl remoteSession;
    final Object lock;
    final Queue pendingDataQueue;

    /**
     * Constructor for client-side session.
     */
    public VmPipeSessionImpl( IoSessionManager manager, Object lock, SocketAddress localAddress,
                   IoHandler handler, IoFilterChainBuilder filterChainBuilder,
                   VmPipe remoteEntry ) throws IOException
    {
        this.manager = manager;
        this.lock = lock;
        this.localAddress = localAddress;
        this.remoteAddress = remoteEntry.getAddress();
        this.handler = handler;
        this.filterChain = new VmPipeFilterChain( this );
        this.pendingDataQueue = new Queue();

        this.managedSessions = remoteEntry.getManagedClientSessions();
        
        remoteSession = new VmPipeSessionImpl( manager, this, remoteEntry );
        
        // initialize remote session
        try
        {
            remoteEntry.getAcceptor().getFilterChainBuilder().buildFilterChain( remoteSession.getFilterChain() );
            remoteEntry.getFilterChainBuilder().buildFilterChain( remoteSession.getFilterChain() );
            ( ( VmPipeFilterChain ) remoteSession.getFilterChain() ).sessionCreated( remoteSession );
        }
        catch( Throwable t )
        {
            ExceptionMonitor.getInstance().exceptionCaught( t );
            IOException e = new IOException( "Failed to initialize remote session." );
            e.initCause( t );
            throw e;
        }
        
        // initialize client session
        try
        {
            manager.getFilterChainBuilder().buildFilterChain( filterChain );
            filterChainBuilder.buildFilterChain( filterChain );
            handler.sessionCreated( this );
        }
        catch( Throwable t )
        {
            ExceptionUtil.throwException( t );
        }

        VmPipeIdleStatusChecker.getInstance().addSession( remoteSession );
        VmPipeIdleStatusChecker.getInstance().addSession( this );
        
        remoteSession.managedSessions.add( remoteSession );
        this.managedSessions.add( this );
        
        ( ( VmPipeFilterChain ) remoteSession.getFilterChain() ).sessionOpened( remoteSession );
        filterChain.sessionOpened( this );
    }

    /**
     * Constructor for server-side session.
     */
    private VmPipeSessionImpl( IoSessionManager manager, VmPipeSessionImpl remoteSession, VmPipe entry )
    {
        this.manager = manager;
        this.lock = remoteSession.lock;
{'fraction_non_alphanumeric': 0.0896404324867991, 'fraction_numerical': 0.0, 'mean_word_length': 2.9814814814814814, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7593463', 'n_tokens_mistral': 2107, 'n_tokens_neox': 2081, 'n_words': 457}