本文整理汇总了Java中org.jboss.netty.channel.ChannelFuture.isSuccess方法的典型用法代码示例。如果您正苦于以下问题:Java ChannelFuture.isSuccess方法的具体用法?Java ChannelFuture.isSuccess怎么用?Java ChannelFuture.isSuccess使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jboss.netty.channel.ChannelFuture
的用法示例。
在下文中一共展示了ChannelFuture.isSuccess方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: operationComplete
import org.jboss.netty.channel.ChannelFuture; //导入方法依赖的package包/类
@Override
public void operationComplete(ChannelFuture cf) throws Exception {
if (!cf.isSuccess()) {
synchronized (connections) {
NodeConnection c = connections.remove(node.getNodeId());
if (c != null) c.nuke();
cf.getChannel().close();
}
String message = "[unknown error]";
if (cf.isCancelled()) message = "Timed out on connect";
if (cf.getCause() != null) message = cf.getCause().getMessage();
logger.debug("[{}->{}] Could not connect to RPC " +
"node: {}",
new Object[]{syncManager.getLocalNodeId(),
node.getNodeId(),
message});
} else {
logger.trace("[{}->{}] Channel future successful",
syncManager.getLocalNodeId(),
node.getNodeId());
}
}
示例2: bootstrap
import org.jboss.netty.channel.ChannelFuture; //导入方法依赖的package包/类
public boolean bootstrap(HostAndPort seed,
Node localNode) throws SyncException {
this.localNode = localNode;
succeeded = false;
SocketAddress sa =
new InetSocketAddress(seed.getHostText(), seed.getPort());
ChannelFuture future = bootstrap.connect(sa);
future.awaitUninterruptibly();
if (!future.isSuccess()) {
logger.debug("Could not connect to " + seed, future.getCause());
return false;
}
Channel channel = future.getChannel();
logger.debug("[{}] Connected to {}",
localNode != null ? localNode.getNodeId() : null,
seed);
try {
channel.getCloseFuture().await();
} catch (InterruptedException e) {
logger.debug("Interrupted while waiting for bootstrap");
return succeeded;
}
return succeeded;
}
示例3: connect
import org.jboss.netty.channel.ChannelFuture; //导入方法依赖的package包/类
protected boolean connect(String hostname, int port) {
ready = false;
if (channel == null || !channel.isConnected()) {
SocketAddress sa =
new InetSocketAddress(hostname, port);
ChannelFuture future = clientBootstrap.connect(sa);
future.awaitUninterruptibly();
if (!future.isSuccess()) {
logger.error("Could not connect to " + hostname +
":" + port, future.getCause());
return false;
}
channel = future.getChannel();
}
while (!ready && channel != null && channel.isConnected()) {
try {
Thread.sleep(10);
} catch (InterruptedException e) { }
}
if (!ready || channel == null || !channel.isConnected()) {
logger.warn("Timed out connecting to {}:{}", hostname, port);
return false;
}
logger.debug("Connected to {}:{}", hostname, port);
return true;
}
示例4: bindToPrivilegedPort
import org.jboss.netty.channel.ChannelFuture; //导入方法依赖的package包/类
/**
* This attempts to bind to privileged ports, starting with 1023 and working downwards, and returns when the first binding succeeds.
*
* <p>
* Some NFS servers apparently may require that some requests originate on
* an Internet port below IPPORT_RESERVED (1024). This is generally not
* used, though, as the client then has to run as a user authorized for
* privileged, which is dangerous. It is also not generally needed.
* </p>
*
* @return
* <ul>
* <li><code>true</code> if the binding succeeds,</li>
* <li><code>false</code> otherwise.</li>
* </ul>
* @throws RpcException If an exception occurs, or if no binding succeeds.
*/
private Channel bindToPrivilegedPort() throws RpcException {
System.out.println("Attempting to use privileged port.");
for (int port = 1023; port > 0; --port) {
try {
ChannelPipeline pipeline = _clientBootstrap.getPipelineFactory().getPipeline();
Channel channel = _clientBootstrap.getFactory().newChannel(pipeline);
channel.getConfig().setOptions(_clientBootstrap.getOptions());
ChannelFuture bindFuture = channel.bind(new InetSocketAddress(port)).awaitUninterruptibly();
if (bindFuture.isSuccess()) {
System.out.println("Success! Bound to port " + port);
return bindFuture.getChannel();
}
} catch (Exception e) {
String msg = String.format("rpc request bind error for address: %s",
getRemoteAddress());
throw new RpcException(RpcStatus.NETWORK_ERROR, msg, e);
}
}
throw new RpcException(RpcStatus.LOCAL_BINDING_ERROR, String.format("Cannot bind a port < 1024: %s", getRemoteAddress()));
}
示例5: send
import org.jboss.netty.channel.ChannelFuture; //导入方法依赖的package包/类
/**
* 发送请求
*/
public void send() {
ChannelFuture writeFuture = channel.write(request);
//阻塞等待,若超时则返回已完成和失败
boolean ret = writeFuture.awaitUninterruptibly(1000, TimeUnit.MILLISECONDS);
if (ret && writeFuture.isSuccess()) {
return;
} else if(writeFuture.getCause() != null) {
invokeMap.remove(request.getRequestID());
throw new RpcException(writeFuture.getCause());
} else {
invokeMap.remove(request.getRequestID());
throw new RpcException("sendRequest error");
}
}
示例6: connect
import org.jboss.netty.channel.ChannelFuture; //导入方法依赖的package包/类
/**
* 尝试连接
*/
public void connect() {
ChannelFuture future = bootstrap.connect(inetAddr);
try{
boolean ret = future.awaitUninterruptibly(Constants.TIMEOUT_CONNECTION_MILLSECOND, TimeUnit.MILLISECONDS);
if (ret && future.isSuccess()) {
Channel newChannel = future.getChannel();
newChannel.setInterestOps(Channel.OP_READ_WRITE);
try {
// 关闭旧的连接
Channel oldChannel = NettyRpcConnection.this.channel;
if (oldChannel != null) {
logger.info("Close old netty channel {} on create new netty channel {}", oldChannel, newChannel);
oldChannel.close();
}
} finally {
if (!isConnected()) {
try {
logger.info("Close new netty channel {}, because the client closed.", newChannel);
newChannel.close();
} finally {
NettyRpcConnection.this.channel = null;
}
} else {
NettyRpcConnection.this.channel = newChannel;
}
}
} else if (null != future.getCause()) {
logger.error("connect fail", future.getCause());
throw new RuntimeException("connect error", future.getCause());
} else {
logger.error("connect fail,connstr: "+this.getConnStr());
throw new RuntimeException("connect error");
}
}finally{
if (! isConnected()) {
future.cancel();
}
}
}
示例7: operationComplete
import org.jboss.netty.channel.ChannelFuture; //导入方法依赖的package包/类
/**
* Only allow the connection to stay open if certificate passes auth
*/
public void operationComplete(ChannelFuture future)
throws SSLPeerUnverifiedException {
if (future.isSuccess()) {
LOG.debug("Successful handshake with session 0x{}",
Long.toHexString(cnxn.sessionId));
SSLEngine eng = sslHandler.getEngine();
SSLSession session = eng.getSession();
cnxn.setClientCertificateChain(session.getPeerCertificates());
String authProviderProp
= System.getProperty(ZKConfig.SSL_AUTHPROVIDER, "x509");
X509AuthenticationProvider authProvider =
(X509AuthenticationProvider)
ProviderRegistry.getProvider(authProviderProp);
if (authProvider == null) {
LOG.error("Auth provider not found: {}", authProviderProp);
cnxn.close();
return;
}
if (KeeperException.Code.OK !=
authProvider.handleAuthentication(cnxn, null)) {
LOG.error("Authentication failed for session 0x{}",
Long.toHexString(cnxn.sessionId));
cnxn.close();
return;
}
allChannels.add(future.getChannel());
addCnxn(cnxn);
} else {
LOG.error("Unsuccessful handshake with session 0x{}",
Long.toHexString(cnxn.sessionId));
cnxn.close();
}
}
示例8: connectToChannelsLight
import org.jboss.netty.channel.ChannelFuture; //导入方法依赖的package包/类
protected NodeChannels connectToChannelsLight(DiscoveryNode node) {
InetSocketAddress address = ((InetSocketTransportAddress) node.address()).address();
ChannelFuture connect = clientBootstrap.connect(address);
connect.awaitUninterruptibly((long) (connectTimeout.millis() * 1.5));
if (!connect.isSuccess()) {
throw new ConnectTransportException(node, "connect_timeout[" + connectTimeout + "]", connect.getCause());
}
Channel[] channels = new Channel[1];
channels[0] = connect.getChannel();
channels[0].getCloseFuture().addListener(new ChannelCloseListener(node));
return new NodeChannels(channels, channels, channels, channels, channels);
}
示例9: operationComplete
import org.jboss.netty.channel.ChannelFuture; //导入方法依赖的package包/类
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (future.isSuccess()) {
shuffleOutputsOK.incr();
} else {
shuffleOutputsFailed.incr();
}
shuffleConnections.decr();
}
示例10: doResume
import org.jboss.netty.channel.ChannelFuture; //导入方法依赖的package包/类
@Override
protected void doResume() throws Exception {
if (channel != null) {
LOG.debug("ServerBootstrap binding to {}:{}", configuration.getHost(), configuration.getPort());
ChannelFuture future = channel.bind(new InetSocketAddress(configuration.getHost(), configuration.getPort()));
future.awaitUninterruptibly();
if (!future.isSuccess()) {
// if we cannot bind, the re-create channel
allChannels.remove(channel);
channel = serverBootstrap.bind(new InetSocketAddress(configuration.getHost(), configuration.getPort()));
allChannels.add(channel);
}
}
}
示例11: operationComplete
import org.jboss.netty.channel.ChannelFuture; //导入方法依赖的package包/类
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
future.getChannel().close();
return;
}
int waitCount = this.reduceContext.getMapsToWait().decrementAndGet();
if (waitCount == 0) {
metrics.operationComplete(future);
future.getChannel().close();
} else {
pipelineFact.getSHUFFLE().sendMap(reduceContext);
}
}
示例12: openChannel
import org.jboss.netty.channel.ChannelFuture; //导入方法依赖的package包/类
protected Channel openChannel(ChannelFuture channelFuture) throws Exception {
// blocking for channel to be done
if (LOG.isTraceEnabled()) {
LOG.trace("Waiting for operation to complete {} for {} millis", channelFuture, configuration.getConnectTimeout());
}
// here we need to wait it in other thread
final CountDownLatch channelLatch = new CountDownLatch(1);
channelFuture.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture cf) throws Exception {
channelLatch.countDown();
}
});
try {
channelLatch.await(configuration.getConnectTimeout(), TimeUnit.MILLISECONDS);
} catch (InterruptedException ex) {
throw new CamelException("Interrupted while waiting for " + "connection to "
+ configuration.getAddress());
}
if (!channelFuture.isDone() || !channelFuture.isSuccess()) {
ConnectException cause = new ConnectException("Cannot connect to " + configuration.getAddress());
if (channelFuture.getCause() != null) {
cause.initCause(channelFuture.getCause());
}
throw cause;
}
Channel answer = channelFuture.getChannel();
// to keep track of all channels in use
allChannels.add(answer);
if (LOG.isDebugEnabled()) {
LOG.debug("Creating connector to address: {}", configuration.getAddress());
}
return answer;
}
示例13: operationComplete
import org.jboss.netty.channel.ChannelFuture; //导入方法依赖的package包/类
@Override
public void operationComplete(ChannelFuture future) throws Exception {
// if it was not a success then thrown an exception
if (!future.isSuccess()) {
Exception e = new CamelExchangeException("Cannot write response to " + remoteAddress, exchange, future.getCause());
consumer.getExceptionHandler().handleException(e);
}
// should channel be closed after complete?
Boolean close;
if (exchange.hasOut()) {
close = exchange.getOut().getHeader(NettyConstants.NETTY_CLOSE_CHANNEL_WHEN_COMPLETE, Boolean.class);
} else {
close = exchange.getIn().getHeader(NettyConstants.NETTY_CLOSE_CHANNEL_WHEN_COMPLETE, Boolean.class);
}
// check the setting on the exchange property
if (close == null) {
close = exchange.getProperty(NettyConstants.NETTY_CLOSE_CHANNEL_WHEN_COMPLETE, Boolean.class);
}
// should we disconnect, the header can override the configuration
boolean disconnect = consumer.getConfiguration().isDisconnect();
if (close != null) {
disconnect = close;
}
if (disconnect) {
if (LOG.isTraceEnabled()) {
LOG.trace("Closing channel when complete at address: {}", remoteAddress);
}
NettyHelper.close(future.getChannel());
}
}
示例14: createClient
import org.jboss.netty.channel.ChannelFuture; //导入方法依赖的package包/类
protected Client createClient(String targetIP, int targetPort, int connectTimeout, String key) throws Exception {
ClientBootstrap bootstrap = new ClientBootstrap(nioClient);
bootstrap.setOption("tcpNoDelay", Boolean.parseBoolean(System.getProperty("nfs.rpc.tcp.nodelay", "true")));
bootstrap.setOption("reuseAddress", Boolean.parseBoolean(System.getProperty("nfs.rpc.tcp.reuseaddress", "true")));
if (connectTimeout < 1000) {
bootstrap.setOption("connectTimeoutMillis", 1000);
} else {
bootstrap.setOption("connectTimeoutMillis", connectTimeout);
}
NettyClientHandler handler = new NettyClientHandler(this, key);
bootstrap.setPipelineFactory(new NettyClientPipelineFactory(handler));
ChannelFuture future = bootstrap.connect(new InetSocketAddress(targetIP, targetPort));
future.awaitUninterruptibly(connectTimeout);
if (!future.isDone()) {
LOGGER.error("Create connection to " + targetIP + ":" + targetPort + " timeout!");
throw new Exception("Create connection to " + targetIP + ":" + targetPort + " timeout!");
}
if (future.isCancelled()) {
LOGGER.error("Create connection to " + targetIP + ":" + targetPort + " cancelled by user!");
throw new Exception("Create connection to " + targetIP + ":" + targetPort + " cancelled by user!");
}
if (!future.isSuccess()) {
LOGGER.error("Create connection to " + targetIP + ":" + targetPort + " error", future.getCause());
throw new Exception("Create connection to " + targetIP + ":" + targetPort + " error", future.getCause());
}
NettyClient client = new NettyClient(future, key, connectTimeout);
handler.setClient(client);
return client;
}
示例15: write
import org.jboss.netty.channel.ChannelFuture; //导入方法依赖的package包/类
public void write(byte[] data, int offest, int length) throws IOException {
ChannelBuffer channelBuffer = ChannelBuffers.wrappedBuffer(data, offest, length);
ChannelFuture channelFuture = httpChannel.channel().write(channelBuffer);
try {
channelFuture.await();
} catch (InterruptedException e) {
throw new IOException(e);
}
if(!channelFuture.isSuccess()){
logger.error("stream write fail. connected[{}]", channelFuture.getChannel().isConnected());
throw new IOException();
}
}