Package java.nio.channels.spi

Examples of java.nio.channels.spi.SelectorProvider


import java.util.Set;

public class Listing_2_10 {

  public static void main(String[] args) {
    SelectorProvider provider = SelectorProvider.provider();
    try {
      NetworkChannel socketChannel = provider.openSocketChannel();
      SocketAddress address = new InetSocketAddress(3080);
      socketChannel = socketChannel.bind(address);

      Set<SocketOption<?>> socketOptions = socketChannel.supportedOptions();
View Full Code Here


     * @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();
View Full Code Here

                final Class<?> providerClazz = Class.forName("sun.nio.ch.EPollSelectorProvider");
                if (providerClazz != null) {
                    try {
                        final Method method = providerClazz.getMethod("provider");
                        if (method != null) {
                            final SelectorProvider selectorProvider = (SelectorProvider) method.invoke(null);
                            if (selectorProvider != null) {
                                result = selectorProvider.openSelector();
                            }
                        }
                    }
                    catch (final Exception e) {
                        // ignore
View Full Code Here

     */
    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();
View Full Code Here

  }

  @Test(timeout = 3000)
  public void testWakeup() throws Exception {

    final SelectorProvider provider = SelectorProviderUDT.DATAGRAM;

    final Selector selector = provider.openSelector();

    final Thread thread = new Thread() {

      @Override
      public void run() {
View Full Code Here

      ServerSocketChannel channel = _ss.getChannel();

      if (channel == null)
        return null;
     
      SelectorProvider provider = channel.provider();

      if (provider != null)
        return provider.openSelector();
      else
        return null;
    } catch (Throwable e) {
      log.log(Level.WARNING, e.toString(), e);
      return null;
View Full Code Here

   * This also works with xinetd. It might work with Apple launchd.
   *
   * TODO: detect inactivity for N minutes, exist - to free resources.
   */
  public void inetdAcceptor(NioChannelCallback cstate) throws IOException {
      SelectorProvider sp=SelectorProvider.provider();

      Channel ch=sp.inheritedChannel();
      if(ch!=null ) {
          log.info("Inherited: " + ch.getClass().getName());
          // blocking mode
          ServerSocketChannel ssc=(ServerSocketChannel)ch;
          ssc.configureBlocking(false);
View Full Code Here

            .forName("sun.nio.ch.EPollSelectorProvider");
        if (providerClazz != null) {
          try {
            Method method = providerClazz.getMethod("provider");
            if (method != null) {
              SelectorProvider selectorProvider = (SelectorProvider) method
                  .invoke(null);
              if (selectorProvider != null) {
                result = selectorProvider.openSelector();
              }
            }
          } catch (Exception e) {
            // ignore
          }
View Full Code Here

     * @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();
View Full Code Here

  }

  @Test(timeout = 3000)
  public void testWakeup() throws Exception {

    final SelectorProvider provider = SelectorProviderUDT.DATAGRAM;

    final Selector selector = provider.openSelector();

    final Thread thread = new Thread() {

      @Override
      public void run() {
View Full Code Here

TOP

Related Classes of java.nio.channels.spi.SelectorProvider

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.