All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.digitalpetri.enip.EtherNetIpShared Maven / Gradle / Ivy

There is a newer version: 1.5.0-RC1
Show newest version
package com.digitalpetri.enip;

import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.HashedWheelTimer;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class EtherNetIpShared {

    private static EventLoopGroup SHARED_EVENT_LOOP;
    private static HashedWheelTimer SHARED_WHEEL_TIMER;
    private static ExecutorService SHARED_EXECUTOR;

    /**
     * @return a shared {@link io.netty.channel.EventLoopGroup}.
     */
    public static synchronized EventLoopGroup sharedEventLoop() {
        if (SHARED_EVENT_LOOP == null) {
            SHARED_EVENT_LOOP = new NioEventLoopGroup();
        }
        return SHARED_EVENT_LOOP;
    }

    /**
     * @return a shared {@link io.netty.util.HashedWheelTimer}.
     */
    public static synchronized HashedWheelTimer sharedWheelTimer() {
        if (SHARED_WHEEL_TIMER == null) {
            SHARED_WHEEL_TIMER = new HashedWheelTimer();
        }
        return SHARED_WHEEL_TIMER;
    }

    /**
     * @return a shared {@link java.util.concurrent.ExecutorService}.
     */
    public static synchronized ExecutorService sharedExecutorService() {
        if (SHARED_EXECUTOR == null) {
            SHARED_EXECUTOR = Executors.newWorkStealingPool();
        }
        return SHARED_EXECUTOR;
    }

    /**
     * Release/shutdown/cleanup any shared resources that were created.
     */
    public static synchronized void releaseSharedResources() {
        if (SHARED_EVENT_LOOP != null) {
            SHARED_EVENT_LOOP.shutdownGracefully();
            SHARED_EVENT_LOOP = null;
        }
        if (SHARED_WHEEL_TIMER != null) {
            SHARED_WHEEL_TIMER.stop();
            SHARED_WHEEL_TIMER = null;
        }
        if (SHARED_EXECUTOR != null) {
            SHARED_EXECUTOR.shutdown();
            SHARED_EXECUTOR = null;
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy