本文整理汇总了Java中org.jboss.netty.channel.ChannelFuture.awaitUninterruptibly方法的典型用法代码示例。如果您正苦于以下问题:Java ChannelFuture.awaitUninterruptibly方法的具体用法?Java ChannelFuture.awaitUninterruptibly怎么用?Java ChannelFuture.awaitUninterruptibly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jboss.netty.channel.ChannelFuture
的用法示例。
在下文中一共展示了ChannelFuture.awaitUninterruptibly方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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");
}
}
示例4: 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();
}
}
}
示例5: 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);
}
示例6: close
import org.jboss.netty.channel.ChannelFuture; //导入方法依赖的package包/类
public synchronized void close() {
List<ChannelFuture> futures = new ArrayList<>();
for (Channel channel : allChannels) {
try {
if (channel != null && channel.isOpen()) {
futures.add(channel.close());
}
} catch (Exception e) {
//ignore
}
}
for (ChannelFuture future : futures) {
future.awaitUninterruptibly();
}
}
示例7: 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;
}
示例8: close
import org.jboss.netty.channel.ChannelFuture; //导入方法依赖的package包/类
public synchronized void close() {
List<ChannelFuture> futures = new ArrayList<ChannelFuture>();
closeChannelsAndWait(low, futures);
closeChannelsAndWait(high, futures);
for (ChannelFuture future : futures) {
future.awaitUninterruptibly();
}
}
示例9: doExecute
import org.jboss.netty.channel.ChannelFuture; //导入方法依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public <R extends ActionRequest, T extends ActionResponse, B extends ActionRequestBuilder<R, T, B>>
void doExecute(Action<R, T, B> action, R request, ActionListener<T> listener) {
HttpAction httpAction = actionMap.get(action);
if (httpAction == null) {
throw new IllegalStateException("failed to find http action [" + action + "] to execute");
}
try {
HttpContext httpContext = new HttpContext(httpAction, listener, request);
httpContext.httpRequest = httpAction.createHttpRequest(url, request);
ChannelFuture future = bootstrap.connect(new InetSocketAddress(url.getHost(), url.getPort()));
future.awaitUninterruptibly();
if (!future.isSuccess()) {
bootstrap.releaseExternalResources();
logger.error("can't connect to {}", url);
} else {
Channel channel = future.getChannel();
httpContext.setChannel(channel);
httpContextMap.put(channel, httpContext);
channel.getConfig().setConnectTimeoutMillis(settings.getAsInt("http.client.timeout", 5000));
httpAction.execute(httpContext, listener);
}
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
示例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: doSuspend
import org.jboss.netty.channel.ChannelFuture; //导入方法依赖的package包/类
@Override
protected void doSuspend() throws Exception {
if (channel != null) {
LOG.debug("ServerBootstrap unbinding from {}:{}", configuration.getHost(), configuration.getPort());
ChannelFuture future = channel.unbind();
future.awaitUninterruptibly();
}
}
示例12: doConnect
import org.jboss.netty.channel.ChannelFuture; //导入方法依赖的package包/类
protected void doConnect() throws Throwable {
long start = System.currentTimeMillis();
ChannelFuture future = bootstrap.connect(getConnectAddress());
try{
boolean ret = future.awaitUninterruptibly(getConnectTimeout(), TimeUnit.MILLISECONDS);
if (ret && future.isSuccess()) {
Channel newChannel = future.getChannel();
newChannel.setInterestOps(Channel.OP_READ_WRITE);
try {
// 关闭旧的连接
Channel oldChannel = NettyClient.this.channel; // copy reference
if (oldChannel != null) {
try {
if (logger.isInfoEnabled()) {
logger.info("Close old netty channel " + oldChannel + " on create new netty channel " + newChannel);
}
oldChannel.close();
} finally {
NettyChannel.removeChannelIfDisconnected(oldChannel);
}
}
} finally {
if (NettyClient.this.isClosed()) {
try {
if (logger.isInfoEnabled()) {
logger.info("Close new netty channel " + newChannel + ", because the client closed.");
}
newChannel.close();
} finally {
NettyClient.this.channel = null;
NettyChannel.removeChannelIfDisconnected(newChannel);
}
} else {
NettyClient.this.channel = newChannel;
}
}
} else if (future.getCause() != null) {
throw new RemotingException(this, "client(url: " + getUrl() + ") failed to connect to server "
+ getRemoteAddress() + ", error message is:" + future.getCause().getMessage(), future.getCause());
} else {
throw new RemotingException(this, "client(url: " + getUrl() + ") failed to connect to server "
+ getRemoteAddress() + " client-side timeout "
+ getConnectTimeout() + "ms (elapsed: " + (System.currentTimeMillis() - start) + "ms) from netty client "
+ NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion());
}
}finally{
if (! isConnected()) {
future.cancel();
}
}
}
示例13: run
import org.jboss.netty.channel.ChannelFuture; //导入方法依赖的package包/类
@Override
public void run() {
if (channel != null && channel.isOpen() && channel.isConnected()) {
if (interfaceType() == OspfInterfaceType.BROADCAST.value()) {
if (interfaceTypeOldValue != interfaceType()) {
try {
callDrElection(channel);
} catch (Exception e) {
log.debug("Error while calling interfaceUp {}", e.getMessage());
}
}
} else {
if (interfaceTypeOldValue != interfaceType()) {
interfaceTypeOldValue = interfaceType();
}
}
HelloPacket hellopacket = new HelloPacket();
//Headers
hellopacket.setOspfVer(OspfUtil.OSPF_VERSION);
hellopacket.setOspftype(OspfPacketType.HELLO.value());
hellopacket.setOspfPacLength(0); //will be modified while encoding
hellopacket.setRouterId(ospfArea.routerId());
hellopacket.setAreaId(ospfArea.areaId());
hellopacket.setChecksum(0); //will be modified while encoding
hellopacket.setAuthType(OspfUtil.NOT_ASSIGNED);
hellopacket.setAuthentication(OspfUtil.NOT_ASSIGNED);
//Body
hellopacket.setNetworkMask(ipNetworkMask());
hellopacket.setOptions(ospfArea.options());
hellopacket.setHelloInterval(helloIntervalTime());
hellopacket.setRouterPriority(routerPriority());
hellopacket.setRouterDeadInterval(routerDeadIntervalTime());
hellopacket.setDr(dr());
hellopacket.setBdr(bdr());
Map<String, OspfNbr> listOfNeighbors = listOfNeighbors();
Set<String> keys = listOfNeighbors.keySet();
Iterator itr = keys.iterator();
while (itr.hasNext()) {
String nbrKey = (String) itr.next();
OspfNbrImpl nbr = (OspfNbrImpl) listOfNeighbors.get(nbrKey);
if (nbr.getState() != OspfNeighborState.DOWN) {
hellopacket.addNeighbor(Ip4Address.valueOf(nbrKey));
}
}
// build a hello Packet
if (channel == null || !channel.isOpen() || !channel.isConnected()) {
log.debug("Hello Packet not sent !!.. Channel Issue...");
return;
}
hellopacket.setDestinationIp(OspfUtil.ALL_SPF_ROUTERS);
byte[] messageToWrite = getMessage(hellopacket);
ChannelFuture future = channel.write(messageToWrite);
if (future.isSuccess()) {
log.debug("Hello Packet successfully sent !!");
} else {
future.awaitUninterruptibly();
}
}
}
示例14: doConnect
import org.jboss.netty.channel.ChannelFuture; //导入方法依赖的package包/类
protected void doConnect() throws Throwable {
long start = System.currentTimeMillis();
ChannelFuture future = bootstrap.connect(getConnectAddress());
try{
boolean ret = future.awaitUninterruptibly(getConnectTimeout(), TimeUnit.MILLISECONDS);
if (ret && future.isSuccess()) {
Channel newChannel = future.getChannel();
newChannel.setInterestOps(Channel.OP_READ_WRITE);
try {
// 关闭旧的连接
Channel oldChannel = NettyClient.this.channel; // copy reference
if (oldChannel != null) {
try {
if (log.isInfoEnabled()) {
log.info("Close old netty channel " + oldChannel + " on create new netty channel " + newChannel);
}
oldChannel.close();
} finally {
NettyChannel.removeChannelIfDisconnected(oldChannel);
}
}
} finally {
if (NettyClient.this.isClosed()) {
try {
if (log.isInfoEnabled()) {
log.info("Close new netty channel " + newChannel + ", because the client closed.");
}
newChannel.close();
} finally {
NettyClient.this.channel = null;
NettyChannel.removeChannelIfDisconnected(newChannel);
}
} else {
NettyClient.this.channel = newChannel;
}
}
} else if (future.getCause() != null) {
throw new RemotingException(this, "client(url: " + getUrl() + ") failed to connect to server "
+ getRemoteAddress() + ", error message is:" + future.getCause().getMessage(), future.getCause());
} else {
throw new RemotingException(this, "client(url: " + getUrl() + ") failed to connect to server "
+ getRemoteAddress() + " client-side timeout "
+ getConnectTimeout() + "ms (elapsed: " + (System.currentTimeMillis() - start) + "ms) from netty client "
+ NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion());
}
}finally{
if (! isConnected()) {
future.cancel();
}
}
}