Package com.barchart.udt

Examples of com.barchart.udt.SocketUDT


  }

  StreamServer(final TypeUDT type, final InetSocketAddress serverAddress,
      final ServiceFactory factory) throws Exception {

    super(new SocketUDT(type), UnitHelp.localSocketAddress(), serverAddress);

    this.factory = factory;

    this.executor = Executors.newCachedThreadPool();
View Full Code Here


  final ExecutorService executor;

  StreamClient(final TypeUDT type, final InetSocketAddress remoteAddress)
      throws Exception {

    super(new SocketUDT(type), UnitHelp.localSocketAddress(), remoteAddress);

    this.executor = Executors.newCachedThreadPool();

  }
View Full Code Here

    startThreadedServer(serverAddress, readStrategy);

    //

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

    final InetSocketAddress clientAddress = UnitHelp.localSocketAddress();

    clientSocket.bind(clientAddress);
    assertTrue("Socket not bound!!", clientSocket.isBound());

    clientSocket.connect(serverAddress);
    assertTrue("Socket not connected!", clientSocket.isConnected());

    final InputStream socketIn = new NetInputStreamUDT(clientSocket);
    final OutputStream socketOut = new NetOutputStreamUDT(clientSocket);

    // Thread.sleep(1000);
View Full Code Here

      final ReadStrategy readStrategy, final AtomicBoolean readyToAccept)
      throws Exception {

    log.info("STARTED");

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

    acceptorSocket.bind(serverAddress);
    assertTrue("Acceptor should be bound", acceptorSocket.isBound());

    acceptorSocket.listen(1);
    assertEquals("Acceptor should be listenin", acceptorSocket.status(),
        StatusUDT.LISTENING);

    readyToAccept.set(true);
    synchronized (readyToAccept) {
      readyToAccept.notifyAll();
    }
    final SocketUDT connectorSocket = acceptorSocket.accept();
    assertTrue(connectorSocket.isBound());
    assertTrue(connectorSocket.isConnected());

    echo(connectorSocket, readStrategy);

  }
View Full Code Here

  @Test
  public void blocking() throws Exception {

    final SelectorProviderUDT provider = SelectorProviderUDT.DATAGRAM;
    final SocketUDT socket = new SocketUDT(TypeUDT.DATAGRAM);
    final SocketChannelUDT channel = new SocketChannelUDT(provider, socket);

    assertTrue(socket.isOpen());
    assertTrue(channel.isOpen());

    assertTrue(socket.isBlocking());
    assertTrue(channel.isBlocking());

    channel.configureBlocking(false);

    assertFalse(socket.isBlocking());
    assertFalse(channel.isBlocking());

    channel.close();

    assertFalse(socket.isOpen());
    assertFalse(channel.isOpen());

  }
View Full Code Here

    // so we need to take that into account if you want
    // to limit wire speed
    final double maxBW = 50 * 0.93;
    log.info("Attempting to rate limit using custom CCC UDPBlast class");

    final SocketUDT serverSocket = new SocketUDT(TypeUDT.STREAM);
    final InetSocketAddress serverAddress = localSocketAddress();
    serverSocket.bind(serverAddress);
    serverSocket.listen(1);
    assertTrue(serverSocket.isBound());

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

    clientSocket.setOption(OptionUDT.UDT_CC, new FactoryUDT<UDPBlast>(
        UDPBlast.class));

    final InetSocketAddress clientAddress = localSocketAddress();

    clientSocket.bind(clientAddress);
    clientSocket.setSoLinger(false, 0);
    assertTrue(clientSocket.isBound());

    clientSocket.connect(serverAddress);
    assertTrue(clientSocket.isConnected());

    final SocketUDT acceptSocket = serverSocket.accept();
    assertTrue(acceptSocket.isConnected());

    final Object obj = clientSocket.getOption(OptionUDT.UDT_CC);

    assertTrue("UDT_CC Object is of unexpected type",
        obj instanceof UDPBlast);

    final UDPBlast objCCC = (UDPBlast) obj;
    objCCC.setRate((int) maxBW);

    final byte[] data = new byte[65536];
    final long start = System.currentTimeMillis();
    long interval = System.currentTimeMillis();
    double maxMbs = -1;

    while ((System.currentTimeMillis() - start) < 15000) {

      clientSocket.send(data);
      acceptSocket.receive(data);

      if (System.currentTimeMillis() - interval > 1000) {

        interval = System.currentTimeMillis();

        clientSocket.updateMonitor(true);

        final MonitorUDT mon = clientSocket.monitor();

        log.info(String.format("Current Rate: %.2f Mbs",
            mon.mbpsSendRate()));

        maxMbs = mon.mbpsSendRate() * 0.93;

      }

    }

    // check we are within 10% of our desired rate
    assertTrue("Max bandwidth exceeded limit",
        maxMbs < (maxBW + (maxBW * 0.1)));

    clientSocket.close();
    acceptSocket.close();
    serverSocket.close();

  }
 
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

  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

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.