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


Java SelectableChannel.isOpen方法代碼示例

本文整理匯總了Java中java.nio.channels.SelectableChannel.isOpen方法的典型用法代碼示例。如果您正苦於以下問題:Java SelectableChannel.isOpen方法的具體用法?Java SelectableChannel.isOpen怎麽用?Java SelectableChannel.isOpen使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.nio.channels.SelectableChannel的用法示例。


在下文中一共展示了SelectableChannel.isOpen方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: handleIOException

import java.nio.channels.SelectableChannel; //導入方法依賴的package包/類
private void handleIOException( SelectionKey key, WebSocket conn, IOException ex ) {
	// onWebsocketError( conn, ex );// conn may be null here
	if( conn != null ) {
		conn.closeConnection( CloseFrame.ABNORMAL_CLOSE, ex.getMessage() );
	} else if( key != null ) {
		SelectableChannel channel = key.channel();
		if( channel != null && channel.isOpen() ) { // this could be the case if the IOException ex is a SSLException
			try {
				channel.close();
			} catch ( IOException e ) {
				// there is nothing that must be done here
			}
			if( WebSocketImpl.DEBUG )
				System.out.println( "Connection closed because of" + ex );
		}
	}
}
 
開發者ID:LDLN,項目名稱:Responder-Android,代碼行數:18,代碼來源:WebSocketServer.java

示例2: implClose

import java.nio.channels.SelectableChannel; //導入方法依賴的package包/類
protected void implClose() throws IOException
{
    if (channelArray != null)
    {
        // prevent further wakeup
        synchronized (interruptLock) {
            interruptTriggered = true;
        }
        wakeupPipe.sink().close();
        wakeupPipe.source().close();
        for (int i = 0; i < channelArray.get_Count(); i++)
        { // Deregister channels
            SelectionKeyImpl ski = (SelectionKeyImpl)channelArray.get_Item(i);
            deregister(ski);
            SelectableChannel selch = ski.channel();
            if (!selch.isOpen() && !selch.isRegistered())
                ((SelChImpl)selch).kill();
        }
        selectedKeys = null;
        channelArray = null;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:23,代碼來源:DotNetSelectorImpl.java

示例3: handleIOException

import java.nio.channels.SelectableChannel; //導入方法依賴的package包/類
private void handleIOException(SelectionKey key, WebSocket conn, IOException ex) {
    // onWebsocketError( conn, ex );// conn may be null here
    if (conn != null) {
        conn.closeConnection(CloseFrame.ABNORMAL_CLOSE, ex.getMessage());
    } else if (key != null) {
        SelectableChannel channel = key.channel();
        if (channel != null && channel.isOpen()) { // this could be the case if the IOException ex is a SSLException
            try {
                channel.close();
            } catch (IOException e) {
                // there is nothing that must be done here
            }
            if (WebSocketImpl.DEBUG) {
                System.out.println("Connection closed because of" + ex);
            }
        }
    }
}
 
開發者ID:GloriousEggroll,項目名稱:quorrabot,代碼行數:19,代碼來源:WebSocketServer.java

示例4: handleIOException

import java.nio.channels.SelectableChannel; //導入方法依賴的package包/類
private void handleIOException(SelectionKey key, WebSocket conn, IOException ex) {
    onWebsocketError(conn, ex);
    if (conn != null) {
        conn.closeConnection(CloseFrame.ABNORMAL_CLOSE, ex.getMessage());
    } else if (key != null) {
        SelectableChannel channel = key.channel();
        if (channel != null && channel.isOpen()) {
            try {
                channel.close();
            } catch (IOException e) {
            }
            if (WebSocketImpl.DEBUG) {
                System.out.println("Connection closed because of" + ex);
            }
        }
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:18,代碼來源:WebSocketServer.java

示例5: implClose

import java.nio.channels.SelectableChannel; //導入方法依賴的package包/類
protected void implClose() throws IOException {
    synchronized (closeLock) {
        if (channelArray != null) {
            if (pollWrapper != null) {
                // prevent further wakeup
                synchronized (interruptLock) {
                    interruptTriggered = true;
                }
                wakeupPipe.sink().close();
                wakeupPipe.source().close();
                for(int i = 1; i < totalChannels; i++) { // Deregister channels
                    if (i % MAX_SELECTABLE_FDS != 0) { // skip wakeupEvent
                        deregister(channelArray[i]);
                        SelectableChannel selch = channelArray[i].channel();
                        if (!selch.isOpen() && !selch.isRegistered())
                            ((SelChImpl)selch).kill();
                    }
                }
                pollWrapper.free();
                pollWrapper = null;
                selectedKeys = null;
                channelArray = null;
                // Make all remaining helper threads exit
                for (SelectThread t: threads)
                     t.makeZombie();
                startLock.startThreads();
            }
        }
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:31,代碼來源:WindowsSelectorImpl.java

示例6: implDereg

import java.nio.channels.SelectableChannel; //導入方法依賴的package包/類
protected void implDereg(SelectionKeyImpl ski) throws IOException{
    int i = ski.getIndex();
    assert (i >= 0);
    synchronized (closeLock) {
        if (i != totalChannels - 1) {
            // Copy end one over it
            SelectionKeyImpl endChannel = channelArray[totalChannels-1];
            channelArray[i] = endChannel;
            endChannel.setIndex(i);
            pollWrapper.replaceEntry(pollWrapper, totalChannels - 1,
                                                            pollWrapper, i);
        }
        ski.setIndex(-1);
    }
    channelArray[totalChannels - 1] = null;
    totalChannels--;
    if ( totalChannels != 1 && totalChannels % MAX_SELECTABLE_FDS == 1) {
        totalChannels--;
        threadsCount--; // The last thread has become redundant.
    }
    fdMap.remove(ski); // Remove the key from fdMap, keys and selectedKeys
    keys.remove(ski);
    selectedKeys.remove(ski);
    deregister(ski);
    SelectableChannel selch = ski.channel();
    if (!selch.isOpen() && !selch.isRegistered())
        ((SelChImpl)selch).kill();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:29,代碼來源:WindowsSelectorImpl.java

示例7: implDereg

import java.nio.channels.SelectableChannel; //導入方法依賴的package包/類
protected void implDereg(SelectionKeyImpl ski) throws IOException
{
    channelArray.Remove(ski);
    fdMap.remove(ski.getSocket());
    keys.remove(ski);
    selectedKeys.remove(ski);
    deregister(ski);
    SelectableChannel selch = ski.channel();
    if (!selch.isOpen() && !selch.isRegistered())
    {
        ((SelChImpl)selch).kill();
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:14,代碼來源:DotNetSelectorImpl.java


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