org.jboss.netty.util.TimerTask Java Examples

The following examples show how to use org.jboss.netty.util.TimerTask. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TSOClient.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
private Timeout newTimeout() {
    if (requestTimeoutInMs > 0) {
        return timeoutExecutor.newTimeout(new TimerTask() {
            @Override
            public void run(Timeout timeout) {
                fsm.sendEvent(new HandshakeTimeoutEvent());
            }
        }, 30, TimeUnit.SECONDS);
    } else {
        return null;
    }
}
 
Example #2
Source File: TSOClient.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
ConnectionFailedState(final StateMachine.Fsm fsm, final Throwable exception) {
    super(fsm);
    LOG.debug("NEW STATE: CONNECTION FAILED [RE-CONNECTION BACKOFF]");
    this.exception = exception;
    reconnectionTimeoutExecutor.newTimeout(new TimerTask() {
        @Override
        public void run(Timeout timeout) {
            fsm.sendEvent(new ReconnectEvent());
        }
    }, tsoReconnectionDelayInSecs, TimeUnit.SECONDS);
}
 
Example #3
Source File: TSOClient.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
private Timeout newTimeout(final StateMachine.Event timeoutEvent) {
    if (requestTimeoutInMs > 0) {
        return timeoutExecutor.newTimeout(new TimerTask() {
            @Override
            public void run(Timeout timeout) {
                fsm.sendEvent(timeoutEvent);
            }
        }, requestTimeoutInMs, TimeUnit.MILLISECONDS);
    } else {
        return null;
    }
}
 
Example #4
Source File: NettySend.java    From jlogstash-input-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e)
		throws Exception {
	logger.warn("channel closed.do connect after:{} seconds.", CONN_DELAY);
	//重连
	timer.newTimeout(	new TimerTask() {
		
		@Override
		public void run(Timeout timeout) throws Exception {
			ChannelFuture channelfuture = client.getBootstrap().connect();
			client.setChannel(channelfuture);
		}
	}, CONN_DELAY, TimeUnit.SECONDS);
}
 
Example #5
Source File: NettyDispatcher.java    From ikasoa with MIT License 4 votes vote down vote up
private void processRequest(final ChannelHandlerContext ctx, final TNettyMessage message,
		final TNettyTransport messageTransport, final TProtocol inProtocol, final TProtocol outProtocol) {

	final int requestSequenceId = dispatcherSequenceId.incrementAndGet();

	if (DispatcherContext.isResponseOrderingRequired(ctx))
		synchronized (responseMap) {
			if (requestSequenceId > lastResponseWrittenId.get() + queuedResponseLimit
					&& !DispatcherContext.isChannelReadBlocked(ctx))
				DispatcherContext.blockChannelReads(ctx);
		}

	try {
		executor.execute(() -> {
			final AtomicBoolean responseSent = new AtomicBoolean(false);
			final AtomicReference<Timeout> expireTimeout = new AtomicReference<>(null);
			try {
				long timeRemaining = 0;
				long timeElapsed = System.currentTimeMillis() - message.getProcessStartTimeMillis();
				if (queueTimeoutMillis > 0)
					if (timeElapsed >= queueTimeoutMillis) {
						sendTApplicationException(
								new TApplicationException(TApplicationException.INTERNAL_ERROR,
										String.format(
												"Task stayed on the queue for %d milliseconds, exceeding configured queue timeout of %d milliseconds .",
												timeElapsed, queueTimeoutMillis)),
								ctx, message, requestSequenceId, messageTransport, inProtocol, outProtocol);
						return;
					} else if (taskTimeoutMillis > 0)
						if (timeElapsed >= taskTimeoutMillis) {
							sendTApplicationException(
									new TApplicationException(TApplicationException.INTERNAL_ERROR,
											String.format(
													"Task stayed on the queue for %d milliseconds, exceeding configured task timeout of %d milliseconds .",
													timeElapsed, taskTimeoutMillis)),
									ctx, message, requestSequenceId, messageTransport, inProtocol, outProtocol);
							return;
						} else
							timeRemaining = taskTimeoutMillis - timeElapsed;

				if (timeRemaining > 0)
					expireTimeout.set(taskTimeoutTimer.newTimeout(new TimerTask() {
						@Override
						public void run(Timeout timeout) throws Exception {
							if (responseSent.compareAndSet(false, true)) {
								ChannelBuffer duplicateBuffer = message.getBuffer().duplicate();
								duplicateBuffer.resetReaderIndex();
								TProtocol protocol = protocolFactory.getProtocol(messageTransport);
								sendTApplicationException(
										new TApplicationException(TApplicationException.INTERNAL_ERROR,
												"Task timed out while executing ."),
										ctx, message, requestSequenceId, new TNettyTransport(ctx.getChannel(),
												duplicateBuffer, message.getTransportType()),
										protocol, protocol);
							}
						}
					}, timeRemaining, TimeUnit.MILLISECONDS));

				if (processorFactory.getProcessor(messageTransport).process(inProtocol, outProtocol)
						&& ctx.getChannel().isConnected() && responseSent.compareAndSet(false, true))
					writeResponse(ctx, message.getMessageFactory().create(messageTransport.getOutputBuffer()),
							requestSequenceId, DispatcherContext.isResponseOrderingRequired(ctx));

			} catch (TException e) {
				onDispatchException(ctx, e);
			}
		});
	} catch (RejectedExecutionException ex) {
		sendTApplicationException(
				new TApplicationException(TApplicationException.INTERNAL_ERROR, "Server overloaded ."), ctx,
				message, requestSequenceId, messageTransport, inProtocol, outProtocol);
	}
}
 
Example #6
Source File: DefaultPinpointClientHandler.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
private void newPingTimeout(TimerTask pingTask) {
    this.channelTimer.newTimeout(pingTask, clientOption.getPingDelay(), TimeUnit.MILLISECONDS);
}