Package com.barchart.udt

Examples of com.barchart.udt.SocketUDT


  @Override
  public SocketChannel accept() throws IOException {
    try {
      begin();
      SocketUDT socketUDT = serverSocketUDT.accept();
      SelectorProvider provider = provider();
      return new ChannelSocketUDT(provider, socketUDT);
    } finally {
      end(true);
    }
View Full Code Here


    return new SelectorUDT(this, maxSelectorSize, maxConnectorSize);
  }

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

    return new ChannelServerSocketUDT(this, serverSocketUDT);
  }

  @Override
  public SocketChannel openSocketChannel() throws IOException {
    SocketUDT socketUDT = new SocketUDT(type);
    return new ChannelSocketUDT(this, socketUDT);
  }
View Full Code Here

    final int remaining = buffer.remaining();

    if (remaining > 0) {

      final SocketUDT socket = socketUDT;
      final boolean isBlocking = isBlockingMode;

      final int sizeReceived;
      try {
        if (isBlocking) {
          begin(); // JDK contract for NIO blocking calls
        }
        if (buffer.isDirect()) {
          sizeReceived = socket.receive(buffer);
        } else {
          assert buffer.hasArray();
          byte[] array = buffer.array();
          int position = buffer.position();
          int limit = buffer.limit();
          sizeReceived = socket.receive(array, position, limit);
          if (0 < sizeReceived && sizeReceived <= remaining) {
            buffer.position(position + sizeReceived);
          }
        }
      } finally {
        if (isBlocking) {
          end(true); // JDK contract for NIO blocking calls
        }
      }

      // see contract for receive()

      if (sizeReceived < 0) {
        log.trace("nothing was received; socketID={}",
            socket.getSocketId());
        return 0;
      }

      if (sizeReceived == 0) {
        log.trace("receive timeout; socketID={}", socket.getSocketId());
        return 0;
      }

      if (sizeReceived <= remaining) {
        return sizeReceived;
      } else { // should not happen
        log.error("unexpected: sizeReceived > remaining; socketID={}",
            socket.getSocketId());
        return 0;
      }

    } else {
      return 0;
View Full Code Here

    final int remaining = buffer.remaining();

    if (remaining > 0) {

      final SocketUDT socket = socketUDT;
      final boolean isBlocking = isBlockingMode;

      final int sizeSent;
      try {
        if (isBlocking) {
          begin(); // JDK contract for NIO blocking calls
        }
        if (buffer.isDirect()) {
          sizeSent = socket.send(buffer);
        } else {
          assert buffer.hasArray();
          byte[] array = buffer.array();
          int position = buffer.position();
          int limit = buffer.limit();
          sizeSent = socket.send(array, position, limit);
          if (0 < sizeSent && sizeSent <= remaining) {
            buffer.position(position + sizeSent);
          }
        }
      } finally {
        if (isBlocking) {
          end(true); // JDK contract for NIO blocking calls
        }
      }

      // see contract for send()

      if (sizeSent < 0) {
        log.trace("no buffer space for send; socketID={}",
            socket.getSocketId());
        // logStatus();
        // log.info("writeCount={} writeSize={}", writeCount,
        // writeSize);
        // System.exit(1);
        return 0;
      }

      if (sizeSent == 0) {
        log.trace("send timeout; socketID={}", socket.getSocketId());
        return 0;
      }

      if (sizeSent <= remaining) {
        // writeSize.addAndGet(sizeSent);
        return sizeSent;
      } else { // should not happen
        log.error("unexpected: sizeSent > remaining; socketID={}",
            socket.getSocketId());
        return 0;
      }

    } else {
      return 0;
View Full Code Here

        throw new IllegalSelectorException();
      }

      ChannelUDT channelUDT = (ChannelUDT) channel;

      SocketUDT socketUDT = channelUDT.getSocketUDT();

      SelectionKeyUDT keyUDT = new SelectionKeyUDT(//
          this, channelUDT, attachment, interestOps);

      // XXX the only place with "add/put"
      registeredKeyMap.put(socketUDT.getSocketId(), keyUDT);
      registeredKeySet.add(keyUDT);

      return keyUDT;

    }
View Full Code Here

        throw new IllegalSelectorException();
      }

      ChannelUDT channelUDT = (ChannelUDT) channel;

      SocketUDT socketUDT = channelUDT.getSocketUDT();

      SelectionKeyUDT keyUDT = new SelectionKeyUDT(//
          this, channelUDT, attachment, interestOps);

      // XXX the only place with "add/put"
      registeredKeyMap.put(socketUDT.getSocketId(), keyUDT);
      registeredKeySet.add(keyUDT);

      return keyUDT;

    }
View Full Code Here

    final int remaining = buffer.remaining();

    if (remaining > 0) {

      final SocketUDT socket = socketUDT;
      final boolean isBlocking = isBlockingMode;

      final int sizeReceived;
      try {
        if (isBlocking) {
          begin(); // JDK contract for NIO blocking calls
        }
        if (buffer.isDirect()) {
          sizeReceived = socket.receive(buffer);
        } else {
          assert buffer.hasArray();
          byte[] array = buffer.array();
          int position = buffer.position();
          int limit = buffer.limit();
          sizeReceived = socket.receive(array, position, limit);
          if (0 < sizeReceived && sizeReceived <= remaining) {
            buffer.position(position + sizeReceived);
          }
        }
      } finally {
        if (isBlocking) {
          end(true); // JDK contract for NIO blocking calls
        }
      }

      // see contract for receive()

      if (sizeReceived < 0) {
        log.trace("nothing was received; socketID={}",
            socket.getSocketId());
        return 0;
      }

      if (sizeReceived == 0) {
        log.trace("receive timeout; socketID={}", socket.getSocketId());
        return 0;
      }

      if (sizeReceived <= remaining) {
        return sizeReceived;
      } else { // should not happen
        log.error("unexpected: sizeReceived > remaining; socketID={}",
            socket.getSocketId());
        return 0;
      }

    } else {
      return 0;
View Full Code Here

    final int remaining = buffer.remaining();

    if (remaining > 0) {

      final SocketUDT socket = socketUDT;
      final boolean isBlocking = isBlockingMode;

      final int sizeSent;
      try {
        if (isBlocking) {
          begin(); // JDK contract for NIO blocking calls
        }
        if (buffer.isDirect()) {
          sizeSent = socket.send(buffer);
        } else {
          assert buffer.hasArray();
          byte[] array = buffer.array();
          int position = buffer.position();
          int limit = buffer.limit();
          sizeSent = socket.send(array, position, limit);
          if (0 < sizeSent && sizeSent <= remaining) {
            buffer.position(position + sizeSent);
          }
        }
      } finally {
        if (isBlocking) {
          end(true); // JDK contract for NIO blocking calls
        }
      }

      // see contract for send()

      if (sizeSent < 0) {
        log.trace("no buffer space for send; socketID={}",
            socket.getSocketId());
        // logStatus();
        // log.info("writeCount={} writeSize={}", writeCount,
        // writeSize);
        // System.exit(1);
        return 0;
      }

      if (sizeSent == 0) {
        log.trace("send timeout; socketID={}", socket.getSocketId());
        return 0;
      }

      if (sizeSent <= remaining) {
        // writeSize.addAndGet(sizeSent);
        return sizeSent;
      } else { // should not happen
        log.error("unexpected: sizeSent > remaining; socketID={}",
            socket.getSocketId());
        return 0;
      }

    } else {
      return 0;
View Full Code Here

  @Override
  public SocketChannel accept() throws IOException {
    try {
      begin();
      SocketUDT socketUDT = serverSocketUDT.accept();
      SelectorProvider provider = provider();
      return new ChannelSocketUDT(provider, socketUDT);
    } finally {
      end(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.