Package com.barchart.udt

Examples of com.barchart.udt.SocketUDT


            apply(channelUDT);
        }
    }

    protected void apply(final ChannelUDT channelUDT) throws IOException {
        final SocketUDT socketUDT = channelUDT.socketUDT();
        socketUDT.setReuseAddress(isReuseAddress());
        socketUDT.setSendBufferSize(getSendBufferSize());
        if (getSoLinger() <= 0) {
            socketUDT.setSoLinger(false, 0);
        } else {
            socketUDT.setSoLinger(true, getSoLinger());
        }
        socketUDT.setOption(OptionUDT.Protocol_Receive_Buffer_Size,
                getProtocolReceiveBufferSize());
        socketUDT.setOption(OptionUDT.Protocol_Send_Buffer_Size,
                getProtocolSendBufferSize());
        socketUDT.setOption(OptionUDT.System_Receive_Buffer_Size,
                getSystemReceiveBufferSize());
        socketUDT.setOption(OptionUDT.System_Send_Buffer_Size,
                getSystemSendBufferSize());
    }
View Full Code Here


    long count = 0;

    while (true) {

      final SocketUDT socket = new SocketUDT(TypeUDT.STREAM);

      queue.put(socket);

      // socket.close();
      // socket = null;
View Full Code Here

    long count = 0;

    while (true) {

      final SocketUDT socket = new SocketUDT(TypeUDT.STREAM);
      socket.bind(UnitHelp.localSocketAddress());
      UnitHelp.socketAwait(socket, StatusUDT.OPENED);

      Thread.sleep(20);

      queue.put(socket);
View Full Code Here

  public static void main(final String[] args) throws Exception {

    log.info("init");

    final SocketUDT socket = new SocketUDT(TypeUDT.DATAGRAM);
    final int socketID = socket.id();
    final int epollID = BenchPollOne.epollCreate0();

    BenchPollOne.epollAdd0(epollID, socketID, EpollUDT.Opt.BOTH.code);

    final AtomicBoolean isOn = new AtomicBoolean(true);
View Full Code Here

  public static void main(final String[] args) throws Exception {

    log.info("init");

    final SocketUDT socket = new SocketUDT(TypeUDT.DATAGRAM);
    final int socketID = socket.id();
    final int epollID = BenchPollTwo.epollCreate0();

    BenchPollTwo.epollAdd0(epollID, socketID, EpollUDT.Opt.BOTH.code);

    final AtomicBoolean isOn = new AtomicBoolean(true);
View Full Code Here

  public static void main(final String[] args) throws Exception {

    log.info("init");

    final SocketUDT accept = new SocketUDT(TypeUDT.DATAGRAM);
    accept.setBlocking(true);
    accept.bind(localSocketAddress());
    accept.listen(1);
    socketAwait(accept, StatusUDT.LISTENING);
    log.info("accept : {}", accept);

    final SocketUDT client = new SocketUDT(TypeUDT.DATAGRAM);
    client.setBlocking(true);
    client.bind(localSocketAddress());
    socketAwait(client, StatusUDT.OPENED);
    client.connect(accept.getLocalSocketAddress());
    socketAwait(client, StatusUDT.CONNECTED);
    log.info("client : {}", client);

    final SocketUDT server = accept.accept();
    server.setBlocking(true);
    socketAwait(server, StatusUDT.CONNECTED);
    log.info("server : {}", server);

    final AtomicBoolean isOn = new AtomicBoolean(true);

    final Runnable clientTask = new Runnable() {

      @Override
      public void run() {
        try {

          while (isOn.get()) {
            runCore();
          }

        } catch (final Exception e) {
          log.error("", e);
        }
      }

      final ByteBuffer buffer = ByteBuffer.allocateDirect(size);

      long sequence;

      void runCore() throws Exception {

        buffer.rewind();
        buffer.putLong(0, sequence++);

        final TimerContext timer = sendTime.time();

        final int count = client.send(buffer);

        timer.stop();

        if (count != size) {
          throw new Exception("count");
        }

        sendRate.mark(count);

      }

    };

    final Runnable serverTask = new Runnable() {

      @Override
      public void run() {
        try {
          while (isOn.get()) {
            runCore();
          }
        } catch (final Exception e) {
          log.error("", e);
        }
      }

      final ByteBuffer buffer = ByteBuffer.allocateDirect(size);

      long sequence;

      void runCore() throws Exception {

        buffer.rewind();

        final TimerContext timer = recvTime.time();

        final int count = server.receive(buffer);

        timer.stop();

        if (count != size) {
          throw new Exception("count");
        }

        if (this.sequence++ != buffer.getLong(0)) {
          throw new Exception("sequence");
        }

        recvRate.mark(count);

      }

    };

    final ExecutorService executor = Executors.newFixedThreadPool(2);

    executor.submit(clientTask);

    executor.submit(serverTask);

    ConsoleReporterUDT.enable(3, TimeUnit.SECONDS);

    Thread.sleep(time);

    isOn.set(false);

    Thread.sleep(1 * 1000);

    executor.shutdownNow();

    Metrics.defaultRegistry().shutdown();

    accept.close();
    client.close();
    server.close();

    log.info("done");

  }
 
View Full Code Here

    final int countMonitor = Integer
        .parseInt(property("udt.count.monitor"));

    try {

      final SocketUDT sender = new SocketUDT(TypeUDT.DATAGRAM);

      // specify maximum upload speed, bytes/sec
      sender.setOption(OptionUDT.UDT_MAXBW, maxBandwidth);

      InetSocketAddress localSocketAddress = new InetSocketAddress( //
          bindAddress, 0);

      log.info("localSocketAddress : {}", localSocketAddress);

      sender.bind(localSocketAddress);
      localSocketAddress = sender.getLocalSocketAddress();
      log.info("bind; localSocketAddress={}", localSocketAddress);

      InetSocketAddress remoteSocketAddress = new InetSocketAddress(//
          remoteAddress, remotePort);

      sender.connect(remoteSocketAddress);
      remoteSocketAddress = sender.getRemoteSocketAddress();
      log.info("connect; remoteSocketAddress={}", remoteSocketAddress);

      StringBuilder text = new StringBuilder(1024);
      OptionUDT.appendSnapshot(sender, text);
      text.append("\t\n");
      log.info("sender options; {}", text);

      long count = 0;

      final MonitorUDT monitor = sender.monitor();

      while (true) {

        for (int k = 0; k < countBatch; k++) {

          final byte[] array = new byte[SIZE];

          putSequenceNumber(array);

          final int result = sender.send(array);

          assert result == SIZE : "wrong size";

        }

        // sleep between batches
        Thread.sleep(countSleep);

        count++;

        if (count % countMonitor == 0) {
          sender.updateMonitor(false);
          text = new StringBuilder(1024);
          monitor.appendSnapshot(text);
          log.info("stats; {}", text);
        }
View Full Code Here

    final int countMonitor = Integer
        .parseInt(property("udt.count.monitor"));

    try {

      final SocketUDT acceptor = new SocketUDT(TypeUDT.DATAGRAM);
      log.info("init; acceptor={}", acceptor.id());

      InetSocketAddress localSocketAddress = new InetSocketAddress(
          bindAddress, localPort);

      acceptor.bind(localSocketAddress);
      localSocketAddress = acceptor.getLocalSocketAddress();
      log.info("bind; localSocketAddress={}", localSocketAddress);

      acceptor.listen(10);
      log.info("listen;");

      final SocketUDT receiver = acceptor.accept();

      log.info("accept; receiver={}", receiver.id());

      assert receiver.id() != acceptor.id();

      final long timeStart = System.currentTimeMillis();

      //

      final InetSocketAddress remoteSocketAddress = receiver
          .getRemoteSocketAddress();

      log.info("receiver; remoteSocketAddress={}", remoteSocketAddress);

      StringBuilder text = new StringBuilder(1024);
      OptionUDT.appendSnapshot(receiver, text);
      text.append("\t\n");
      log.info("receiver options; {}", text);

      final MonitorUDT monitor = receiver.monitor();

      while (true) {

        final byte[] array = new byte[SIZE];

        final int result = receiver.receive(array);

        assert result == SIZE : "wrong size";

        getSequenceNumber(array);

        if (sequenceNumber % countMonitor == 0) {

          receiver.updateMonitor(false);
          text = new StringBuilder(1024);
          monitor.appendSnapshot(text);
          log.info("stats; {}", text);

          final long timeFinish = System.currentTimeMillis();
View Full Code Here

            apply(channelUDT);
        }
    }

    protected void apply(final ChannelUDT channelUDT) throws IOException {
        final SocketUDT socketUDT = channelUDT.socketUDT();
        socketUDT.setReuseAddress(isReuseAddress());
        socketUDT.setSendBufferSize(getSendBufferSize());
        if (getSoLinger() <= 0) {
            socketUDT.setSoLinger(false, 0);
        } else {
            socketUDT.setSoLinger(true, getSoLinger());
        }
        socketUDT.setOption(OptionUDT.Protocol_Receive_Buffer_Size,
                getProtocolReceiveBufferSize());
        socketUDT.setOption(OptionUDT.Protocol_Send_Buffer_Size,
                getProtocolSendBufferSize());
        socketUDT.setOption(OptionUDT.System_Receive_Buffer_Size,
                getSystemReceiveBufferSize());
        socketUDT.setOption(OptionUDT.System_Send_Buffer_Size,
                getSystemSendBufferSize());
    }
View Full Code Here

    return new SelectorUDT(this, maxSelectorSize);
  }

  @Override
  public ChannelServerSocketUDT openServerSocketChannel() throws IOException {
    final SocketUDT serverSocketUDT = new SocketUDT(type);
    return new ChannelServerSocketUDT(this, serverSocketUDT);
  }
View Full Code Here

TOP

Related Classes of com.barchart.udt.SocketUDT

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.