當前位置: 首頁>>代碼示例>>Java>>正文


Java Channel.close方法代碼示例

本文整理匯總了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();
    }
}
 
開發者ID:nsg-ethz,項目名稱:iTAP-controller,代碼行數:26,代碼來源:AbstractRPCChannelHandler.java

示例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);
    }
}
 
開發者ID:nsg-ethz,項目名稱:iTAP-controller,代碼行數:25,代碼來源:RemoteSyncChannelHandler.java

示例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();
           }
       }
}
 
開發者ID:zhaoshiling1017,項目名稱:voyage,代碼行數:43,代碼來源:NettyRpcConnection.java

示例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();
   }
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:13,代碼來源:NettyServerCnxnFactory.java

示例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();
        }
    }
}
 
開發者ID:dachengxi,項目名稱:EatDubbo,代碼行數:53,代碼來源:NettyClient.java

示例6: closeChannel

import org.jboss.netty.channel.Channel; //導入方法依賴的package包/類
private void closeChannel(Channel channel) {
    if (!(channel instanceof DatagramChannel)) {
        channel.close();
    }
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:6,代碼來源:MainEventHandler.java

示例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.
}
 
開發者ID:nsg-ethz,項目名稱:iTAP-controller,代碼行數:45,代碼來源:RPCChannelHandler.java


注:本文中的org.jboss.netty.channel.Channel.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。