public void run() { while (true) { LinkedList<PacketCallbackStruct> list = null; try { queuedPacketCallbacksLock.lock(); try { queuedPacketCallbacksNotEmpty.await(); } catch (Exception e) { Log.error( "RDPServer.PacketCallbackThread: queuedPacketCallbacksNotEmpty.await() caught exception " + e.getMessage()); } list = queuedPacketCallbacks; queuedPacketCallbacks = new LinkedList<PacketCallbackStruct>(); } finally { queuedPacketCallbacksLock.unlock(); } if (Log.loggingNet) Log.net("RDPServer.PacketCallbackThread: Got " + list.size() + " queued packets"); for (PacketCallbackStruct pcs : list) { try { callbackProcessPacket(pcs.cb, pcs.con, pcs.packet); } catch (Exception e) { Log.exception("RDPServer.PacketCallbackThread: ", e); } } } }
public void run() { try { for (; ; ) { Target t = null; synchronized (pending) { while (pending.size() == 0) pending.wait(); t = (Target) pending.removeFirst(); } t.show(); } } catch (InterruptedException x) { return; } }
public void printFinishedTargets() { // 打印finisedTargets队列中的任务 try { for (; ; ) { Target target = null; synchronized (finishedTargets) { while (finishedTargets.size() == 0) finishedTargets.wait(); target = (Target) finishedTargets.removeFirst(); } target.show(); } } catch (InterruptedException x) { return; } }
void processPendingTargets() throws IOException { synchronized (pending) { while (pending.size() > 0) { Target t = (Target) pending.removeFirst(); try { t.channel.register(sel, SelectionKey.OP_CONNECT, t); } catch (IOException x) { t.channel.close(); t.failure = x; printer.add(t); } } } }
public void registerTargets() { // 取出targets队列中的任务,向Selector注册连接就绪事件 synchronized (targets) { while (targets.size() > 0) { Target target = (Target) targets.removeFirst(); try { target.channel.register(selector, SelectionKey.OP_CONNECT, target); } catch (IOException x) { try { target.channel.close(); } catch (IOException e) { e.printStackTrace(); } target.failure = x; addFinishedTarget(target); } } } }
private void processPending() { synchronized (pending) { while (pending.size() > 0) { SocketEntry entry = (SocketEntry) pending.removeFirst(); try { // Register the channel with the selector, indicating // interest in connection completion and attaching the // target object so that we can get the target back // after the key is added to the selector's // selected-key set if (entry.getSocket().isConnected()) { entry.getSocket().getChannel().register(selector, SelectionKey.OP_WRITE, entry); } else { entry.getSocket().getChannel().register(selector, SelectionKey.OP_CONNECT, entry); } } catch (IOException iox) { logger.error(iox); // Something went wrong, so close the channel and // record the failure try { entry.getSocket().getChannel().close(); TransportStateEvent e = new TransportStateEvent( DefaultTcpTransportMapping.this, entry.getPeerAddress(), TransportStateEvent.STATE_CLOSED, iox); fireConnectionStateChanged(e); } catch (IOException ex) { logger.error(ex); } lastError = iox; } } } }