Java 类java.nio.channels.spi.AbstractSelectableChannel 实例源码

项目:BiglyBT    文件:VirtualChannelSelector.java   
/**
 * Pause selection operations for the given channel
 * @param channel to pause
 */
public void pauseSelects( AbstractSelectableChannel channel ) {
  if( SAFE_SELECTOR_MODE_ENABLED ) {
    try{  selectors_mon.enter();
        //System.out.println( "pause - " + channel.hashCode() + " - " + Debug.getCompressedStackTrace());
    for( Map.Entry<VirtualChannelSelectorImpl, ArrayList<AbstractSelectableChannel>> entry: selectors.entrySet()) {

        VirtualChannelSelectorImpl          sel         = entry.getKey();
        ArrayList<AbstractSelectableChannel>    channels    = entry.getValue();

        if( channels.contains( channel ) ) {
          sel.pauseSelects( channel );
          return;
        }
      }

      Debug.out( "pauseSelects():: channel not found!" );
    }
    finally{ selectors_mon.exit();  }
  }
  else {
    selector_impl.pauseSelects( channel );
  }
}
项目:BiglyBT    文件:VirtualChannelSelector.java   
/**
 * Resume selection operations for the given channel
 * @param channel to resume
 */
public void resumeSelects( AbstractSelectableChannel channel ) {
  if( SAFE_SELECTOR_MODE_ENABLED ) {
    try{  selectors_mon.enter();
        //System.out.println( "resume - " + channel.hashCode() + " - " + Debug.getCompressedStackTrace());
    for( Map.Entry<VirtualChannelSelectorImpl, ArrayList<AbstractSelectableChannel>> entry: selectors.entrySet()) {

        VirtualChannelSelectorImpl          sel         = entry.getKey();
        ArrayList<AbstractSelectableChannel>    channels    = entry.getValue();

        if( channels.contains( channel ) ) {
          sel.resumeSelects( channel );
          return;
        }
      }

      Debug.out( "resumeSelects():: channel not found!" );
    }
    finally{ selectors_mon.exit();  }
  }
  else {
    selector_impl.resumeSelects( channel );
  }
}
项目:BiglyBT    文件:VirtualChannelSelector.java   
/**
 * Cancel the selection operations for the given channel.
 * @param channel channel originally registered
 */
public void cancel( AbstractSelectableChannel channel ) {
  if( SAFE_SELECTOR_MODE_ENABLED ) {
    try{  selectors_mon.enter();
        //System.out.println( "cancel - " + channel.hashCode()  + " - " + Debug.getCompressedStackTrace());
    for( Map.Entry<VirtualChannelSelectorImpl, ArrayList<AbstractSelectableChannel>> entry: selectors.entrySet()) {

        VirtualChannelSelectorImpl          sel         = entry.getKey();
        ArrayList<AbstractSelectableChannel>    channels    = entry.getValue();

        if( channels.remove( channel ) ) {
          sel.cancel( channel );
          return;
        }
      }
    }
    finally{ selectors_mon.exit();  }
  }
  else {
    if( selector_impl != null )  selector_impl.cancel( channel );
  }
}
项目:BiglyBT    文件:VirtualChannelSelector.java   
public void
 selectFailure(
VirtualAbstractSelectorListener     listener,
AbstractSelectableChannel           sc,
Object                              attachment,
Throwable                           msg)
 {
  if ( op == OP_ACCEPT ){

      ((VirtualAcceptSelectorListener)listener).selectFailure( VirtualChannelSelector.this, (ServerSocketChannel)sc, attachment, msg );
  }else{

      ((VirtualSelectorListener)listener).selectFailure( VirtualChannelSelector.this, (SocketChannel)sc, attachment, msg );

  }
 }
项目:BiglyBT    文件:VirtualChannelSelectorImpl.java   
public void pauseSelects( AbstractSelectableChannel channel ) {

      //System.out.println( "pauseSelects: " + channel + " - " + Debug.getCompressedStackTrace() );

      if( channel == null ) {
        return;
      }

      SelectionKey key = channel.keyFor( selector );

      if( key != null && key.isValid() ) {
        key.interestOps( key.interestOps() & ~INTEREST_OP );
      }
      else {  //channel not (yet?) registered
        if( channel.isOpen() ) {  //only bother if channel has not already been closed
          try{  register_cancel_list_mon.enter();

            paused_states.put( channel, Boolean.TRUE);  //ensure the op is paused upon reg select-time reg

          }
          finally{  register_cancel_list_mon.exit();  }
        }
      }
    }
项目:Direct-File-Downloader    文件:VirtualChannelSelector.java   
/**
 * Pause selection operations for the given channel
 * @param channel to pause
 */
public void pauseSelects( AbstractSelectableChannel channel ) {
  if( SAFE_SELECTOR_MODE_ENABLED ) {
    try{  selectors_mon.enter();
        //System.out.println( "pause - " + channel.hashCode() + " - " + Debug.getCompressedStackTrace());
    for( Map.Entry<VirtualChannelSelectorImpl, ArrayList<AbstractSelectableChannel>> entry: selectors.entrySet()) {

        VirtualChannelSelectorImpl          sel         = entry.getKey();
        ArrayList<AbstractSelectableChannel>    channels    = entry.getValue();

        if( channels.contains( channel ) ) {
          sel.pauseSelects( channel );
          return;
        }
      }

      Debug.out( "pauseSelects():: channel not found!" );
    }
    finally{ selectors_mon.exit();  }
  }
  else {
    selector_impl.pauseSelects( channel );
  }
}
项目:Direct-File-Downloader    文件:VirtualChannelSelector.java   
/**
 * Resume selection operations for the given channel
 * @param channel to resume
 */
public void resumeSelects( AbstractSelectableChannel channel ) {
  if( SAFE_SELECTOR_MODE_ENABLED ) {
    try{  selectors_mon.enter();
        //System.out.println( "resume - " + channel.hashCode() + " - " + Debug.getCompressedStackTrace());
    for( Map.Entry<VirtualChannelSelectorImpl, ArrayList<AbstractSelectableChannel>> entry: selectors.entrySet()) {

        VirtualChannelSelectorImpl          sel         = entry.getKey();
        ArrayList<AbstractSelectableChannel>    channels    = entry.getValue();

        if( channels.contains( channel ) ) {
          sel.resumeSelects( channel );
          return;
        }
      }

      Debug.out( "resumeSelects():: channel not found!" );
    }
    finally{ selectors_mon.exit();  }
  }
  else {
    selector_impl.resumeSelects( channel );
  }
}
项目:Direct-File-Downloader    文件:VirtualChannelSelector.java   
/**
 * Cancel the selection operations for the given channel.
 * @param channel channel originally registered
 */
public void cancel( AbstractSelectableChannel channel ) {
  if( SAFE_SELECTOR_MODE_ENABLED ) {
    try{  selectors_mon.enter();
        //System.out.println( "cancel - " + channel.hashCode()  + " - " + Debug.getCompressedStackTrace());
    for( Map.Entry<VirtualChannelSelectorImpl, ArrayList<AbstractSelectableChannel>> entry: selectors.entrySet()) {

        VirtualChannelSelectorImpl          sel         = entry.getKey();
        ArrayList<AbstractSelectableChannel>    channels    = entry.getValue();

        if( channels.remove( channel ) ) {
          sel.cancel( channel );
          return;
        }
      }
    }
    finally{ selectors_mon.exit();  }
  }
  else {
    if( selector_impl != null )  selector_impl.cancel( channel );
  }
}
项目:Direct-File-Downloader    文件:VirtualChannelSelector.java   
public void
 selectFailure(
VirtualAbstractSelectorListener     listener,
AbstractSelectableChannel           sc, 
Object                              attachment, 
Throwable                           msg)
 {
  if ( op == OP_ACCEPT ){

      ((VirtualAcceptSelectorListener)listener).selectFailure( VirtualChannelSelector.this, (ServerSocketChannel)sc, attachment, msg );
  }else{

      ((VirtualSelectorListener)listener).selectFailure( VirtualChannelSelector.this, (SocketChannel)sc, attachment, msg );

  }
 }
项目:Direct-File-Downloader    文件:VirtualChannelSelectorImpl.java   
public void pauseSelects( AbstractSelectableChannel channel ) {

  //System.out.println( "pauseSelects: " + channel + " - " + Debug.getCompressedStackTrace() );

  if( channel == null ) {
    return;
  }

  SelectionKey key = channel.keyFor( selector );

  if( key != null && key.isValid() ) {
    key.interestOps( key.interestOps() & ~INTEREST_OP );
  }
  else {  //channel not (yet?) registered
    if( channel.isOpen() ) {  //only bother if channel has not already been closed
      try{  register_cancel_list_mon.enter();

        paused_states.put( channel, new Boolean( true ) );  //ensure the op is paused upon reg select-time reg

      }
      finally{  register_cancel_list_mon.exit();  }
    }
  }
}
项目:Coerce    文件:NioEventExecutor.java   
public void register(AbstractSelectableChannel channel, GroupPurpose purpose, Object attachment) {
    int ops = 0;

    switch (purpose) {
        case ACCEPT:
        default:
            ops = SelectionKey.OP_ACCEPT;
            break;

        case IO:
            ops = SelectionKey.OP_READ | SelectionKey.OP_WRITE;
            break;
    }

    try {
        if (attachment != null) {
            channel.register(this.selector, ops, attachment);
        } else {
            channel.register(this.selector, ops);
        }
    } catch (Exception e) {
        log.warn("Error during selector registration", e);
    }
}
项目:javify    文件:SelectorImpl.java   
protected final SelectionKey register (AbstractSelectableChannel ch, int ops,
                                       Object att)
{
  SelectionKeyImpl result;

  if (ch instanceof SocketChannelImpl)
    result = new SocketChannelSelectionKey (ch, this);
  else if (ch instanceof DatagramChannelImpl)
    result = new DatagramChannelSelectionKey (ch, this);
  else if (ch instanceof ServerSocketChannelImpl)
    result = new ServerSocketChannelSelectionKey (ch, this);
  else if (ch instanceof gnu.java.nio.SocketChannelImpl)
    result = new gnu.java.nio.SocketChannelSelectionKeyImpl((gnu.java.nio.SocketChannelImpl)ch, this);
  else
    throw new InternalError ("No known channel type");

  synchronized (keys)
    {
      keys.add (result);

      result.interestOps (ops);
      result.attach (att);
    }

  return result;
}
项目:jvm-stm    文件:SelectorImpl.java   
protected final SelectionKey register (AbstractSelectableChannel ch, int ops,
                                        Object att)
 {
   SelectionKeyImpl result;

   if (ch instanceof SocketChannelImpl)
     result = new SocketChannelSelectionKey (ch, this);
   else if (ch instanceof DatagramChannelImpl)
     result = new DatagramChannelSelectionKey (ch, this);
   else if (ch instanceof ServerSocketChannelImpl)
     result = new ServerSocketChannelSelectionKey (ch, this);
   else if (ch instanceof gnu.java.nio.SocketChannelImpl)
     result = new gnu.java.nio.SocketChannelSelectionKeyImpl((gnu.java.nio.SocketChannelImpl)ch, this);
   else
     throw new InternalError ("No known channel type");

   synchronized (keys)
     {
       keys.add (result);

result.interestOps (ops);
result.attach (att);
     }

   return result;
 }
项目:In-the-Box-Fork    文件:AbstractSelectorTest.java   
/**
 * @tests AbstractSelector#register(AbstractSelectableChannel,int,Object)
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "Verifies register method from SelectableChannel class.",
    method = "register",
    args = {AbstractSelectableChannel.class, int.class, java.lang.Object.class}
)
public void test_register_LAbstractSelectableChannelIObject()
        throws Exception {
    Selector acceptSelector = new MockSelectorProvider().openSelector();
    ServerSocketChannel ssc = ServerSocketChannel.open();
    ssc.configureBlocking(false);

    assertFalse(ssc.isRegistered());
    ssc.register(acceptSelector, SelectionKey.OP_ACCEPT);
    assertTrue(ssc.isRegistered());
    assertTrue(((MockAbstractSelector)acceptSelector).isRegisterCalled);
}
项目:AcademicTorrents-Downloader    文件:VirtualChannelSelector.java   
/**
 * Pause selection operations for the given channel
 * @param channel to pause
 */
public void pauseSelects( AbstractSelectableChannel channel ) {
  if( SAFE_SELECTOR_MODE_ENABLED ) {
    try{  selectors_mon.enter();
        //System.out.println( "pause - " + channel.hashCode() + " - " + Debug.getCompressedStackTrace());
    for( Map.Entry<VirtualChannelSelectorImpl, ArrayList<AbstractSelectableChannel>> entry: selectors.entrySet()) {

        VirtualChannelSelectorImpl          sel         = entry.getKey();
        ArrayList<AbstractSelectableChannel>    channels    = entry.getValue();

        if( channels.contains( channel ) ) {
          sel.pauseSelects( channel );
          return;
        }
      }

      Debug.out( "pauseSelects():: channel not found!" );
    }
    finally{ selectors_mon.exit();  }
  }
  else {
    selector_impl.pauseSelects( channel );
  }
}
项目:AcademicTorrents-Downloader    文件:VirtualChannelSelector.java   
/**
 * Resume selection operations for the given channel
 * @param channel to resume
 */
public void resumeSelects( AbstractSelectableChannel channel ) {
  if( SAFE_SELECTOR_MODE_ENABLED ) {
    try{  selectors_mon.enter();
        //System.out.println( "resume - " + channel.hashCode() + " - " + Debug.getCompressedStackTrace());
    for( Map.Entry<VirtualChannelSelectorImpl, ArrayList<AbstractSelectableChannel>> entry: selectors.entrySet()) {

        VirtualChannelSelectorImpl          sel         = entry.getKey();
        ArrayList<AbstractSelectableChannel>    channels    = entry.getValue();

        if( channels.contains( channel ) ) {
          sel.resumeSelects( channel );
          return;
        }
      }

      Debug.out( "resumeSelects():: channel not found!" );
    }
    finally{ selectors_mon.exit();  }
  }
  else {
    selector_impl.resumeSelects( channel );
  }
}
项目:AcademicTorrents-Downloader    文件:VirtualChannelSelector.java   
/**
 * Cancel the selection operations for the given channel.
 * @param channel channel originally registered
 */
public void cancel( AbstractSelectableChannel channel ) {
  if( SAFE_SELECTOR_MODE_ENABLED ) {
    try{  selectors_mon.enter();
        //System.out.println( "cancel - " + channel.hashCode()  + " - " + Debug.getCompressedStackTrace());
    for( Map.Entry<VirtualChannelSelectorImpl, ArrayList<AbstractSelectableChannel>> entry: selectors.entrySet()) {

        VirtualChannelSelectorImpl          sel         = entry.getKey();
        ArrayList<AbstractSelectableChannel>    channels    = entry.getValue();

        if( channels.remove( channel ) ) {
          sel.cancel( channel );
          return;
        }
      }
    }
    finally{ selectors_mon.exit();  }
  }
  else {
    if( selector_impl != null )  selector_impl.cancel( channel );
  }
}
项目:AcademicTorrents-Downloader    文件:VirtualChannelSelector.java   
public void
 selectFailure(
VirtualAbstractSelectorListener     listener,
AbstractSelectableChannel           sc, 
Object                              attachment, 
Throwable                           msg)
 {
  if ( op == OP_ACCEPT ){

      ((VirtualAcceptSelectorListener)listener).selectFailure( VirtualChannelSelector.this, (ServerSocketChannel)sc, attachment, msg );
  }else{

      ((VirtualSelectorListener)listener).selectFailure( VirtualChannelSelector.this, (SocketChannel)sc, attachment, msg );

  }
 }
项目:AcademicTorrents-Downloader    文件:VirtualChannelSelectorImpl.java   
public void pauseSelects( AbstractSelectableChannel channel ) {

  //System.out.println( "pauseSelects: " + channel + " - " + Debug.getCompressedStackTrace() );

  if( channel == null ) {
    return;
  }

  SelectionKey key = channel.keyFor( selector );

  if( key != null && key.isValid() ) {
    key.interestOps( key.interestOps() & ~INTEREST_OP );
  }
  else {  //channel not (yet?) registered
    if( channel.isOpen() ) {  //only bother if channel has not already been closed
      try{  register_cancel_list_mon.enter();

        paused_states.put( channel, new Boolean( true ) );  //ensure the op is paused upon reg select-time reg

      }
      finally{  register_cancel_list_mon.exit();  }
    }
  }
}
项目:AcademicTorrents-Downloader    文件:VirtualChannelSelector.java   
/**
 * Pause selection operations for the given channel
 * @param channel to pause
 */
public void pauseSelects( AbstractSelectableChannel channel ) {
  if( SAFE_SELECTOR_MODE_ENABLED ) {
    try{  selectors_mon.enter();
        //System.out.println( "pause - " + channel.hashCode() + " - " + Debug.getCompressedStackTrace());
    for( Map.Entry<VirtualChannelSelectorImpl, ArrayList<AbstractSelectableChannel>> entry: selectors.entrySet()) {

        VirtualChannelSelectorImpl          sel         = entry.getKey();
        ArrayList<AbstractSelectableChannel>    channels    = entry.getValue();

        if( channels.contains( channel ) ) {
          sel.pauseSelects( channel );
          return;
        }
      }

      Debug.out( "pauseSelects():: channel not found!" );
    }
    finally{ selectors_mon.exit();  }
  }
  else {
    selector_impl.pauseSelects( channel );
  }
}
项目:AcademicTorrents-Downloader    文件:VirtualChannelSelector.java   
/**
 * Resume selection operations for the given channel
 * @param channel to resume
 */
public void resumeSelects( AbstractSelectableChannel channel ) {
  if( SAFE_SELECTOR_MODE_ENABLED ) {
    try{  selectors_mon.enter();
        //System.out.println( "resume - " + channel.hashCode() + " - " + Debug.getCompressedStackTrace());
    for( Map.Entry<VirtualChannelSelectorImpl, ArrayList<AbstractSelectableChannel>> entry: selectors.entrySet()) {

        VirtualChannelSelectorImpl          sel         = entry.getKey();
        ArrayList<AbstractSelectableChannel>    channels    = entry.getValue();

        if( channels.contains( channel ) ) {
          sel.resumeSelects( channel );
          return;
        }
      }

      Debug.out( "resumeSelects():: channel not found!" );
    }
    finally{ selectors_mon.exit();  }
  }
  else {
    selector_impl.resumeSelects( channel );
  }
}
项目:AcademicTorrents-Downloader    文件:VirtualChannelSelector.java   
/**
 * Cancel the selection operations for the given channel.
 * @param channel channel originally registered
 */
public void cancel( AbstractSelectableChannel channel ) {
  if( SAFE_SELECTOR_MODE_ENABLED ) {
    try{  selectors_mon.enter();
        //System.out.println( "cancel - " + channel.hashCode()  + " - " + Debug.getCompressedStackTrace());
    for( Map.Entry<VirtualChannelSelectorImpl, ArrayList<AbstractSelectableChannel>> entry: selectors.entrySet()) {

        VirtualChannelSelectorImpl          sel         = entry.getKey();
        ArrayList<AbstractSelectableChannel>    channels    = entry.getValue();

        if( channels.remove( channel ) ) {
          sel.cancel( channel );
          return;
        }
      }
    }
    finally{ selectors_mon.exit();  }
  }
  else {
    if( selector_impl != null )  selector_impl.cancel( channel );
  }
}
项目:AcademicTorrents-Downloader    文件:VirtualChannelSelector.java   
public void
 selectFailure(
VirtualAbstractSelectorListener     listener,
AbstractSelectableChannel           sc, 
Object                              attachment, 
Throwable                           msg)
 {
  if ( op == OP_ACCEPT ){

      ((VirtualAcceptSelectorListener)listener).selectFailure( VirtualChannelSelector.this, (ServerSocketChannel)sc, attachment, msg );
  }else{

      ((VirtualSelectorListener)listener).selectFailure( VirtualChannelSelector.this, (SocketChannel)sc, attachment, msg );

  }
 }
项目:AcademicTorrents-Downloader    文件:VirtualChannelSelectorImpl.java   
public void pauseSelects( AbstractSelectableChannel channel ) {

  //System.out.println( "pauseSelects: " + channel + " - " + Debug.getCompressedStackTrace() );

  if( channel == null ) {
    return;
  }

  SelectionKey key = channel.keyFor( selector );

  if( key != null && key.isValid() ) {
    key.interestOps( key.interestOps() & ~INTEREST_OP );
  }
  else {  //channel not (yet?) registered
    if( channel.isOpen() ) {  //only bother if channel has not already been closed
      try{  register_cancel_list_mon.enter();

        paused_states.put( channel, new Boolean( true ) );  //ensure the op is paused upon reg select-time reg

      }
      finally{  register_cancel_list_mon.exit();  }
    }
  }
}
项目:cn1    文件:EpollSelectorImpl.java   
protected SelectionKey register(AbstractSelectableChannel channel,
        int operations, Object attachment) {
    if (!provider().equals(channel.provider())) {
        throw new IllegalSelectorException();
    }
    synchronized (this) {
        synchronized (keysSet) {

            // System.out.println("Registering channel");
            // create the key
            SelectionKey sk = new EpollSelectionKeyImpl(channel,
                    operations, attachment, this);

            int index = addKey(sk);
            ((EpollSelectionKeyImpl) sk).setIndex(index);

            // System.out.println(" channel registered with index = " +
            // index);
            return sk;
        }
    }
}
项目:cn1    文件:SelectorImpl.java   
/**
 * @see java.nio.channels.spi.AbstractSelector#register(java.nio.channels.spi.AbstractSelectableChannel,
 *      int, java.lang.Object)
 */
@Override
protected SelectionKey register(AbstractSelectableChannel channel,
        int operations, Object attachment) {
    if (!provider().equals(channel.provider())) {
        throw new IllegalSelectorException();
    }
    synchronized (this) {
        synchronized (unmodifiableKeys) {
            // create the key
            SelectionKeyImpl selectionKey = new SelectionKeyImpl(
                    channel, operations, attachment, this);
            addKey(selectionKey);
            mutableKeys.add(selectionKey);
            return selectionKey;
        }
    }
}
项目:JamVM-PH    文件:SelectorImpl.java   
protected final SelectionKey register (AbstractSelectableChannel ch, int ops,
                                        Object att)
 {
   SelectionKeyImpl result;

   if (ch instanceof SocketChannelImpl)
     result = new SocketChannelSelectionKey (ch, this);
   else if (ch instanceof DatagramChannelImpl)
     result = new DatagramChannelSelectionKey (ch, this);
   else if (ch instanceof ServerSocketChannelImpl)
     result = new ServerSocketChannelSelectionKey (ch, this);
   else if (ch instanceof gnu.java.nio.SocketChannelImpl)
     result = new gnu.java.nio.SocketChannelSelectionKeyImpl((gnu.java.nio.SocketChannelImpl)ch, this);
   else
     throw new InternalError ("No known channel type");

   synchronized (keys)
     {
       keys.add (result);

result.interestOps (ops);
result.attach (att);
     }

   return result;
 }
项目:ffmq    文件:NIOTcpMultiplexer.java   
protected void addInterest( AbstractSelectableChannel channel ,  int interest , Object attachment , Selector selector )
{
    try
    {
     SelectionKey sk = channel.keyFor(selector);
     if (sk != null)
     {
        if (!sk.isValid())
            return;

         int actualInterests = sk.interestOps();
         if ((actualInterests & interest) != interest)
             sk.interestOps(actualInterests | interest);
         if (attachment != null)
             sk.attach(attachment);
     }
     else
         channel.register(selector, interest, attachment);
    }
    catch (ClosedChannelException e)
    {
        log.warn("Cannot add interest to selector channel : channel is closed");
    }
}
项目:classpath    文件:SelectorImpl.java   
protected final SelectionKey register (AbstractSelectableChannel ch, int ops,
                                       Object att)
{
  SelectionKeyImpl result;

  if (ch instanceof SocketChannelImpl)
    result = new SocketChannelSelectionKey (ch, this);
  else if (ch instanceof DatagramChannelImpl)
    result = new DatagramChannelSelectionKey (ch, this);
  else if (ch instanceof ServerSocketChannelImpl)
    result = new ServerSocketChannelSelectionKey (ch, this);
  else if (ch instanceof gnu.java.nio.SocketChannelImpl)
    result = new gnu.java.nio.SocketChannelSelectionKeyImpl((gnu.java.nio.SocketChannelImpl)ch, this);
  else
    throw new InternalError ("No known channel type");

  synchronized (keys)
    {
      keys.add (result);

      result.interestOps (ops);
      result.attach (att);
    }

  return result;
}
项目:freeVM    文件:EpollSelectorImpl.java   
protected SelectionKey register(AbstractSelectableChannel channel,
        int operations, Object attachment) {
    if (!provider().equals(channel.provider())) {
        throw new IllegalSelectorException();
    }
    synchronized (this) {
        synchronized (keysSet) {

            // System.out.println("Registering channel");
            // create the key
            SelectionKey sk = new EpollSelectionKeyImpl(channel,
                    operations, attachment, this);

            int index = addKey(sk);
            ((EpollSelectionKeyImpl) sk).setIndex(index);

            // System.out.println(" channel registered with index = " +
            // index);
            return sk;
        }
    }
}
项目:freeVM    文件:SelectorImpl.java   
/**
 * @see java.nio.channels.spi.AbstractSelector#register(java.nio.channels.spi.AbstractSelectableChannel,
 *      int, java.lang.Object)
 */
@Override
protected SelectionKey register(AbstractSelectableChannel channel,
        int operations, Object attachment) {
    if (!provider().equals(channel.provider())) {
        throw new IllegalSelectorException();
    }
    synchronized (this) {
        synchronized (unmodifiableKeys) {
            // create the key
            SelectionKeyImpl selectionKey = new SelectionKeyImpl(
                    channel, operations, attachment, this);
            addKey(selectionKey);
            mutableKeys.add(selectionKey);
            return selectionKey;
        }
    }
}
项目:JCaelum    文件:Server.java   
@Override
public UUID connect(AbstractSelectableChannel ch)
{
    assert ch != null;

    if (this.clients.size() == this.maxPlayers)
    {
        return null;
    }

    Connection next = new HSConnection(this, ch, this.master.getEncryptionBitCount());

    this.clients.add(next);

    return next.getId();
}
项目:boohee_v5.6    文件:SocketChannelIOHelper.java   
public static void writeBlocking(WebSocketImpl ws, ByteChannel channel) throws InterruptedException, IOException {
    if (!$assertionsDisabled && (channel instanceof AbstractSelectableChannel) && !((AbstractSelectableChannel) channel).isBlocking()) {
        throw new AssertionError();
    } else if ($assertionsDisabled || !(channel instanceof WrappedByteChannel) || ((WrappedByteChannel) channel).isBlocking()) {
        ByteBuffer buf = (ByteBuffer) ws.outQueue.take();
        while (buf.hasRemaining()) {
            channel.write(buf);
        }
    } else {
        throw new AssertionError();
    }
}
项目:jdk8u-jdk    文件:AdaptorCloseAndInterrupt.java   
void doAsyncClose(final AbstractSelectableChannel sc) {
    AdaptorCloseAndInterrupt.pool.schedule(new Callable<Void>() {
        public Void call() throws Exception {
            sc.close();
            return null;
        }
    }, new Random().nextInt(1000), TimeUnit.MILLISECONDS);
}
项目:openjdk-jdk10    文件:SelectorImpl.java   
protected final SelectionKey register(AbstractSelectableChannel ch,
                                      int ops,
                                      Object attachment)
{
    if (!(ch instanceof SelChImpl))
        throw new IllegalSelectorException();
    SelectionKeyImpl k = new SelectionKeyImpl((SelChImpl)ch, this);
    k.attach(attachment);
    synchronized (publicKeys) {
        implRegister(k);
    }
    k.interestOps(ops);
    return k;
}
项目:openjdk-jdk10    文件:AdaptorCloseAndInterrupt.java   
void doAsyncClose(final AbstractSelectableChannel sc) {
    AdaptorCloseAndInterrupt.pool.schedule(new Callable<Void>() {
        public Void call() throws Exception {
            sc.close();
            isClosed.set(true);
            return null;
        }
    }, new Random().nextInt(1000), TimeUnit.MILLISECONDS);
}
项目:BiglyBT    文件:VirtualChannelSelector.java   
private void initSafeMode() {
//System.out.println( "***************** SAFE SOCKET SELECTOR MODE ENABLED *****************" );

   if (Logger.isEnabled()) {
    Logger.log(new LogEvent(LOGID, "***************** SAFE SOCKET SELECTOR MODE ENABLED *****************"));
   }

   selector_impl = null;
   selectors = new HashMap<>();
   selectors_mon = new AEMonitor( "VirtualChannelSelector:FM" );
   selectors.put( new VirtualChannelSelectorImpl( this, op, pause, randomise_keys ), new ArrayList<AbstractSelectableChannel>() );
   selectors_keyset_cow = new HashSet<>(selectors.keySet());
 }
项目:BiglyBT    文件:VirtualChannelSelector.java   
public boolean
 selectSuccess(
VirtualAbstractSelectorListener     listener,
AbstractSelectableChannel           sc,
Object                              attachment )
 {
  if ( op == OP_ACCEPT ){

      return(((VirtualAcceptSelectorListener)listener).selectSuccess( VirtualChannelSelector.this, (ServerSocketChannel)sc, attachment ));
  }else{

      return(((VirtualSelectorListener)listener).selectSuccess( VirtualChannelSelector.this, (SocketChannel)sc, attachment ));
  }
 }
项目:BiglyBT    文件:VirtualChannelSelectorImpl.java   
public void resumeSelects( AbstractSelectableChannel channel ) {
  //System.out.println( "resumeSelects: " + channel + " - " + Debug.getCompressedStackTrace() );
  if( channel == null ) {
    Debug.printStackTrace( new Exception( "resumeSelects():: channel == null" ) );
    return;
  }

  SelectionKey key = channel.keyFor( selector );

  if( key != null && key.isValid() ) {
        // if we're resuming a non-interested key then reset the metrics

    if (( key.interestOps() & INTEREST_OP ) == 0 ){
       RegistrationData data = (RegistrationData)key.attachment();

       data.last_select_success_time    = SystemTime.getCurrentTime();
       data.non_progress_count          = 0;
    }
    key.interestOps( key.interestOps() | INTEREST_OP );
  }
  else {  //channel not (yet?) registered
    try{  register_cancel_list_mon.enter();
      paused_states.remove( channel );  //check if the channel's op has been already paused before select-time reg
    }
    finally{  register_cancel_list_mon.exit();  }
  }

  //try{
  //  selector.wakeup();
  //}
  //catch( Throwable t ) {  Debug.out( "selector.wakeup():: caught exception: ", t );   }
}
项目:BiglyBT    文件:VirtualChannelSelectorImpl.java   
RegistrationData( AbstractSelectableChannel _channel, VirtualChannelSelector.VirtualAbstractSelectorListener _listener, Object _attachment ) {
    channel         = _channel;
    listener        = _listener;
    attachment      = _attachment;

    last_select_success_time    = SystemTime.getCurrentTime();
}