當前位置: 首頁>>代碼示例>>Java>>正文


Java Timeout類代碼示例

本文整理匯總了Java中io.netty.util.Timeout的典型用法代碼示例。如果您正苦於以下問題:Java Timeout類的具體用法?Java Timeout怎麽用?Java Timeout使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Timeout類屬於io.netty.util包,在下文中一共展示了Timeout類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: awaitResultAsync

import io.netty.util.Timeout; //導入依賴的package包/類
@Override
protected void awaitResultAsync(final RemoteInvocationOptions optionsCopy, final RemotePromise<Object> result,
        final RemoteServiceRequest request, final String responseName) {
    if (!optionsCopy.isResultExpected()) {
        return;
    }
    
    Long startTime = 0L;
    if (request != null && request.getArgs() != null && request.getArgs().length > 3) {
        startTime = (Long)request.getArgs()[3];
    }
    long delay = startTime - System.currentTimeMillis();
    if (delay > 0) {
        commandExecutor.getConnectionManager().newTimeout(new TimerTask() {
            @Override
            public void run(Timeout timeout) throws Exception {
                ScheduledTasksService.super.awaitResultAsync(optionsCopy, result, request, responseName);
            }
        }, delay, TimeUnit.MILLISECONDS);
    } else {
        super.awaitResultAsync(optionsCopy, result, request, responseName);
    }
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:24,代碼來源:ScheduledTasksService.java

示例2: scheduleReconnect

import io.netty.util.Timeout; //導入依賴的package包/類
private synchronized void scheduleReconnect()
{
	if (_stop)
		return;
	if (_timeout != null)
		return;
	Constants.ahessianLogger.warn("channel closed wait to reconnect ...");
	_retryCounter++;
	long retryIntervall = Math.min(RECONNECT_DELAY * _retryCounter,
			MAX_RECONNECT_DELAY);
	_timeout = _timer.newTimeout(new TimerTask()
	{
		public void run(Timeout timeout) throws Exception
		{
			_timeout = null;
			connect(_bootstrap.getBootstrap());

		}
	}, retryIntervall, TimeUnit.MILLISECONDS);
}
 
開發者ID:yajsw,項目名稱:yajsw,代碼行數:21,代碼來源:ReconnectHandler.java

示例3: HeartbeatHandlerInbound

import io.netty.util.Timeout; //導入依賴的package包/類
public HeartbeatHandlerInbound(final String name, final Timer timer,
		final long timeout)
{
	_name = name;
	final TimerTask task = new TimerTask()
	{
		public void run(Timeout nTimeout) throws Exception
		{
			if (((getLastCalled() + timeout) <= System.currentTimeMillis())
					&& isConnected())
				try
				{
					_action.timedOut(_ctx);
				}
				catch (Exception e)
				{
					Constants.ahessianLogger.warn("", e);
				}
		}

	};
	_intervalTimer = new IntervalTimer(timer, task, timeout);
}
 
開發者ID:yajsw,項目名稱:yajsw,代碼行數:24,代碼來源:HeartbeatHandlerInbound.java

示例4: poll

import io.netty.util.Timeout; //導入依賴的package包/類
public T poll(int group)
{
	LinkedList<T> q = _queues[group];
	T result = null;
	if (q != null)
	{
		result = q.poll();
		if (result != null)
		{
			Timeout timer = _timers.remove(result);
			if (timer != null)
				timer.cancel();
		}
	}
	return result;
}
 
開發者ID:yajsw,項目名稱:yajsw,代碼行數:17,代碼來源:TimedBlockingPriorityQueue.java

示例5: run

import io.netty.util.Timeout; //導入依賴的package包/類
@Override
public void run(Timeout timeout) throws Exception {
    Connection connection = this.connection;

    if (connection == null || !connection.isConnected()) {
        Logs.HB.info("heartbeat timeout times={}, connection disconnected, conn={}", timeoutTimes, connection);
        return;
    }

    if (connection.isReadTimeout()) {
        if (++timeoutTimes > CC.mp.core.max_hb_timeout_times) {
            connection.close();
            Logs.HB.warn("client heartbeat timeout times={}, do close conn={}", timeoutTimes, connection);
            return;
        } else {
            Logs.HB.info("client heartbeat timeout times={}, connection={}", timeoutTimes, connection);
        }
    } else {
        timeoutTimes = 0;
    }
    startTimeout();
}
 
開發者ID:mpusher,項目名稱:mpush,代碼行數:23,代碼來源:ServerConnectionManager.java

示例6: run

import io.netty.util.Timeout; //導入依賴的package包/類
@Override
public void run(Timeout timeout) throws Exception {
    if (timeout.isCancelled()) {
        return;
    }
    if (log.isDebugEnabled()) {
        log.debug("[{}] [{}] Batching the messages from the batch container from timer thread", topic,
                producerName);
    }
    // semaphore acquired when message was enqueued to container
    synchronized (ProducerImpl.this) {
        batchMessageAndSend();
    }
    // schedule the next batch message task
    client.timer().newTimeout(this, conf.getBatchingMaxPublishDelayMs(), TimeUnit.MILLISECONDS);
}
 
開發者ID:apache,項目名稱:incubator-pulsar,代碼行數:17,代碼來源:ProducerImpl.java

示例7: start

import io.netty.util.Timeout; //導入依賴的package包/類
public void start(PulsarClientImpl client, ConsumerBase consumerBase, long ackTimeoutMillis) {
    this.stop();
    timeout = client.timer().newTimeout(new TimerTask() {
        @Override
        public void run(Timeout t) throws Exception {
            if (isAckTimeout()) {
                log.warn("[{}] {} messages have timed-out", consumerBase, oldOpenSet.size());
                Set<MessageIdImpl> messageIds = new HashSet<>();
                oldOpenSet.forEach(messageIds::add);
                oldOpenSet.clear();
                consumerBase.redeliverUnacknowledgedMessages(messageIds);
            }
            toggle();
            timeout = client.timer().newTimeout(this, ackTimeoutMillis, TimeUnit.MILLISECONDS);
        }
    }, ackTimeoutMillis, TimeUnit.MILLISECONDS);
}
 
開發者ID:apache,項目名稱:incubator-pulsar,代碼行數:18,代碼來源:UnAckedMessageTracker.java

示例8: newTimeout

import io.netty.util.Timeout; //導入依賴的package包/類
/**
 * {@inheritDoc}
 * @see io.netty.util.Timer#newTimeout(io.netty.util.TimerTask, long, java.util.concurrent.TimeUnit)
 */
@Override
public Timeout newTimeout(final TimerTask task, final long delay, final TimeUnit unit) {
	final WrappedTimeout[] t = new WrappedTimeout[1];
	t[0] = new WrappedTimeout(timer.newTimeout(new TimerTask(){
		@Override
		public void run(final Timeout timeout) throws Exception {
			try {
				task.run(t[0]);
			} finally {
				pendingTimeouts.decrementAndGet();
				timeouts.increment();
			}				
		}			
	}, delay, unit));
	return t[0];
}
 
開發者ID:nickman,項目名稱:HeliosStreams,代碼行數:21,代碼來源:TimeoutService.java

示例9: scheduleRequestTimeout

import io.netty.util.Timeout; //導入依賴的package包/類
private void scheduleRequestTimeout(RequestHeader requestHeader) {
    UInteger requestHandle = requestHeader.getRequestHandle();

    long timeoutHint = requestHeader.getTimeoutHint() != null ?
        requestHeader.getTimeoutHint().longValue() : DEFAULT_TIMEOUT_MS;

    Timeout timeout = wheelTimer.newTimeout(t -> {
        if (timeouts.remove(requestHandle) != null && !t.isCancelled()) {
            CompletableFuture<UaResponseMessage> f = pending.remove(requestHandle);
            if (f != null) {
                String message = "request timed out after " + timeoutHint + "ms";
                f.completeExceptionally(new UaException(StatusCodes.Bad_Timeout, message));
            }
        }
    }, timeoutHint, TimeUnit.MILLISECONDS);

    timeouts.put(requestHandle, timeout);
}
 
開發者ID:eclipse,項目名稱:milo,代碼行數:19,代碼來源:UaTcpStackClient.java

示例10: run

import io.netty.util.Timeout; //導入依賴的package包/類
@Override
public void run(Timeout timeout) throws Exception {
    log.debug("Timeout occured for Session {}", id);
    //Notify the listener that timeout has occured
    final SessionValue session = sessionManager.getSession(id);

    //Do not proceed if the session is null
    if (session == null) {
        log.error("could not find session value for id {}. Registry Size : {}", id, sessionManager.getSessionEntries().size());
        return;
    }

    //Check first if the promise has been completed
    if (session.getClientPromise() != null && !session.getClientPromise().isDone() && !session.getClientPromise().isCancelled() && !timeout.isCancelled()) {
        //Send a ReadTimeoutException to the client
        session.getClientPromise().completeExceptionally(new ReadTimeoutException(id, String.format("Timeout occured for '%s' Started: %f seconds ago", id, ((double) Duration.ofMillis(System.currentTimeMillis() - session.getTimeRegistered()).toMillis() / 1000.0))));
    }
}
 
開發者ID:ribasco,項目名稱:async-gamequery-lib,代碼行數:19,代碼來源:ReadRequestTimeoutTimerTask.java

示例11: TimedDeferredRequest

import io.netty.util.Timeout; //導入依賴的package包/類
/**
 * Intentional private local constructor
 * @param key the request key
 * @param request the request object
 * @param window the window
 * @param timeoutMillis the time after which this future will be cancelled
 * @param timer the timer used to implement the timeout functionality
 */
private TimedDeferredRequest(final K key,
                             final R request,
                             final Window<K, R, D> window,
                             final Timer timer,
                             final long timeoutMillis) {
    super(key, request, window);
    this.timeout = checkNotNull(timer).newTimeout(new TimerTask() {
                                                      @Override
                                                      public void run(Timeout timerTask) throws Exception {
                                                          window.fail(checkNotNull(key),
                                                                      new TimeoutException("The operation timed out (Window full)"));
                                                      }
                                                  },
                                                  timeoutMillis,
                                                  TimeUnit.MILLISECONDS);
}
 
開發者ID:spapageo,項目名稱:jannel,代碼行數:25,代碼來源:TimedDeferredRequest.java

示例12: newRefreshTask

import io.netty.util.Timeout; //導入依賴的package包/類
private void newRefreshTask() {
    if (refreshTaskMap.containsKey(getName())) {
        return;
    }

    Timeout task = commandExecutor.getConnectionManager().newTimeout(new TimerTask() {
        @Override
        public void run(Timeout timeout) throws Exception {
            expire(internalLockLeaseTime, TimeUnit.MILLISECONDS);
            refreshTaskMap.remove(getName());
            newRefreshTask(); // reschedule itself
        }
    }, internalLockLeaseTime / 3, TimeUnit.MILLISECONDS);

    if (refreshTaskMap.putIfAbsent(getName(), task) != null) {
        task.cancel();
    }
}
 
開發者ID:rollenholt-SourceReading,項目名稱:redisson,代碼行數:19,代碼來源:RedissonLock.java

示例13: itemsReceived

import io.netty.util.Timeout; //導入依賴的package包/類
@Override
public void itemsReceived(CpfItem[] items) {
    int connectionId = ((ConnectedAddressItem) items[0]).getConnectionId();
    ByteBuf buffer = ((ConnectedDataItemResponse) items[1]).getData();

    int sequenceNumber = buffer.readShort();
    ByteBuf data = buffer.readSlice(buffer.readableBytes()).retain();

    Timeout timeout = timeouts.remove(sequenceNumber);
    if (timeout != null) timeout.cancel();

    CompletableFuture<ByteBuf> future = pending.remove(sequenceNumber);

    if (future != null) {
        future.complete(data);
    } else {
        ReferenceCountUtil.release(data);
    }

    ReferenceCountUtil.release(buffer);
}
 
開發者ID:digitalpetri,項目名稱:ethernet-ip,代碼行數:22,代碼來源:CipClient.java

示例14: PendingRequest

import io.netty.util.Timeout; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private PendingRequest(CompletableFuture<T> future, Timeout timeout) {
    this.timeout = timeout;

    promise.whenComplete((r, ex) -> {
        if (r != null) {
            try {
                future.complete((T) r);
            } catch (ClassCastException e) {
                future.completeExceptionally(e);
            }
        } else {
            future.completeExceptionally(ex);
        }
    });
}
 
開發者ID:digitalpetri,項目名稱:ethernet-ip,代碼行數:17,代碼來源:EtherNetIpClient.java

示例15: run

import io.netty.util.Timeout; //導入依賴的package包/類
/**
     * {@inheritDoc}
     * <br/>
     * Sends for each remote participant a report containing the status
     * of this session participant. 
     */
    @Override
    public void run(Timeout timeout) throws Exception {
        if (!this.running.get()) {
            return;
        }
        // send status update per remote participant
        final long currentSsrc = this.localParticipant.getSsrc();
        final SourceDescriptionPacket sdesPacket = buildSdesPacket(currentSsrc);
        this.participantDatabase.doWithReceivers(new ParticipantOperation() {
            @Override
            public void doWithParticipant(RtpParticipant participant) throws Exception {
                AbstractReportPacket report = buildReportPacket(currentSsrc, participant);
                // TODO: really to all other participants?
                // i would use:
//                writeToControl(new CompoundControlPacket(report, sdesPacket), participant.getControlDestination());
                internalSendControl(new CompoundControlPacket(report, sdesPacket));
            }
        });

        if (!this.running.get()) {
            return;
        }
        this.timer.newTimeout(this, this.updatePeriodicRtcpSendInterval(), TimeUnit.SECONDS);
    }
 
開發者ID:SAS-Systems,項目名稱:imflux,代碼行數:31,代碼來源:AbstractRtpSession.java


注:本文中的io.netty.util.Timeout類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。