Java Code Examples for org.jboss.netty.util.Timeout#isCancelled()

The following examples show how to use org.jboss.netty.util.Timeout#isCancelled() . 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: 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 3
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 4
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 5
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 6
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 7
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 8
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 9
Source File: RSHandshakeTimeoutHandler.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.syncManager.ready == false)
        ctx.getChannel().disconnect();
}
 
Example 10
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 11
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 (!handler.isClientConnection && 
        ((handler.remoteNode == null ||
         !handler.rpcService.isConnected(handler.remoteNode.
                                         getNodeId()))))
        Channels.fireExceptionCaught(ctx, EXCEPTION);
}
 
Example 12
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 13
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 14
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 15
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 16
Source File: ProxyClientManager.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
@Override
public void run(Timeout timeout) throws Exception {
    if (timeout.isCancelled() || closed) {
        return;
    }
    if (periodicHandshakeEnabled) {
        final boolean syncOwnerships = lastOwnershipSyncStopwatch.elapsed(TimeUnit.MILLISECONDS)
            >= clientConfig.getPeriodicOwnershipSyncIntervalMs();

        final Set<SocketAddress> hostsSnapshot = hostProvider.getHosts();
        final AtomicInteger numHosts = new AtomicInteger(hostsSnapshot.size());
        final AtomicInteger numStreams = new AtomicInteger(0);
        final AtomicInteger numSuccesses = new AtomicInteger(0);
        final AtomicInteger numFailures = new AtomicInteger(0);
        final ConcurrentMap<SocketAddress, Integer> streamDistributions =
                new ConcurrentHashMap<SocketAddress, Integer>();
        final Stopwatch stopwatch = Stopwatch.createStarted();
        for (SocketAddress host : hostsSnapshot) {
            final SocketAddress address = host;
            final ProxyClient client = getClient(address);
            handshake(address, client, new FutureEventListener<ServerInfo>() {
                @Override
                public void onSuccess(ServerInfo serverInfo) {
                    numStreams.addAndGet(serverInfo.getOwnershipsSize());
                    numSuccesses.incrementAndGet();
                    notifyHandshakeSuccess(address, client, serverInfo, false, stopwatch);
                    if (clientConfig.isHandshakeTracingEnabled()) {
                        streamDistributions.putIfAbsent(address, serverInfo.getOwnershipsSize());
                    }
                    complete();
                }

                @Override
                public void onFailure(Throwable cause) {
                    numFailures.incrementAndGet();
                    notifyHandshakeFailure(address, client, cause, stopwatch);
                    complete();
                }

                private void complete() {
                    if (0 == numHosts.decrementAndGet()) {
                        if (syncOwnerships) {
                            logger.info("Periodic handshaked with {} hosts : {} streams returned,"
                                + " {} hosts succeeded, {} hosts failed",
                                new Object[] {
                                    hostsSnapshot.size(),
                                    numStreams.get(),
                                    numSuccesses.get(),
                                    numFailures.get()});
                            if (clientConfig.isHandshakeTracingEnabled()) {
                                logger.info("Periodic handshaked stream distribution : {}", streamDistributions);
                            }
                        }
                    }
                }
            }, false, syncOwnerships);
        }

        if (syncOwnerships) {
            lastOwnershipSyncStopwatch.reset().start();
        }
    }
    scheduleHandshake();
}
 
Example 17
Source File: ConnectionFactory.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
@Override
public void run(Timeout timeout) {
    if (timeout.isCancelled()) {
        return;
    }

    // Just return not to try reconnection when event has been fired but pinpointClient already closed.
    if (pinpointClient.isClosed()) {
        logger.debug("pinpointClient is already closed.");
        return;
    }
    logger.warn("try reconnect. connectAddress:{}", socketAddressProvider);

    final Connection connection = connectionFactory.connect(socketAddressProvider, true);

    final PinpointClientHandler pinpointClientHandler = connection.getPinpointClientHandler();
    pinpointClientHandler.setPinpointClient(pinpointClient);

    ChannelFuture channelFuture = connection.getConnectFuture();
    channelFuture.addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
            if (future.isSuccess()) {
                Channel channel = future.getChannel();
                logger.info("reconnect success {}, {}", socketAddressProvider, channel);
                pinpointClient.reconnectSocketHandler(pinpointClientHandler);
            } else {
                if (!pinpointClient.isClosed()) {

                 /*
                    // comment out because exception message can be taken at exceptionCaught
                    if (logger.isWarnEnabled()) {
                        Throwable cause = future.getCause();
                        logger.warn("reconnect fail. {} Caused:{}", socketAddress, cause.getMessage());
                    }
                  */
                    connectionFactory.reconnect(pinpointClient, socketAddressProvider);
                } else {
                    logger.info("pinpointClient is closed. stop reconnect.");
                }
            }
        }
    });


}
 
Example 18
Source File: HealthCheckManager.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
@Override
public void run(Timeout timeout) throws Exception {
    if (isStopped) {
        return;
    }

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

    for (Channel channel : channelGroup) {
        PinpointServer pinpointServer = getPinpointServer(channel);
        if (pinpointServer == null) {
            continue;
        }

        HealthCheckState healthCheckState = pinpointServer.getHealthCheckState();
        switch (healthCheckState) {
            case RECEIVED:
                if (isDebug) {
                    logger.debug("ping write. channel:{}, packet:{}.", channel, PING_PACKET);
                }
                channel.write(PING_PACKET).addListener(writeFailListener);
                break;
            case RECEIVED_LEGACY:
                if (isDebug) {
                    logger.debug("ping write. channel:{}, packet:{}.", channel, LEGACY_PING_PACKET);
                }
                channel.write(LEGACY_PING_PACKET).addListener(writeFailListener);
                break;
            case WAIT:
                if (hasExpiredReceivingPing(pinpointServer)) {
                    logger.warn("expired while waiting to receive ping. channel:{} will be closed", channel);
                    channel.close();
                }
                break;
        }
    }

    if (!isStopped) {
        registerTask(this);
    }
}
 
Example 19
Source File: ProxyClientManager.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
@Override
public void run(Timeout timeout) throws Exception {
    if (timeout.isCancelled() || closed) {
        return;
    }
    if (periodicHandshakeEnabled) {
        final boolean syncOwnerships;
        syncOwnerships = lastOwnershipSyncStopwatch.elapsed(TimeUnit.MILLISECONDS) >= clientConfig.getPeriodicOwnershipSyncIntervalMs();

        final Set<SocketAddress> hostsSnapshot = hostProvider.getHosts();
        final AtomicInteger numHosts = new AtomicInteger(hostsSnapshot.size());
        final AtomicInteger numStreams = new AtomicInteger(0);
        final AtomicInteger numSuccesses = new AtomicInteger(0);
        final AtomicInteger numFailures = new AtomicInteger(0);
        final ConcurrentMap<SocketAddress, Integer> streamDistributions =
                new ConcurrentHashMap<SocketAddress, Integer>();
        final Stopwatch stopwatch = Stopwatch.createStarted();
        for (SocketAddress host : hostsSnapshot) {
            final SocketAddress address = host;
            final ProxyClient client = getClient(address);
            handshake(address, client, new FutureEventListener<ServerInfo>() {
                @Override
                public void onSuccess(ServerInfo serverInfo) {
                    numStreams.addAndGet(serverInfo.getOwnershipsSize());
                    numSuccesses.incrementAndGet();
                    notifyHandshakeSuccess(address, client, serverInfo, false, stopwatch);
                    if (clientConfig.isHandshakeTracingEnabled()) {
                        streamDistributions.putIfAbsent(address, serverInfo.getOwnershipsSize());
                    }
                    complete();
                }

                @Override
                public void onFailure(Throwable cause) {
                    numFailures.incrementAndGet();
                    notifyHandshakeFailure(address, client, cause, stopwatch);
                    complete();
                }

                private void complete() {
                    if (0 == numHosts.decrementAndGet()) {
                        if (syncOwnerships) {
                            logger.info("Periodic handshaked with {} hosts : {} streams returned," +
                                            " {} hosts succeeded, {} hosts failed",
                                    new Object[]{hostsSnapshot.size(), numStreams.get(),
                                            numSuccesses.get(), numFailures.get()});
                            if (clientConfig.isHandshakeTracingEnabled()) {
                                logger.info("Periodic handshaked stream distribution : {}", streamDistributions);
                            }
                        }
                    }
                }
            }, false, syncOwnerships);
        }

        if (syncOwnerships) {
            lastOwnershipSyncStopwatch.reset().start();
        }
    }
    scheduleHandshake();
}