Search in sources :

Example 6 with SocketStateCode

use of com.navercorp.pinpoint.rpc.common.SocketStateCode in project pinpoint by naver.

the class DefaultPinpointClientHandler method channelClosed.

@Override
public void channelClosed(final ChannelHandlerContext ctx, final ChannelStateEvent e) throws Exception {
    logger.info("{} channelClosed() started.", objectUniqName);
    try {
        boolean factoryReleased = clientFactory.isReleased();
        boolean needReconnect = false;
        SocketStateCode currentStateCode = state.getCurrentStateCode();
        if (currentStateCode == SocketStateCode.BEING_CLOSE_BY_CLIENT) {
            state.toClosed();
        } else if (currentStateCode == SocketStateCode.BEING_CLOSE_BY_SERVER) {
            needReconnect = state.toClosedByPeer().isChange();
        } else if (currentStateCode.isRun() && factoryReleased) {
            state.toUnexpectedClosed();
        } else if (currentStateCode.isRun()) {
            needReconnect = state.toUnexpectedClosedByPeer().isChange();
        } else if (currentStateCode.isBeforeConnected()) {
            state.toConnectFailed();
        } else {
            state.toErrorUnknown();
        }
        if (needReconnect) {
            clientFactory.reconnect(this.pinpointClient, this.connectSocketAddress);
        }
    } finally {
        closeResources();
        connectFuture.setResult(Result.FAIL);
    }
}
Also used : SocketStateCode(com.navercorp.pinpoint.rpc.common.SocketStateCode)

Example 7 with SocketStateCode

use of com.navercorp.pinpoint.rpc.common.SocketStateCode in project pinpoint by naver.

the class DefaultPinpointClientHandler method exceptionCaught.

@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    Throwable cause = e.getCause();
    SocketStateCode currentStateCode = state.getCurrentStateCode();
    if (currentStateCode == SocketStateCode.BEING_CONNECT) {
        // removed stackTrace when reconnect. so many logs.
        logger.info("{} exceptionCaught() occurred. state:{}, caused:{}.", objectUniqName, currentStateCode, cause.getMessage());
    } else {
        logger.warn("{} exceptionCaught() occurred. state:{}. Caused:{}", objectUniqName, currentStateCode, cause.getMessage(), cause);
    }
// need to handle a error more precisely.
// below code dose not reconnect when node on channel is just hang up or dead without specific reasons.
//        state.setClosed();
//        Channel channel = e.getChannel();
//        if (channel.isConnected()) {
//            channel.close();
//        }
}
Also used : SocketStateCode(com.navercorp.pinpoint.rpc.common.SocketStateCode)

Aggregations

SocketStateCode (com.navercorp.pinpoint.rpc.common.SocketStateCode)7 AgentEventType (com.navercorp.pinpoint.common.server.util.AgentEventType)2 AgentLifeCycleState (com.navercorp.pinpoint.common.server.util.AgentLifeCycleState)2 PinpointServer (com.navercorp.pinpoint.rpc.server.PinpointServer)2 HashSet (java.util.HashSet)1 ChannelFuture (org.jboss.netty.channel.ChannelFuture)1 Test (org.junit.Test)1