Search in sources :

Example 1 with MulticastMessageChannel

use of org.xnio.channels.MulticastMessageChannel in project undertow by undertow-io.

the class MCMPAdvertiseTask method advertise.

static void advertise(final ModClusterContainer container, final MCMPConfig.AdvertiseConfig config, final XnioWorker worker) throws IOException {
    InetSocketAddress bindAddress;
    final InetAddress group = InetAddress.getByName(config.getAdvertiseAddress());
    if (group == null) {
        bindAddress = new InetSocketAddress(config.getAdvertisePort());
    } else {
        bindAddress = new InetSocketAddress(group, config.getAdvertisePort());
    }
    MulticastMessageChannel channel;
    try {
        channel = worker.createUdpServer(bindAddress, null, OptionMap.EMPTY);
    } catch (IOException e) {
        if (group != null && (linuxLike || windows)) {
            //try again with no group
            //see UNDERTOW-454
            UndertowLogger.ROOT_LOGGER.potentialCrossTalking(group, (group instanceof Inet4Address) ? "IPv4" : "IPv6", e.getLocalizedMessage());
            bindAddress = new InetSocketAddress(config.getAdvertisePort());
            channel = worker.createUdpServer(bindAddress, null, OptionMap.EMPTY);
        } else {
            throw e;
        }
    }
    final MCMPAdvertiseTask task = new MCMPAdvertiseTask(container, config, channel);
    //execute immediately, so there is no delay before load balancing starts working
    channel.getIoThread().execute(task);
    channel.getIoThread().executeAtInterval(task, config.getAdvertiseFrequency(), TimeUnit.MILLISECONDS);
}
Also used : Inet4Address(java.net.Inet4Address) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) InetAddress(java.net.InetAddress) MulticastMessageChannel(org.xnio.channels.MulticastMessageChannel)

Aggregations

IOException (java.io.IOException)1 Inet4Address (java.net.Inet4Address)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 MulticastMessageChannel (org.xnio.channels.MulticastMessageChannel)1