Java Code Examples for org.apache.thrift.transport.TTransportException#ALREADY_OPEN

The following examples show how to use org.apache.thrift.transport.TTransportException#ALREADY_OPEN . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TCustomSocket.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
/**
 * Connects the socket, creating a new socket object if necessary.
 */
public void open() throws TTransportException {
  if (isOpen()) {
    throw new TTransportException(TTransportException.ALREADY_OPEN, "Socket already connected.");
  }

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

  if (socket == null) {
    initSocket();
  }

  try {
    socket.connect(new InetSocketAddress(host, port), timeout);
    inputStream_ = new BufferedInputStream(socket.getInputStream(), 1024);
    outputStream_ = new BufferedOutputStream(socket.getOutputStream(), 1024);
  } catch (IOException iox) {
    close();
    throw new TTransportException(TTransportException.NOT_OPEN, iox);
  }
}
 
Example 2
Source File: GfxdTSSLSocket.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
  }
}
 
Example 3
Source File: GfxdTSocket.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
  }
}
 
Example 4
Source File: GfxdTSSLSocket.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
  }
}
 
Example 5
Source File: GfxdTSocket.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
  }
}
 
Example 6
Source File: ThriftExceptionUtil.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public static String getExceptionString(Throwable t) {
  String typeMessage = null;
  if (t instanceof TTransportException) {
    TTransportException tte = (TTransportException)t;
    switch (tte.getType()) {
      case TTransportException.ALREADY_OPEN:
        typeMessage = "SOCKET ALREADY OPEN";
        break;
      case TTransportException.END_OF_FILE:
        typeMessage = "SOCKET END OF TRANSMISSION";
        break;
      case TTransportException.NOT_OPEN:
        typeMessage = "SOCKET NOT OPEN";
        break;
      case TTransportException.TIMED_OUT:
        typeMessage = "SOCKET TIMED OUT";
        break;
      default:
        typeMessage = "UNKNOWN SOCKET ERROR";
        break;
    }
  }
  else if (t instanceof TProtocolException) {
    TProtocolException tpe = (TProtocolException)t;
    switch (tpe.getType()) {
      case TProtocolException.BAD_VERSION:
        typeMessage = "BAD PROTOCOL VERSION";
        break;
      case TProtocolException.INVALID_DATA:
        typeMessage = "INVALID DATA IN PROTOCOL";
        break;
      case TProtocolException.NEGATIVE_SIZE:
        typeMessage = "NEGATIVE SIZE IN PROTOCOL";
        break;
      case TProtocolException.NOT_IMPLEMENTED:
        typeMessage = "NOT IMPLEMENTED";
        break;
      case TProtocolException.SIZE_LIMIT:
        typeMessage = "PROTOCOL SIZE LIMIT HIT";
        break;
      default:
        typeMessage = "UNKNOWN PROTOCOL ERROR";
        break;
    }
  }
  else if (t instanceof TApplicationException) {
    TApplicationException tae = (TApplicationException)t;
    switch (tae.getType()) {
      case TApplicationException.BAD_SEQUENCE_ID:
        typeMessage = "BAD SEQUENCE ID";
        break;
      case TApplicationException.INTERNAL_ERROR:
        typeMessage = "INTERNAL ERROR";
        break;
      case TApplicationException.INVALID_MESSAGE_TYPE:
        typeMessage = "INVALID MESSAGE TYPE";
        break;
      case TApplicationException.MISSING_RESULT:
        typeMessage = "MISSING RESULT";
        break;
      case TApplicationException.PROTOCOL_ERROR:
        typeMessage = "PROTOCOL ERROR";
        break;
      case TApplicationException.UNKNOWN_METHOD:
        typeMessage = "UNKNOWN METHOD";
        break;
      case TApplicationException.WRONG_METHOD_NAME:
        typeMessage = "WRONG METHOD NAME";
        break;
      default:
        typeMessage = "UNKNOWN APPLICATION ERROR";
        break;
    }
  }
  String message = t.getLocalizedMessage();
  if (message == null || message.length() == 0) {
    message = t.getClass().getName();
  }
  if (typeMessage != null) {
    return message + " [" + typeMessage + ']';
  }
  else {
    return message;
  }
}
 
Example 7
Source File: ThriftExceptionUtil.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public static String getExceptionString(Throwable t) {
  String typeMessage = null;
  if (t instanceof TTransportException) {
    TTransportException tte = (TTransportException)t;
    switch (tte.getType()) {
      case TTransportException.ALREADY_OPEN:
        typeMessage = "SOCKET ALREADY OPEN";
        break;
      case TTransportException.END_OF_FILE:
        typeMessage = "SOCKET END OF TRANSMISSION";
        break;
      case TTransportException.NOT_OPEN:
        typeMessage = "SOCKET NOT OPEN";
        break;
      case TTransportException.TIMED_OUT:
        typeMessage = "SOCKET TIMED OUT";
        break;
      default:
        typeMessage = "UNKNOWN SOCKET ERROR";
        break;
    }
  }
  else if (t instanceof TProtocolException) {
    TProtocolException tpe = (TProtocolException)t;
    switch (tpe.getType()) {
      case TProtocolException.BAD_VERSION:
        typeMessage = "BAD PROTOCOL VERSION";
        break;
      case TProtocolException.INVALID_DATA:
        typeMessage = "INVALID DATA IN PROTOCOL";
        break;
      case TProtocolException.NEGATIVE_SIZE:
        typeMessage = "NEGATIVE SIZE IN PROTOCOL";
        break;
      case TProtocolException.NOT_IMPLEMENTED:
        typeMessage = "NOT IMPLEMENTED";
        break;
      case TProtocolException.SIZE_LIMIT:
        typeMessage = "PROTOCOL SIZE LIMIT HIT";
        break;
      default:
        typeMessage = "UNKNOWN PROTOCOL ERROR";
        break;
    }
  }
  else if (t instanceof TApplicationException) {
    TApplicationException tae = (TApplicationException)t;
    switch (tae.getType()) {
      case TApplicationException.BAD_SEQUENCE_ID:
        typeMessage = "BAD SEQUENCE ID";
        break;
      case TApplicationException.INTERNAL_ERROR:
        typeMessage = "INTERNAL ERROR";
        break;
      case TApplicationException.INVALID_MESSAGE_TYPE:
        typeMessage = "INVALID MESSAGE TYPE";
        break;
      case TApplicationException.MISSING_RESULT:
        typeMessage = "MISSING RESULT";
        break;
      case TApplicationException.PROTOCOL_ERROR:
        typeMessage = "PROTOCOL ERROR";
        break;
      case TApplicationException.UNKNOWN_METHOD:
        typeMessage = "UNKNOWN METHOD";
        break;
      case TApplicationException.WRONG_METHOD_NAME:
        typeMessage = "WRONG METHOD NAME";
        break;
      default:
        typeMessage = "UNKNOWN APPLICATION ERROR";
        break;
    }
  }
  String message = t.getLocalizedMessage();
  if (message == null || message.length() == 0) {
    message = t.getClass().getName();
  }
  if (typeMessage != null) {
    return message + " [" + typeMessage + ']';
  }
  else {
    return message;
  }
}