當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。