當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。