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(ThreadFactory threadFactory, long tickDuration, TimeUnit unit, int ticksPerWheel) 

Source Link

Document

Creates a new timer.

Usage

From source file:org.apache.bookkeeper.client.TestRackawarePolicyNotificationUpdates.java

License:Apache License

@Override
protected void setUp() throws Exception {
    super.setUp();
    conf.setProperty(REPP_DNS_RESOLVER_CLASS, StaticDNSResolver.class.getName());

    StaticDNSResolver.reset();/*from  w  w  w . ja  v  a2 s .  co m*/
    StaticDNSResolver.addNodeToRack(InetAddress.getLocalHost().getHostAddress(),
            NetworkTopology.DEFAULT_REGION_AND_RACK);
    StaticDNSResolver.addNodeToRack("127.0.0.1", NetworkTopology.DEFAULT_REGION_AND_RACK);
    StaticDNSResolver.addNodeToRack("localhost", NetworkTopology.DEFAULT_REGION_AND_RACK);
    LOG.info("Set up static DNS Resolver.");

    timer = new HashedWheelTimer(new ThreadFactoryBuilder().setNameFormat("TestTimer-%d").build(),
            conf.getTimeoutTimerTickDurationMs(), TimeUnit.MILLISECONDS, conf.getTimeoutTimerNumTicks());

    repp = new RackawareEnsemblePlacementPolicy();
    repp.initialize(conf, Optional.<DNSToSwitchMapping>empty(), timer, DISABLE_ALL, NullStatsLogger.INSTANCE);
    repp.withDefaultRack(NetworkTopology.DEFAULT_REGION_AND_RACK);
}

From source file:org.apache.bookkeeper.client.TestRegionAwareEnsemblePlacementPolicy.java

License:Apache License

@Override
protected void setUp() throws Exception {
    super.setUp();
    StaticDNSResolver.reset();//from  ww w .  jav  a  2 s  .c  o  m
    updateMyRack(NetworkTopology.DEFAULT_REGION_AND_RACK);
    LOG.info("Set up static DNS Resolver.");
    conf.setProperty(REPP_DNS_RESOLVER_CLASS, StaticDNSResolver.class.getName());

    addr1 = new BookieSocketAddress("127.0.0.2", 3181);
    addr2 = new BookieSocketAddress("127.0.0.3", 3181);
    addr3 = new BookieSocketAddress("127.0.0.4", 3181);
    addr4 = new BookieSocketAddress("127.0.0.5", 3181);
    // update dns mapping
    StaticDNSResolver.addNodeToRack(addr1.getHostName(), "/r1/rack1");
    StaticDNSResolver.addNodeToRack(addr2.getHostName(), NetworkTopology.DEFAULT_REGION_AND_RACK);
    StaticDNSResolver.addNodeToRack(addr3.getHostName(), NetworkTopology.DEFAULT_REGION_AND_RACK);
    StaticDNSResolver.addNodeToRack(addr4.getHostName(), "/r1/rack2");
    ensemble.add(addr1);
    ensemble.add(addr2);
    ensemble.add(addr3);
    ensemble.add(addr4);

    writeSet = writeSetFromValues(0, 1, 2, 3);

    timer = new HashedWheelTimer(new ThreadFactoryBuilder().setNameFormat("TestTimer-%d").build(),
            conf.getTimeoutTimerTickDurationMs(), TimeUnit.MILLISECONDS, conf.getTimeoutTimerNumTicks());

    repp = new RegionAwareEnsemblePlacementPolicy();
    repp.initialize(conf, Optional.<DNSToSwitchMapping>empty(), timer, DISABLE_ALL, NullStatsLogger.INSTANCE);
}

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

License:Apache License

public BookieRequestProcessor(ServerConfiguration serverCfg, Bookie bookie, StatsLogger statsLogger,
        SecurityHandlerFactory shFactory, ByteBufAllocator allocator) throws SecurityException {
    this.serverCfg = serverCfg;
    this.allocator = allocator;
    this.waitTimeoutOnBackpressureMillis = serverCfg.getWaitTimeoutOnResponseBackpressureMillis();
    this.preserveMdcForTaskExecution = serverCfg.getPreserveMdcForTaskExecution();
    this.bookie = bookie;
    this.readThreadPool = createExecutor(this.serverCfg.getNumReadWorkerThreads(), "BookieReadThreadPool",
            serverCfg.getMaxPendingReadRequestPerThread(), statsLogger);
    this.writeThreadPool = createExecutor(this.serverCfg.getNumAddWorkerThreads(), "BookieWriteThreadPool",
            serverCfg.getMaxPendingAddRequestPerThread(), statsLogger);
    if (serverCfg.getNumLongPollWorkerThreads() <= 0 && readThreadPool != null) {
        this.longPollThreadPool = this.readThreadPool;
    } else {//w  w w .j  av  a2s  .  c om
        int numThreads = this.serverCfg.getNumLongPollWorkerThreads();
        if (numThreads <= 0) {
            numThreads = Runtime.getRuntime().availableProcessors();
        }
        this.longPollThreadPool = createExecutor(numThreads,
                "BookieLongPollThread-" + serverCfg.getBookiePort(), OrderedExecutor.NO_TASK_LIMIT,
                statsLogger);
    }
    this.highPriorityThreadPool = createExecutor(this.serverCfg.getNumHighPriorityWorkerThreads(),
            "BookieHighPriorityThread-" + serverCfg.getBookiePort(), OrderedExecutor.NO_TASK_LIMIT,
            statsLogger);
    this.shFactory = shFactory;
    if (shFactory != null) {
        shFactory.init(NodeType.Server, serverCfg, allocator);
    }

    this.requestTimer = new HashedWheelTimer(
            new ThreadFactoryBuilder().setNameFormat("BookieRequestTimer-%d").build(),
            this.serverCfg.getRequestTimerTickDurationMs(), TimeUnit.MILLISECONDS,
            this.serverCfg.getRequestTimerNumTicks());

    if (waitTimeoutOnBackpressureMillis > 0) {
        blacklistedChannels = Optional.of(CacheBuilder.newBuilder()
                .expireAfterWrite(waitTimeoutOnBackpressureMillis, TimeUnit.MILLISECONDS).build());
    } else {
        blacklistedChannels = Optional.empty();
    }

    if (serverCfg.getCloseChannelOnResponseTimeout()) {
        onResponseTimeout = (ch) -> {
            LOG.warn("closing channel {} because it was non-writable for longer than {} ms", ch,
                    waitTimeoutOnBackpressureMillis);
            ch.close();
        };
    } else {
        // noop
        onResponseTimeout = (ch) -> {
        };
    }

    // Expose Stats
    this.statsEnabled = serverCfg.isStatisticsEnabled();
    this.requestStats = new RequestStats(statsLogger);

    int maxAdds = serverCfg.getMaxAddsInProgressLimit();
    addsSemaphore = maxAdds > 0 ? new Semaphore(maxAdds, true) : null;

    int maxReads = serverCfg.getMaxReadsInProgressLimit();
    readsSemaphore = maxReads > 0 ? new Semaphore(maxReads, true) : null;
}

From source file:org.apache.distributedlog.impl.BKNamespaceDriver.java

License:Apache License

private void initializeBookKeeperClients() throws IOException {
    this.eventLoopGroup = getDefaultEventLoopGroup(conf.getBKClientNumberIOThreads());
    this.requestTimer = new HashedWheelTimer(
            new ThreadFactoryBuilder().setNameFormat("DLFactoryTimer-%d").build(),
            conf.getTimeoutTimerTickDurationMs(), TimeUnit.MILLISECONDS, conf.getTimeoutTimerNumTicks());
    // Build bookkeeper client for writers
    this.sharedWriterBKCBuilder = createBKCBuilder(String.format("bk:%s:factory_writer_shared", namespace),
            conf, bkdlConfig.getBkZkServersForWriter(), bkdlConfig.getBkLedgersPath(), eventLoopGroup,
            requestTimer, Optional.of(featureProvider.scope("bkc")), statsLogger);
    this.writerBKC = this.sharedWriterBKCBuilder.build();

    // Build bookkeeper client for readers
    if (bkdlConfig.getBkZkServersForWriter().equals(bkdlConfig.getBkZkServersForReader())) {
        this.sharedReaderBKCBuilder = this.sharedWriterBKCBuilder;
    } else {/*from w w w.ja v  a 2 s  .c om*/
        this.sharedReaderBKCBuilder = createBKCBuilder(String.format("bk:%s:factory_reader_shared", namespace),
                conf, bkdlConfig.getBkZkServersForReader(), bkdlConfig.getBkLedgersPath(), eventLoopGroup,
                requestTimer, Optional.<FeatureProvider>absent(), statsLogger);
    }
    this.readerBKC = this.sharedReaderBKCBuilder.build();
}

From source file:org.waarp.common.filemonitor.FileMonitor.java

License:Open Source License

public void start() {
    if (timer == null) {
        timer = new HashedWheelTimer(new WaarpThreadFactory("TimerFileMonitor_" + name), 100,
                TimeUnit.MILLISECONDS, 8);
        future = new WaarpFuture(true);
        internalfuture = new WaarpFuture(true);
        if (commandValidFileFactory != null && executor == null) {
            if (fixedThreadPool > 1) {
                executor = Executors.newFixedThreadPool(fixedThreadPool,
                        new WaarpThreadFactory("FileMonitorRunner_" + name));
            } else if (fixedThreadPool == 0) {
                executor = Executors.newCachedThreadPool(new WaarpThreadFactory("FileMonitorRunner_" + name));
            }/* w  ww. ja va  2s.  c  o  m*/
        }
        timer.newTimeout(new FileMonitorTimerTask(this), elapseTime, TimeUnit.MILLISECONDS);
    } // else already started
    if (elapseWaarpTime >= defaultDelay && timerWaarp == null && commandCheckIteration != null) {
        timerWaarp = new HashedWheelTimer(new WaarpThreadFactory("TimerFileMonitorWaarp_" + name), 100,
                TimeUnit.MILLISECONDS, 8);
        timerWaarp.newTimeout(new FileMonitorTimerInformationTask(commandCheckIteration), elapseWaarpTime,
                TimeUnit.MILLISECONDS);
    }
}