当前位置: 首页>>代码示例>>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;未经允许,请勿转载。