alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (SctpTestPermutation.java)

This example Java source code file (SctpTestPermutation.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

arraylist, bootstrap, bootstrapcombofactory, bootstrapfactory, bosses, defaultthreadfactory, eventloopgroup, list, nioeventloopgroup, override, sctptestpermutation, serverbootstrap, util, workers

The SctpTestPermutation.java Java example source code

/*
 * Copyright 2012 The Netty Project
 *
 * The Netty Project licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package io.netty.testsuite.transport.sctp;

import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.oio.OioEventLoopGroup;
import io.netty.channel.sctp.nio.NioSctpChannel;
import io.netty.channel.sctp.nio.NioSctpServerChannel;
import io.netty.channel.sctp.oio.OioSctpChannel;
import io.netty.channel.sctp.oio.OioSctpServerChannel;
import io.netty.testsuite.util.TestUtils;
import io.netty.testsuite.transport.TestsuitePermutation.BootstrapComboFactory;
import io.netty.testsuite.transport.TestsuitePermutation.BootstrapFactory;
import io.netty.util.concurrent.DefaultThreadFactory;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public final class SctpTestPermutation {

    private static final int BOSSES = 2;
    private static final int WORKERS = 3;
    private static final EventLoopGroup nioBossGroup =
            new NioEventLoopGroup(BOSSES, new DefaultThreadFactory("testsuite-sctp-nio-boss", true));
    private static final EventLoopGroup nioWorkerGroup =
            new NioEventLoopGroup(WORKERS, new DefaultThreadFactory("testsuite-sctp-nio-worker", true));
    private static final EventLoopGroup oioBossGroup =
            new OioEventLoopGroup(Integer.MAX_VALUE, new DefaultThreadFactory("testsuite-sctp-oio-boss", true));
    private static final EventLoopGroup oioWorkerGroup =
            new OioEventLoopGroup(Integer.MAX_VALUE, new DefaultThreadFactory("testsuite-sctp-oio-worker", true));

    static List<BootstrapFactory sctpServerChannel() {
        if (!TestUtils.isSctpSupported()) {
            return Collections.emptyList();
        }

        List<BootstrapFactory list = new ArrayList>();
        // Make the list of ServerBootstrap factories.
        list.add(new BootstrapFactory<ServerBootstrap>() {
            @Override
            public ServerBootstrap newInstance() {
                return new ServerBootstrap().
                        group(nioBossGroup, nioWorkerGroup).
                        channel(NioSctpServerChannel.class);
            }
        });
        list.add(new BootstrapFactory<ServerBootstrap>() {
            @Override
            public ServerBootstrap newInstance() {
                return new ServerBootstrap().
                        group(oioBossGroup, oioWorkerGroup).
                        channel(OioSctpServerChannel.class);
            }
        });

        return list;
    }

    static List<BootstrapFactory sctpClientChannel() {
        if (!TestUtils.isSctpSupported()) {
            return Collections.emptyList();
        }

        List<BootstrapFactory list = new ArrayList>();
        list.add(new BootstrapFactory<Bootstrap>() {
            @Override
            public Bootstrap newInstance() {
                return new Bootstrap().group(nioWorkerGroup).channel(NioSctpChannel.class);
            }
        });
        list.add(new BootstrapFactory<Bootstrap>() {
            @Override
            public Bootstrap newInstance() {
                return new Bootstrap().group(oioWorkerGroup).channel(OioSctpChannel.class);
            }
        });
        return list;
    }

    static List<BootstrapComboFactory sctpChannel() {
        List<BootstrapComboFactory list =
                new ArrayList<BootstrapComboFactory();

        // Make the list of SCTP ServerBootstrap factories.
        List<BootstrapFactory sbfs = sctpServerChannel();

        // Make the list of SCTP Bootstrap factories.
        List<BootstrapFactory cbfs = sctpClientChannel();

        // Populate the combinations
        for (BootstrapFactory<ServerBootstrap> sbf: sbfs) {
            for (BootstrapFactory<Bootstrap> cbf: cbfs) {
                final BootstrapFactory<ServerBootstrap> sbf0 = sbf;
                final BootstrapFactory<Bootstrap> cbf0 = cbf;
                list.add(new BootstrapComboFactory<ServerBootstrap, Bootstrap>() {
                    @Override
                    public ServerBootstrap newServerInstance() {
                        return sbf0.newInstance();
                    }

                    @Override
                    public Bootstrap newClientInstance() {
                        return cbf0.newInstance();
                    }
                });
            }
        }

        return list;
    }

    private SctpTestPermutation() { }
}

Other Java examples (source code examples)

Here is a short list of links related to this Java SctpTestPermutation.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.