Search in sources :

Example 1 with SocketStateCode

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

the class DefaultPinpointClientHandler method close.

// Calling this method on a closed PinpointClientHandler has no effect.
public void close() {
    logger.debug("{} close() started.", objectUniqName);
    SocketStateCode currentStateCode = state.getCurrentStateCode();
    if (currentStateCode.isRun()) {
        state.toBeingClose();
        closeChannel();
    } else if (currentStateCode.isBeforeConnected()) {
        state.toClosed();
        closeResources();
    } else if (currentStateCode.onClose() || currentStateCode.isClosed()) {
        logger.warn("close() failed. Already closed.");
    } else {
        logger.warn("Illegal State :{}.", currentStateCode);
    }
}
Also used : SocketStateCode(com.navercorp.pinpoint.rpc.common.SocketStateCode)

Example 2 with SocketStateCode

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

the class DefaultPinpointServer method stop.

public void stop(boolean serverStop) {
    try {
        SocketStateCode currentStateCode = getCurrentStateCode();
        if (SocketStateCode.BEING_CLOSE_BY_SERVER == currentStateCode) {
            state.toClosed();
        } else if (SocketStateCode.BEING_CLOSE_BY_CLIENT == currentStateCode) {
            state.toClosedByPeer();
        } else if (SocketStateCode.isRun(currentStateCode) && serverStop) {
            state.toUnexpectedClosed();
        } else if (SocketStateCode.isRun(currentStateCode)) {
            state.toUnexpectedClosedByPeer();
        } else if (SocketStateCode.isClosed(currentStateCode)) {
            logger.warn("{} stop(). Socket has closed state({}).", objectUniqName, currentStateCode);
        } else {
            state.toErrorUnknown();
            logger.warn("{} stop(). Socket has unexpected state.", objectUniqName, currentStateCode);
        }
        if (this.channel.isConnected()) {
            channel.close();
        }
    } finally {
        streamChannelManager.close();
    }
}
Also used : SocketStateCode(com.navercorp.pinpoint.rpc.common.SocketStateCode)

Example 3 with SocketStateCode

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

the class DefaultPinpointServer method handlePingPacket.

private void handlePingPacket(Channel channel, PingPacket packet) {
    logger.debug("{} handlePingPacket() started. packet:{}", objectUniqName, packet);
    SocketStateCode statusCode = state.getCurrentStateCode();
    if (statusCode.getId() == packet.getStateCode()) {
        stateChecker.unmark();
        messageListener.handlePing(packet, this);
        PongPacket pongPacket = PongPacket.PONG_PACKET;
        ChannelFuture write = channel.write(pongPacket);
        write.addListener(pongWriteFutureListener);
    } else {
        logger.warn("Session state sync failed. channel:{}, packet:{}, server-state:{}", channel, packet, statusCode);
        if (stateChecker.markAndCheckCondition()) {
            state.toErrorSyncStateSession();
            stop();
        }
    }
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) SocketStateCode(com.navercorp.pinpoint.rpc.common.SocketStateCode)

Example 4 with SocketStateCode

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

the class AgentLifeCycleChangeEventHandlerTest method unmanagedStatesShouldNotBeHandled.

@Test
public void unmanagedStatesShouldNotBeHandled() throws Exception {
    // given
    final Set<SocketStateCode> unmanagedStates = new HashSet<>();
    for (SocketStateCode socketStateCode : SocketStateCode.values()) {
        if (ManagedAgentLifeCycle.getManagedAgentLifeCycleByStateCode(socketStateCode) == AgentLifeCycleChangeEventHandler.STATE_NOT_MANAGED) {
            unmanagedStates.add(socketStateCode);
        }
    }
    for (SocketStateCode unmanagedState : unmanagedStates) {
        // when
        this.lifeCycleChangeEventHandler.eventPerformed(this.server, unmanagedState);
        // then
        verify(this.lifeCycleHandler, never()).handleLifeCycleEvent(any(PinpointServer.class), anyLong(), any(AgentLifeCycleState.class), anyInt());
        verify(this.eventHandler, never()).handleEvent(any(PinpointServer.class), anyLong(), any(AgentEventType.class));
    }
}
Also used : AgentEventType(com.navercorp.pinpoint.common.server.util.AgentEventType) SocketStateCode(com.navercorp.pinpoint.rpc.common.SocketStateCode) PinpointServer(com.navercorp.pinpoint.rpc.server.PinpointServer) AgentLifeCycleState(com.navercorp.pinpoint.common.server.util.AgentLifeCycleState) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with SocketStateCode

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

the class AgentLifeCycleChangeEventHandlerTest method runAndVerifyByStateCodes.

private void runAndVerifyByStateCodes(Set<SocketStateCode> socketStates) throws Exception {
    int testCount = 0;
    for (SocketStateCode socketState : socketStates) {
        this.lifeCycleChangeEventHandler.eventPerformed(this.server, socketState);
        testCount++;
        verify(this.lifeCycleHandler, times(testCount)).handleLifeCycleEvent(any(PinpointServer.class), anyLong(), any(AgentLifeCycleState.class), anyInt());
        verify(this.eventHandler, times(testCount)).handleEvent(any(PinpointServer.class), anyLong(), any(AgentEventType.class));
    }
}
Also used : AgentEventType(com.navercorp.pinpoint.common.server.util.AgentEventType) SocketStateCode(com.navercorp.pinpoint.rpc.common.SocketStateCode) PinpointServer(com.navercorp.pinpoint.rpc.server.PinpointServer) AgentLifeCycleState(com.navercorp.pinpoint.common.server.util.AgentLifeCycleState)

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