Java 类io.netty.channel.socket.InternetProtocolFamily 实例源码

项目:hekate    文件:MulticastSeedNodeProvider.java   
/**
 * Constructs new instance.
 *
 * @param cfg Configuration.
 *
 * @throws UnknownHostException If failed to resolve multicast group address.
 */
public MulticastSeedNodeProvider(MulticastSeedNodeProviderConfig cfg) throws UnknownHostException {
    ConfigCheck check = ConfigCheck.get(getClass());

    check.notNull(cfg, "configuration");
    check.positive(cfg.getPort(), "port");
    check.nonNegative(cfg.getTtl(), "TTL");
    check.notEmpty(cfg.getGroup(), "multicast group");
    check.positive(cfg.getInterval(), "discovery interval");
    check.positive(cfg.getWaitTime(), "wait time");
    check.that(cfg.getInterval() < cfg.getWaitTime(), "discovery interval must be greater than wait time "
        + "[discovery-interval=" + cfg.getInterval() + ", wait-time=" + cfg.getWaitTime() + ']');

    InetAddress groupAddress = InetAddress.getByName(cfg.getGroup());

    check.isTrue(groupAddress.isMulticastAddress(), "address is not a multicast address [address=" + groupAddress + ']');

    group = new InetSocketAddress(groupAddress, cfg.getPort());
    ttl = cfg.getTtl();
    interval = cfg.getInterval();
    waitTime = cfg.getWaitTime();
    loopBackDisabled = cfg.isLoopBackDisabled();

    ipVer = group.getAddress() instanceof Inet6Address ? InternetProtocolFamily.IPv6 : InternetProtocolFamily.IPv4;
}
项目:zosma    文件:MulticastPublisher.java   
@Override
public void subscribe(final Subscriber<? super O> subscriber) {
  try {
    final List<NetworkInterface> interfaces = Collections
        .list(NetworkInterface.getNetworkInterfaces());

    UdpServer
        .create(opts ->
            opts.option(ChannelOption.SO_REUSEADDR, true)
                .connectAddress(() -> new InetSocketAddress(this.port))
                .protocolFamily(InternetProtocolFamily.IPv4))
        .newHandler((in, out) -> {
          Flux.fromIterable(interfaces)
              .flatMap(iface -> in.join(this.address, iface))
              .thenMany(in.receive().asByteArray())
              .map(this.parser)
              .subscribe(subscriber);
          return Flux.never();
        })
        .subscribe();
  } catch (final SocketException exception) {
    Flux.<O>error(exception).subscribe(subscriber);
  }
}
项目:kume    文件:MulticastServerHandler.java   
public MulticastServerHandler(Cluster cluster, InetSocketAddress address) throws InterruptedException {
    this.address = address;

    handler = new Bootstrap()
            .channelFactory(() -> new NioDatagramChannel(InternetProtocolFamily.IPv4))
            .localAddress(address)
            .group(new NioEventLoopGroup())
            .option(ChannelOption.SO_REUSEADDR, true)
            .option(ChannelOption.IP_MULTICAST_IF, multicastInterface)
            .option(ChannelOption.AUTO_READ, false)
            .handler(new ChannelInitializer<NioDatagramChannel>() {
                @Override
                public void initChannel(NioDatagramChannel ch) throws Exception {
                    ch.pipeline().addLast(new MulticastChannelAdapter(cluster));
                }
            });
    localMember = cluster.getLocalMember();
}
项目:zosma    文件:UDPPublisher.java   
@Override
public void subscribe(final Subscriber<? super DatagramPacket> subscriber) {
  UdpClient
      .create(opts -> opts
          .option(ChannelOption.SO_REUSEADDR, true)
          .port(this.port)
          .protocolFamily(InternetProtocolFamily.IPv4))
      .newHandler((in, out) -> {
        in.receive().asByteArray()
            .map(bytes -> new DatagramPacket(bytes, bytes.length))
            .subscribe(subscriber);
        return Flux.never();
      })
      .subscribe();
}
项目:ditb    文件:ClusterStatusPublisher.java   
@Override
public T newChannel() {
    try {
      return ReflectionUtils.instantiateWithCustomCtor(clazz.getName(),
        new Class[] { InternetProtocolFamily.class }, new Object[] { family });

    } catch (Throwable t) {
        throw new ChannelException("Unable to create Channel from class " + clazz, t);
    }
}
项目:netty4.0.27Learn    文件:SocketTestPermutation.java   
public List<BootstrapComboFactory<Bootstrap, Bootstrap>> datagram() {
    // Make the list of Bootstrap factories.
    List<BootstrapFactory<Bootstrap>> bfs = Arrays.asList(
            new BootstrapFactory<Bootstrap>() {
                @Override
                public Bootstrap newInstance() {
                    return new Bootstrap().group(nioWorkerGroup).channelFactory(new ChannelFactory<Channel>() {
                        @Override
                        public Channel newChannel() {
                            return new NioDatagramChannel(InternetProtocolFamily.IPv4);
                        }

                        @Override
                        public String toString() {
                            return NioDatagramChannel.class.getSimpleName() + ".class";
                        }
                    });
                }
            },
            new BootstrapFactory<Bootstrap>() {
                @Override
                public Bootstrap newInstance() {
                    return new Bootstrap().group(oioWorkerGroup).channel(OioDatagramChannel.class);
                }
            }
    );

    // Populare the combinations.
    return combo(bfs, bfs);
}
项目:netty4.0.27Learn    文件:ProtocolFamilyConverter.java   
/**
 * Convert the {@link InternetProtocolFamily}. This MUST only be called on jdk version >= 7.
 */
public static ProtocolFamily convert(InternetProtocolFamily family) {
    switch (family) {
    case IPv4:
        return StandardProtocolFamily.INET;
    case IPv6:
        return StandardProtocolFamily.INET6;
    default:
        throw new IllegalArgumentException();
    }
}
项目:netty4.0.27Learn    文件:NioDatagramChannel.java   
private static DatagramChannel newSocket(SelectorProvider provider, InternetProtocolFamily ipFamily) {
    if (ipFamily == null) {
        return newSocket(provider);
    }

    checkJavaVersion();

    try {
        return provider.openDatagramChannel(ProtocolFamilyConverter.convert(ipFamily));
    } catch (IOException e) {
        throw new ChannelException("Failed to open a socket.", e);
    }
}
项目:netty4.0.27Learn    文件:EpollSocketTestPermutation.java   
@Override
public List<TestsuitePermutation.BootstrapComboFactory<Bootstrap, Bootstrap>> datagram() {
    // Make the list of Bootstrap factories.
    List<BootstrapFactory<Bootstrap>> bfs = Arrays.asList(
            new BootstrapFactory<Bootstrap>() {
                @Override
                public Bootstrap newInstance() {
                    return new Bootstrap().group(nioWorkerGroup).channelFactory(new ChannelFactory<Channel>() {
                        @Override
                        public Channel newChannel() {
                            return new NioDatagramChannel(InternetProtocolFamily.IPv4);
                        }

                        @Override
                        public String toString() {
                            return NioDatagramChannel.class.getSimpleName() + ".class";
                        }
                    });
                }
            },
            new BootstrapFactory<Bootstrap>() {
                @Override
                public Bootstrap newInstance() {
                    return new Bootstrap().group(EPOLL_WORKER_GROUP).channel(EpollDatagramChannel.class);
                }
            }
    );
    return combo(bfs, bfs);
}
项目:pbase    文件:ClusterStatusPublisher.java   
@Override
public T newChannel() {
    try {
      return ReflectionUtils.instantiateWithCustomCtor(clazz.getName(),
        new Class[] { InternetProtocolFamily.class }, new Object[] { family });

    } catch (Throwable t) {
        throw new ChannelException("Unable to create Channel from class " + clazz, t);
    }
}
项目:netty4study    文件:ProtocolFamilyConverter.java   
/**
 * Convert the {@link InternetProtocolFamily}. This MUST only be called on jdk version >= 7.
 */
public static ProtocolFamily convert(InternetProtocolFamily family) {
    switch (family) {
    case IPv4:
        return StandardProtocolFamily.INET;
    case IPv6:
        return StandardProtocolFamily.INET6;
    default:
        throw new IllegalArgumentException();
    }
}
项目:netty4study    文件:NioDatagramChannel.java   
private static DatagramChannel newSocket(InternetProtocolFamily ipFamily) {
    if (ipFamily == null) {
        return newSocket();
    }

    if (PlatformDependent.javaVersion() < 7) {
        throw new UnsupportedOperationException();
    }

    try {
        return DatagramChannel.open(ProtocolFamilyConverter.convert(ipFamily));
    } catch (IOException e) {
        throw new ChannelException("Failed to open a socket.", e);
    }
}
项目:bigio    文件:MeMemberUDP.java   
public DataServerThread() {
    dataBossGroup = new NioEventLoopGroup(DATA_BOSS_THREADS);
    dataWorkerGroup = new NioEventLoopGroup(DATA_WORKER_THREADS);
    try {
        Bootstrap b = new Bootstrap();
        b.group(dataWorkerGroup)
                .channelFactory(new ChannelFactory<Channel>() {
                    @Override
                    public Channel newChannel() {
                        return new NioDatagramChannel(InternetProtocolFamily.IPv4);
                    }

                    @Override
                    public String toString() {
                        return NioDatagramChannel.class.getSimpleName() + ".class";
                    }
                }).handler(new ChannelInitializer<DatagramChannel>() {
                    @Override
                    public void initChannel(DatagramChannel ch) throws Exception {
                        ch.config().setAllocator(UnpooledByteBufAllocator.DEFAULT);
                        ch.pipeline().addLast(new DataMessageHandler());
                        if (LOG.isTraceEnabled()) {
                            ch.pipeline().addLast(new LoggingHandler(LogLevel.TRACE));
                        }
                    }

                    @Override
                    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
                        LOG.error("Cannot initialize data server.", cause);
                    }
                });

        // Bind and start to accept incoming connections.
        f = b.bind(getIp(), getDataPort()).sync();
    } catch (InterruptedException ex) {
        LOG.error("Message data interrupted.", ex);
    }
}
项目:netty-netty-5.0.0.Alpha1    文件:ProtocolFamilyConverter.java   
/**
 * Convert the {@link InternetProtocolFamily}. This MUST only be called on jdk version >= 7.
 */
public static ProtocolFamily convert(InternetProtocolFamily family) {
    switch (family) {
    case IPv4:
        return StandardProtocolFamily.INET;
    case IPv6:
        return StandardProtocolFamily.INET6;
    default:
        throw new IllegalArgumentException();
    }
}
项目:netty-netty-5.0.0.Alpha1    文件:NioDatagramChannel.java   
private static DatagramChannel newSocket(InternetProtocolFamily ipFamily) {
    if (ipFamily == null) {
        return newSocket();
    }

    if (PlatformDependent.javaVersion() < 7) {
        throw new UnsupportedOperationException();
    }

    try {
        return DatagramChannel.open(ProtocolFamilyConverter.convert(ipFamily));
    } catch (IOException e) {
        throw new ChannelException("Failed to open a socket.", e);
    }
}
项目:ditb    文件:ClusterStatusPublisher.java   
HBaseDatagramChannelFactory(Class<? extends T> clazz, InternetProtocolFamily family) {
    this.clazz = clazz;
    this.family = family;
}
项目:pbase    文件:ClusterStatusPublisher.java   
HBaseDatagramChannelFactory(Class<? extends T> clazz, InternetProtocolFamily family) {
    this.clazz = clazz;
    this.family = family;
}
项目:KIARA    文件:NioDatagramChannelFactory.java   
public NioDatagramChannelFactory(InternetProtocolFamily ipFamily) {
    this.ipFamily = ipFamily;
}
项目:netty4study    文件:SocketTestPermutation.java   
static List<Entry<Factory<Bootstrap>, Factory<Bootstrap>>> datagram() {
    List<Entry<Factory<Bootstrap>, Factory<Bootstrap>>> list =
            new ArrayList<Entry<Factory<Bootstrap>, Factory<Bootstrap>>>();

    // Make the list of Bootstrap factories.
    List<Factory<Bootstrap>> bfs =
            new ArrayList<Factory<Bootstrap>>();
    bfs.add(new Factory<Bootstrap>() {
        @Override
        public Bootstrap newInstance() {
            return new Bootstrap().group(nioWorkerGroup).channelFactory(new ChannelFactory<Channel>() {
                @Override
                public Channel newChannel() {
                   return new NioDatagramChannel(InternetProtocolFamily.IPv4);
                }

                @Override
                public String toString() {
                    return NioDatagramChannel.class.getSimpleName() + ".class";
                }
            });
        }
    });
    bfs.add(new Factory<Bootstrap>() {
        @Override
        public Bootstrap newInstance() {
            return new Bootstrap().group(oioWorkerGroup).channel(OioDatagramChannel.class);
        }
    });

    // Populate the combinations
    for (Factory<Bootstrap> sbf: bfs) {
        for (Factory<Bootstrap> cbf: bfs) {
            final Factory<Bootstrap> sbf0 = sbf;
            final Factory<Bootstrap> cbf0 = cbf;
            list.add(new Entry<Factory<Bootstrap>, Factory<Bootstrap>>() {
                @Override
                public Factory<Bootstrap> getKey() {
                    return sbf0;
                }

                @Override
                public Factory<Bootstrap> getValue() {
                    return cbf0;
                }

                @Override
                public Factory<Bootstrap> setValue(Factory<Bootstrap> value) {
                    throw new UnsupportedOperationException();
                }
            });
        }
    }

    return list;
}
项目:netty-netty-5.0.0.Alpha1    文件:SocketTestPermutation.java   
static List<Entry<Factory<Bootstrap>, Factory<Bootstrap>>> datagram() {
    List<Entry<Factory<Bootstrap>, Factory<Bootstrap>>> list =
            new ArrayList<Entry<Factory<Bootstrap>, Factory<Bootstrap>>>();

    // Make the list of Bootstrap factories.
    List<Factory<Bootstrap>> bfs = new ArrayList<Factory<Bootstrap>>();
    bfs.add(new Factory<Bootstrap>() {
        @Override
        public Bootstrap newInstance() {
            return new Bootstrap().group(nioWorkerGroup).channelFactory(new ChannelFactory<Channel>() {
                @Override
                public Channel newChannel(EventLoop eventLoop) {
                   return new NioDatagramChannel(eventLoop, InternetProtocolFamily.IPv4);
                }

                @Override
                public String toString() {
                    return NioDatagramChannel.class.getSimpleName() + ".class";
                }
            });
        }
    });
    bfs.add(new Factory<Bootstrap>() {
        @Override
        public Bootstrap newInstance() {
            return new Bootstrap().group(oioWorkerGroup).channel(OioDatagramChannel.class);
        }
    });

    // Populate the combinations
    for (Factory<Bootstrap> sbf: bfs) {
        for (Factory<Bootstrap> cbf: bfs) {
            final Factory<Bootstrap> sbf0 = sbf;
            final Factory<Bootstrap> cbf0 = cbf;
            list.add(new Entry<Factory<Bootstrap>, Factory<Bootstrap>>() {
                @Override
                public Factory<Bootstrap> getKey() {
                    return sbf0;
                }

                @Override
                public Factory<Bootstrap> getValue() {
                    return cbf0;
                }

                @Override
                public Factory<Bootstrap> setValue(Factory<Bootstrap> value) {
                    throw new UnsupportedOperationException();
                }
            });
        }
    }

    return list;
}
项目:netty4.0.27Learn    文件:NioDatagramChannel.java   
/**
 * Create a new instance using the given {@link InternetProtocolFamily}. If {@code null} is used it will depend
 * on the Operation Systems default which will be chosen.
 */
public NioDatagramChannel(InternetProtocolFamily ipFamily) {
    this(newSocket(DEFAULT_SELECTOR_PROVIDER, ipFamily));
}
项目:netty4.0.27Learn    文件:NioDatagramChannel.java   
/**
 * Create a new instance using the given {@link SelectorProvider} and {@link InternetProtocolFamily}.
 * If {@link InternetProtocolFamily} is {@code null} it will depend on the Operation Systems default
 * which will be chosen.
 */
public NioDatagramChannel(SelectorProvider provider, InternetProtocolFamily ipFamily) {
    this(newSocket(provider, ipFamily));
}
项目:netty4study    文件:NioDatagramChannel.java   
/**
 * Create a new instance using the given {@link InternetProtocolFamily}. If {@code null} is used it will depend
 * on the Operation Systems default which will be chosen.
 */
public NioDatagramChannel(InternetProtocolFamily ipFamily) {
    this(newSocket(ipFamily));
}
项目:netty-netty-5.0.0.Alpha1    文件:NioDatagramChannel.java   
/**
 * Create a new instance using the given {@link InternetProtocolFamily}. If {@code null} is used it will depend
 * on the Operation Systems default which will be chosen.
 */
public NioDatagramChannel(EventLoop eventLoop, InternetProtocolFamily ipFamily) {
    this(eventLoop, newSocket(ipFamily));
}