AsynchronousChannelGroupImpl(AsynchronousChannelProvider provider, ThreadPool pool) { super(provider); this.pool = pool; if (pool.isFixedThreadPool()) { taskQueue = new ConcurrentLinkedQueue<Runnable>(); } else { taskQueue = null; // not used } // use default thread factory as thread should not be visible to // application (it doesn't execute completion handlers). this.timeoutExecutor = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(1, ThreadPool.defaultThreadFactory()); this.timeoutExecutor.setRemoveOnCancelPolicy(true); }
AsynchronousChannelGroupImpl(AsynchronousChannelProvider provider, ThreadPool pool) { super(provider); this.pool = pool; if (pool.isFixedThreadPool()) { taskQueue = new ConcurrentLinkedQueue<>(); } else { taskQueue = null; // not used } // use default thread factory as thread should not be visible to // application (it doesn't execute completion handlers). this.timeoutExecutor = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(1, ThreadPool.defaultThreadFactory()); this.timeoutExecutor.setRemoveOnCancelPolicy(true); }
Iocp(AsynchronousChannelProvider provider, ThreadPool pool) throws IOException { super(provider, pool); this.port = createIoCompletionPort(INVALID_HANDLE_VALUE, 0, 0, fixedThreadCount()); this.nextCompletionKey = 1; }
/** * Returns the default AsynchronousChannelProvider. */ public static AsynchronousChannelProvider create() { String osname = AccessController .doPrivileged(new GetPropertyAction("os.name")); if (osname.equals("SunOS")) return createProvider("sun.nio.ch.SolarisAsynchronousChannelProvider"); if (osname.equals("Linux")) return createProvider("sun.nio.ch.LinuxAsynchronousChannelProvider"); if (osname.contains("OS X")) return createProvider("sun.nio.ch.BsdAsynchronousChannelProvider"); if (osname.equals("AIX")) return createProvider("sun.nio.ch.AixAsynchronousChannelProvider"); throw new InternalError("platform not recognized"); }
KQueuePort(AsynchronousChannelProvider provider, ThreadPool pool) throws IOException { super(provider, pool); // open kqueue this.kqfd = kqueue(); // create socket pair for wakeup mechanism int[] sv = new int[2]; try { socketpair(sv); // register one end with kqueue keventRegister(kqfd, sv[0], EVFILT_READ, EV_ADD); } catch (IOException x) { close0(kqfd); throw x; } this.sp = sv; // allocate the poll array this.address = allocatePollArray(MAX_KEVENTS_TO_POLL); // create the queue and offer the special event to ensure that the first // threads polls this.queue = new ArrayBlockingQueue<Event>(MAX_KEVENTS_TO_POLL); this.queue.offer(NEED_TO_POLL); }
SolarisEventPort(AsynchronousChannelProvider provider, ThreadPool pool) throws IOException { super(provider, pool); // create event port this.port = port_create(); }
EPollPort(AsynchronousChannelProvider provider, ThreadPool pool) throws IOException { super(provider, pool); // open epoll this.epfd = epollCreate(); // create socket pair for wakeup mechanism int[] sv = new int[2]; try { socketpair(sv); // register one end with epoll epollCtl(epfd, EPOLL_CTL_ADD, sv[0], Net.POLLIN); } catch (IOException x) { close0(epfd); throw x; } this.sp = sv; // allocate the poll array this.address = allocatePollArray(MAX_EPOLL_EVENTS); // create the queue and offer the special event to ensure that the first // threads polls this.queue = new ArrayBlockingQueue<Event>(MAX_EPOLL_EVENTS); this.queue.offer(NEED_TO_POLL); }
public static void main(String[] args) { Class<?> c = AsynchronousChannelProvider.provider().getClass(); String expected = args[0]; String actual = c.getName(); if (!actual.equals(expected)) throw new RuntimeException("Provider is of type '" + actual + "', expected '" + expected + "'"); }
EPollPort(AsynchronousChannelProvider provider, ThreadPool pool) throws IOException { super(provider, pool); // open epoll this.epfd = epollCreate(); // create socket pair for wakeup mechanism int[] sv = new int[2]; try { socketpair(sv); // register one end with epoll epollCtl(epfd, EPOLL_CTL_ADD, sv[0], Net.POLLIN); } catch (IOException x) { close0(epfd); throw x; } this.sp = sv; // allocate the poll array this.address = allocatePollArray(MAX_EPOLL_EVENTS); // create the queue and offer the special event to ensure that the first // threads polls this.queue = new ArrayBlockingQueue<>(MAX_EPOLL_EVENTS); this.queue.offer(NEED_TO_POLL); }
/** * Returns the default AsynchronousChannelProvider. */ public static AsynchronousChannelProvider create() { String osname = GetPropertyAction.privilegedGetProperty("os.name"); if (osname.equals("SunOS")) return createProvider("sun.nio.ch.SolarisAsynchronousChannelProvider"); if (osname.equals("Linux")) return createProvider("sun.nio.ch.LinuxAsynchronousChannelProvider"); if (osname.contains("OS X")) return createProvider("sun.nio.ch.BsdAsynchronousChannelProvider"); if (osname.equals("AIX")) return createProvider("sun.nio.ch.AixAsynchronousChannelProvider"); throw new InternalError("platform not recognized"); }