Java Code Examples for java.nio.channels.SelectableChannel#provider()

The following examples show how to use java.nio.channels.SelectableChannel#provider() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SocketIOWithTimeout.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: SocketIOWithTimeout.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: SocketIOWithTimeout.java    From RDFS with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 4
Source File: SocketIOWithTimeout.java    From stratosphere with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source File: SocketIOWithTimeout.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}