當前位置: 首頁>>代碼示例>>Java>>正文


Java TTransportException.NOT_OPEN屬性代碼示例

本文整理匯總了Java中org.apache.thrift.transport.TTransportException.NOT_OPEN屬性的典型用法代碼示例。如果您正苦於以下問題:Java TTransportException.NOT_OPEN屬性的具體用法?Java TTransportException.NOT_OPEN怎麽用?Java TTransportException.NOT_OPEN使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.apache.thrift.transport.TTransportException的用法示例。


在下文中一共展示了TTransportException.NOT_OPEN屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: write

@Override
public void write(byte[] bytes, int offset, int length) throws TTransportException {
    if (!isOpen()) {
        throw new TTransportException(TTransportException.NOT_OPEN);
    }

    synchronized (sendLock) {
        if (writeBuffer.position() + length > MAX_BUFFER_SIZE) {
            throw new TTransportException(
                String.format("Message size too large: %d is greater than available size %d",
                    length,
                    MAX_BUFFER_SIZE - writeBuffer.position()
                )
            );
        }

        writeBuffer.put(bytes, offset, length);
    }
}
 
開發者ID:uber-java,項目名稱:tally,代碼行數:19,代碼來源:TUdpTransport.java

示例2: GfxdTSSLSocket

/**
 * Constructor that takes an already created socket.
 * 
 * @param socket
 *          Already created socket object
 * 
 * @throws TTransportException
 *           if there is an error setting up the streams
 */
public GfxdTSSLSocket(Socket socket, int timeout, SocketParameters params,
    SystemProperties props) throws TTransportException {
  super(socket);

  if (isOpen()) {
    try {
      setProperties(socket, timeout, params, props);
      this.inputStream_ = new BufferedInputStream(socket.getInputStream(),
          this.inputBufferSize);
      this.outputStream_ = new BufferedOutputStream(socket.getOutputStream(),
          this.outputBufferSize);
    } catch (IOException ioe) {
      close();
      throw new TTransportException(TTransportException.NOT_OPEN, ioe);
    }
  }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:26,代碼來源:GfxdTSSLSocket.java

示例3: setProperties

/**
 * Sets the socket properties like timeout, keepalive, buffer sizes.
 * 
 * @param timeout
 *          Milliseconds timeout
 * @param params
 *          Socket parameters including buffer sizes and keep-alive settings
 * @param props
 *          the system properties instance to use and initialize global socket
 *          options like keepalive and buffer sizes that are not set in params
 */
protected void setProperties(Socket socket, int timeout,
    SocketParameters params, SystemProperties props)
    throws TTransportException {
  this.inputBufferSize = params.getInputBufferSize(props
      .getSocketInputBufferSize());
  this.outputBufferSize = params.getOutputBufferSize(props
      .getSocketOutputBufferSize());
  try {
    socket.setSoLinger(false, 0);
    socket.setTcpNoDelay(true);
    this.timeout = GfxdTSocket.setTimeout(socket, timeout, params, props);
  } catch (SocketException se) {
    LOGGER.warn("Could not set socket timeout.", se);
    throw new TTransportException(TTransportException.NOT_OPEN,
        "Could not set socket timeout.", se);
  }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:28,代碼來源:GfxdTSSLSocket.java

示例4: GfxdTSocket

/**
 * Constructor that takes an already created socket.
 * 
 * @param socket
 *          Already created socket object
 * @param params
 *          Socket parameters including buffer sizes and keep-alive settings
 * @param props
 *          the system properties instance to use and initialize global socket
 *          options like keepalive and buffer sizes that are not set in params
 * 
 * @throws TTransportException
 *           if there is an error setting up the streams
 */
public GfxdTSocket(SocketChannel socketChannel, boolean blocking,
    int timeout, SocketParameters params, SystemProperties props)
    throws TTransportException {
  this.socketChannel = socketChannel;
  if (!socketChannel.isConnected())
    throw new TTransportException(TTransportException.NOT_OPEN,
        "Socket must already be connected");

  try {
    socketChannel.configureBlocking(blocking);
    setProperties(socketChannel.socket(), timeout, params, props);

    this.inputStream = UnsafeHolder.newChannelBufferFramedInputStream(
        socketChannel, this.inputBufferSize);
    this.outputStream = UnsafeHolder.newChannelBufferOutputStream(
        socketChannel, this.outputBufferSize);
    this.framedWrites = false;
  } catch (IOException ioe) {
    close();
    throw new TTransportException(TTransportException.NOT_OPEN, ioe);
  }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:36,代碼來源:GfxdTSocket.java

示例5: initSocket

/**
 * Initializes the socket object
 */
private static SocketChannel initSocket(boolean blocking)
    throws TTransportException {
  try {
    SocketChannel socketChannel = SocketChannel.open();
    socketChannel.configureBlocking(blocking);
    return socketChannel;
  } catch (SocketException se) {
    LOGGER.error("Could not configure socket.", se);
    throw new TTransportException(TTransportException.NOT_OPEN,
        "Could not configure socket.", se);
  } catch (IOException ioe) {
    throw new TTransportException(TTransportException.NOT_OPEN,
        "Could not open socket channel.", ioe);
  }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:18,代碼來源:GfxdTSocket.java

示例6: setProperties

/**
 * Sets the socket properties like timeout, keepalive, buffer sizes.
 * 
 * @param timeout
 *          Milliseconds timeout
 * @param params
 *          Socket parameters including buffer sizes and keep-alive settings
 * @param props
 *          the system properties instance to use and initialize global socket
 *          options like keepalive and buffer sizes that are not set in params
 */
protected void setProperties(Socket socket, int timeout,
    SocketParameters params, SystemProperties props)
    throws TTransportException {
  this.inputBufferSize = params.getInputBufferSize(props
      .getSocketInputBufferSize());
  this.outputBufferSize = params.getOutputBufferSize(props
      .getSocketOutputBufferSize());
  try {
    socket.setSoLinger(false, 0);
    socket.setTcpNoDelay(true);
    this.timeout = setTimeout(socket, timeout, params, props);
  } catch (SocketException se) {
    LOGGER.warn("Could not set socket timeout.", se);
    throw new TTransportException(TTransportException.NOT_OPEN,
        "Could not set socket timeout.", se);
  }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:28,代碼來源:GfxdTSocket.java

示例7: read

/**
 * {@inheritDoc}
 */
@Override
public final int read(byte[] buf, int off, int len)
    throws TTransportException {
  int bytesRead;
  try {
    bytesRead = this.inputStream.read(buf, off, len);
  } catch (ClosedChannelException cce) {
    throw new TTransportException(TTransportException.NOT_OPEN,
        "Cannot read from closed channel.");
  } catch (IOException ioe) {
    throw new TTransportException(TTransportException.UNKNOWN, ioe);
  }
  if (bytesRead >= 0) {
    return bytesRead;
  }
  else {
    throw new TTransportException(TTransportException.END_OF_FILE,
        "Channel closed.");
  }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:23,代碼來源:GfxdTSocket.java

示例8: createClient

private static SSLSocket createClient(SSLSocketFactory factory,
    InetAddress hostAddress, int port, int timeout,
    final SocketParameters params) throws TTransportException {
  try {
    SSLSocket socket = (SSLSocket)factory.createSocket(hostAddress, port);
    socket.setSoTimeout(timeout);
    if (params != null) {
      if (params.getSSLEnabledProtocols() != null) {
        socket.setEnabledProtocols(params.getSSLEnabledProtocols());
      }
      if (params.getSSLCipherSuites() != null) {
        socket.setEnabledCipherSuites(params.getSSLCipherSuites());
      }
    }
    return socket;
  } catch (IOException ioe) {
    throw new TTransportException(TTransportException.NOT_OPEN, ioe);
  } catch (Exception e) {
    throw new TTransportException(TTransportException.NOT_OPEN,
        "Could not connect to " + hostAddress + " on port " + port, e);
  }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:22,代碼來源:GfxdTSSLSocketFactory.java

示例9: GfxdTSSLServerSocket

/**
 * Creates a server socket from underlying socket object
 */
public GfxdTSSLServerSocket(ServerSocket serverSocket,
    InetSocketAddress bindAddress, SocketParameters params)
    throws TTransportException {
  this.socketParams = params;
  try {
    this.serverSocket = serverSocket;
    // Prevent 2MSL delay problem on server restarts
    serverSocket.setReuseAddress(true);
    // Bind to listening port
    if (!serverSocket.isBound()) {
      // backlog hardcoded to 100 as in TSSLTransportFactory
      serverSocket.bind(bindAddress, 100);
    }
  } catch (IOException ioe) {
    throw new TTransportException(TTransportException.NOT_OPEN,
        "Could not bind to host:port " + bindAddress.toString(), ioe);
  }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:21,代碼來源:GfxdTSSLServerSocket.java

示例10: createServer

private static GfxdTSSLServerSocket createServer(
    SSLServerSocketFactory factory, InetSocketAddress bindAddress,
    SocketParameters params) throws TTransportException {
  try {
    SSLServerSocket serverSocket = (SSLServerSocket)factory
        .createServerSocket(bindAddress.getPort(), 100,
            bindAddress.getAddress());
    if (params != null) {
      if (params.getSSLEnabledProtocols() != null) {
        serverSocket.setEnabledProtocols(params.getSSLEnabledProtocols());
      }
      if (params.getSSLCipherSuites() != null) {
        serverSocket.setEnabledCipherSuites(params.getSSLCipherSuites());
      }
      serverSocket.setNeedClientAuth(params.getSSLClientAuth());
    }
    return new GfxdTSSLServerSocket(serverSocket, bindAddress, params);
  } catch (Exception e) {
    throw new TTransportException(TTransportException.NOT_OPEN,
        "Could not bind to host:port " + bindAddress.toString(), e);
  }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:22,代碼來源:GfxdTSSLServerSocketFactory.java

示例11: GfxdTServerSocket

/**
 * Creates a port listening server socket
 */
public GfxdTServerSocket(InetSocketAddress bindAddress, boolean blocking,
    boolean clientBlocking, SocketParameters params)
    throws TTransportException {
  this.clientBlocking = clientBlocking;
  this.socketParams = params;
  try {
    // Make server socket
    this.serverSockChannel = ServerSocketChannel.open();
    this.serverSockChannel.configureBlocking(blocking);
    ServerSocket socket = this.serverSockChannel.socket();
    // Prevent 2MSL delay problem on server restarts
    socket.setReuseAddress(true);
    // Bind to listening port
    socket.bind(bindAddress);
  } catch (IOException ioe) {
    throw new TTransportException(TTransportException.NOT_OPEN,
        "Could not bind to host:port " + bindAddress.toString(), ioe);
  }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:22,代碼來源:GfxdTServerSocket.java

示例12: read

@Override
public int read(byte[] bytes, int offset, int length) throws TTransportException {
    if (!isOpen()) {
        throw new TTransportException(TTransportException.NOT_OPEN);
    }

    synchronized (receiveLock) {
        if (!receiveBuffer.hasRemaining()) {
            // Use ByteBuffer's backing array and manually set the position and limit to
            // avoid having to re-copy contents to a new array via `get`
            DatagramPacket packet = new DatagramPacket(receiveBuffer.array(), MAX_BUFFER_SIZE);

            try {
                socket.receive(packet);
            } catch (IOException e) {
                throw new TTransportException("Error from underlying socket", e);
            }

            receiveBuffer.position(0);
            receiveBuffer.limit(packet.getLength());
        }

        length = Math.min(length, receiveBuffer.remaining());

        receiveBuffer.get(bytes, offset, length);

        return length;
    }
}
 
開發者ID:uber-java,項目名稱:tally,代碼行數:29,代碼來源:TUdpTransport.java

示例13: open

/**
 * Connects the socket, creating a new socket object if necessary.
 */
@Override
public void open() throws TTransportException {
  if (isOpen()) {
    throw new TTransportException(TTransportException.ALREADY_OPEN,
        "Socket already connected.");
  }

  if (this.hostAddress == null) {
    throw new TTransportException(TTransportException.NOT_OPEN,
        "Cannot open null host.");
  }
  if (this.port <= 0) {
    throw new TTransportException(TTransportException.NOT_OPEN,
        "Cannot open without port.");
  }

  final Socket socket = getSocket();
  try {
    socket.connect(new InetSocketAddress(this.hostAddress, this.port),
        this.timeout);
    this.inputStream_ = new BufferedInputStream(socket.getInputStream(),
        this.inputBufferSize);
    this.outputStream_ = new BufferedOutputStream(socket.getOutputStream(),
        this.outputBufferSize);
  } catch (IOException ioe) {
    close();
    throw new TTransportException(TTransportException.NOT_OPEN, ioe);
  }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:32,代碼來源:GfxdTSSLSocket.java

示例14: open

/**
 * Connects the socket, creating a new socket object if necessary.
 */
@Override
public void open() throws TTransportException {
  if (isOpen()) {
    throw new TTransportException(TTransportException.ALREADY_OPEN,
        "Socket already connected.");
  }

  if (this.socketAddress == null) {
    throw new TTransportException(TTransportException.NOT_OPEN,
        "Cannot open null host.");
  }
  if (this.socketAddress.getPort() <= 0) {
    throw new TTransportException(TTransportException.NOT_OPEN,
        "Cannot open without port.");
  }

  final Socket socket = getSocket();
  try {
    socket.connect(this.socketAddress, this.timeout);
    this.inputStream = UnsafeHolder.newChannelBufferFramedInputStream(
        this.socketChannel, this.inputBufferSize);
    this.outputStream = this.framedWrites
        ? UnsafeHolder.newChannelBufferFramedOutputStream(this.socketChannel,
            this.outputBufferSize)
        : UnsafeHolder.newChannelBufferOutputStream(this.socketChannel,
            this.outputBufferSize);
  } catch (IOException ioe) {
    close();
    throw new TTransportException(TTransportException.NOT_OPEN, ioe);
  }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:34,代碼來源:GfxdTSocket.java

示例15: write

/**
 * {@inheritDoc}
 */
@Override
public final void write(byte[] buf, int off, int len)
    throws TTransportException {
  try {
    this.outputStream.write(buf, off, len);
  } catch (ClosedChannelException cce) {
    throw new TTransportException(TTransportException.NOT_OPEN,
        "Cannot write to closed channel.");
  } catch (IOException ioe) {
    throw new TTransportException(TTransportException.UNKNOWN, ioe);
  }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:15,代碼來源:GfxdTSocket.java


注:本文中的org.apache.thrift.transport.TTransportException.NOT_OPEN屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。