当前位置: 首页>>代码示例>>Java>>正文


Java AbstractSelectableChannel.keyFor方法代码示例

本文整理汇总了Java中java.nio.channels.spi.AbstractSelectableChannel.keyFor方法的典型用法代码示例。如果您正苦于以下问题:Java AbstractSelectableChannel.keyFor方法的具体用法?Java AbstractSelectableChannel.keyFor怎么用?Java AbstractSelectableChannel.keyFor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.channels.spi.AbstractSelectableChannel的用法示例。


在下文中一共展示了AbstractSelectableChannel.keyFor方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: pauseSelects

import java.nio.channels.spi.AbstractSelectableChannel; //导入方法依赖的package包/类
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();  }
        }
      }
    }
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:25,代码来源:VirtualChannelSelectorImpl.java

示例2: pauseSelects

import java.nio.channels.spi.AbstractSelectableChannel; //导入方法依赖的package包/类
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();  }
    }
  }
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:25,代码来源:VirtualChannelSelectorImpl.java

示例3: addInterest

import java.nio.channels.spi.AbstractSelectableChannel; //导入方法依赖的package包/类
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");
	}
}
 
开发者ID:timewalker74,项目名称:ffmq,代码行数:25,代码来源:NIOTcpMultiplexer.java

示例4: resumeSelects

import java.nio.channels.spi.AbstractSelectableChannel; //导入方法依赖的package包/类
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 );   }
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:33,代码来源:VirtualChannelSelectorImpl.java

示例5: resumeSelects

import java.nio.channels.spi.AbstractSelectableChannel; //导入方法依赖的package包/类
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 );   }
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:33,代码来源:VirtualChannelSelectorImpl.java

示例6: closeSocketChannel

import java.nio.channels.spi.AbstractSelectableChannel; //导入方法依赖的package包/类
private void closeSocketChannel( AbstractSelectableChannel channel , Selector selector )
{
    try
    {
        SelectionKey sk = channel.keyFor(selector);
        if (sk != null && sk.isValid())
            sk.cancel();
        if (channel.isOpen())
            channel.close();
    }
    catch (Exception e)
    {
        log.error("Could not close channel : "+e.toString());
    }
}
 
开发者ID:timewalker74,项目名称:ffmq,代码行数:16,代码来源:NIOTcpMultiplexer.java

示例7: removeInterest

import java.nio.channels.spi.AbstractSelectableChannel; //导入方法依赖的package包/类
private void removeInterest( AbstractSelectableChannel channel ,  int interest , Selector selector )
{
    SelectionKey sk = channel.keyFor(selector);
    if (sk != null && sk.isValid())
    {
        int actualInterests = sk.interestOps();
        if ((actualInterests & interest) != 0)
            sk.interestOps(sk.interestOps() & ~interest);
    }
}
 
开发者ID:timewalker74,项目名称:ffmq,代码行数:11,代码来源:NIOTcpMultiplexer.java

示例8: deregister

import java.nio.channels.spi.AbstractSelectableChannel; //导入方法依赖的package包/类
public VanillaSelector deregister(@NotNull AbstractSelectableChannel channel, int ops) throws IOException {
    SelectionKey selectionKey = channel.keyFor(this.selector);
    if (selectionKey != null) {
        selectionKey.interestOps(selectionKey.interestOps() & ~ops);
    }

    return this;
}
 
开发者ID:OpenHFT,项目名称:Chronicle-Common,代码行数:9,代码来源:VanillaSelector.java


注:本文中的java.nio.channels.spi.AbstractSelectableChannel.keyFor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。