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


Java SelectorProvider类代码示例

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


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

示例1: init

import java.nio.channels.spi.SelectorProvider; //导入依赖的package包/类
/**
 * open the serverSocketChannel and register accept action
 */
public void init() {
    lock.lock();
    try {
        if (!running) {
            selector = SelectorProvider.provider().openSelector();
            serverSocketChannel = ServerSocketChannel.open();
            serverSocketChannel.configureBlocking(false);
            serverSocketChannel.bind(new InetSocketAddress(network.port()));
            serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT);
        }
    } catch (IOException e) {
        serverClose();
        throw new NulsRuntimeException(ErrorCode.NET_SERVER_START_ERROR, e);
    } finally {
        lock.unlock();
    }
}
 
开发者ID:nuls-io,项目名称:nuls,代码行数:21,代码来源:ConnectionManager.java

示例2: main

import java.nio.channels.spi.SelectorProvider; //导入依赖的package包/类
public static void main(String args[]) {

        // test the assertion that SelectorProvider.inheritedChannel()
        // and System.inheritedChannel return null when standard input
        // is not connected to a socket

        Channel c1, c2;
        try {
            c1 = SelectorProvider.provider().inheritedChannel();
            c2 = System.inheritedChannel();
        } catch (IOException ioe) {
            throw new RuntimeException("Unexpected IOException: " + ioe);
        }
        if (c1 != null || c2 != null) {
            throw new RuntimeException("Channel returned - unexpected");
        }
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:NullTest.java

示例3: main

import java.nio.channels.spi.SelectorProvider; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    SelectorProvider sp = SelectorProvider.provider();
    Pipe p = sp.openPipe();
    Pipe.SinkChannel sink = p.sink();
    Pipe.SourceChannel source = p.source();

    byte[] someBytes = new byte[0];
    ByteBuffer outgoingdata = ByteBuffer.wrap(someBytes);

    int totalWritten = 0;
    int written = sink.write(outgoingdata);
    if (written < 0)
        throw new Exception("Write failed");

    ByteBuffer incomingdata = ByteBuffer.allocateDirect(0);
    int read = source.read(incomingdata);
    if (read < 0)
        throw new Exception("Read EOF");

    sink.close();
    source.close();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:EmptyRead.java

示例4: main

import java.nio.channels.spi.SelectorProvider; //导入依赖的package包/类
public static void main(String[] args) throws Exception {

        // Load necessary classes ahead of time
        DatagramChannel dc = DatagramChannel.open();
        Exception se = new SocketException();
        SelectorProvider sp = SelectorProvider.provider();
        Pipe p = sp.openPipe();
        ServerSocketChannel ssc = ServerSocketChannel.open();

        test1();
        test2();
        test3();
        test4();
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:Open.java

示例5: SctpChannelImpl

import java.nio.channels.spi.SelectorProvider; //导入依赖的package包/类
/**
 * Constructor for sockets obtained from branching
 */
public SctpChannelImpl(SelectorProvider provider,
                       FileDescriptor fd,
                       Association association)
        throws IOException {
    super(provider);
    this.fd = fd;
    this.fdVal = IOUtil.fdVal(fd);
    this.state = ChannelState.CONNECTED;
    port = (Net.localAddress(fd)).getPort();

    if (association != null) { /* branched */
        this.association = association;
    } else { /* obtained from server channel */
        /* Receive COMM_UP */
        ByteBuffer buf = Util.getTemporaryDirectBuffer(50);
        try {
            receive(buf, null, null, true);
        } finally {
            Util.releaseTemporaryDirectBuffer(buf);
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:26,代码来源:SctpChannelImpl.java

示例6: SctpMultiChannelImpl

import java.nio.channels.spi.SelectorProvider; //导入依赖的package包/类
public SctpMultiChannelImpl(SelectorProvider provider)
        throws IOException {
    //TODO: update provider, remove public modifier
    super(provider);
    this.fd = SctpNet.socket(false /*one-to-many*/);
    this.fdVal = IOUtil.fdVal(fd);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:SctpMultiChannelImpl.java

示例7: NioServer

import java.nio.channels.spi.SelectorProvider; //导入依赖的package包/类
/**
 * Creates a new server which is capable of listening for incoming connections and processing client provided data
 * using {@link StreamConnection}s created by the given {@link StreamConnectionFactory}
 *
 * @throws IOException If there is an issue opening the server socket or binding fails for some reason
 */
public NioServer(final StreamConnectionFactory connectionFactory, InetSocketAddress bindAddress) throws IOException {
    this.connectionFactory = connectionFactory;

    sc = ServerSocketChannel.open();
    sc.configureBlocking(false);
    sc.socket().bind(bindAddress);
    selector = SelectorProvider.provider().openSelector();
    sc.register(selector, SelectionKey.OP_ACCEPT);
}
 
开发者ID:creativechain,项目名称:creacoinj,代码行数:16,代码来源:NioServer.java

示例8: NioClientManager

import java.nio.channels.spi.SelectorProvider; //导入依赖的package包/类
/**
 * Creates a new client manager which uses Java NIO for socket management. Uses a single thread to handle all select
 * calls.
 */
public NioClientManager() {
    try {
        selector = SelectorProvider.provider().openSelector();
    } catch (IOException e) {
        throw new RuntimeException(e); // Shouldn't ever happen
    }
}
 
开发者ID:creativechain,项目名称:creacoinj,代码行数:12,代码来源:NioClientManager.java

示例9: RCONServer

import java.nio.channels.spi.SelectorProvider; //导入依赖的package包/类
public RCONServer(String address, int port, String password) throws IOException {
    this.setName("RCON");
    this.running = true;

    this.serverChannel = ServerSocketChannel.open();
    this.serverChannel.configureBlocking(false);
    this.serverChannel.socket().bind(new InetSocketAddress(address, port));

    this.selector = SelectorProvider.provider().openSelector();
    this.serverChannel.register(this.selector, SelectionKey.OP_ACCEPT);

    this.password = password;
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:14,代码来源:RCONServer.java

示例10: get

import java.nio.channels.spi.SelectorProvider; //导入依赖的package包/类
/**
 * Takes one selector from end of LRU list of free selectors.
 * If there are no selectors awailable, it creates a new selector.
 * Also invokes trimIdleSelectors(). 
 * 
 * @param channel
 * @return 
 * @throws IOException
 */
private synchronized SelectorInfo get(SelectableChannel channel) 
                                                     throws IOException {
  SelectorInfo selInfo = null;
  
  SelectorProvider provider = channel.provider();
  
  // pick the list : rarely there is more than one provider in use.
  ProviderInfo pList = providerList;
  while (pList != null && pList.provider != provider) {
    pList = pList.next;
  }      
  if (pList == null) {
    //LOG.info("Creating new ProviderInfo : " + provider.toString());
    pList = new ProviderInfo();
    pList.provider = provider;
    pList.queue = new LinkedList<SelectorInfo>();
    pList.next = providerList;
    providerList = pList;
  }
  
  LinkedList<SelectorInfo> queue = pList.queue;
  
  if (queue.isEmpty()) {
    Selector selector = provider.openSelector();
    selInfo = new SelectorInfo();
    selInfo.selector = selector;
    selInfo.queue = queue;
  } else {
    selInfo = queue.removeLast();
  }
  
  trimIdleSelectors(System.currentTimeMillis());
  return selInfo;
}
 
开发者ID:spafka,项目名称:spark_deep,代码行数:44,代码来源:SocketIOWithTimeout.java

示例11: test

import java.nio.channels.spi.SelectorProvider; //导入依赖的package包/类
static void test(TestServers.DayTimeServer daytimeServer) throws Exception {
    InetSocketAddress isa
        = new InetSocketAddress(daytimeServer.getAddress(),
                                daytimeServer.getPort());
    SocketChannel sc = SocketChannel.open();
    sc.configureBlocking(false);
    final boolean immediatelyConnected = sc.connect(isa);

    Selector selector = SelectorProvider.provider().openSelector();
    try {
        SelectionKey key = sc.register(selector, SelectionKey.OP_CONNECT);
        int keysAdded = selector.select();
        if (keysAdded > 0) {
            boolean result = sc.finishConnect();
            if (result) {
                keysAdded = selector.select(5000);
                // 4750573: keysAdded should not be incremented when op is dropped
                // from a key already in the selected key set
                if (keysAdded > 0)
                    throw new Exception("Test failed: 4750573 detected");
                Set<SelectionKey> sel = selector.selectedKeys();
                Iterator<SelectionKey> i = sel.iterator();
                SelectionKey sk = i.next();
                // 4737146: isConnectable should be false while connected
                if (sk.isConnectable())
                    throw new Exception("Test failed: 4737146 detected");
            }
        } else {
            if (!immediatelyConnected) {
                throw new Exception("Select failed");
            } else {
                System.out.println("IsConnectable couldn't be fully tested for "
                        + System.getProperty("os.name"));
            }
        }
    } finally {
        sc.close();
        selector.close();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:41,代码来源:IsConnectable.java

示例12: SctpChannelImpl

import java.nio.channels.spi.SelectorProvider; //导入依赖的package包/类
/**
 * Constructor for normal connecting sockets
 */
public SctpChannelImpl(SelectorProvider provider) throws IOException {
    //TODO: update provider remove public modifier
    super(provider);
    this.fd = SctpNet.socket(true);
    this.fdVal = IOUtil.fdVal(fd);
    this.state = ChannelState.UNCONNECTED;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:SctpChannelImpl.java

示例13: SctpServerChannelImpl

import java.nio.channels.spi.SelectorProvider; //导入依赖的package包/类
/**
 * Initializes a new instance of this class.
 */
public SctpServerChannelImpl(SelectorProvider provider)
        throws IOException {
    //TODO: update provider remove public modifier
    super(provider);
    this.fd = SctpNet.socket(true);
    this.fdVal = IOUtil.fdVal(fd);
    this.state = ChannelState.INUSE;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:SctpServerChannelImpl.java

示例14: WindowsSelectorImpl

import java.nio.channels.spi.SelectorProvider; //导入依赖的package包/类
WindowsSelectorImpl(SelectorProvider sp) throws IOException {
    super(sp);
    pollWrapper = new PollArrayWrapper(INIT_CAP);
    wakeupPipe = Pipe.open();
    wakeupSourceFd = ((SelChImpl)wakeupPipe.source()).getFDVal();

    // Disable the Nagle algorithm so that the wakeup is more immediate
    SinkChannelImpl sink = (SinkChannelImpl)wakeupPipe.sink();
    (sink.sc).socket().setTcpNoDelay(true);
    wakeupSinkFd = ((SelChImpl)sink).getFDVal();

    pollWrapper.addWakeupSocket(wakeupSourceFd, 0);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:WindowsSelectorImpl.java

示例15: SelectorImpl

import java.nio.channels.spi.SelectorProvider; //导入依赖的package包/类
protected SelectorImpl(SelectorProvider sp) {
    super(sp);
    keys = new HashSet<>();
    selectedKeys = new HashSet<>();
    publicKeys = Collections.unmodifiableSet(keys);
    publicSelectedKeys = Util.ungrowableSet(selectedKeys);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:SelectorImpl.java


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