org.jruby.util.io
Class SelectorPool

java.lang.Object
  extended by org.jruby.util.io.SelectorPool

public class SelectorPool
extends java.lang.Object

This is a simple implementation of a hard-referenced java.nio.channels.Selector pool. It is intended to allow us to reuse a small pool of selectors rather than creating them new for each use (which causes problem for Windows and its socket-per-selector impl) or saving them per-thread (which causes problems when there are many not-quite-dead threads in flight. The selectors are kept open in the pool and you should call cleanup() for releasing selectors.

Author:
headius

Constructor Summary
SelectorPool()
           
 
Method Summary
 void cleanup()
          Clean up a pool.
 java.nio.channels.Selector get()
          Get a selector from the pool (or create a new one).
 void put(java.nio.channels.Selector selector)
          Put a selector back into the pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SelectorPool

public SelectorPool()
Method Detail

get

public java.nio.channels.Selector get()
                               throws java.io.IOException
Get a selector from the pool (or create a new one). Selectors come from the default selector provider on the current JVM.

Returns:
a java.nio.channels.Selector
Throws:
java.io.IOException - if there's a problem opening a new selector

put

public void put(java.nio.channels.Selector selector)
Put a selector back into the pool.

Parameters:
selector - the selector to put back

cleanup

public void cleanup()
Clean up a pool. All selectors in a pool are closed and the pool gets empty.



Copyright © 2002-2009 JRuby Team. All Rights Reserved.