本文整理匯總了Java中org.jboss.netty.channel.Channel.close方法的典型用法代碼示例。如果您正苦於以下問題:Java Channel.close方法的具體用法?Java Channel.close怎麽用?Java Channel.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jboss.netty.channel.Channel
的用法示例。
在下文中一共展示了Channel.close方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handshake
import org.jboss.netty.channel.Channel; //導入方法依賴的package包/類
@LogMessageDoc(level="WARN",
message="Failed to authenticate connection from {remote}: {message}",
explanation="Challenge/Response authentication failed",
recommendation="Check the included error message, and " +
"verify the shared secret is correctly-configured")
protected void handshake(HelloMessage request, Channel channel) {
try {
switch (getAuthScheme()) {
case CHALLENGE_RESPONSE:
handshakeChallengeResponse(request, channel);
break;
case NO_AUTH:
// shouldn't get here
break;
}
} catch (AuthException e) {
logger.warn("[{}->{}] Failed to authenticate connection: {}",
new Object[]{getLocalNodeIdString(),
getRemoteNodeIdString(),
e.getMessage()});
channel.write(getError(request.getHeader().getTransactionId(),
e, MessageType.HELLO));
channel.close();
}
}
示例2: handleError
import org.jboss.netty.channel.Channel; //導入方法依賴的package包/類
@Override
protected void handleError(ErrorMessage error, Channel channel) {
ErrorType errType = ErrorType.GENERIC;
for (ErrorType e : ErrorType.values()) {
if (e.getValue() == error.getError().getErrorCode()) {
errType = e;
break;
}
}
SyncException ex =
SyncException.newInstance(errType,
error.getError().getMessage(),
null);
if (ChannelState.CONNECTED.equals(channelState) ||
ChannelState.OPEN.equals(channelState) ||
ErrorType.AUTH.equals(errType)) {
syncManager.channelDisconnected(ex);
channel.close();
} else {
SyncReply reply = new SyncReply(null, null, false, ex, 0);
syncManager.dispatchReply(error.getHeader().getTransactionId(),
reply);
}
}
示例3: connect
import org.jboss.netty.channel.Channel; //導入方法依賴的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();
}
}
}
示例4: reconfigure
import org.jboss.netty.channel.Channel; //導入方法依賴的package包/類
public void reconfigure(InetSocketAddress addr) {
Channel oldChannel = parentChannel;
try {
LOG.info("binding to port {}", addr);
parentChannel = bootstrap.bind(addr);
localAddress = addr;
} catch (Exception e) {
LOG.error("Error while reconfiguring", e);
} finally {
oldChannel.close();
}
}
示例5: doConnect
import org.jboss.netty.channel.Channel; //導入方法依賴的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();
}
}
}
示例6: closeChannel
import org.jboss.netty.channel.Channel; //導入方法依賴的package包/類
private void closeChannel(Channel channel) {
if (!(channel instanceof DatagramChannel)) {
channel.close();
}
}
示例7: handleHello
import org.jboss.netty.channel.Channel; //導入方法依賴的package包/類
@Override
@LogMessageDoc(level="ERROR",
message="[{id}->{id}] Attempted connection from unrecognized " +
"floodlight node {id}; disconnecting",
explanation="A unknown node connected. This can happen " +
"transiently if new nodes join the cluster.",
recommendation="If the problem persists, verify your cluster" +
"configuration and that you don't have unauthorized agents " +
"in your network.")
protected void handleHello(HelloMessage hello, Channel channel) {
if (!hello.isSetNodeId()) {
// this is a client connection. Don't set this up as a node
// connection
isClientConnection = true;
return;
}
remoteNode = syncManager.getClusterConfig().getNode(hello.getNodeId());
if (remoteNode == null) {
logger.error("[{}->{}] Attempted connection from unrecognized " +
"floodlight node {}; disconnecting",
new Object[]{getLocalNodeIdString(),
getRemoteNodeIdString(),
hello.getNodeId()});
channel.close();
return;
}
rpcService.nodeConnected(remoteNode.getNodeId(), channel);
FullSyncRequestMessage srm = new FullSyncRequestMessage();
AsyncMessageHeader header = new AsyncMessageHeader();
header.setTransactionId(getTransactionId());
srm.setHeader(header);
SyncMessage bsm = new SyncMessage(MessageType.FULL_SYNC_REQUEST);
channel.write(bsm);
// XXX - TODO - if last connection was longer ago than the tombstone
// timeout, then we need to do a complete flush and reload of our
// state. This is complex though since this applies across entire
// partitions and not just single nodes. We'd need to identify the
// partition and nuke the smaller half (or lower priority in the case
// of an even split). Downstream listeners would need to be able to
// handle a state nuke as well. A simple way to nuke would be to ensure
// floodlight is restarted in the smaller partition.
}