org.jboss.netty.util.Timeout Java Examples

The following examples show how to use org.jboss.netty.util.Timeout. 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: BgpSession.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void run(Timeout timeout) throws Exception {
    if (timeout.isCancelled()) {
        return;
    }
    if (!ctx.getChannel().isOpen()) {
        return;
    }

    log.debug("BGP Session Timeout: peer {}", remoteInfo.address());
    //
    // ERROR: Invalid Optional Parameter Length field: Unspecific
    //
    // Send NOTIFICATION and close the connection
    int errorCode = BgpConstants.Notifications.HoldTimerExpired.ERROR_CODE;
    int errorSubcode = BgpConstants.Notifications.ERROR_SUBCODE_UNSPECIFIC;
    ChannelBuffer txMessage =
        BgpNotification.prepareBgpNotification(errorCode, errorSubcode,
                                               null);
    ctx.getChannel().write(txMessage);
    closeChannel(ctx);
}
 
Example #2
Source File: HashedWheelTimerTaskScheduler.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
/**
 * Executed after the delay specified with
 * {@link Timer#newTimeout(TimerTask, long, TimeUnit)}.
 *
 * @param timeout a handle which is associated with this task
 */
@Override
@Synchronized
public void run(Timeout timeout) throws Exception {
  Map<String, String> originalContext = MDC.getCopyOfContextMap();
  if (this.context != null) {
    MDC.setContextMap(context);
  }
  try {
    this.task.runOneIteration();
  } finally {
    if (this.future != null) {
      this.future = this.timer.newTimeout(this, this.period, this.unit);
    }
    if (originalContext != null) {
      MDC.setContextMap(originalContext);
    } else {
      MDC.clear();
    }
  }
}
 
Example #3
Source File: PinpointClientHandshaker.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Override
public void run(Timeout timeout) throws Exception {
    logger.debug("{} HandshakeJob started.", id);

    if (timeout.isCancelled()) {
        reserveHandshake(this);
        return;
    }

    int currentState = currentState();
    
    if (isRun(currentState)) {
        handshake(this);
        reserveHandshake(this);
    } else if (isFinished(currentState)) {
        logger.info("{} HandshakeJob completed.", id);
    } else {
        logger.warn("{} HandshakeJob will be stop. caused:unexpected state.", id);
    }
}
 
Example #4
Source File: DefaultPinpointClientFactory.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
public void release() {
    if (this.closed.isClosed()) {
        return;
    }
    if (!this.closed.close()) {
        return;
    }

    if (!useExternalResource) {
        final ChannelFactory channelFactory = this.channelFactory;
        if (channelFactory != null) {
            channelFactory.releaseExternalResources();
        }
        Set<Timeout> stop = this.timer.stop();
        if (!stop.isEmpty()) {
            logger.info("stop Timeout:{}", stop.size());
        }

        // stop, cancel something?
    }
}
 
Example #5
Source File: BgpChannelHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void run(Timeout timeout) throws Exception {
    if (timeout.isCancelled()) {
        return;
    }
    if (!channel.isOpen()) {
        return;
    }

    log.debug("BGP hold timer expired: peer {}", channel.getRemoteAddress());

    sendNotification(BgpErrorType.HOLD_TIMER_EXPIRED, (byte) 0, null);
    bgpController.closedSessionExceptionAdd(peerAddr, "BGP hold timer expired");
    stopSessionTimers();
    state = ChannelState.IDLE;
    channel.close();
}
 
Example #6
Source File: BgpSession.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void run(Timeout timeout) throws Exception {
    if (timeout.isCancelled()) {
        return;
    }
    if (!ctx.getChannel().isOpen()) {
        return;
    }

    // Transmit the KEEPALIVE
    ChannelBuffer txMessage = BgpKeepalive.prepareBgpKeepalive();
    ctx.getChannel().write(txMessage);

    // Restart the KEEPALIVE timer
    restartKeepaliveTimer(ctx);
}
 
Example #7
Source File: ControllerHandshakeTimeoutHandler.java    From FlowSpaceFirewall with Apache License 2.0 5 votes vote down vote up
@Override
public void run(Timeout timeout) throws Exception {
    if (timeout.isCancelled()) {
        return;
    }

    if (!ctx.getChannel().isOpen()) {
        return;
    }
    if (!channelHandler.isHandshakeComplete())
        Channels.fireExceptionCaught(ctx, EXCEPTION);
}
 
Example #8
Source File: FlinkServerRegister.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public void run(Timeout timeout) throws Exception {
    logger.info("Reserved {} started.", ClassUtils.simpleClassName(this));

    if (!isConnected()) {
        return;
    }

    if (!clusterDataManagerHelper.pushZnode(client, getCreateNodeMessage())) {
        timer.newTimeout(this, getRetryInterval(), TimeUnit.MILLISECONDS);
    }
}
 
Example #9
Source File: DefaultFuture.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public void run(Timeout timeout) throws Exception {
    if (timeout.isCancelled()) {
        return;
    }
    this.fireTimeout();
}
 
Example #10
Source File: DefaultFuture.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
private void cancelTimeout() {
    final Timeout timeout = this.timeout;
    if (timeout != null) {
        timeout.cancel();
        this.timeout = null;
    }
}
 
Example #11
Source File: RequestManager.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
private void addTimeoutTask(DefaultFuture future, long timeoutMillis) {
    if (future == null) {
        throw new NullPointerException("future");
    }
    try {
        Timeout timeout = timer.newTimeout(future, timeoutMillis, TimeUnit.MILLISECONDS);
        future.setTimeout(timeout);
    } catch (IllegalStateException e) {
        // this case is that timer has been shutdown. That maybe just means that socket has been closed.
        future.setFailure(new PinpointSocketException("socket closed")) ;
    }
}
 
Example #12
Source File: DefaultPinpointClientHandler.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public void run(Timeout timeout) throws Exception {
    if (timeout.isCancelled()) {
        newPingTimeout(this);
        return;
    }

    if (state.isClosed()) {
        return;
    }

    writePing();
    newPingTimeout(this);
}
 
Example #13
Source File: ZookeeperClusterDataManager.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public void run(Timeout timeout) throws Exception {
    if (isStopped) {
        logger.info("PeriodicSyncTask will be discarded. message:already stopped");
        return;
    }

    logger.info("PeriodicSyncTask started");
    try {
        syncPullCollectorCluster();
    } catch (Exception e) {
        logger.warn("Failed to sync data. message:{}", e.getMessage(), e);
    }
    timer.newTimeout(this, intervalMillis, TimeUnit.MILLISECONDS);
}
 
Example #14
Source File: ZookeeperClusterDataManager.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public void run(Timeout timeout) throws Exception {
    logger.info("Reserved {} started.", ClassUtils.simpleClassName(this));

    if (!isConnected()) {
        return;
    }

    if (!syncPullCollectorCluster()) {
        timer.newTimeout(new PullCollectorClusterJob(), PULL_RETRY_INTERVAL_TIME_MILLIS, TimeUnit.MILLISECONDS);
    }
}
 
Example #15
Source File: ZookeeperClusterDataManager.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public void run(Timeout timeout) throws Exception {
    logger.info("Reserved {} started.", ClassUtils.simpleClassName(this));

    if (!isConnected()) {
        return;
    }

    if (!clusterDataManagerHelper.pushZnode(client, getCreateNodeMessage())) {
        timer.newTimeout(this, getRetryInterval(), TimeUnit.MILLISECONDS);
    }
}
 
Example #16
Source File: NioClientBoss.java    From simple-netty-source with Apache License 2.0 5 votes vote down vote up
public void run(Timeout timeout) throws Exception {
    // This is needed to prevent a possible race that can lead to a NPE
    // when the selector is closed before this is run
    //
    // See https://github.com/netty/netty/issues/685
    Selector selector = NioClientBoss.this.selector;

    if (selector != null) {
        if (wakenUp.compareAndSet(false, true)) {
            selector.wakeup();
        }
    }
}
 
Example #17
Source File: NioClientBoss.java    From android-netty with Apache License 2.0 5 votes vote down vote up
public void run(Timeout timeout) throws Exception {
    // This is needed to prevent a possible race that can lead to a NPE
    // when the selector is closed before this is run
    //
    // See https://github.com/netty/netty/issues/685
    Selector selector = NioClientBoss.this.selector;

    if (selector != null) {
        if (wakenUp.compareAndSet(false, true)) {
            selector.wakeup();
        }
    }
}
 
Example #18
Source File: HandshakeTimeoutHandler.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
@Override
public void run(Timeout timeout) throws Exception {
    if (timeout.isCancelled()) {
        return;
    }

    if (!ctx.getChannel().isOpen()) {
        return;
    }
    if (!channelHandler.isHandshakeComplete())
        Channels.fireExceptionCaught(ctx, EXCEPTION);
}
 
Example #19
Source File: BootstrapTimeoutHandler.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
@Override
public void run(Timeout timeout) throws Exception {
    if (timeout.isCancelled()) {
        return;
    }

    if (!ctx.getChannel().isOpen()) {
        return;
    }
    ctx.getChannel().disconnect();
}
 
Example #20
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 #21
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 #22
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 #23
Source File: ProxyClientManager.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
public void close() {
    closed = true;
    Timeout task = periodicHandshakeTask;
    if (null != task) {
        task.cancel();
    }
    for (ProxyClient sc : address2Services.values()) {
        sc.close();
    }
}
 
Example #24
Source File: DistributedLogClientImpl.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void run(Timeout timeout) throws Exception {
    if (!timeout.isCancelled() && null != nextAddressToSend) {
        doSend(nextAddressToSend);
    } else {
        fail(null, new CancelledRequestException());
    }
}
 
Example #25
Source File: OwnershipCache.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Override
public void run(Timeout timeout) throws Exception {
    if (timeout.isCancelled()) {
        return;
    }
    logger.info("Ownership cache : {} streams cached, {} hosts cached",
            stream2Addresses.size(), address2Streams.size());
    logger.info("Cached streams : {}", stream2Addresses);
    scheduleDumpOwnershipCache();
}
 
Example #26
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 #27
Source File: ProxyClientManager.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
public void close() {
    closed = true;
    Timeout task = periodicHandshakeTask;
    if (null != task) {
        task.cancel();
    }
    for (ProxyClient sc : address2Services.values()) {
        sc.close();
    }
}
 
Example #28
Source File: DistributedLogClientImpl.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Override
synchronized public void run(Timeout timeout) throws Exception {
    if (!timeout.isCancelled() && null != nextAddressToSend) {
        doSend(nextAddressToSend);
    } else {
        fail(null, new CancelledRequestException());
    }
}
 
Example #29
Source File: OwnershipCache.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Override
public void run(Timeout timeout) throws Exception {
    if (timeout.isCancelled()) {
        return;
    }
    logger.info("Ownership cache : {} streams cached, {} hosts cached",
            stream2Addresses.size(), address2Streams.size());
    logger.info("Cached streams : {}", stream2Addresses);
    scheduleDumpOwnershipCache();
}
 
Example #30
Source File: HostMonitor.java    From atrium-odl with Apache License 2.0 5 votes vote down vote up
@Override
public void run(Timeout arg0) throws Exception {

	LOG.info("**Timer triggered**");

	List<AtriumIpAddress> resolvedIps = new ArrayList<>();
	for (AtriumIpAddress ip : monitoredAddresses) {
		Host host = hostService.getHost(new HostId(ip.toString()));
		if (host == null) {
			LOG.info("Host not found.Sending ARP request for:" + ip);
			// TODO : check if we can resolve from config
			sendArpRequest(ip);
		} else {
			LOG.info("IP resolved:" + ip);
			HostEvent hostEvent = new HostEvent(HostEvent.Type.HOST_ADDED, host);
			resolvedIps.add(ip);
			hostUpdatesListener.sendHostAddEvent(hostEvent);
		}
	}

	if (resolvedIps != null && !resolvedIps.isEmpty()) {
		for (AtriumIpAddress resolvedIp : resolvedIps) {
			synchronized (monitoredAddresses) {
				monitoredAddresses.remove(resolvedIp);
			}
		}
		resolvedIps.clear();
	}
	LOG.info("setting timer again");
	this.timeout = AtriumTimer.getTimer().newTimeout(this, probeRate, TimeUnit.MILLISECONDS);
}