Search in sources :

Example 16 with PinpointSocket

use of com.navercorp.pinpoint.rpc.PinpointSocket in project pinpoint by naver.

the class AgentServiceImpl method invoke.

@Override
public Map<AgentInfo, PinpointRouteResponse> invoke(List<AgentInfo> agentInfoList, byte[] payload, long timeout) throws TException {
    Map<AgentInfo, Future<ResponseMessage>> futureMap = new HashMap<>();
    for (AgentInfo agentInfo : agentInfoList) {
        TCommandTransfer transferObject = createCommandTransferObject(agentInfo, payload);
        List<PinpointSocket> socketList = clusterManager.getSocket(agentInfo);
        if (CollectionUtils.nullSafeSize(socketList) == 1) {
            PinpointSocket socket = socketList.get(0);
            Future<ResponseMessage> future = socket.request(serializeRequest(transferObject));
            futureMap.put(agentInfo, future);
        } else {
            futureMap.put(agentInfo, null);
        }
    }
    long startTime = System.currentTimeMillis();
    Map<AgentInfo, PinpointRouteResponse> result = new HashMap<>();
    for (Map.Entry<AgentInfo, Future<ResponseMessage>> futureEntry : futureMap.entrySet()) {
        AgentInfo agentInfo = futureEntry.getKey();
        Future<ResponseMessage> future = futureEntry.getValue();
        PinpointRouteResponse response = getResponse(future, getTimeoutMillis(startTime, timeout));
        result.put(agentInfo, response);
    }
    return result;
}
Also used : TCommandTransfer(com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer) HashMap(java.util.HashMap) ResponseMessage(com.navercorp.pinpoint.rpc.ResponseMessage) PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) Future(com.navercorp.pinpoint.rpc.Future) AgentInfo(com.navercorp.pinpoint.web.vo.AgentInfo) PinpointRouteResponse(com.navercorp.pinpoint.web.cluster.PinpointRouteResponse) FailedPinpointRouteResponse(com.navercorp.pinpoint.web.cluster.FailedPinpointRouteResponse) DefaultPinpointRouteResponse(com.navercorp.pinpoint.web.cluster.DefaultPinpointRouteResponse) HashMap(java.util.HashMap) Map(java.util.Map)

Example 17 with PinpointSocket

use of com.navercorp.pinpoint.rpc.PinpointSocket in project pinpoint by naver.

the class AgentServiceImpl method invoke.

@Override
public PinpointRouteResponse invoke(AgentInfo agentInfo, byte[] payload, long timeout) throws TException {
    TCommandTransfer transferObject = createCommandTransferObject(agentInfo, payload);
    List<PinpointSocket> socketList = clusterManager.getSocket(agentInfo);
    Future<ResponseMessage> future = null;
    if (CollectionUtils.nullSafeSize(socketList) == 1) {
        PinpointSocket socket = socketList.get(0);
        future = socket.request(serializeRequest(transferObject));
    }
    PinpointRouteResponse response = getResponse(future, timeout);
    return response;
}
Also used : TCommandTransfer(com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer) PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) PinpointRouteResponse(com.navercorp.pinpoint.web.cluster.PinpointRouteResponse) FailedPinpointRouteResponse(com.navercorp.pinpoint.web.cluster.FailedPinpointRouteResponse) DefaultPinpointRouteResponse(com.navercorp.pinpoint.web.cluster.DefaultPinpointRouteResponse) ResponseMessage(com.navercorp.pinpoint.rpc.ResponseMessage)

Example 18 with PinpointSocket

use of com.navercorp.pinpoint.rpc.PinpointSocket in project pinpoint by naver.

the class AgentServiceImpl method openStreamAndAwait.

@Override
public ClientStreamChannel openStreamAndAwait(AgentInfo agentInfo, byte[] payload, ClientStreamChannelEventHandler streamChannelEventHandler, long timeout) throws TException, StreamException {
    assertClusterEnabled();
    TCommandTransfer transferObject = createCommandTransferObject(agentInfo, payload);
    List<PinpointSocket> socketList = clusterManager.getSocket(agentInfo);
    if (CollectionUtils.nullSafeSize(socketList) == 1) {
        PinpointSocket socket = socketList.get(0);
        return socket.openStreamAndAwait(serializeRequest(transferObject), streamChannelEventHandler, timeout);
    } else if (CollectionUtils.isEmpty(socketList)) {
        throw new StreamException(StreamCode.CONNECTION_NOT_FOUND);
    } else {
        throw new StreamException(StreamCode.CONNECTION_DUPLICATED);
    }
}
Also used : TCommandTransfer(com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer) PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) StreamException(com.navercorp.pinpoint.rpc.stream.StreamException)

Example 19 with PinpointSocket

use of com.navercorp.pinpoint.rpc.PinpointSocket in project pinpoint by naver.

the class AgentServiceImpl method openStream.

@Override
public ClientStreamChannel openStream(AgentInfo agentInfo, byte[] payload, ClientStreamChannelEventHandler streamChannelEventHandler) throws TException, StreamException {
    assertClusterEnabled();
    TCommandTransfer transferObject = createCommandTransferObject(agentInfo, payload);
    List<PinpointSocket> socketList = clusterManager.getSocket(agentInfo);
    if (CollectionUtils.nullSafeSize(socketList) == 1) {
        PinpointSocket socket = socketList.get(0);
        return socket.openStream(serializeRequest(transferObject), streamChannelEventHandler);
    } else if (CollectionUtils.isEmpty(socketList)) {
        throw new StreamException(StreamCode.CONNECTION_NOT_FOUND);
    } else {
        throw new StreamException(StreamCode.CONNECTION_DUPLICATED);
    }
}
Also used : TCommandTransfer(com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer) PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) StreamException(com.navercorp.pinpoint.rpc.stream.StreamException)

Example 20 with PinpointSocket

use of com.navercorp.pinpoint.rpc.PinpointSocket in project pinpoint by naver.

the class HandshakeTest method handshakeTest2.

@Test
public void handshakeTest2() throws InterruptedException {
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
    int bindPort = testPinpointServerAcceptor.bind();
    Map<String, Object> params = PinpointRPCTestUtils.getParams();
    TestPinpointClient testPinpointClient = new TestPinpointClient(testServerMessageListenerFactory.create(), params);
    try {
        testPinpointClient.connect(bindPort);
        testPinpointServerAcceptor.assertAwaitClientConnected(1, 3000);
        PinpointSocket writableServer = getWritableServer("application", "agent", (Long) params.get(HandshakePropertyType.START_TIMESTAMP.getName()), testPinpointServerAcceptor.getConnectedPinpointSocketList());
        Assert.assertNotNull(writableServer);
        writableServer = getWritableServer("application", "agent", (Long) params.get(HandshakePropertyType.START_TIMESTAMP.getName()) + 1, testPinpointServerAcceptor.getConnectedPinpointSocketList());
        Assert.assertNull(writableServer);
    } finally {
        testPinpointClient.closeAll();
        testPinpointServerAcceptor.close();
    }
}
Also used : TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) TestPinpointClient(com.navercorp.pinpoint.test.client.TestPinpointClient) PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) Test(org.junit.Test)

Aggregations

PinpointSocket (com.navercorp.pinpoint.rpc.PinpointSocket)27 TestPinpointServerAcceptor (com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor)10 Test (org.junit.Test)10 TestPinpointClient (com.navercorp.pinpoint.test.client.TestPinpointClient)8 PinpointServer (com.navercorp.pinpoint.rpc.server.PinpointServer)5 TCommandTransfer (com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer)5 Map (java.util.Map)5 ServerMessageListener (com.navercorp.pinpoint.rpc.server.ServerMessageListener)3 RecordedStreamChannelMessageListener (com.navercorp.pinpoint.rpc.RecordedStreamChannelMessageListener)2 ResponseMessage (com.navercorp.pinpoint.rpc.ResponseMessage)2 HandshakeResponseCode (com.navercorp.pinpoint.rpc.packet.HandshakeResponseCode)2 PingPacket (com.navercorp.pinpoint.rpc.packet.PingPacket)2 RequestPacket (com.navercorp.pinpoint.rpc.packet.RequestPacket)2 SendPacket (com.navercorp.pinpoint.rpc.packet.SendPacket)2 PinpointServerAcceptor (com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor)2 StreamException (com.navercorp.pinpoint.rpc.stream.StreamException)2 DefaultPinpointRouteResponse (com.navercorp.pinpoint.web.cluster.DefaultPinpointRouteResponse)2 FailedPinpointRouteResponse (com.navercorp.pinpoint.web.cluster.FailedPinpointRouteResponse)2 PinpointRouteResponse (com.navercorp.pinpoint.web.cluster.PinpointRouteResponse)2 ArrayList (java.util.ArrayList)2