当前位置: 首页>>代码示例>>Java>>正文


Java HashedWheelTimer类代码示例

本文整理汇总了Java中io.netty.util.HashedWheelTimer的典型用法代码示例。如果您正苦于以下问题:Java HashedWheelTimer类的具体用法?Java HashedWheelTimer怎么用?Java HashedWheelTimer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HashedWheelTimer类属于io.netty.util包,在下文中一共展示了HashedWheelTimer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testTryWithResourcesShouldCloseAllClustersButNotTimerIfProvided

import io.netty.util.HashedWheelTimer; //导入依赖的package包/类
@Test
public void testTryWithResourcesShouldCloseAllClustersButNotTimerIfProvided() throws Exception {
  EventLoopGroup eventLoop;
  Timer timer = new HashedWheelTimer();

  try (Server server = Server.builder().withTimer(timer).build()) {
    // Do nothing here, since this is a unit test, we don't want to create any inet sockets
    // which is what Server does by default.
    eventLoop = server.eventLoopGroup;
  }

  // event loop should have been closed since a custom one was not provided.
  assertThat(eventLoop.isShutdown()).isTrue();
  // timer should not have been closed since a custom one was provided.
  timer.newTimeout(
      timeout -> {
        // noop
      },
      1,
      TimeUnit.SECONDS);
  timer.stop();
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:23,代码来源:ServerTest.java

示例2: createConfig

import io.netty.util.HashedWheelTimer; //导入依赖的package包/类
/**
 * 生成默认的httpclient config
 *
 * @return the config
 */
public static AsyncHttpClientConfig createConfig(int connectTimeout, int requestTimeout) {
    HashedWheelTimer timer = new HashedWheelTimer();
    timer.start();
    DefaultChannelPool channelPool = new DefaultChannelPool(60000,
            -1,
            DefaultChannelPool.PoolLeaseStrategy.LIFO,
            timer,
            3000);

    return new DefaultAsyncHttpClientConfig.Builder()
            .setConnectTimeout(connectTimeout)
            .setRequestTimeout(requestTimeout)
            .setMaxConnectionsPerHost(10000)
            .setValidateResponseHeaders(false)
            .setMaxRequestRetry(0)
            .setChannelPool(channelPool)
            .build();
}
 
开发者ID:darren-fu,项目名称:RestyPass,代码行数:24,代码来源:AsyncHttpConfigFactory.java

示例3: initTimer

import io.netty.util.HashedWheelTimer; //导入依赖的package包/类
protected void initTimer(MasterSlaveServersConfig config) {
    int[] timeouts = new int[]{config.getRetryInterval(), config.getTimeout(), config.getReconnectionTimeout()};
    Arrays.sort(timeouts);
    int minTimeout = timeouts[0];
    if (minTimeout % 100 != 0) {
        minTimeout = (minTimeout % 100) / 2;
    } else if (minTimeout == 100) {
        minTimeout = 50;
    } else {
        minTimeout = 100;
    }
    
    timer = new HashedWheelTimer(Executors.defaultThreadFactory(), minTimeout, TimeUnit.MILLISECONDS, 1024);
    
    // to avoid assertion error during timer.stop invocation
    try {
        Field leakField = HashedWheelTimer.class.getDeclaredField("leak");
        leakField.setAccessible(true);
        leakField.set(timer, null);
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
    
    connectionWatcher = new IdleConnectionWatcher(this, config);
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:26,代码来源:MasterSlaveConnectionManager.java

示例4: init

import io.netty.util.HashedWheelTimer; //导入依赖的package包/类
public void init() throws SyncException {
    cg = new DefaultChannelGroup("Cluster Bootstrap", GlobalEventExecutor.INSTANCE);

    workerExecutor = new NioEventLoopGroup();
    timer = new HashedWheelTimer();
    
    bootstrap = new Bootstrap()
    .group(workerExecutor)
    .channel(NioSocketChannel.class)
    .option(ChannelOption.SO_REUSEADDR, true)
    .option(ChannelOption.SO_KEEPALIVE, true)
    .option(ChannelOption.TCP_NODELAY, true)
    .option(ChannelOption.SO_SNDBUF, RPCService.SEND_BUFFER_SIZE)
    .option(ChannelOption.SO_RCVBUF, RPCService.SEND_BUFFER_SIZE)
    .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, RPCService.CONNECT_TIMEOUT);
    
    pipelineFactory = new BootstrapChannelInitializer(timer, this);
    bootstrap.handler(pipelineFactory);
}
 
开发者ID:xuraylei,项目名称:fresco_floodlight,代码行数:20,代码来源:BootstrapClient.java

示例5: startUp

import io.netty.util.HashedWheelTimer; //导入依赖的package包/类
@Override
public void startUp(FloodlightModuleContext context) 
        throws FloodlightModuleException {
    shutdown = false;
    workerExecutor = new NioEventLoopGroup();
    timer = new HashedWheelTimer();
    
    pipelineFactory = new RemoteSyncChannelInitializer(timer, this);
    
    final Bootstrap bootstrap = new Bootstrap()
    .channel(NioSocketChannel.class)
    .group(workerExecutor)
    .option(ChannelOption.SO_REUSEADDR, true)
    .option(ChannelOption.SO_KEEPALIVE, true)
    .option(ChannelOption.TCP_NODELAY, true)
    .option(ChannelOption.SO_SNDBUF, RPCService.SEND_BUFFER_SIZE)
    .option(ChannelOption.SO_RCVBUF, RPCService.SEND_BUFFER_SIZE)
    .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, RPCService.CONNECT_TIMEOUT)
    .handler(pipelineFactory);
    
    clientBootstrap = bootstrap;
}
 
开发者ID:xuraylei,项目名称:fresco_floodlight,代码行数:23,代码来源:RemoteSyncManager.java

示例6: doStart

import io.netty.util.HashedWheelTimer; //导入依赖的package包/类
@Override
protected void doStart(Listener listener) throws Throwable {
    workerGroup = new NioEventLoopGroup(http_work, new DefaultThreadFactory(ThreadNames.T_HTTP_CLIENT));
    b = new Bootstrap();
    b.group(workerGroup);
    b.channel(NioSocketChannel.class);
    b.option(ChannelOption.SO_KEEPALIVE, true);
    b.option(ChannelOption.TCP_NODELAY, true);
    b.option(ChannelOption.SO_REUSEADDR, true);
    b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 4000);
    b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    b.handler(new ChannelInitializer<SocketChannel>() {
        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline().addLast("decoder", new HttpResponseDecoder());
            ch.pipeline().addLast("aggregator", new HttpObjectAggregator(maxContentLength));
            ch.pipeline().addLast("encoder", new HttpRequestEncoder());
            ch.pipeline().addLast("handler", new HttpClientHandler(NettyHttpClient.this));
        }
    });
    timer = new HashedWheelTimer(new NamedThreadFactory(T_HTTP_TIMER), 1, TimeUnit.SECONDS, 64);
    listener.onSuccess();
}
 
开发者ID:mpusher,项目名称:mpush,代码行数:24,代码来源:NettyHttpClient.java

示例7: PulsarClientImpl

import io.netty.util.HashedWheelTimer; //导入依赖的package包/类
public PulsarClientImpl(String serviceUrl, ClientConfiguration conf, EventLoopGroup eventLoopGroup,
        ConnectionPool cnxPool)
        throws PulsarClientException {
    if (isBlank(serviceUrl) || conf == null || eventLoopGroup == null) {
        throw new PulsarClientException.InvalidConfigurationException("Invalid client configuration");
    }
    this.eventLoopGroup = eventLoopGroup;
    this.conf = conf;
    conf.getAuthentication().start();
    this.cnxPool = cnxPool;
    if (serviceUrl.startsWith("http")) {
        lookup = new HttpLookupService(serviceUrl, conf, eventLoopGroup);
    } else {
        lookup = new BinaryProtoLookupService(this, serviceUrl, conf.isUseTls());
    }
    timer = new HashedWheelTimer(new DefaultThreadFactory("pulsar-timer"), 1, TimeUnit.MILLISECONDS);
    externalExecutorProvider = new ExecutorProvider(conf.getListenerThreads(), "pulsar-external-listener");
    producers = Maps.newIdentityHashMap();
    consumers = Maps.newIdentityHashMap();
    state.set(State.Open);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:22,代码来源:PulsarClientImpl.java

示例8: HashedWheelGatherer

import io.netty.util.HashedWheelTimer; //导入依赖的package包/类
/**
 *
 * @param handler Called with a request when all parts are received or it expires.
 * @param numParts number of parts for each request
 * @param timeoutDuration Expiration time for incomplete requests
 * @param unit time unit for timeoutDuration
 * @param timeoutMaxError a value in range (0 and 1], where the timeout might happen at time timeoutDuration + timeoutMaxError*timeoutDuration. A larger value means a more efficient data structure.
 */
public HashedWheelGatherer(RequestHandler<T> handler, int numParts, long timeoutDuration, TimeUnit unit, double timeoutMaxError) {

	if (timeoutMaxError <= 0 || timeoutMaxError > 1) {
		throw new IllegalArgumentException(String.format("timeoutMaxError must be in range (0, 1] (got %f)", timeoutMaxError));
	}

	timeoutDurationNs = unit.toNanos(timeoutDuration);
	inflightRequests = new ConcurrentHashMap<>();

	// create the wheel timer
	int numSteps = (int)Math.round(1. / timeoutMaxError);
	long tickDurationNs = Math.max(unit.toNanos(timeoutDuration) / numSteps, 1);

	hashedWheelTimer = new HashedWheelTimer(r -> {
		// Use daemon threads
		Thread t = Executors.defaultThreadFactory().newThread(r);
		t.setDaemon(true);
		return t;
	}, tickDurationNs, TimeUnit.NANOSECONDS, numSteps);

	hashedWheelTimer.start();

	this.numParts = numParts;
	this.handler = handler;
}
 
开发者ID:turn,项目名称:gatherer,代码行数:34,代码来源:HashedWheelGatherer.java

示例9: init

import io.netty.util.HashedWheelTimer; //导入依赖的package包/类
public void init() throws SyncException {
    cg = new DefaultChannelGroup("Cluster Bootstrap", GlobalEventExecutor.INSTANCE);

    workerExecutor = new NioEventLoopGroup();
    timer = new HashedWheelTimer();

    bootstrap = new Bootstrap()
    .group(workerExecutor)
    .channel(NioSocketChannel.class)
    .option(ChannelOption.SO_REUSEADDR, true)
    .option(ChannelOption.SO_KEEPALIVE, true)
    .option(ChannelOption.TCP_NODELAY, true)
    .option(ChannelOption.SO_SNDBUF, RPCService.SEND_BUFFER_SIZE)
    .option(ChannelOption.SO_RCVBUF, RPCService.SEND_BUFFER_SIZE)
    .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, RPCService.CONNECT_TIMEOUT);

    pipelineFactory = new BootstrapChannelInitializer(timer, this);
    bootstrap.handler(pipelineFactory);
}
 
开发者ID:zhenshengcai,项目名称:floodlight-hardware,代码行数:20,代码来源:BootstrapClient.java

示例10: startUp

import io.netty.util.HashedWheelTimer; //导入依赖的package包/类
@Override
public void startUp(FloodlightModuleContext context)
        throws FloodlightModuleException {
    shutdown = false;
    workerExecutor = new NioEventLoopGroup();
    timer = new HashedWheelTimer();

    pipelineFactory = new RemoteSyncChannelInitializer(timer, this);

    final Bootstrap bootstrap = new Bootstrap()
    .channel(NioSocketChannel.class)
    .group(workerExecutor)
    .option(ChannelOption.SO_REUSEADDR, true)
    .option(ChannelOption.SO_KEEPALIVE, true)
    .option(ChannelOption.TCP_NODELAY, true)
    .option(ChannelOption.SO_SNDBUF, RPCService.SEND_BUFFER_SIZE)
    .option(ChannelOption.SO_RCVBUF, RPCService.SEND_BUFFER_SIZE)
    .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, RPCService.CONNECT_TIMEOUT)
    .handler(pipelineFactory);

    clientBootstrap = bootstrap;
}
 
开发者ID:zhenshengcai,项目名称:floodlight-hardware,代码行数:23,代码来源:RemoteSyncManager.java

示例11: NettyCenter

import io.netty.util.HashedWheelTimer; //导入依赖的package包/类
/**
 * 私有构造函数
 */
private NettyCenter() {
    int maybeThreadSize = Runtime.getRuntime().availableProcessors();
    if (maybeThreadSize == 1) maybeThreadSize += 2;
    else if (maybeThreadSize == 8) maybeThreadSize = 2;
    else if (maybeThreadSize > 8) maybeThreadSize /= 2;
    /**
     * 构造事件循环组
     */
    eventLoopGroup = new NioEventLoopGroup(maybeThreadSize, new DefaultThreadFactory("NettyNioLoopGroup"));
    /**
     * 构造定时器
     */
    hashedWheelTimer = new HashedWheelTimer(new DefaultThreadFactory("NettyHashedWheelTimer"));
    /**
     * 构造 SSL 环境
     */
    try {
        SslContextBuilder sslContextBuilder = SslContextBuilder.forClient();
        sslContextBuilder.clientAuth(ClientAuth.OPTIONAL);
        simpleClientSslContext = sslContextBuilder.build();
    } catch (Throwable e) {
        log.error("NettyCenter :: initialize client sslcontext error!", e);
    }
}
 
开发者ID:316181444,项目名称:GameServerFramework,代码行数:28,代码来源:NettyCenter.java

示例12: setup

import io.netty.util.HashedWheelTimer; //导入依赖的package包/类
private void setup() {
  MetricsRegistry registry = new MetricsRegistry();
  _timedExecutor = new ScheduledThreadPoolExecutor(1);
  _service = new ThreadPoolExecutor(10, 10, 10, TimeUnit.DAYS, new LinkedBlockingDeque<Runnable>());
  _eventLoopGroup = new NioEventLoopGroup(10);
  _timer = new HashedWheelTimer();

  NettyClientMetrics clientMetrics = new NettyClientMetrics(registry, "client_");
  PooledNettyClientResourceManager rm = new PooledNettyClientResourceManager(_eventLoopGroup, _timer, clientMetrics);
  _pool =
      new KeyedPoolImpl<ServerInstance, NettyClientConnection>(1, _maxActiveConnections, 300000, 10, rm,
          _timedExecutor, MoreExecutors.sameThreadExecutor(), registry);
  rm.setPool(_pool);
  _scatterGather = new ScatterGatherImpl(_pool, _service);
  for (AsyncReader r : _readerThreads) {
    r.start();
  }
}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:19,代码来源:ScatterGatherPerfClient.java

示例13: EtherNetIpClientConfig

import io.netty.util.HashedWheelTimer; //导入依赖的package包/类
public EtherNetIpClientConfig(String hostname,
                              int port,
                              int vendorId,
                              int serialNumber,
                              Duration timeout,
                              ExecutorService executor,
                              EventLoopGroup eventLoop,
                              HashedWheelTimer wheelTimer,
                              Consumer<Bootstrap> bootstrapConsumer) {

    this.hostname = hostname;
    this.port = port;
    this.vendorId = vendorId;
    this.serialNumber = serialNumber;
    this.timeout = timeout;
    this.executor = executor;
    this.eventLoop = eventLoop;
    this.wheelTimer = wheelTimer;
    this.bootstrapConsumer = bootstrapConsumer;
}
 
开发者ID:digitalpetri,项目名称:ethernet-ip,代码行数:21,代码来源:EtherNetIpClientConfig.java

示例14: ModbusTcpMasterConfig

import io.netty.util.HashedWheelTimer; //导入依赖的package包/类
public ModbusTcpMasterConfig(String address,
                             int port,
                             Duration timeout,
                             @Deprecated boolean autoConnect,
                             Optional<String> instanceId,
                             ExecutorService executor,
                             EventLoopGroup eventLoop,
                             HashedWheelTimer wheelTimer,
                             Consumer<Bootstrap> bootstrapConsumer) {
    this.address = address;
    this.port = port;
    this.timeout = timeout;
    this.autoConnect = autoConnect;
    this.instanceId = instanceId;
    this.executor = executor;
    this.eventLoop = eventLoop;
    this.wheelTimer = wheelTimer;
    this.bootstrapConsumer = bootstrapConsumer;
}
 
开发者ID:digitalpetri,项目名称:modbus,代码行数:20,代码来源:ModbusTcpMasterConfig.java

示例15: AbstractRedisClient

import io.netty.util.HashedWheelTimer; //导入依赖的package包/类
/**
 * Create a new instance with client resources.
 *
 * @param clientResources the client resources. If {@literal null}, the client will create a new dedicated instance of
 *        client resources and keep track of them.
 */
protected AbstractRedisClient(ClientResources clientResources) {

    if (clientResources == null) {
        sharedResources = false;
        this.clientResources = DefaultClientResources.create();
    } else {
        sharedResources = true;
        this.clientResources = clientResources;
    }

    unit = TimeUnit.SECONDS;

    genericWorkerPool = this.clientResources.eventExecutorGroup();
    channels = new DefaultChannelGroup(genericWorkerPool.next());
    timer = (HashedWheelTimer) this.clientResources.timer();
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:23,代码来源:AbstractRedisClient.java


注:本文中的io.netty.util.HashedWheelTimer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。