Package etch.util.core.nio

Examples of etch.util.core.nio.Tcp2Connection


  /** @throws Exception */
  @Test
  public void constructor9() throws Exception
  {
    SessionData dh = new MyDataHandler();
    Tcp2Connection c = new Tcp2Connection( "tcp://localhost:"+port, r );
    c.setSession( dh );
    assertSame( dh, c.getSession() );
  }
View Full Code Here


    SocketChannel t = lh.accepted.waitUntilNotEqAndSet( null, TIMEOUT, null );
   
    MyDataHandler dh = new MyDataHandler();
   
    r.put( "connection", s );
    Tcp2Connection c = new Tcp2Connection( "tcp:", r );
    c.setSession( dh );

    assertFalse( c.isStarted() );
    c.start();
    assertTrue( c.isStarted() );
   
    c.waitUp( TIMEOUT );
   
    assertWhat( What.UP, dh.what );
    assertNull( dh.xsender );
    assertNull( dh.xbuf );
   
//    c.flush();
    assertNotNull( c.remoteAddress() );
    assertNotNull( c.localAddress() );
    assertEquals( c.remoteAddress(), t.socket().getLocalSocketAddress() );
    assertEquals( c.localAddress(), t.socket().getRemoteSocketAddress() );
   
    t.close();
   
    assertWhat( What.DOWN, dh.what );
    assertNull( dh.xsender );
View Full Code Here

    SocketChannel t = lh.accepted.waitUntilNotEqAndSet( null, TIMEOUT, null );
   
    MyDataHandler dh = new MyDataHandler();

    r.put( "connection", s );
    Tcp2Connection c = new Tcp2Connection( "tcp:", r );
    c.setSession( dh );
   
    assertFalse( c.isStarted() );
    c.start();
    assertTrue( c.isStarted() );
   
    assertWhat( What.UP, dh.what );
    assertNull( dh.xsender );
    assertNull( dh.xbuf );
   
    assertTrue( c.isStarted() );
    c.stop();
    assertFalse( c.isStarted() );
   
    c.waitDown( TIMEOUT );
   
    assertWhat( What.DOWN, dh.what );
    assertNull( dh.xsender );
    assertNull( dh.xbuf );
   
View Full Code Here

    SocketChannel t = lh.accepted.waitUntilNotEqAndSet( null, TIMEOUT, null );
   
    MyDataHandler dh = new MyDataHandler();

    r.put( "connection", s );
    Tcp2Connection c = new Tcp2Connection( "tcp:", r );
    c.setSession( dh );
   
    assertFalse( c.isStarted() );
    c.start();
    assertTrue( c.isStarted() );
   
    assertWhat( What.UP, dh.what );
    assertNull( dh.xsender );
    assertNull( dh.xbuf );
   
    assertTrue( c.isStarted() );
    c.close();
   
    c.waitDown( TIMEOUT );
   
    assertWhat( What.DOWN, dh.what );
    assertNull( dh.xsender );
    assertNull( dh.xbuf );
   
View Full Code Here

    SocketChannel t = lh.accepted.waitUntilNotEqAndSet( null, TIMEOUT, null );
   
    MyDataHandler dh = new MyDataHandler();

    r.put( "connection", s );
    Tcp2Connection c = new Tcp2Connection( "tcp:", r );
    c.setSession( dh );
   
    assertFalse( c.isStarted() );
    c.start();
    assertTrue( c.isStarted() );
   
    assertWhat( What.UP, dh.what );
    assertNull( dh.xsender );
    assertNull( dh.xbuf );
   
    assertTrue( c.isStarted() );
    c.close( false );
   
    c.waitDown( TIMEOUT );
   
    assertWhat( What.DOWN, dh.what );
    assertNull( dh.xsender );
    assertNull( dh.xbuf );
   
View Full Code Here

    SocketChannel t = lh.accepted.waitUntilNotEqAndSet( null, TIMEOUT, null );
   
    MyDataHandler dh = new MyDataHandler();

    r.put( "connection", s );
    Tcp2Connection c = new Tcp2Connection( "tcp:", r );
    c.setSession( dh );
   
    assertFalse( c.isStarted() );
    c.start();
    assertTrue( c.isStarted() );
   
    assertWhat( What.UP, dh.what );
    assertNull( dh.xsender );
    assertNull( dh.xbuf );
   
    assertTrue( c.isStarted() );
    c.close( true );
   
    c.waitDown( TIMEOUT );
   
    assertWhat( What.DOWN, dh.what );
    assertNull( dh.xsender );
    assertNull( dh.xbuf );
   
View Full Code Here

  {
    Log.report( "--- start6 ------------------------------" );
   
    MyDataHandler dh = new MyDataHandler();
   
    Tcp2Connection c = new Tcp2Connection( "tcp://127.0.0.1:"+port, r );
    c.setSession( dh );
   
    assertFalse( c.isStarted() );
    c.start();
    assertTrue( c.isStarted() );
    SocketChannel t = lh.accepted.waitUntilNotEqAndSet( null, TIMEOUT, null );
   
    assertWhat( What.UP, dh.what );
    assertNull( dh.xsender );
    assertNull( dh.xbuf );
   
    assertTrue( c.isStarted() );
    c.stop();
    assertFalse( c.isStarted() );
   
    assertWhat( What.DOWN, dh.what );
    assertNull( dh.xsender );
    assertNull( dh.xbuf );
   
View Full Code Here

  {
    Log.report( "--- restart1 ------------------------------" );
   
    MyDataHandler dh = new MyDataHandler();
   
    Tcp2Connection c = new Tcp2Connection( "tcp://127.0.0.1:"+port+"?TcpTransport.reconnectDelay=200", r );
    c.setSession( dh );
   
    c.start();
    c.waitUp( TIMEOUT );
   
    int n = 10;
    int i = 0;
    while (++i <= n)
    {
      SocketChannel t = lh.accepted.waitUntilNotEqAndSet( null, TIMEOUT, null );

      Log.report( "accepted", "i", i,
        "t.local", t.socket().getLocalSocketAddress(),
        "t.remote", t.socket().getRemoteSocketAddress() );
     
      assertWhat( What.UP, dh.what );
     
      assertEquals( t.socket().getLocalSocketAddress(), c.remoteAddress() );
      assertEquals( t.socket().getRemoteSocketAddress(), c.localAddress() );
     
      write( t, i );
      assertWhat( What.DATA, dh.what );
      assertNull( dh.xsender );
      assertNotNull( dh.xbuf );
      assertEquals( 1, dh.xbuf.length );
      assertEquals( (byte) i, dh.xbuf[0] );

      t.socket().shutdownOutput();
      t.close();
      t = null;
     
      assertWhat( What.DOWN, dh.what );
    }
   
    Thread t1 = new MonitorHarvester<SocketChannel>( lh.accepted );
    t1.start();
    Thread t2 = new MonitorHarvester<What>( dh.what );
    t2.start();

    Log.report( "stopping" );
    c.stop();
    c.waitDown( TIMEOUT );
    Log.report( "stoppped" );
   
    t1.join();
    t2.join();
  }
View Full Code Here

  {
    Log.report( "--- restart2 ------------------------------" );
   
    MyDataHandler dh = new MyDataHandler();
   
    Tcp2Connection c = new Tcp2Connection( "tcp://127.0.0.1:"+port+"?TcpTransport.reconnectDelay=200", r );
    c.setSession( dh );
   
    c.start();
    c.waitUp( TIMEOUT );
   
    int n = 10;
    int i = 0;
    while (++i <= n)
    {
//      Log.report( "--- waitAccepted" );
      SocketChannel t = lh.accepted.waitUntilNotEqAndSet( null, TIMEOUT, null );

      Log.report( "accepted", "i", i,
        "t.local", t.socket().getLocalSocketAddress(),
        "t.remote", t.socket().getRemoteSocketAddress() );
     
      assertWhat( What.UP, dh.what );
//      Log.report( "up", "c.local", c.localAddress(), "c.remote", c.remoteAddress() );
     
      assertEquals( t.socket().getLocalSocketAddress(), c.remoteAddress() );
      assertEquals( t.socket().getRemoteSocketAddress(), c.localAddress() );
     
      write( t, i );
      assertWhat( What.DATA, dh.what );
      assertNull( dh.xsender );
      assertNotNull( dh.xbuf );
      assertEquals( 1, dh.xbuf.length );
      assertEquals( (byte) i, dh.xbuf[0] );

//      Log.report( "c.shutingDownOutput" );
      c.shutdownOutput();
//      Log.report( "c.shutdownOutput" );
     
//      Log.report( "t.reading" );
      assertEquals( -1, read( t ) );
//      Log.report( "t.eof" );
     
      t.socket().shutdownOutput();
      t.close();
      t = null;
     
      assertWhat( What.DOWN, dh.what );
//      Log.report( "down" );
    }
   
    Thread t1 = new MonitorHarvester<SocketChannel>( lh.accepted );
    t1.start();
    Thread t2 = new MonitorHarvester<What>( dh.what );
    t2.start();
   
    Log.report( "stopping" );
    c.stop();
    c.waitDown( TIMEOUT );
    Log.report( "stopped" );
   
    t1.join();
    t2.join();
  }
View Full Code Here

  @Test
  public void data1() throws Exception
  {
    MyDataHandler dh = new MyDataHandler();
   
    Tcp2Connection c = new Tcp2Connection( "tcp://127.0.0.1:"+port, r );
    c.setSession( dh );
   
    assertFalse( c.isStarted() );
    c.start();
    assertTrue( c.isStarted() );
   
    SocketChannel t = lh.accepted.waitUntilNotEqAndSet( null, TIMEOUT, null );
   
    assertWhat( What.UP, dh.what );
    assertNull( dh.xsender );
    assertNull( dh.xbuf );
   
    write( t, 23 );
   
    assertWhat( What.DATA, dh.what );
    assertNull( dh.xsender );
    assertNotNull( dh.xbuf );
    assertEquals( 1, dh.xbuf.length );
    assertEquals( (byte) 23, dh.xbuf[0] );
   
    assertTrue( c.isStarted() );
    c.stop();
    assertFalse( c.isStarted() );
   
    assertWhat( What.DOWN, dh.what );
    assertNull( dh.xsender );
    assertNull( dh.xbuf );
   
View Full Code Here

TOP

Related Classes of etch.util.core.nio.Tcp2Connection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.