當前位置: 首頁>>代碼示例>>Java>>正文


Java ClosedSelectorException類代碼示例

本文整理匯總了Java中java.nio.channels.ClosedSelectorException的典型用法代碼示例。如果您正苦於以下問題:Java ClosedSelectorException類的具體用法?Java ClosedSelectorException怎麽用?Java ClosedSelectorException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ClosedSelectorException類屬於java.nio.channels包,在下文中一共展示了ClosedSelectorException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: runForever

import java.nio.channels.ClosedSelectorException; //導入依賴的package包/類
/**
 * Runs the event loop and catches any thrown runtime exception and
 * logs it.
 * This routine will exit if the selector is closed during
 * its operation.
 */
public void runForever() {
  // set the I/O thread's priority to max
  Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
  // loop
  while (!(quit_ && selector_.keys().isEmpty())) {
    try {
      run();
    } catch (ClosedSelectorException cse) {
      // time to exit...all keys with sockets are already closed
      break;
    } catch (Exception e) {
      logger_.log(Level.SEVERE, "select loop exception", e);
    }
  }
  if (quit_ && selector_.isOpen()) {
    close();
  }
}
 
開發者ID:bboypscmylife,項目名稱:opengse,代碼行數:25,代碼來源:NetSelector.java

示例2: run

import java.nio.channels.ClosedSelectorException; //導入依賴的package包/類
public void run() {
    System.out.println("MemcachedConnector listening on " + srv_sock.getLocalSocketAddress());
    while(thread != null && Thread.currentThread().equals(thread)) {
        Socket client_sock=null;
        try {
            client_sock=srv_sock.accept();
            // System.out.println("ACCEPT: " + client_sock.getRemoteSocketAddress());
            final RequestHandler handler=new RequestHandler(client_sock);
            /*new Thread() {
                public void run() {
                    handler.run();
                }
            }.start();
            */
            thread_pool.execute(handler);
        }
        catch(ClosedSelectorException closed) {
            Util.close(client_sock);
            break;
        }
        catch(Throwable e) {
        }
    }
}
 
開發者ID:zjumty,項目名稱:jgroups-3.6.4-fixed,代碼行數:25,代碼來源:MemcachedConnector.java

示例3: transitionMethods

import java.nio.channels.ClosedSelectorException; //導入依賴的package包/類
private void transitionMethods() {
  try {
    Iterator<SelectionKey> keys = selector.selectedKeys().iterator();
    while (keys.hasNext()) {
      SelectionKey key = keys.next();
      keys.remove();
      if (!key.isValid()) {
        // this can happen if the method call experienced an error and the
        // key was cancelled. can also happen if we timeout a method, which
        // results in a channel close.
        // just skip
        continue;
      }
      TAsyncMethodCall methodCall = (TAsyncMethodCall)key.attachment();
      methodCall.transition(key);

      // If done or error occurred, remove from timeout watch set
      if (methodCall.isFinished() || methodCall.getClient().hasError()) {
        timeoutWatchSet.remove(methodCall);
      }
    }
  } catch (ClosedSelectorException e) {
    LOGGER.error("Caught ClosedSelectorException in TAsyncClientManager!", e);
  }
}
 
開發者ID:adityayadav76,項目名稱:internet_of_things_simulator,代碼行數:26,代碼來源:TAsyncClientManager.java

示例4: testSerializationSelf

import java.nio.channels.ClosedSelectorException; //導入依賴的package包/類
/**
 * @tests serialization/deserialization compatibility.
 */
@TestTargets({
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "Verifies serialization/deserialization compatibility.",
        method = "!SerializationSelf",
        args = {}
    ),
    @TestTargetNew(
        level = TestLevel.PARTIAL_COMPLETE,
        notes = "Verifies serialization/deserialization compatibility.",
        method = "ClosedSelectorException",
        args = {}
    )
})
public void testSerializationSelf() throws Exception {

    SerializationTest.verifySelf(new ClosedSelectorException());
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:22,代碼來源:ClosedSelectorExceptionTest.java

示例5: testSerializationCompatibility

import java.nio.channels.ClosedSelectorException; //導入依賴的package包/類
/**
 * @tests serialization/deserialization compatibility with RI.
 */
@TestTargets({
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "Verifies serialization/deserialization compatibility.",
        method = "!SerializationGolden",
        args = {}
    ),
    @TestTargetNew(
        level = TestLevel.PARTIAL_COMPLETE,
        notes = "Verifies serialization/deserialization compatibility.",
        method = "ClosedSelectorException",
        args = {}
    )
})
public void testSerializationCompatibility() throws Exception {

    SerializationTest.verifyGolden(this, new ClosedSelectorException());
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:22,代碼來源:ClosedSelectorExceptionTest.java

示例6: doSelect

import java.nio.channels.ClosedSelectorException; //導入依賴的package包/類
protected int doSelect(long timeout) throws IOException {
    if (channelArray == null)
        throw new ClosedSelectorException();
    this.timeout = timeout; // set selector timeout
    processDeregisterQueue();
    if (interruptTriggered) {
        resetWakeupSocket();
        return 0;
    }
    // Calculate number of helper threads needed for poll. If necessary
    // threads are created here and start waiting on startLock
    adjustThreadsCount();
    finishLock.reset(); // reset finishLock
    // Wakeup helper threads, waiting on startLock, so they start polling.
    // Redundant threads will exit here after wakeup.
    startLock.startThreads();
    // do polling in the main thread. Main thread is responsible for
    // first MAX_SELECTABLE_FDS entries in pollArray.
    try {
        begin();
        try {
            subSelector.poll();
        } catch (IOException e) {
            finishLock.setException(e); // Save this exception
        }
        // Main thread is out of poll(). Wakeup others and wait for them
        if (threads.size() > 0)
            finishLock.waitForHelperThreads();
      } finally {
          end();
      }
    // Done with poll(). Set wakeupSocket to nonsignaled  for the next run.
    finishLock.checkForException();
    processDeregisterQueue();
    int updated = updateSelectedKeys();
    // Done with poll(). Set wakeupSocket to nonsignaled  for the next run.
    resetWakeupSocket();
    return updated;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:40,代碼來源:WindowsSelectorImpl.java

示例7: implRegister

import java.nio.channels.ClosedSelectorException; //導入依賴的package包/類
protected void implRegister(SelectionKeyImpl ski) {
    synchronized (closeLock) {
        if (pollWrapper == null)
            throw new ClosedSelectorException();
        growIfNeeded();
        channelArray[totalChannels] = ski;
        ski.setIndex(totalChannels);
        fdMap.put(ski);
        keys.add(ski);
        pollWrapper.addEntry(totalChannels, ski);
        totalChannels++;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:14,代碼來源:WindowsSelectorImpl.java

示例8: putEventOps

import java.nio.channels.ClosedSelectorException; //導入依賴的package包/類
public void putEventOps(SelectionKeyImpl sk, int ops) {
    synchronized (closeLock) {
        if (pollWrapper == null)
            throw new ClosedSelectorException();
        // make sure this sk has not been removed yet
        int index = sk.getIndex();
        if (index == -1)
            throw new CancelledKeyException();
        pollWrapper.putEventOps(index, ops);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:12,代碼來源:WindowsSelectorImpl.java

示例9: lockAndDoSelect

import java.nio.channels.ClosedSelectorException; //導入依賴的package包/類
private int lockAndDoSelect(long timeout) throws IOException {
    synchronized (this) {
        if (!isOpen())
            throw new ClosedSelectorException();
        synchronized (publicKeys) {
            synchronized (publicSelectedKeys) {
                return doSelect(timeout);
            }
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:SelectorImpl.java

示例10: main

import java.nio.channels.ClosedSelectorException; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    final Selector sel = Selector.open();

    Runnable r = new Runnable() {
        public void run() {
            try {
                sel.select();
            } catch (IOException x) {
                x.printStackTrace();
            } catch (ClosedSelectorException y) {
                System.err.println
                    ("Caught expected ClosedSelectorException");
            }
        }
    };

    // start thread to block in Selector
    Thread t = new Thread(r);
    t.start();

    // give thread time to start
    Thread.sleep(1000);

    // interrupt, close, and wakeup is the magic sequence to provoke the NPE
    t.interrupt();
    sel.close();
    sel.wakeup();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:29,代碼來源:WakeupAfterClose.java

示例11: cancelledKeys

import java.nio.channels.ClosedSelectorException; //導入依賴的package包/類
/**
 * Returns the cancelled keys set.
 *
 * @return the cancelled keys set
 */
protected final Set<SelectionKey> cancelledKeys()
{
  if (! isOpen())
    throw new ClosedSelectorException();

  return cancelledKeys;
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:13,代碼來源:AbstractSelector.java

示例12: keys

import java.nio.channels.ClosedSelectorException; //導入依賴的package包/類
public final Set<SelectionKey> keys()
{
  if (!isOpen())
    throw new ClosedSelectorException();

  return Collections.unmodifiableSet (keys);
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:8,代碼來源:SelectorImpl.java

示例13: selectedKeys

import java.nio.channels.ClosedSelectorException; //導入依賴的package包/類
public final Set<SelectionKey> selectedKeys()
{
  if (!isOpen())
    throw new ClosedSelectorException();

  return selected;
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:8,代碼來源:SelectorImpl.java

示例14: keys

import java.nio.channels.ClosedSelectorException; //導入依賴的package包/類
public Set keys()
{
  if (!isOpen())
    throw new ClosedSelectorException();

  return new HashSet(keys.values());
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:8,代碼來源:KqueueSelectorImpl.java

示例15: selectedKeys

import java.nio.channels.ClosedSelectorException; //導入依賴的package包/類
public Set selectedKeys()
{
  if (!isOpen())
    throw new ClosedSelectorException();

  return selected;
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:8,代碼來源:KqueueSelectorImpl.java


注:本文中的java.nio.channels.ClosedSelectorException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。