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


Java SelectorProvider.openSelector方法代碼示例

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


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

示例1: openSelector

import java.nio.channels.spi.SelectorProvider; //導入方法依賴的package包/類
private Selector openSelector() {
    Selector result = null;
    // 在linux平台,盡量啟用epoll實現
    if (isLinuxPlatform()) {
        try {
            final Class<?> providerClazz = Class.forName("sun.nio.ch.EPollSelectorProvider");
            if (providerClazz != null) {
                final Method method = providerClazz.getMethod("provider");
                if (method != null) {
                    final SelectorProvider selectorProvider = (SelectorProvider) method.invoke(null);
                    if (selectorProvider != null) {
                        result = selectorProvider.openSelector();
                    }
                }
            }
        } catch (final Exception ignored) {
        }
    }

    if (result == null) {
        try {
            result = SelectorProvider.provider().openSelector();
        } catch (IOException e) {
            throw new NioException("open selector error:" + e.getMessage(), e);
        }
    }
    return result;
}
 
開發者ID:lemonJun,項目名稱:TakinRPC,代碼行數:29,代碼來源:NioSelectorLoop.java

示例2: get

import java.nio.channels.spi.SelectorProvider; //導入方法依賴的package包/類
/**
 * Takes one selector from end of LRU list of free selectors.
 * If there are no selectors awailable, it creates a new selector.
 * Also invokes trimIdleSelectors(). 
 * 
 * @param channel
 * @return 
 * @throws IOException
 */
private synchronized SelectorInfo get(SelectableChannel channel) 
                                                     throws IOException {
  SelectorInfo selInfo = null;
  
  SelectorProvider provider = channel.provider();
  
  // pick the list : rarely there is more than one provider in use.
  ProviderInfo pList = providerList;
  while (pList != null && pList.provider != provider) {
    pList = pList.next;
  }      
  if (pList == null) {
    //LOG.info("Creating new ProviderInfo : " + provider.toString());
    pList = new ProviderInfo();
    pList.provider = provider;
    pList.queue = new LinkedList<SelectorInfo>();
    pList.next = providerList;
    providerList = pList;
  }
  
  LinkedList<SelectorInfo> queue = pList.queue;
  
  if (queue.isEmpty()) {
    Selector selector = provider.openSelector();
    selInfo = new SelectorInfo();
    selInfo.selector = selector;
    selInfo.queue = queue;
  } else {
    selInfo = queue.removeLast();
  }
  
  trimIdleSelectors(Time.now());
  return selInfo;
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:44,代碼來源:SocketIOWithTimeout.java

示例3: get

import java.nio.channels.spi.SelectorProvider; //導入方法依賴的package包/類
/**
 * Takes one selector from end of LRU list of free selectors.
 * If there are no selectors awailable, it creates a new selector.
 * Also invokes trimIdleSelectors(). 
 * 
 * @param channel
 * @return 
 * @throws IOException
 */
private synchronized SelectorInfo get(SelectableChannel channel) 
                                                     throws IOException {
  SelectorInfo selInfo = null;
  
  SelectorProvider provider = channel.provider();
  
  // pick the list : rarely there is more than one provider in use.
  ProviderInfo pList = providerList;
  while (pList != null && pList.provider != provider) {
    pList = pList.next;
  }      
  if (pList == null) {
    //LOG.info("Creating new ProviderInfo : " + provider.toString());
    pList = new ProviderInfo();
    pList.provider = provider;
    pList.queue = new LinkedList<SelectorInfo>();
    pList.next = providerList;
    providerList = pList;
  }
  
  LinkedList<SelectorInfo> queue = pList.queue;
  
  if (queue.isEmpty()) {
    Selector selector = provider.openSelector();
    selInfo = new SelectorInfo();
    selInfo.selector = selector;
    selInfo.queue = queue;
  } else {
    selInfo = queue.removeLast();
  }
  
  trimIdleSelectors(System.currentTimeMillis());
  return selInfo;
}
 
開發者ID:spafka,項目名稱:spark_deep,代碼行數:44,代碼來源:SocketIOWithTimeout.java


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