Example usage for io.netty.util HashedWheelTimer HashedWheelTimer

List of usage examples for io.netty.util HashedWheelTimer HashedWheelTimer

Introduction

In this page you can find the example usage for io.netty.util HashedWheelTimer HashedWheelTimer.

Prototype

public HashedWheelTimer() 

Source Link

Document

Creates a new timer with the default thread factory ( Executors#defaultThreadFactory() ), default tick duration, and default number of ticks per wheel.

Usage

From source file:io.github.stormcloud_dev.stormcloud.StormCloud.java

License:Apache License

public StormCloud(int port) {
    this.port = port;
    logger = Logger.getLogger(getClass().getName());
    loadConfiguration();/*from ww w. j a  va 2s.c  o  m*/
    timer = new HashedWheelTimer();
    commandManager = new CommandManager();
    eventManager = new EventManager();
    roomManager = new RoomManager(this);
    roomManager.loadRooms();
}

From source file:io.scalecube.socketio.session.SocketIOHeartbeatSchedulerTest.java

License:Apache License

@Before
public void init() {
    timer = new HashedWheelTimer();
    timer.start();/*from   w w w.  j  a  va 2s.  com*/
    jmockContext = new JUnit4Mockery() {
        {
            setThreadingPolicy(new Synchroniser());
        }
    };
    SocketIOHeartbeatScheduler.setHashedWheelTimer(timer);
    SocketIOHeartbeatScheduler.setHeartbeatInterval(1);
    SocketIOHeartbeatScheduler.setHeartbeatTimeout(3);
    session = jmockContext.mock(ManagedSession.class);
    scheduler = new SocketIOHeartbeatScheduler(session);
}

From source file:me.schiz.jmeter.ring.tcp.Ring.java

License:Apache License

public Ring init() {
    //hashedWheelTimer = new HashedWheelTimer();
    //hashedWheelTimer.start();
    for (int i = 0; i < hashedWheelTimers.length; i++) {
        hashedWheelTimers[i] = new HashedWheelTimer();
        hashedWheelTimers[i].start();/*from   w ww. ja  va  2  s. c  o  m*/
    }

    for (int i = 0; i < selectorsCount; i++) {
        try {
            selectors[i] = Selector.open();
        } catch (IOException e) {
            log.error("can't open selector ", e);
        }
    }

    for (int i = 0; i < selectorsCount; ++i) {
        eventLoopRunnables[i] = new EventLoopRunnable(this, selectors[i]);
        threads[i] = new Thread(eventLoopRunnables[i]);
        threads[i].setDaemon(true);
        threads[i].setName("EventLoopThread#" + i);
        threads[i].start();
    }

    weakSocketToTokenMap = new MapMaker().concurrencyLevel(Runtime.getRuntime().availableProcessors())
            .initialCapacity(socketsCount).softKeys().makeMap();

    for (int i = 0; i < socketsCount; i++) {
        String[] addr;
        String host = "localhost";
        int port;
        try {
            addr = addrs[i % addrs.length].split(":");
            host = addr[0];
            port = Integer.parseInt(addr[1]);
        } catch (PatternSyntaxException | NumberFormatException e) {
            log.error("bad address \"" + addrs[i % addrs.length] + "\"", e);
            return this;
        }
        try {
            Token t = ring.get(i);
            t.id = i;
            t.targetAddress = new InetSocketAddress(host, port);
            setSocketOptions(t.socketChannel);
            try {
                eventLoopRunnables[i % selectorsCount].register(t.socketChannel,
                        SelectionKey.OP_CONNECT | SelectionKey.OP_READ);
            } catch (InterruptedException e) {
                log.error("InterruptedException when register SocketChannel", e);
                break;
            }
            ring.get(i).connectStartTS = System.nanoTime();
            ring.get(i).socketChannel.connect(ring.get(i).targetAddress);
            ring.get(i).timeout = hashedWheelTimers[i % hashedWheelTimers.length]
                    .newTimeout(new TimeoutTask(this, i, "connect"), connectTimeout, TimeUnit.MILLISECONDS);
            weakSocketToTokenMap.putIfAbsent(t.socketChannel, t);
        } catch (IOException e) {
            log.error("IOException ", e);
        }
    }

    schedEx.scheduleWithFixedDelay(new RingInfoRunnable(this), 0, 1000, TimeUnit.MILLISECONDS);

    return this;
}

From source file:me.schiz.jmeter.ring.udp.Ring.java

License:Apache License

public Ring init() {
    hashedWheelTimer = new HashedWheelTimer();
    eventLoopRunnables = new EventLoopRunnable[THREADS];
    for (int i = 0; i < selectorsCount; ++i) {
        eventLoopRunnables[i] = new EventLoopRunnable(this);
        threads[i] = new Thread(eventLoopRunnables[i]);
        threads[i].setDaemon(true);//from   w ww . java2  s.  c om
        threads[i].setName("EventLoopThread#" + i);
    }

    weakSocketToTokenMap = new MapMaker().concurrencyLevel(Runtime.getRuntime().availableProcessors())
            .initialCapacity(capacity).softKeys().makeMap();

    for (int i = 0; i < capacity; i++) {
        String[] addr;
        String host = "localhost";
        int port;
        try {
            addr = addrs[i % addrs.length].split(":");
            host = addr[0];
            port = Integer.parseInt(addr[1]);
        } catch (PatternSyntaxException | NumberFormatException e) {
            log.error("bad address \"" + addrs[i % addrs.length] + "\"", e);
            return this;
        }
        try {
            Token t = ring.get(i);
            t.id = i;
            t.targetAddress = new InetSocketAddress(host, port);
            setSocketOptions(t.datagramChannel);
            try {
                eventLoopRunnables[i % selectorsCount].register(t.datagramChannel, SelectionKey.OP_READ);
            } catch (InterruptedException e) {
                log.error("InterruptedException when register SocketChannel", e);
                break;
            }
            ring.get(i).datagramChannel.connect(ring.get(i).targetAddress);
            weakSocketToTokenMap.putIfAbsent(t.datagramChannel, t);
        } catch (IOException e) {
            log.error("IOException ", e);
        }
    }

    for (int i = 0; i < selectorsCount; i++)
        threads[i].start();

    //schedEx.scheduleWithFixedDelay(new RingInfoRunnable(this), 0, 1000, TimeUnit.MILLISECONDS);

    return this;
}

From source file:mmo.server.ServerModule.java

License:Open Source License

@Provides
@Singleton
HashedWheelTimer provideHashedWheelTimer() {
    return new HashedWheelTimer();
}

From source file:net.floodlightcontroller.core.internal.Controller.java

License:Apache License

/**
 * Initialize internal data structures//from w w  w  . ja  v a2 s  . c o  m
 */
public void init(Map<String, String> configParams) throws FloodlightModuleException {

    this.moduleLoaderState = ModuleLoaderState.INIT;

    // These data structures are initialized here because other
    // module's startUp() might be called before ours        
    this.messageListeners = new ConcurrentHashMap<OFType, ListenerDispatcher<OFType, IOFMessageListener>>();
    this.haListeners = new ListenerDispatcher<HAListenerTypeMarker, IHAListener>();
    this.controllerNodeIPsCache = new HashMap<String, String>();
    this.updates = new LinkedBlockingQueue<IUpdate>();
    this.providerMap = new HashMap<String, List<IInfoProvider>>();
    this.completionListeners = new ConcurrentLinkedQueue<IControllerCompletionListener>();

    setConfigParams(configParams);

    HARole initialRole = getInitialRole(configParams);
    this.notifiedRole = initialRole;
    this.shutdownService = new ShutdownServiceImpl();

    this.roleManager = new RoleManager(this, this.shutdownService, this.notifiedRole,
            INITIAL_ROLE_CHANGE_DESCRIPTION);
    this.timer = new HashedWheelTimer();

    // Switch Service Startup
    this.switchService.registerLogicalOFMessageCategory(LogicalOFMessageCategory.MAIN);
    this.switchService.addOFSwitchListener(new NotificationSwitchListener());

    this.counters = new ControllerCounters(debugCounterService);
}

From source file:net.hasor.rsf.remoting.transport.customer.RsfRequestManager.java

License:Apache License

public RsfRequestManager(AbstractRsfContext rsfContext) {
    this.rsfContext = rsfContext;
    this.clientManager = new InnerClientManager(this);
    this.rsfResponse = new ConcurrentHashMap<Long, RsfFuture>();
    this.timer = new HashedWheelTimer();
    this.requestCount = new AtomicInteger(0);
}

From source file:net.javaforge.netty.servlet.bridge.ServletBridgeChannelPipelineFactory.java

License:Apache License

public ServletBridgeChannelPipelineFactory(WebappConfiguration config) {

    this.timer = new HashedWheelTimer();
    this.idleStateHandler = new IdleStateHandler(60, 30, 0); // timer
    // must/*from w  ww  .  ja v a2  s  .com*/
    // be
    // shared.

    ServletBridgeWebapp webapp = ServletBridgeWebapp.get();
    webapp.init(config, allChannels);

    new Thread(this.watchdog = new HttpSessionWatchdog()).start();
}

From source file:org.apache.bookkeeper.proto.LongPollReadEntryProcessorV3Test.java

License:Apache License

@Before
public void setup() {
    executor = Executors.newSingleThreadExecutor();
    timer = new HashedWheelTimer();
}

From source file:org.apache.camel.component.netty4.NettyComponent.java

License:Apache License

@Override
protected void doStart() throws Exception {
    if (timer == null) {
        timer = new HashedWheelTimer();
    }/*from  w ww. j  a  va 2s.c o m*/

    if (configuration == null) {
        configuration = new NettyConfiguration();
    }
    if (configuration.isOrderedThreadPoolExecutor()) {
        executorService = createExecutorService();
    }

    super.doStart();
}