Java Code Examples for com.sun.nio.sctp.SctpMultiChannel#close()

The following examples show how to use com.sun.nio.sctp.SctpMultiChannel#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Branch.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
void doTest(SocketAddress peerAddress) {
    SctpMultiChannel channel = null;
    ByteBuffer buffer = ByteBuffer.allocate(Util.LARGE_BUFFER);
    MessageInfo info = MessageInfo.createOutgoing(null, 0);

    try {
        channel = SctpMultiChannel.open();

        /* setup an association implicitly by sending a small message */
        int streamNumber = 0;
        debug("sending to " + peerAddress + " on stream number: " + streamNumber);
        info = MessageInfo.createOutgoing(peerAddress, streamNumber);
        buffer.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1"));
        buffer.flip();
        int position = buffer.position();
        int remaining = buffer.remaining();

        debug("sending small message: " + buffer);
        int sent = channel.send(buffer, info);

        check(sent == remaining, "sent should be equal to remaining");
        check(buffer.position() == (position + sent),
                "buffers position should have been incremented by sent");

        /* Receive the COMM_UP */
        buffer.clear();
        BranchNotificationHandler handler = new BranchNotificationHandler();
        info = channel.receive(buffer, null, handler);
        check(handler.receivedCommUp(), "COMM_UP no received");
        Set<Association> associations = channel.associations();
        check(!associations.isEmpty(),"There should be some associations");
        Association bassoc = associations.iterator().next();

        /* TEST 1: branch */
        SctpChannel bchannel = channel.branch(bassoc);

        check(!bchannel.getAllLocalAddresses().isEmpty(),
                               "branched channel should be bound");
        check(!bchannel.getRemoteAddresses().isEmpty(),
                               "branched channel should be connected");
        check(channel.associations().isEmpty(),
              "there should be no associations since the only one was branched off");

        buffer.clear();
        info = bchannel.receive(buffer, null, null);
        buffer.flip();
        check(info != null, "info is null");
        check(info.streamNumber() == streamNumber,
                "message not sent on the correct stream");
        check(info.bytes() == Util.SMALL_MESSAGE.getBytes("ISO-8859-1").
              length, "bytes received not equal to message length");
        check(info.bytes() == buffer.remaining(), "bytes != remaining");
        check(Util.compare(buffer, Util.SMALL_MESSAGE),
          "received message not the same as sent message");

    } catch (IOException ioe) {
        unexpected(ioe);
    } finally {
        clientFinishedLatch.countDown();
        try { serverFinishedLatch.await(10L, TimeUnit.SECONDS); }
        catch (InterruptedException ie) { unexpected(ie); }
        if (channel != null) {
            try { channel.close(); }
            catch (IOException e) { unexpected (e);}
        }
    }
}
 
Example 2
Source File: Branch.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
void doTest(SocketAddress peerAddress) {
    SctpMultiChannel channel = null;
    ByteBuffer buffer = ByteBuffer.allocate(Util.LARGE_BUFFER);
    MessageInfo info = MessageInfo.createOutgoing(null, 0);

    try {
        channel = SctpMultiChannel.open();

        /* setup an association implicitly by sending a small message */
        int streamNumber = 0;
        debug("sending to " + peerAddress + " on stream number: " + streamNumber);
        info = MessageInfo.createOutgoing(peerAddress, streamNumber);
        buffer.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1"));
        buffer.flip();
        int position = buffer.position();
        int remaining = buffer.remaining();

        debug("sending small message: " + buffer);
        int sent = channel.send(buffer, info);

        check(sent == remaining, "sent should be equal to remaining");
        check(buffer.position() == (position + sent),
                "buffers position should have been incremented by sent");

        /* Receive the COMM_UP */
        buffer.clear();
        BranchNotificationHandler handler = new BranchNotificationHandler();
        info = channel.receive(buffer, null, handler);
        check(handler.receivedCommUp(), "COMM_UP no received");
        Set<Association> associations = channel.associations();
        check(!associations.isEmpty(),"There should be some associations");
        Association bassoc = associations.iterator().next();

        /* TEST 1: branch */
        SctpChannel bchannel = channel.branch(bassoc);

        check(!bchannel.getAllLocalAddresses().isEmpty(),
                               "branched channel should be bound");
        check(!bchannel.getRemoteAddresses().isEmpty(),
                               "branched channel should be connected");
        check(channel.associations().isEmpty(),
              "there should be no associations since the only one was branched off");

        buffer.clear();
        info = bchannel.receive(buffer, null, null);
        buffer.flip();
        check(info != null, "info is null");
        check(info.streamNumber() == streamNumber,
                "message not sent on the correct stream");
        check(info.bytes() == Util.SMALL_MESSAGE.getBytes("ISO-8859-1").
              length, "bytes received not equal to message length");
        check(info.bytes() == buffer.remaining(), "bytes != remaining");
        check(Util.compare(buffer, Util.SMALL_MESSAGE),
          "received message not the same as sent message");

    } catch (IOException ioe) {
        unexpected(ioe);
    } finally {
        clientFinishedLatch.countDown();
        try { serverFinishedLatch.await(10L, TimeUnit.SECONDS); }
        catch (InterruptedException ie) { unexpected(ie); }
        if (channel != null) {
            try { channel.close(); }
            catch (IOException e) { unexpected (e);}
        }
    }
}
 
Example 3
Source File: Branch.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
void doTest(SocketAddress peerAddress) {
    SctpMultiChannel channel = null;
    ByteBuffer buffer = ByteBuffer.allocate(Util.LARGE_BUFFER);
    MessageInfo info = MessageInfo.createOutgoing(null, 0);

    try {
        channel = SctpMultiChannel.open();

        /* setup an association implicitly by sending a small message */
        int streamNumber = 0;
        debug("sending to " + peerAddress + " on stream number: " + streamNumber);
        info = MessageInfo.createOutgoing(peerAddress, streamNumber);
        buffer.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1"));
        buffer.flip();
        int position = buffer.position();
        int remaining = buffer.remaining();

        debug("sending small message: " + buffer);
        int sent = channel.send(buffer, info);

        check(sent == remaining, "sent should be equal to remaining");
        check(buffer.position() == (position + sent),
                "buffers position should have been incremented by sent");

        /* Receive the COMM_UP */
        buffer.clear();
        BranchNotificationHandler handler = new BranchNotificationHandler();
        info = channel.receive(buffer, null, handler);
        check(handler.receivedCommUp(), "COMM_UP no received");
        Set<Association> associations = channel.associations();
        check(!associations.isEmpty(),"There should be some associations");
        Association bassoc = associations.iterator().next();

        /* TEST 1: branch */
        SctpChannel bchannel = channel.branch(bassoc);

        check(!bchannel.getAllLocalAddresses().isEmpty(),
                               "branched channel should be bound");
        check(!bchannel.getRemoteAddresses().isEmpty(),
                               "branched channel should be connected");
        check(channel.associations().isEmpty(),
              "there should be no associations since the only one was branched off");

        buffer.clear();
        info = bchannel.receive(buffer, null, null);
        buffer.flip();
        check(info != null, "info is null");
        check(info.streamNumber() == streamNumber,
                "message not sent on the correct stream");
        check(info.bytes() == Util.SMALL_MESSAGE.getBytes("ISO-8859-1").
              length, "bytes received not equal to message length");
        check(info.bytes() == buffer.remaining(), "bytes != remaining");
        check(Util.compare(buffer, Util.SMALL_MESSAGE),
          "received message not the same as sent message");

    } catch (IOException ioe) {
        unexpected(ioe);
    } finally {
        clientFinishedLatch.countDown();
        try { serverFinishedLatch.await(10L, TimeUnit.SECONDS); }
        catch (InterruptedException ie) { unexpected(ie); }
        if (channel != null) {
            try { channel.close(); }
            catch (IOException e) { unexpected (e);}
        }
    }
}
 
Example 4
Source File: Branch.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
void doTest(SocketAddress peerAddress) {
    SctpMultiChannel channel = null;
    ByteBuffer buffer = ByteBuffer.allocate(Util.LARGE_BUFFER);
    MessageInfo info = MessageInfo.createOutgoing(null, 0);

    try {
        channel = SctpMultiChannel.open();

        /* setup an association implicitly by sending a small message */
        int streamNumber = 0;
        debug("sending to " + peerAddress + " on stream number: " + streamNumber);
        info = MessageInfo.createOutgoing(peerAddress, streamNumber);
        buffer.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1"));
        buffer.flip();
        int position = buffer.position();
        int remaining = buffer.remaining();

        debug("sending small message: " + buffer);
        int sent = channel.send(buffer, info);

        check(sent == remaining, "sent should be equal to remaining");
        check(buffer.position() == (position + sent),
                "buffers position should have been incremented by sent");

        /* Receive the COMM_UP */
        buffer.clear();
        BranchNotificationHandler handler = new BranchNotificationHandler();
        info = channel.receive(buffer, null, handler);
        check(handler.receivedCommUp(), "COMM_UP no received");
        Set<Association> associations = channel.associations();
        check(!associations.isEmpty(),"There should be some associations");
        Association bassoc = associations.iterator().next();

        /* TEST 1: branch */
        SctpChannel bchannel = channel.branch(bassoc);

        check(!bchannel.getAllLocalAddresses().isEmpty(),
                               "branched channel should be bound");
        check(!bchannel.getRemoteAddresses().isEmpty(),
                               "branched channel should be connected");
        check(channel.associations().isEmpty(),
              "there should be no associations since the only one was branched off");

        buffer.clear();
        info = bchannel.receive(buffer, null, null);
        buffer.flip();
        check(info != null, "info is null");
        check(info.streamNumber() == streamNumber,
                "message not sent on the correct stream");
        check(info.bytes() == Util.SMALL_MESSAGE.getBytes("ISO-8859-1").
              length, "bytes received not equal to message length");
        check(info.bytes() == buffer.remaining(), "bytes != remaining");
        check(Util.compare(buffer, Util.SMALL_MESSAGE),
          "received message not the same as sent message");

    } catch (IOException ioe) {
        unexpected(ioe);
    } finally {
        clientFinishedLatch.countDown();
        try { serverFinishedLatch.await(10L, TimeUnit.SECONDS); }
        catch (InterruptedException ie) { unexpected(ie); }
        if (channel != null) {
            try { channel.close(); }
            catch (IOException e) { unexpected (e);}
        }
    }
}
 
Example 5
Source File: Branch.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
void doTest(SocketAddress peerAddress) {
    SctpMultiChannel channel = null;
    ByteBuffer buffer = ByteBuffer.allocate(Util.LARGE_BUFFER);
    MessageInfo info = MessageInfo.createOutgoing(null, 0);

    try {
        channel = SctpMultiChannel.open();

        /* setup an association implicitly by sending a small message */
        int streamNumber = 0;
        debug("sending to " + peerAddress + " on stream number: " + streamNumber);
        info = MessageInfo.createOutgoing(peerAddress, streamNumber);
        buffer.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1"));
        buffer.flip();
        int position = buffer.position();
        int remaining = buffer.remaining();

        debug("sending small message: " + buffer);
        int sent = channel.send(buffer, info);

        check(sent == remaining, "sent should be equal to remaining");
        check(buffer.position() == (position + sent),
                "buffers position should have been incremented by sent");

        /* Receive the COMM_UP */
        buffer.clear();
        BranchNotificationHandler handler = new BranchNotificationHandler();
        info = channel.receive(buffer, null, handler);
        check(handler.receivedCommUp(), "COMM_UP no received");
        Set<Association> associations = channel.associations();
        check(!associations.isEmpty(),"There should be some associations");
        Association bassoc = associations.iterator().next();

        /* TEST 1: branch */
        SctpChannel bchannel = channel.branch(bassoc);

        check(!bchannel.getAllLocalAddresses().isEmpty(),
                               "branched channel should be bound");
        check(!bchannel.getRemoteAddresses().isEmpty(),
                               "branched channel should be connected");
        check(channel.associations().isEmpty(),
              "there should be no associations since the only one was branched off");

        buffer.clear();
        info = bchannel.receive(buffer, null, null);
        buffer.flip();
        check(info != null, "info is null");
        check(info.streamNumber() == streamNumber,
                "message not sent on the correct stream");
        check(info.bytes() == Util.SMALL_MESSAGE.getBytes("ISO-8859-1").
              length, "bytes received not equal to message length");
        check(info.bytes() == buffer.remaining(), "bytes != remaining");
        check(Util.compare(buffer, Util.SMALL_MESSAGE),
          "received message not the same as sent message");

    } catch (IOException ioe) {
        unexpected(ioe);
    } finally {
        clientFinishedLatch.countDown();
        try { serverFinishedLatch.await(10L, TimeUnit.SECONDS); }
        catch (InterruptedException ie) { unexpected(ie); }
        if (channel != null) {
            try { channel.close(); }
            catch (IOException e) { unexpected (e);}
        }
    }
}
 
Example 6
Source File: Branch.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
void doTest(SocketAddress peerAddress) {
    SctpMultiChannel channel = null;
    ByteBuffer buffer = ByteBuffer.allocate(Util.LARGE_BUFFER);
    MessageInfo info = MessageInfo.createOutgoing(null, 0);

    try {
        channel = SctpMultiChannel.open();

        /* setup an association implicitly by sending a small message */
        int streamNumber = 0;
        debug("sending to " + peerAddress + " on stream number: " + streamNumber);
        info = MessageInfo.createOutgoing(peerAddress, streamNumber);
        buffer.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1"));
        buffer.flip();
        int position = buffer.position();
        int remaining = buffer.remaining();

        debug("sending small message: " + buffer);
        int sent = channel.send(buffer, info);

        check(sent == remaining, "sent should be equal to remaining");
        check(buffer.position() == (position + sent),
                "buffers position should have been incremented by sent");

        /* Receive the COMM_UP */
        buffer.clear();
        BranchNotificationHandler handler = new BranchNotificationHandler();
        info = channel.receive(buffer, null, handler);
        check(handler.receivedCommUp(), "COMM_UP no received");
        Set<Association> associations = channel.associations();
        check(!associations.isEmpty(),"There should be some associations");
        Association bassoc = associations.iterator().next();

        /* TEST 1: branch */
        SctpChannel bchannel = channel.branch(bassoc);

        check(!bchannel.getAllLocalAddresses().isEmpty(),
                               "branched channel should be bound");
        check(!bchannel.getRemoteAddresses().isEmpty(),
                               "branched channel should be connected");
        check(channel.associations().isEmpty(),
              "there should be no associations since the only one was branched off");

        buffer.clear();
        info = bchannel.receive(buffer, null, null);
        buffer.flip();
        check(info != null, "info is null");
        check(info.streamNumber() == streamNumber,
                "message not sent on the correct stream");
        check(info.bytes() == Util.SMALL_MESSAGE.getBytes("ISO-8859-1").
              length, "bytes received not equal to message length");
        check(info.bytes() == buffer.remaining(), "bytes != remaining");
        check(Util.compare(buffer, Util.SMALL_MESSAGE),
          "received message not the same as sent message");

    } catch (IOException ioe) {
        unexpected(ioe);
    } finally {
        clientFinishedLatch.countDown();
        try { serverFinishedLatch.await(10L, TimeUnit.SECONDS); }
        catch (InterruptedException ie) { unexpected(ie); }
        if (channel != null) {
            try { channel.close(); }
            catch (IOException e) { unexpected (e);}
        }
    }
}
 
Example 7
Source File: Branch.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
void doTest(SocketAddress peerAddress) {
    SctpMultiChannel channel = null;
    ByteBuffer buffer = ByteBuffer.allocate(Util.LARGE_BUFFER);
    MessageInfo info = MessageInfo.createOutgoing(null, 0);

    try {
        channel = SctpMultiChannel.open();

        /* setup an association implicitly by sending a small message */
        int streamNumber = 0;
        debug("sending to " + peerAddress + " on stream number: " + streamNumber);
        info = MessageInfo.createOutgoing(peerAddress, streamNumber);
        buffer.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1"));
        buffer.flip();
        int position = buffer.position();
        int remaining = buffer.remaining();

        debug("sending small message: " + buffer);
        int sent = channel.send(buffer, info);

        check(sent == remaining, "sent should be equal to remaining");
        check(buffer.position() == (position + sent),
                "buffers position should have been incremented by sent");

        /* Receive the COMM_UP */
        buffer.clear();
        BranchNotificationHandler handler = new BranchNotificationHandler();
        info = channel.receive(buffer, null, handler);
        check(handler.receivedCommUp(), "COMM_UP no received");
        Set<Association> associations = channel.associations();
        check(!associations.isEmpty(),"There should be some associations");
        Association bassoc = associations.iterator().next();

        /* TEST 1: branch */
        SctpChannel bchannel = channel.branch(bassoc);

        check(!bchannel.getAllLocalAddresses().isEmpty(),
                               "branched channel should be bound");
        check(!bchannel.getRemoteAddresses().isEmpty(),
                               "branched channel should be connected");
        check(channel.associations().isEmpty(),
              "there should be no associations since the only one was branched off");

        buffer.clear();
        info = bchannel.receive(buffer, null, null);
        buffer.flip();
        check(info != null, "info is null");
        check(info.streamNumber() == streamNumber,
                "message not sent on the correct stream");
        check(info.bytes() == Util.SMALL_MESSAGE.getBytes("ISO-8859-1").
              length, "bytes received not equal to message length");
        check(info.bytes() == buffer.remaining(), "bytes != remaining");
        check(Util.compare(buffer, Util.SMALL_MESSAGE),
          "received message not the same as sent message");

    } catch (IOException ioe) {
        unexpected(ioe);
    } finally {
        clientFinishedLatch.countDown();
        try { serverFinishedLatch.await(10L, TimeUnit.SECONDS); }
        catch (InterruptedException ie) { unexpected(ie); }
        if (channel != null) {
            try { channel.close(); }
            catch (IOException e) { unexpected (e);}
        }
    }
}
 
Example 8
Source File: Branch.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
void doTest(SocketAddress peerAddress) {
    SctpMultiChannel channel = null;
    ByteBuffer buffer = ByteBuffer.allocate(Util.LARGE_BUFFER);
    MessageInfo info = MessageInfo.createOutgoing(null, 0);

    try {
        channel = SctpMultiChannel.open();

        /* setup an association implicitly by sending a small message */
        int streamNumber = 0;
        debug("sending to " + peerAddress + " on stream number: " + streamNumber);
        info = MessageInfo.createOutgoing(peerAddress, streamNumber);
        buffer.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1"));
        buffer.flip();
        int position = buffer.position();
        int remaining = buffer.remaining();

        debug("sending small message: " + buffer);
        int sent = channel.send(buffer, info);

        check(sent == remaining, "sent should be equal to remaining");
        check(buffer.position() == (position + sent),
                "buffers position should have been incremented by sent");

        /* Receive the COMM_UP */
        buffer.clear();
        BranchNotificationHandler handler = new BranchNotificationHandler();
        info = channel.receive(buffer, null, handler);
        check(handler.receivedCommUp(), "COMM_UP no received");
        Set<Association> associations = channel.associations();
        check(!associations.isEmpty(),"There should be some associations");
        Association bassoc = associations.iterator().next();

        /* TEST 1: branch */
        SctpChannel bchannel = channel.branch(bassoc);

        check(!bchannel.getAllLocalAddresses().isEmpty(),
                               "branched channel should be bound");
        check(!bchannel.getRemoteAddresses().isEmpty(),
                               "branched channel should be connected");
        check(channel.associations().isEmpty(),
              "there should be no associations since the only one was branched off");

        buffer.clear();
        info = bchannel.receive(buffer, null, null);
        buffer.flip();
        check(info != null, "info is null");
        check(info.streamNumber() == streamNumber,
                "message not sent on the correct stream");
        check(info.bytes() == Util.SMALL_MESSAGE.getBytes("ISO-8859-1").
              length, "bytes received not equal to message length");
        check(info.bytes() == buffer.remaining(), "bytes != remaining");
        check(Util.compare(buffer, Util.SMALL_MESSAGE),
          "received message not the same as sent message");

    } catch (IOException ioe) {
        unexpected(ioe);
    } finally {
        clientFinishedLatch.countDown();
        try { serverFinishedLatch.await(10L, TimeUnit.SECONDS); }
        catch (InterruptedException ie) { unexpected(ie); }
        if (channel != null) {
            try { channel.close(); }
            catch (IOException e) { unexpected (e);}
        }
    }
}
 
Example 9
Source File: Branch.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
void doTest(SocketAddress peerAddress) {
    SctpMultiChannel channel = null;
    ByteBuffer buffer = ByteBuffer.allocate(Util.LARGE_BUFFER);
    MessageInfo info = MessageInfo.createOutgoing(null, 0);

    try {
        channel = SctpMultiChannel.open();

        /* setup an association implicitly by sending a small message */
        int streamNumber = 0;
        debug("sending to " + peerAddress + " on stream number: " + streamNumber);
        info = MessageInfo.createOutgoing(peerAddress, streamNumber);
        buffer.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1"));
        buffer.flip();
        int position = buffer.position();
        int remaining = buffer.remaining();

        debug("sending small message: " + buffer);
        int sent = channel.send(buffer, info);

        check(sent == remaining, "sent should be equal to remaining");
        check(buffer.position() == (position + sent),
                "buffers position should have been incremented by sent");

        /* Receive the COMM_UP */
        buffer.clear();
        BranchNotificationHandler handler = new BranchNotificationHandler();
        info = channel.receive(buffer, null, handler);
        check(handler.receivedCommUp(), "COMM_UP no received");
        Set<Association> associations = channel.associations();
        check(!associations.isEmpty(),"There should be some associations");
        Association bassoc = associations.iterator().next();

        /* TEST 1: branch */
        SctpChannel bchannel = channel.branch(bassoc);

        check(!bchannel.getAllLocalAddresses().isEmpty(),
                               "branched channel should be bound");
        check(!bchannel.getRemoteAddresses().isEmpty(),
                               "branched channel should be connected");
        check(channel.associations().isEmpty(),
              "there should be no associations since the only one was branched off");

        buffer.clear();
        info = bchannel.receive(buffer, null, null);
        buffer.flip();
        check(info != null, "info is null");
        check(info.streamNumber() == streamNumber,
                "message not sent on the correct stream");
        check(info.bytes() == Util.SMALL_MESSAGE.getBytes("ISO-8859-1").
              length, "bytes received not equal to message length");
        check(info.bytes() == buffer.remaining(), "bytes != remaining");
        check(Util.compare(buffer, Util.SMALL_MESSAGE),
          "received message not the same as sent message");

    } catch (IOException ioe) {
        unexpected(ioe);
    } finally {
        clientFinishedLatch.countDown();
        try { serverFinishedLatch.await(10L, TimeUnit.SECONDS); }
        catch (InterruptedException ie) { unexpected(ie); }
        if (channel != null) {
            try { channel.close(); }
            catch (IOException e) { unexpected (e);}
        }
    }
}
 
Example 10
Source File: Branch.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
void doTest(SocketAddress peerAddress) {
    SctpMultiChannel channel = null;
    ByteBuffer buffer = ByteBuffer.allocate(Util.LARGE_BUFFER);
    MessageInfo info = MessageInfo.createOutgoing(null, 0);

    try {
        channel = SctpMultiChannel.open();

        /* setup an association implicitly by sending a small message */
        int streamNumber = 0;
        debug("sending to " + peerAddress + " on stream number: " + streamNumber);
        info = MessageInfo.createOutgoing(peerAddress, streamNumber);
        buffer.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1"));
        buffer.flip();
        int position = buffer.position();
        int remaining = buffer.remaining();

        debug("sending small message: " + buffer);
        int sent = channel.send(buffer, info);

        check(sent == remaining, "sent should be equal to remaining");
        check(buffer.position() == (position + sent),
                "buffers position should have been incremented by sent");

        /* Receive the COMM_UP */
        buffer.clear();
        BranchNotificationHandler handler = new BranchNotificationHandler();
        info = channel.receive(buffer, null, handler);
        check(handler.receivedCommUp(), "COMM_UP no received");
        Set<Association> associations = channel.associations();
        check(!associations.isEmpty(),"There should be some associations");
        Association bassoc = associations.iterator().next();

        /* TEST 1: branch */
        SctpChannel bchannel = channel.branch(bassoc);

        check(!bchannel.getAllLocalAddresses().isEmpty(),
                               "branched channel should be bound");
        check(!bchannel.getRemoteAddresses().isEmpty(),
                               "branched channel should be connected");
        check(channel.associations().isEmpty(),
              "there should be no associations since the only one was branched off");

        buffer.clear();
        info = bchannel.receive(buffer, null, null);
        buffer.flip();
        check(info != null, "info is null");
        check(info.streamNumber() == streamNumber,
                "message not sent on the correct stream");
        check(info.bytes() == Util.SMALL_MESSAGE.getBytes("ISO-8859-1").
              length, "bytes received not equal to message length");
        check(info.bytes() == buffer.remaining(), "bytes != remaining");
        check(Util.compare(buffer, Util.SMALL_MESSAGE),
          "received message not the same as sent message");

    } catch (IOException ioe) {
        unexpected(ioe);
    } finally {
        clientFinishedLatch.countDown();
        try { serverFinishedLatch.await(10L, TimeUnit.SECONDS); }
        catch (InterruptedException ie) { unexpected(ie); }
        if (channel != null) {
            try { channel.close(); }
            catch (IOException e) { unexpected (e);}
        }
    }
}
 
Example 11
Source File: Branch.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
void doTest(SocketAddress peerAddress) {
    SctpMultiChannel channel = null;
    ByteBuffer buffer = ByteBuffer.allocate(Util.LARGE_BUFFER);
    MessageInfo info = MessageInfo.createOutgoing(null, 0);

    try {
        channel = SctpMultiChannel.open();

        /* setup an association implicitly by sending a small message */
        int streamNumber = 0;
        debug("sending to " + peerAddress + " on stream number: " + streamNumber);
        info = MessageInfo.createOutgoing(peerAddress, streamNumber);
        buffer.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1"));
        buffer.flip();
        int position = buffer.position();
        int remaining = buffer.remaining();

        debug("sending small message: " + buffer);
        int sent = channel.send(buffer, info);

        check(sent == remaining, "sent should be equal to remaining");
        check(buffer.position() == (position + sent),
                "buffers position should have been incremented by sent");

        /* Receive the COMM_UP */
        buffer.clear();
        BranchNotificationHandler handler = new BranchNotificationHandler();
        info = channel.receive(buffer, null, handler);
        check(handler.receivedCommUp(), "COMM_UP no received");
        Set<Association> associations = channel.associations();
        check(!associations.isEmpty(),"There should be some associations");
        Association bassoc = associations.iterator().next();

        /* TEST 1: branch */
        SctpChannel bchannel = channel.branch(bassoc);

        check(!bchannel.getAllLocalAddresses().isEmpty(),
                               "branched channel should be bound");
        check(!bchannel.getRemoteAddresses().isEmpty(),
                               "branched channel should be connected");
        check(channel.associations().isEmpty(),
              "there should be no associations since the only one was branched off");

        buffer.clear();
        info = bchannel.receive(buffer, null, null);
        buffer.flip();
        check(info != null, "info is null");
        check(info.streamNumber() == streamNumber,
                "message not sent on the correct stream");
        check(info.bytes() == Util.SMALL_MESSAGE.getBytes("ISO-8859-1").
              length, "bytes received not equal to message length");
        check(info.bytes() == buffer.remaining(), "bytes != remaining");
        check(Util.compare(buffer, Util.SMALL_MESSAGE),
          "received message not the same as sent message");

    } catch (IOException ioe) {
        unexpected(ioe);
    } finally {
        clientFinishedLatch.countDown();
        try { serverFinishedLatch.await(10L, TimeUnit.SECONDS); }
        catch (InterruptedException ie) { unexpected(ie); }
        if (channel != null) {
            try { channel.close(); }
            catch (IOException e) { unexpected (e);}
        }
    }
}
 
Example 12
Source File: Branch.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
void doTest(SocketAddress peerAddress) {
    SctpMultiChannel channel = null;
    ByteBuffer buffer = ByteBuffer.allocate(Util.LARGE_BUFFER);
    MessageInfo info = MessageInfo.createOutgoing(null, 0);

    try {
        channel = SctpMultiChannel.open();

        /* setup an association implicitly by sending a small message */
        int streamNumber = 0;
        debug("sending to " + peerAddress + " on stream number: " + streamNumber);
        info = MessageInfo.createOutgoing(peerAddress, streamNumber);
        buffer.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1"));
        buffer.flip();
        int position = buffer.position();
        int remaining = buffer.remaining();

        debug("sending small message: " + buffer);
        int sent = channel.send(buffer, info);

        check(sent == remaining, "sent should be equal to remaining");
        check(buffer.position() == (position + sent),
                "buffers position should have been incremented by sent");

        /* Receive the COMM_UP */
        buffer.clear();
        BranchNotificationHandler handler = new BranchNotificationHandler();
        info = channel.receive(buffer, null, handler);
        check(handler.receivedCommUp(), "COMM_UP no received");
        Set<Association> associations = channel.associations();
        check(!associations.isEmpty(),"There should be some associations");
        Association bassoc = associations.iterator().next();

        /* TEST 1: branch */
        SctpChannel bchannel = channel.branch(bassoc);

        check(!bchannel.getAllLocalAddresses().isEmpty(),
                               "branched channel should be bound");
        check(!bchannel.getRemoteAddresses().isEmpty(),
                               "branched channel should be connected");
        check(channel.associations().isEmpty(),
              "there should be no associations since the only one was branched off");

        buffer.clear();
        info = bchannel.receive(buffer, null, null);
        buffer.flip();
        check(info != null, "info is null");
        check(info.streamNumber() == streamNumber,
                "message not sent on the correct stream");
        check(info.bytes() == Util.SMALL_MESSAGE.getBytes("ISO-8859-1").
              length, "bytes received not equal to message length");
        check(info.bytes() == buffer.remaining(), "bytes != remaining");
        check(Util.compare(buffer, Util.SMALL_MESSAGE),
          "received message not the same as sent message");

    } catch (IOException ioe) {
        unexpected(ioe);
    } finally {
        clientFinishedLatch.countDown();
        try { serverFinishedLatch.await(10L, TimeUnit.SECONDS); }
        catch (InterruptedException ie) { unexpected(ie); }
        if (channel != null) {
            try { channel.close(); }
            catch (IOException e) { unexpected (e);}
        }
    }
}
 
Example 13
Source File: Branch.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
void doTest(SocketAddress peerAddress) {
    SctpMultiChannel channel = null;
    ByteBuffer buffer = ByteBuffer.allocate(Util.LARGE_BUFFER);
    MessageInfo info = MessageInfo.createOutgoing(null, 0);

    try {
        channel = SctpMultiChannel.open();

        /* setup an association implicitly by sending a small message */
        int streamNumber = 0;
        debug("sending to " + peerAddress + " on stream number: " + streamNumber);
        info = MessageInfo.createOutgoing(peerAddress, streamNumber);
        buffer.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1"));
        buffer.flip();
        int position = buffer.position();
        int remaining = buffer.remaining();

        debug("sending small message: " + buffer);
        int sent = channel.send(buffer, info);

        check(sent == remaining, "sent should be equal to remaining");
        check(buffer.position() == (position + sent),
                "buffers position should have been incremented by sent");

        /* Receive the COMM_UP */
        buffer.clear();
        BranchNotificationHandler handler = new BranchNotificationHandler();
        info = channel.receive(buffer, null, handler);
        check(handler.receivedCommUp(), "COMM_UP no received");
        Set<Association> associations = channel.associations();
        check(!associations.isEmpty(),"There should be some associations");
        Association bassoc = associations.iterator().next();

        /* TEST 1: branch */
        SctpChannel bchannel = channel.branch(bassoc);

        check(!bchannel.getAllLocalAddresses().isEmpty(),
                               "branched channel should be bound");
        check(!bchannel.getRemoteAddresses().isEmpty(),
                               "branched channel should be connected");
        check(channel.associations().isEmpty(),
              "there should be no associations since the only one was branched off");

        buffer.clear();
        info = bchannel.receive(buffer, null, null);
        buffer.flip();
        check(info != null, "info is null");
        check(info.streamNumber() == streamNumber,
                "message not sent on the correct stream");
        check(info.bytes() == Util.SMALL_MESSAGE.getBytes("ISO-8859-1").
              length, "bytes received not equal to message length");
        check(info.bytes() == buffer.remaining(), "bytes != remaining");
        check(Util.compare(buffer, Util.SMALL_MESSAGE),
          "received message not the same as sent message");

    } catch (IOException ioe) {
        unexpected(ioe);
    } finally {
        clientFinishedLatch.countDown();
        try { serverFinishedLatch.await(10L, TimeUnit.SECONDS); }
        catch (InterruptedException ie) { unexpected(ie); }
        if (channel != null) {
            try { channel.close(); }
            catch (IOException e) { unexpected (e);}
        }
    }
}