亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? selectorthread.java

?? Examples to create your Conferencing System in .NET, C# VOIP & Video Conferencing Systems using H.32
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
/*
 * Copyright 2004 WIT-Software, Lda. 
 * - web: http://www.wit-software.com 
 * - email: info@wit-software.com
 *
 * All rights reserved. Relased under terms of the 
 * Creative Commons' Attribution-NonCommercial-ShareAlike license.
 */
package io;


import java.io.IOException;
import java.nio.channels.CancelledKeyException;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import ssl.SSLChannelManager;

/**
 * Event queue for I/O events raised by a selector. This class receives the
 * lower level events raised by a Selector and dispatches them to the 
 * appropriate handler. It also manages all other operations on the selector,
 * like registering and unregistering channels, or updating the events of 
 * interest for each monitored socket.
 *   
 * This class is inspired on the java.awt.EventQueue and follows a similar 
 * model. The EventQueue class is responsible for making sure that all
 * operations on AWT objects are performed on a single thread, the one managed
 * internally by EventQueue. The SelectorThread class performs a similar
 * task. In particular:
 * 
 * - Only the thread created by instances of this class should be allowed 
 * to access the selector and all sockets managed by it. This means that
 * all I/O operations on the sockets should be peformed on the corresponding
 * selector's thread. If some other thread wants to access objects managed
 * by this selector, then it should use <code>invokeLater()</code> or the
 * <code>invokeAndWait()</code> to dispatch a runnable to this thread.
 * 
 * - This thread should not be used to perform lenghty operations. In 
 * particular, it should never be used to perform blocking I/O operations. 
 * To perform a time consuming task use a worker thread.  
 * 
 * 
 * This architecture is required for two main reasons: 
 * 
 * The first, is to make synchronization in the objects of a connection 
 * unnecessary. This is good for performance and essential for keeping 
 * the complexity low. Getting synchronization right within the objects 
 * of a connection would be extremely tricky.
 * 
 * The second is to make sure that all actions over the selector, its 
 * keys and related sockets are carried in the same thread. My personal
 * experience with selectors is that they don't work well when being 
 * accessed concurrently by several threads. This is mostly the result
 * of bugs in some of the version of Sun's Java SDK (these problems were
 * found with version 1.4.2_02). Some of the bugs have already been 
 * identified and fixed by Sun. But it is better to work around them 
 * by avoiding multithreaded access to the selector.
 * 
 * @author Nuno Santos
 */
final public class SelectorThread implements Runnable {
  /** Selector used for I/O multiplexing */
  private Selector selector;
  
  /** The thread associated with this selector */
  private final Thread selectorThread;
  
  /** 
   * Flag telling if this object should terminate, that is, 
   * if it should close the selector and kill the associated 
   * thread. Used for graceful termination.
   */
  private boolean closeRequested = false;
  
  /**
   * List of tasks to be executed in the selector thread.
   * Submitted using invokeLater() and executed in the main
   * select loop.
   */
  private final List pendingInvocations = new ArrayList(32);
  
  private final SSLChannelManager sscManager = new SSLChannelManager();

  /**
   * Creates a new selector and the associated thread. The thread
   * is started by this constructor, thereby making this object 
   * ready to be used. 
   * 
   * @throws IOException
   */
  public SelectorThread() throws IOException {
    // Selector for incoming time requests
    selector = Selector.open();
    selectorThread = new Thread(this);   
    selectorThread.start();
  }
  
  /**
   * Raises an internal flag that will result on this thread dying
   * the next time it goes through the dispatch loop. The thread 
   * executes all pending tasks before dying.
   */
  public void requestClose() {
    closeRequested = true;
    // Nudges the selector.
    selector.wakeup();
  }
  
//  public int getChannelInterest(SelectableChannel channel) {
//  	SelectionKey sk = channel.keyFor(selector);
//  	return sk.interestOps();
//  }
//  
//  public boolean isOperationRegistered(SelectableChannel channel, int op) {
//  	SelectionKey sk = channel.keyFor(selector);  	
//  	return (sk.interestOps() & op) != 0;
//  }
   
  /**
   * Adds a new interest to the list of events where a channel is
   * registered. This means that the associated event handler will
   * start receiving events for the specified interest.
   * 
   * This method should only be called on the selector thread. Otherwise
   * an exception is thrown. Use the addChannelInterestLater() when calling
   * from another thread.
   *  
   * @param channel The channel to be updated. Must be registered.
   * @param interest The interest to add. Should be one of the 
   * constants defined on SelectionKey.
   */
  public void addChannelInterestNow(SelectableChannel channel, 
                                    int interest) throws IOException {
    if (Thread.currentThread() != selectorThread) {
      throw new IOException("Method can only be called from selector thread");
    }
    SelectionKey sk = channel.keyFor(selector);
    changeKeyInterest(sk, sk.interestOps() | interest);
  }

  /**
   * Like addChannelInterestNow(), but executed asynchronouly on the 
   * selector thread. It returns after scheduling the task, without 
   * waiting for it to be executed.
   *
   * @param channel The channel to be updated. Must be registered.
   * @param interest The new interest to add. Should be one of the 
   * constants defined on SelectionKey.
   * @param errorHandler Callback used if an exception is raised when executing the task.
   */
  public void addChannelInterestLater(final SelectableChannel channel, 
																			final int interest,
																			final CallbackErrorHandler errorHandler) {
    // Add a new runnable to the list of tasks to be executed in the selector thread
    invokeLater(new Runnable() {
      public void run() {
        try {
          addChannelInterestNow(channel, interest);
        } catch (IOException e) {
          errorHandler.handleError(e);
        }
      }
    });
  }
  
  /**
   * Removes an interest from the list of events where a channel is
   * registered. The associated event handler will stop receiving events 
   * for the specified interest.
   *
   * This method should only be called on the selector thread. Otherwise
   * an exception is thrown. Use the removeChannelInterestLater() when calling
   * from another thread.
   *  
   * @param channel The channel to be updated. Must be registered.
   * @param interest The interest to be removed. Should be one of the 
   * constants defined on SelectionKey.
   */
  public void removeChannelInterestNow(SelectableChannel channel, 
                                       int interest) throws IOException {
    if (Thread.currentThread() != selectorThread) {
      throw new IOException("Method can only be called from selector thread");
    }
    SelectionKey sk = channel.keyFor(selector);
    changeKeyInterest(sk, sk.interestOps() & ~interest);
  }
  
  /**
   * Like removeChannelInterestNow(), but executed asynchronouly on
   * the selector thread. This method returns after scheduling the task, 
   * without waiting for it to be executed.
   *
   * @param channel The channel to be updated. Must be registered.
   * @param interest The interest to remove. Should be one of the 
   * constants defined on SelectionKey.
   * @param errorHandler Callback used if an exception is raised when 
   * executing the task.
   */
  public void removeChannelInterestLater(final SelectableChannel channel, 
																				 final int interest,
																				 final CallbackErrorHandler errorHandler)  {
    invokeLater(new Runnable() {
      public void run() {
        try {
          removeChannelInterestNow(channel, interest);
        } catch (IOException e) {
          errorHandler.handleError(e);
        }
      }
    });
  }

  /**
   * Updates the interest set associated with a selection key. The 
   * old interest is discarded, being replaced by the new one. 
   * 
   * @param sk The key to be updated.
   * @param newInterest 
   * @throws IOException
   */
  private void changeKeyInterest(SelectionKey sk, 
                         int newInterest) throws IOException {
    /* This method might throw two unchecked exceptions:
     * 1. IllegalArgumentException  - Should never happen. It is a bug if it happens
     * 2. CancelledKeyException - Might happen if the channel is closed while
     * a packet is being dispatched. 
     */
    try {
      sk.interestOps(newInterest);
    } catch (CancelledKeyException cke) {
      IOException ioe = new IOException("Failed to change channel interest.");
      ioe.initCause(cke);
      throw ioe;
    }
  }

  /**
   * Like registerChannelLater(), but executed asynchronouly on the 
   * selector thread. It returns after scheduling the task, without 
   * waiting for it to be executed.
   * 
   * @param channel The channel to be monitored.
   * @param selectionKeys The interest set. Should be a combination of
   * SelectionKey constants.
   * @param handler The handler for events raised on the registered channel.
   * @param errorHandler Used for asynchronous error handling.
   * 
   * @throws IOException
   */
  public void registerChannelLater(final SelectableChannel channel, 
                                   final int selectionKeys, 

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美国产国产综合| 亚洲一区二区三区四区在线观看 | 黄一区二区三区| av网站免费线看精品| 日韩欧美国产一区二区三区| 亚洲天天做日日做天天谢日日欢| 视频一区二区三区中文字幕| 91在线观看高清| 国产人成亚洲第一网站在线播放| 天天综合天天综合色| 91小视频免费观看| 国产欧美日韩另类视频免费观看| 日韩精品91亚洲二区在线观看| 成人激情视频网站| 久久精品欧美一区二区三区麻豆| 日韩精品一区第一页| 在线视频一区二区免费| 一区视频在线播放| 国产91丝袜在线观看| 日韩三级电影网址| 天堂午夜影视日韩欧美一区二区| 91亚洲精品乱码久久久久久蜜桃 | 欧美片在线播放| 亚洲精品成人在线| 91麻豆精品一区二区三区| 国产午夜精品一区二区三区视频| 奇米影视一区二区三区| 在线播放视频一区| 五月天婷婷综合| 在线不卡的av| 日本麻豆一区二区三区视频| 欧美日韩国产在线观看| 亚洲成av人片在线观看无码| 色八戒一区二区三区| 亚洲激情五月婷婷| 色噜噜夜夜夜综合网| 亚洲黄色小说网站| 欧美日韩国产中文| 视频在线在亚洲| 日韩三级在线免费观看| 蜜桃91丨九色丨蝌蚪91桃色| 日韩欧美中文字幕精品| 麻豆高清免费国产一区| 欧美精品一区男女天堂| 国产麻豆视频一区| 国产精品美女一区二区三区| 99精品在线免费| 亚洲va欧美va人人爽午夜| 欧美精品亚洲一区二区在线播放| 日本亚洲天堂网| 国产日韩一级二级三级| 99亚偷拍自图区亚洲| 亚洲国产精品一区二区久久 | 日韩欧美黄色影院| 国产成人综合视频| 亚洲另类在线一区| 欧美丰满少妇xxxxx高潮对白| 青青草97国产精品免费观看无弹窗版 | 欧洲精品在线观看| 日产国产欧美视频一区精品| 精品精品欲导航| 99精品久久99久久久久| 亚洲一区视频在线观看视频| 欧美一区二区在线免费观看| 国产成人在线电影| 亚洲高清三级视频| 久久午夜老司机| 欧美在线短视频| 国产精品亚洲一区二区三区在线 | 欧美zozo另类异族| 91麻豆精东视频| 午夜亚洲国产au精品一区二区| 精品少妇一区二区三区免费观看| 成人91在线观看| 午夜国产精品影院在线观看| 久久久久久久国产精品影院| 欧美三级资源在线| 成人美女在线观看| 久久精品国产免费| 亚洲综合一区二区精品导航| 亚洲精品一区二区三区在线观看| 一本色道亚洲精品aⅴ| 99精品热视频| 一区二区欧美视频| 久久久精品人体av艺术| 欧美视频一区在线| 不卡的av网站| 九九精品一区二区| 天天免费综合色| 亚洲欧美视频在线观看| 久久欧美一区二区| 欧美一区二区三区免费在线看| www.欧美日韩| 国产美女视频一区| 青娱乐精品在线视频| 亚洲一区二区三区四区五区中文 | 中文字幕成人网| 欧美v日韩v国产v| 欧美巨大另类极品videosbest| 99综合影院在线| 波多野结衣视频一区| 国产精品香蕉一区二区三区| 蜜臀av一区二区在线免费观看| 亚洲国产一二三| 亚洲综合免费观看高清完整版在线| 国产视频一区二区在线观看| 精品理论电影在线观看| 日韩欧美美女一区二区三区| 在线电影欧美成精品| 欧美日韩国产一二三| 欧洲精品中文字幕| 欧美日韩一区高清| 欧美日韩国产经典色站一区二区三区 | 中文字幕亚洲精品在线观看| 国产欧美日韩综合精品一区二区 | 亚洲亚洲精品在线观看| 久久精品亚洲乱码伦伦中文 | 91久久免费观看| 91丝袜美女网| 色老汉av一区二区三区| a美女胸又www黄视频久久| 成人小视频在线| 9色porny自拍视频一区二区| 岛国精品在线播放| 色综合中文字幕| 91福利在线看| 5月丁香婷婷综合| 日韩免费性生活视频播放| 精品国产免费久久 | 国产在线麻豆精品观看| 国产伦精一区二区三区| 福利一区二区在线| 99久久精品国产一区二区三区| 91在线精品秘密一区二区| 91黄色免费网站| 这里只有精品视频在线观看| 欧美一区二区国产| 日本一区二区三区高清不卡| 亚洲欧洲一区二区三区| 性做久久久久久久免费看| 久久不见久久见中文字幕免费| 国产乱码精品一区二区三| 91社区在线播放| 欧美色网一区二区| 3atv一区二区三区| 国产精品全国免费观看高清 | 欧美在线一二三| 日韩女优av电影在线观看| 久久精品亚洲精品国产欧美kt∨| 亚洲欧洲日产国码二区| 亚洲国产日韩av| 欧美精品 国产精品| 欧美三级中文字幕在线观看| 久久一区二区三区四区| 亚洲美女视频在线观看| 免费精品99久久国产综合精品| 成人午夜免费视频| 欧美精品日韩精品| 中文字幕在线一区二区三区| 香蕉影视欧美成人| 不卡高清视频专区| 日韩一区二区在线观看视频播放| 国产精品久久午夜| 精品一区二区三区日韩| 91浏览器在线视频| 久久亚洲一级片| 亚洲超碰精品一区二区| 国产91精品一区二区| 日韩欧美高清一区| 亚洲一区二区三区视频在线播放 | 亚洲国产aⅴ成人精品无吗| 国产精品一级片| 91精品欧美一区二区三区综合在| 国产精品免费人成网站| 国内成+人亚洲+欧美+综合在线| 日本久久电影网| 久久精品人人爽人人爽| 日本在线播放一区二区三区| 91久久精品一区二区| 中文在线一区二区| 韩国一区二区视频| 91精品福利在线一区二区三区 | 日韩国产欧美在线视频| 日本大香伊一区二区三区| 国产丝袜在线精品| 国内精品久久久久影院色| 欧美日韩高清一区二区| 亚洲精品国产高清久久伦理二区| 国产美女久久久久| 久久九九久精品国产免费直播| 日本aⅴ精品一区二区三区| 欧美日韩在线精品一区二区三区激情| 国产精品久久久久aaaa| 国产伦精品一区二区三区视频青涩 | 亚洲国产精品99久久久久久久久 | 午夜精品123| 欧美无乱码久久久免费午夜一区| 中文字幕在线观看一区二区| 成人小视频在线| 欧美激情一区在线观看|