本文整理汇总了Java中java.nio.channels.spi.AbstractSelectableChannel类的典型用法代码示例。如果您正苦于以下问题:Java AbstractSelectableChannel类的具体用法?Java AbstractSelectableChannel怎么用?Java AbstractSelectableChannel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AbstractSelectableChannel类属于java.nio.channels.spi包,在下文中一共展示了AbstractSelectableChannel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pauseSelects
import java.nio.channels.spi.AbstractSelectableChannel; //导入依赖的package包/类
/**
* 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 );
}
}
示例2: resumeSelects
import java.nio.channels.spi.AbstractSelectableChannel; //导入依赖的package包/类
/**
* 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 );
}
}
示例3: cancel
import java.nio.channels.spi.AbstractSelectableChannel; //导入依赖的package包/类
/**
* 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 );
}
}
示例4: selectFailure
import java.nio.channels.spi.AbstractSelectableChannel; //导入依赖的package包/类
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 );
}
}
示例5: 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(); }
}
}
}
示例6: pauseSelects
import java.nio.channels.spi.AbstractSelectableChannel; //导入依赖的package包/类
/**
* 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 );
}
}
示例7: resumeSelects
import java.nio.channels.spi.AbstractSelectableChannel; //导入依赖的package包/类
/**
* 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 );
}
}
示例8: cancel
import java.nio.channels.spi.AbstractSelectableChannel; //导入依赖的package包/类
/**
* 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 );
}
}
示例9: selectFailure
import java.nio.channels.spi.AbstractSelectableChannel; //导入依赖的package包/类
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 );
}
}
示例10: 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(); }
}
}
}
示例11: register
import java.nio.channels.spi.AbstractSelectableChannel; //导入依赖的package包/类
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);
}
}
示例12: register
import java.nio.channels.spi.AbstractSelectableChannel; //导入依赖的package包/类
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;
}
示例13: register
import java.nio.channels.spi.AbstractSelectableChannel; //导入依赖的package包/类
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;
}
示例14: test_register_LAbstractSelectableChannelIObject
import java.nio.channels.spi.AbstractSelectableChannel; //导入依赖的package包/类
/**
* @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);
}
示例15: register
import java.nio.channels.spi.AbstractSelectableChannel; //导入依赖的package包/类
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;
}
}
}