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

The following examples show how to use org.apache.thrift.transport.TTransportException#UNKNOWN . 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: GfxdTSocket.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * {@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.");
  }
}
 
Example 2
Source File: GfxdTSocket.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * {@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.");
  }
}
 
Example 3
Source File: GfxdTSocket.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@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);
  }
}
 
Example 4
Source File: GfxdTSocket.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Flushes the underlying output stream if not null.
 */
public void flush() throws TTransportException {
    try {
      this.outputStream.flush();
    } catch (ClosedChannelException cce) {
      throw new TTransportException(TTransportException.NOT_OPEN,
          "Cannot write to closed channel.");
    } catch (IOException ioe) {
      throw new TTransportException(TTransportException.UNKNOWN, ioe);
    }
}
 
Example 5
Source File: AstyanaxDataWriterDAO.java    From emodb with Apache License 2.0 5 votes vote down vote up
private boolean isThriftFramedTransportSizeOverrun(Execution<?> execution, ConnectionException exception) {
    // Thrift framed transport size overruns don't have an explicit exception, but they fall under the general
    // umbrella of "unknown" thrift transport exceptions.
    Optional<Throwable> thriftException =
            Iterables.tryFind(Throwables.getCausalChain(exception), Predicates.instanceOf(TTransportException.class));
    //noinspection ThrowableResultOfMethodCallIgnored
    if (!thriftException.isPresent() || ((TTransportException) thriftException.get()).getType() != TTransportException.UNKNOWN) {
        return false;
    }

    return execution instanceof MutationBatch &&
            getMutationBatchSize((MutationBatch) execution) >= MAX_THRIFT_FRAMED_TRANSPORT_SIZE;
}
 
Example 6
Source File: GfxdTSocket.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@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);
  }
}
 
Example 7
Source File: GfxdTSocket.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Flushes the underlying output stream if not null.
 */
public void flush() throws TTransportException {
    try {
      this.outputStream.flush();
    } catch (ClosedChannelException cce) {
      throw new TTransportException(TTransportException.NOT_OPEN,
          "Cannot write to closed channel.");
    } catch (IOException ioe) {
      throw new TTransportException(TTransportException.UNKNOWN, ioe);
    }
}
 
Example 8
Source File: THttp2Client.java    From armeria with Apache License 2.0 4 votes vote down vote up
THttp2Client(String uriStr, HttpHeaders defaultHeaders) throws TTransportException {
    uri = URI.create(uriStr);
    this.defaultHeaders = defaultHeaders;

    int port;
    switch (uri.getScheme()) {
    case "http":
        port = uri.getPort();
        if (port < 0) {
            port = 80;
        }
        sslCtx = null;
        break;
    case "https":
        port = uri.getPort();
        if (port < 0) {
            port = 443;
        }

        try {
            sslCtx = SslContextBuilder.forClient()
                    .ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE)
                    .trustManager(InsecureTrustManagerFactory.INSTANCE)
                    .applicationProtocolConfig(new ApplicationProtocolConfig(
                            Protocol.ALPN,
                            // NO_ADVERTISE is currently the only mode supported by both OpenSsl and
                            // JDK providers.
                            SelectorFailureBehavior.NO_ADVERTISE,
                            // ACCEPT is currently the only mode supported by both OpenSsl and
                            // JDK providers.
                            SelectedListenerFailureBehavior.ACCEPT,
                            ApplicationProtocolNames.HTTP_2))
                    .build();
        } catch (SSLException e) {
            throw new TTransportException(TTransportException.UNKNOWN, e);
        }
        break;
    default:
        throw new IllegalArgumentException("unknown scheme: " + uri.getScheme());
    }

    final String host = uri.getHost();
    if (host == null) {
        throw new IllegalArgumentException("host not specified: " + uriStr);
    }

    final String path = uri.getPath();
    if (path == null) {
        throw new IllegalArgumentException("path not specified: " + uriStr);
    }

    this.host = host;
    this.port = port;
    this.path = path;
}