List of usage examples for java.nio.channels Selector open
public static Selector open() throws IOException
From source file:net.socket.nio.TimeClientHandle.java
public TimeClientHandle(String host, int port) { this.host = host == null ? "127.0.0.1" : host; this.port = port; try {//from w ww .ja v a 2 s. c o m selector = Selector.open(); socketChannel = SocketChannel.open(); socketChannel.configureBlocking(false); } catch (IOException e) { e.printStackTrace(); System.exit(1); } }
From source file:com.github.neoio.nio.util.NIOUtils.java
public static Selector selectorOpen() throws NetSelectorException { try {//from ww w .ja v a 2 s . c o m return Selector.open(); } catch (IOException e) { throw new NetSelectorException(e); } }
From source file:com.l2jfree.network.mmocore.AbstractSelectorThread.java
protected AbstractSelectorThread(MMOController<T, RP, SP> mmoController, MMOConfig config) throws IOException { super(mmoController); _sleepTime = config.getSelectorSleepTime(); _selector = Selector.open(); }
From source file:org.sipfoundry.sipxrelay.DataShuffler.java
private static synchronized void initializeSelector() { try {//w w w .j a va 2 s . c o m checkWorkQueue(); if (selector != null) { selector.close(); } selector = Selector.open(); for (Bridge bridge : ConcurrentSet.getBridges()) { for (Sym session : bridge.sessions) { try { if (session.getReceiver() != null && bridge.getState() == BridgeState.RUNNING && session.getReceiver().getDatagramChannel().isOpen()) { session.getReceiver().getDatagramChannel().configureBlocking(false); session.getReceiver().getDatagramChannel().register(selector, SelectionKey.OP_READ); } } catch (ClosedChannelException ex) { // Avoid loading any closed channels in our select set. continue; } } initializeSelectors.set(false); } } catch (IOException ex) { logger.error("Unepxected exception", ex); return; } }
From source file:me.schiz.jmeter.ring.udp.EventLoopRunnable.java
public EventLoopRunnable(Ring ring) { this.ring = ring; byteBuffer = ByteBuffer.allocateDirect(ring.getBufferSize()); registerQueue = new ArrayBlockingQueue<KeyValue>(REGS_PER_ITERATION * 4); try {/* ww w . j av a 2 s. co m*/ this.selector = Selector.open(); } catch (IOException e) { log.error("Can't open selector", e); } }
From source file:net.ymate.platform.serv.nio.support.NioEventProcessor.java
public NioEventProcessor(NioEventGroup<LISTENER> eventGroup, String name) throws IOException { super(name);/*from w w w .j a va 2 s .co m*/ __flag = true; __eventGroup = eventGroup; __selector = Selector.open(); }
From source file:org.reunionemu.jreunion.server.Network.java
public Network() throws Exception { super(); selector = Selector.open(); }
From source file:kilim.nio.NioSelectorScheduler.java
/** * @throws IOException//from w w w .j a v a 2 s .c o m */ public NioSelectorScheduler() throws IOException { this.sel = Selector.open(); selectorThread = new SelectorThread(this); selectorThread.start(); Task t = new RegistrationTask(registrationMbx, sel); t.setScheduler(this); t.start(); }
From source file:eu.stratosphere.nephele.taskmanager.bytebuffered.OutgoingConnectionThread.java
public OutgoingConnectionThread() throws IOException { super("Outgoing Connection Thread"); this.selector = Selector.open(); }
From source file:com.net.monitor.LocalVPNService.java
@Override public void onCreate() { super.onCreate(); isRunning = true;//from w ww .j ava 2 s . co m setupVPN(); try { udpSelector = Selector.open(); tcpSelector = Selector.open(); deviceToNetworkUDPQueue = new ConcurrentLinkedQueue<>(); deviceToNetworkTCPQueue = new ConcurrentLinkedQueue<>(); networkToDeviceQueue = new ConcurrentLinkedQueue<>(); executorService = Executors.newFixedThreadPool(10); executorService.submit(new UDPInput(networkToDeviceQueue, udpSelector)); executorService.submit(new UDPOutput(deviceToNetworkUDPQueue, udpSelector, this)); executorService.submit(new TCPInput(networkToDeviceQueue, tcpSelector)); for (int i = 0; i < VpnConfig.TCP_OUT_THREAD_NUM; i++) { executorService .submit(new TCPOutput(deviceToNetworkTCPQueue, networkToDeviceQueue, tcpSelector, this)); } // executorService.submit(new VpnRead(vpnInterface.getFileDescriptor(), // deviceToNetworkUDPQueue, deviceToNetworkTCPQueue)); // executorService.submit(new VpnWrite(vpnInterface.getFileDescriptor(), networkToDeviceQueue)); executorService.submit(new VpnRunable(vpnInterface.getFileDescriptor(), deviceToNetworkUDPQueue, deviceToNetworkTCPQueue, networkToDeviceQueue)); LocalBroadcastManager.getInstance(this) .sendBroadcast(new Intent(BROADCAST_VPN_STATE).putExtra("running", true)); Log.i(TAG, "Started"); } catch (IOException e) { // TODO: Here and elsewhere, we should explicitly notify the user of any errors // and suggest that they stop the service, since we can't do it ourselves Log.e(TAG, "Error starting service", e); cleanup(); } }