当前位置: 首页>>代码示例>>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;未经允许,请勿转载。