List of usage examples for java.nio.channels Selector open
public static Selector open() throws IOException
From source file:kilim.nio.MultiNioSelectorThreadScheduler.java
private SelectorThread newSelectorThread(String namePostFix) throws IOException { Selector sel = Selector.open(); SelectorThread result = new SelectorThread(namePostFix, sel, this); result.start();/*from w w w .j a va 2 s .c om*/ Task t = new RegistrationTask(result.registrationMbx, sel, result); t.setScheduler(this); t.start(); return result; }
From source file:eu.stratosphere.nephele.taskmanager.bytebuffered.IncomingConnectionThread.java
public IncomingConnectionThread(ByteBufferedChannelManager byteBufferedChannelManager, boolean isListeningThread, InetSocketAddress listeningAddress) throws IOException { super("Incoming Connection Thread"); this.selector = Selector.open(); this.byteBufferedChannelManager = byteBufferedChannelManager; if (isListeningThread) { this.listeningSocket = ServerSocketChannel.open(); this.listeningSocket.configureBlocking(false); listeningSocket.register(this.selector, SelectionKey.OP_ACCEPT); this.listeningSocket.socket().bind(listeningAddress); LOG.debug("Listening on " + this.listeningSocket.socket().getLocalSocketAddress()); } else {/*w ww . ja va 2s . c o m*/ this.listeningSocket = null; } }
From source file:org.commoncrawl.io.internal.NIOSocketSelector.java
/** Constructor - creates a new NIO Selector */ public NIOSocketSelector(EventLoop eventLoop) throws IOException { _eventLoop = eventLoop; _selector = Selector.open(); }
From source file:net.sf.cindy.impl.SimpleEventGenerator.java
protected void doStart() { try {//from w ww . jav a2s . c o m if (log.isTraceEnabled()) log.trace("start EventGenerator " + id); lastSelectTime = null; register.clear(); close = false; selector = Selector.open(); thread = new Thread() { public void run() { SimpleEventGenerator.this.run(); } }; thread.setName(Utils.getClassSimpleName(getClass()) + id); thread.setPriority(priority); thread.start(); } catch (IOException e) { log.error(e, e); } }
From source file:com.openteach.diamond.network.waverider.network.DefaultNetWorkServer.java
@Override public boolean init() { try {/*from w ww .j a v a 2 s . c o m*/ selector = Selector.open(); serverSocketChannel = ServerSocketChannel.open(); serverSocketChannel.configureBlocking(false); serverSocketChannel.socket() .bind(hostName == null ? new InetSocketAddress(port) : new InetSocketAddress(hostName, port)); serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT); // ?? // ?, socket? //readerExecutor = Executors.newFixedThreadPool(1, new WaveriderThreadFactory(NET_WORK_READER, null, true)); //writerExecutor = Executors.newFixedThreadPool(1, new WaveriderThreadFactory(NET_WORK_WRITER, null, true)); // ? netWorkServerThread = new Thread(this, NET_WORK_SERVER_THREAD_NAME); netWorkServerThread.setDaemon(true); } catch (IOException e) { logger.error("Init DefaultNetworkServer failed: ", e); throw new RuntimeException(e); } return true; }
From source file:SystemUtils.java
public static final Selector openSelector() throws IOException { Selector result = null;// w w w. j a va 2s .c o m // check if it is linux os if (SystemUtils.isLinuxPlatform()) { try { Class<?> providerClazz = Class.forName("sun.nio.ch.EPollSelectorProvider"); if (providerClazz != null) { try { Method method = providerClazz.getMethod("provider"); if (method != null) { SelectorProvider selectorProvider = (SelectorProvider) method.invoke(null); if (selectorProvider != null) { result = selectorProvider.openSelector(); } } } catch (Exception e) { // ignore } } } catch (Exception e) { // ignore } } if (result == null) { result = Selector.open(); } return result; }
From source file:com.alibaba.napoli.gecko.core.util.SelectorFactory.java
/** * Increase <code>Selector</code> pool size *//*www . j av a2s.c o m*/ private static void grow(int size) throws IOException { for (int i = 0; i < size - maxSelectors; i++) { selectors.add(Selector.open()); } }
From source file:oz.hadoop.yarn.api.net.AbstractSocketHandler.java
/** * Will asynchronously start this socket handler (client or server) * returning the {@link SocketAddress} which represents server address for * clients and bind address for server. See {@link ApplicationContainerServerImpl} and {@link ApplicationContainerClientImpl} *//*from w ww. j ava 2 s .c o m*/ public InetSocketAddress start() { InetSocketAddress serverAddress = this.address; try { if (this.selector == null) { this.selector = Selector.open(); this.init(); this.executor.execute(this.listenerTask); if (logger.isDebugEnabled()) { logger.debug("Started listener for " + AbstractSocketHandler.this.getClass().getSimpleName()); } serverAddress = (InetSocketAddress) this.rootChannel.getLocalAddress(); } } catch (IOException e) { throw new IllegalStateException("Failed to start " + this.getClass().getName(), e); } return serverAddress; }
From source file:org.apache.synapse.transport.udp.IODispatcher.java
/** * Constructor./*from w w w.ja v a 2 s . c om*/ * * @param workerPool the worker pool to dispatch processing task to * @throws IOException if the {@link Selector} instance could not be created */ public IODispatcher(WorkerPool workerPool) throws IOException { this.workerPool = workerPool; selector = Selector.open(); }
From source file:org.cloudata.core.commitlog.WorkerPool.java
Worker(WorkerPool workerPool, int workerNo, int port, AsyncFileWriter asyncWriter) throws IOException { this.workerNo = workerNo; this.port = port; this.workerPool = workerPool; this.asyncWriter = asyncWriter; this.setName("Worker #" + workerNo + " on " + port); selector = Selector.open(); }