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


Java CancelledKeyException類代碼示例

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


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

示例1: doAsyncWrite

import java.nio.channels.CancelledKeyException; //導入依賴的package包/類
private void doAsyncWrite(SelectionKey key) throws IOException {
  Call call = (Call)key.attachment();
  if (call == null) {
    return;
  }
  if (key.channel() != call.connection.channel) {
    throw new IOException("doAsyncWrite: bad channel");
  }

  synchronized(call.connection.responseQueue) {
    if (processResponse(call.connection.responseQueue, false)) {
      try {
        key.interestOps(0);
      } catch (CancelledKeyException e) {
        /* The Listener/reader might have closed the socket.
         * We don't explicitly cancel the key, so not sure if this will
         * ever fire.
         * This warning could be removed.
         */
        LOG.warn("Exception while changing ops : " + e);
      }
    }
  }
}
 
開發者ID:tenggyut,項目名稱:HIndex,代碼行數:25,代碼來源:RpcServer.java

示例2: processDebuggerActivity

import java.nio.channels.CancelledKeyException; //導入依賴的package包/類
private void processDebuggerActivity(SelectionKey key) {
    Debugger dbg = (Debugger)key.attachment();

    try {
        if (key.isAcceptable()) {
            try {
                acceptNewDebugger(dbg, null);
            } catch (IOException ioe) {
                Log.w("ddms", "debugger accept() failed");
                ioe.printStackTrace();
            }
        } else if (key.isReadable()) {
            processDebuggerData(key);
        } else {
            Log.d("ddm-debugger", "key in unknown state");
        }
    } catch (CancelledKeyException cke) {
        // key has been cancelled we can ignore that.
    }
}
 
開發者ID:i25ffz,項目名稱:screenshot,代碼行數:21,代碼來源:MonitorThread.java

示例3: sendPacket

import java.nio.channels.CancelledKeyException; //導入依賴的package包/類
public final void sendPacket(final SendablePacket<T> sp)
 {
     sp._client = _client;

     if (_pendingClose)
return;
     
     synchronized (getSendQueue())
     {
     	_sendQueue.addLast(sp);
     }

     if (!_sendQueue.isEmpty())
     {
         try
         {
             _selectionKey.interestOps(_selectionKey.interestOps() | SelectionKey.OP_WRITE);
         }
         catch (CancelledKeyException e)
         {
             // ignore
         }
     }
 }
 
開發者ID:L2jBrasil,項目名稱:L2jBrasil,代碼行數:25,代碼來源:MMOConnection.java

示例4: sendPacket

import java.nio.channels.CancelledKeyException; //導入依賴的package包/類
public final void sendPacket(SendablePacket<T> sp)
{
	sp._client = _client;
	
	if (_pendingClose)
	{
		return;
	}
	
	synchronized (getSendQueue())
	{
		_sendQueue.addLast(sp);
	}
	
	if (!_sendQueue.isEmpty())
	{
		try
		{
			_selectionKey.interestOps(_selectionKey.interestOps() | SelectionKey.OP_WRITE);
		}
		catch (CancelledKeyException e)
		{
			// ignore
		}
	}
}
 
開發者ID:rubenswagner,項目名稱:L2J-Global,代碼行數:27,代碼來源:MMOConnection.java

示例5: registerSelector

import java.nio.channels.CancelledKeyException; //導入依賴的package包/類
public static SelectionKey registerSelector(final Selector selector,
        final SocketChannel channel, final int op)
        throws CancelledKeyException, ClosedChannelException {
    // Register the selector at the channel, so that it will be notified
    // on the socket's events
    synchronized (RegisterGate) {
        // Wakeup the currently blocking reader/writer thread; we have
        // locked the RegisterGate to prevent the awakened thread to block again
        selector.wakeup();

        // Lock the selector to prevent the waiting worker threads going
        // into selector.select() which would block the selector.
        synchronized (selector) {
            return channel.register(selector, op, null);
        }
    }
}
 
開發者ID:Anoncheg1,項目名稱:dibd,代碼行數:18,代碼來源:NNTPDaemon.java

示例6: testValidSelectionKey

import java.nio.channels.CancelledKeyException; //導入依賴的package包/類
@Test(timeout = 30000)
public void testValidSelectionKey() throws Exception {
    final ZooKeeper zk = createZKClient(hostPort, 3000);
    try {
        Iterable<ServerCnxn> connections = serverFactory.getConnections();
        for (ServerCnxn serverCnxn : connections) {
            MockNIOServerCnxn mock = new MockNIOServerCnxn((NIOServerCnxn) serverCnxn);
            // Cancel key
            ((NIOServerCnxn) serverCnxn).sock.keyFor(((NIOServerCnxnFactory) serverFactory).selector).cancel();;
            mock.mockSendBuffer(ByteBuffer.allocate(8));
        }
    } catch (CancelledKeyException e) {
        LOG.error("Exception while sending bytes!", e);
        Assert.fail(e.toString());
    } finally {
        zk.close();
    }
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:19,代碼來源:NIOServerCnxnTest.java

示例7: doAsyncWrite

import java.nio.channels.CancelledKeyException; //導入依賴的package包/類
private void doAsyncWrite(SelectionKey key) throws IOException {
  Connection connection = (Connection) key.attachment();
  if (connection == null) {
    throw new IOException("doAsyncWrite: no connection");
  }
  if (key.channel() != connection.channel) {
    throw new IOException("doAsyncWrite: bad channel");
  }

  if (processAllResponses(connection)) {
    try {
      // We wrote everything, so we don't need to be told when the socket is ready for
      //  write anymore.
     key.interestOps(0);
    } catch (CancelledKeyException e) {
      /* The Listener/reader might have closed the socket.
       * We don't explicitly cancel the key, so not sure if this will
       * ever fire.
       * This warning could be removed.
       */
      LOG.warn("Exception while changing ops : " + e);
    }
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:25,代碼來源:RpcServer.java

示例8: disable

import java.nio.channels.CancelledKeyException; //導入依賴的package包/類
private void disable()
{
   if (m_enabled)
   {
      try
      {
         m_key.interestOps(0);               // pass zero which means that we are not interested in being
                                             // notified of anything for this channel.
      }
      catch (CancelledKeyException eat)      // If we finished writing and didn't get an exception, then
      {                                      // we probably don't need to throw this exception (if they try to write
                                             // again, we will then throw an exception).
      }
      m_enabled = false;
   }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:17,代碼來源:ConnectionTableNIO.java

示例9: send

import java.nio.channels.CancelledKeyException; //導入依賴的package包/類
/**
 * Send a message. Whether it's over TCP or UDP is determined by the message flag.
 *
 * @param message The message to send.
 * @throws IOException When a writing error occurs.
 */
public void send(Message message) throws IOException {
    if (!isConnected) throw new IOException("Not connected yet. Use connect() first.");

    try {
        if (message.isReliable()) {
            messageQueue.add(message);
            if (!isConnector) {
                tcp.socketChannel.keyFor(tcp.selector).interestOps(SelectionKey.OP_READ | SelectionKey.OP_WRITE);
            } else {
                tcpChannel.keyFor(tcp.selector).interestOps(SelectionKey.OP_READ | SelectionKey.OP_WRITE);
            }
        } else {
            udp.sendObject(message);
        }
    } catch (CancelledKeyException e) {
        // Client was disconnected.
    }
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:25,代碼來源:Client.java

示例10: processKeyChangeRequests

import java.nio.channels.CancelledKeyException; //導入依賴的package包/類
private void processKeyChangeRequests() {
	KeyChangeRequest keyChangeRequest;

	if (AsyncGlobals.debug && debug) {
		Log.fine("processKeyChangeRequests");
	}
	do {
		keyChangeRequest = keyChangeRequests.poll();
		if (keyChangeRequest != null) {
			try {
				processKeyChangeRequest(keyChangeRequest);
			} catch (CancelledKeyException cke) {
				Log.warning("Ignoring CancelledKeyException");
			}
	    }
	} while (keyChangeRequest != null);
}
 
開發者ID:Morgan-Stanley,項目名稱:SilverKing,代碼行數:18,代碼來源:SelectorController.java

示例11: interestOps

import java.nio.channels.CancelledKeyException; //導入依賴的package包/類
public SelectionKey interestOps(int ops)
{
  if (cancelled)
    throw new CancelledKeyException();
  if ((ops & ~(channel.validOps())) != 0)
    throw new IllegalArgumentException("unsupported channel ops");
  try
    {
      selector.epoll_modify(this, ops);
      interestOps = ops;
    }
  catch (IOException ioe)
    {
      throw new IllegalArgumentException(ioe);
    }
  return this;
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:18,代碼來源:EpollSelectionKeyImpl.java

示例12: run

import java.nio.channels.CancelledKeyException; //導入依賴的package包/類
@Override
public void run() {

    if (selfCancel) {
        throw new CancelledKeyException();
    }

    if (cancelled) {
        terminated = true;
        disposeTimer();
    }
    queue.offer(NEXT);
    if (enter()) {
        drainLoop();
    }

}
 
開發者ID:akarnokd,項目名稱:rxjava2-backport,代碼行數:18,代碼來源:NbpOperatorWindowTimed.java

示例13: run

import java.nio.channels.CancelledKeyException; //導入依賴的package包/類
@Override
public void run() {

    if (selfCancel) {
        throw new CancelledKeyException();
    }

    if (cancelled) {
        terminated = true;
        dispose();
    }
    queue.offer(NEXT);
    if (enter()) {
        drainLoop();
    }

}
 
開發者ID:akarnokd,項目名稱:rxjava2-backport,代碼行數:18,代碼來源:OperatorWindowTimed.java

示例14: doRegister

import java.nio.channels.CancelledKeyException; //導入依賴的package包/類
@Override
protected void doRegister() throws Exception {
    boolean selected = false;
    for (;;) {
        try {
            selectionKey = javaChannel().register(eventLoop().selector, 0, this);
            return;
        } catch (CancelledKeyException e) {
            if (!selected) {
                // Force the Selector to select now as the "canceled" SelectionKey may still be
                // cached and not removed because no Select.select(..) operation was called yet.
                eventLoop().selectNow();
                selected = true;
            } else {
                // We forced a select operation on the selector before but the SelectionKey is still cached
                // for whatever reason. JDK bug ?
                throw e;
            }
        }
    }
}
 
開發者ID:wuyinxian124,項目名稱:netty4.0.27Learn,代碼行數:22,代碼來源:AbstractNioChannel.java

示例15: setInterestOp

import java.nio.channels.CancelledKeyException; //導入依賴的package包/類
/**
 * Set one or more SelectionKey bits in the select mask.
 * 
 * May be called from outside Worker thread
 * May recursively lock selectorLock_
 * 
 * @param op - OP_READ | OP_WRITE: may be 0 just to force wakeup
 */
private void setInterestOp(int op) {
    synchronized (selectorLock_) {
        final SelectionKey key = selectionKey_;
        if (key != null && key.isValid()) {
            try {
                key.interestOps(key.interestOps() | op);
                
                /*
                 * We could check that we have actually changed the mask before
                 * invoking a wakeup. The usage pattern, however, is such that
                 * such a check would almost always be true.
                 */
                final Selector selector = key.selector();
                // Check "isOpen" to avoid Android crash see
                //   https://code.google.com/p/android/issues/detail?id=80785
                if (selector.isOpen()) {
                    selector.wakeup();
                }
            } catch (CancelledKeyException e) {
                // channel has been closed
            }
        }
    }
}
 
開發者ID:swift,項目名稱:stroke,代碼行數:33,代碼來源:JavaConnection.java


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