当前位置: 首页>>代码示例>>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;未经允许,请勿转载。