use of com.navercorp.pinpoint.rpc.packet.PingPacket in project pinpoint by naver.
the class TCPReceiver method start.
@PostConstruct
public void start() {
afterPropertiesSet();
// take care when attaching message handlers as events are generated from the IO thread.
// pass them to a separate queue and handle them in a different thread.
this.serverAcceptor.setMessageListener(new ServerMessageListener() {
@Override
public HandshakeResponseCode handleHandshake(Map properties) {
if (properties == null) {
return HandshakeResponseType.ProtocolError.PROTOCOL_ERROR;
}
boolean hasRequiredKeys = HandshakePropertyType.hasRequiredKeys(properties);
if (!hasRequiredKeys) {
return HandshakeResponseType.PropertyError.PROPERTY_ERROR;
}
boolean supportServer = MapUtils.getBoolean(properties, HandshakePropertyType.SUPPORT_SERVER.getName(), true);
if (supportServer) {
return HandshakeResponseType.Success.DUPLEX_COMMUNICATION;
} else {
return HandshakeResponseType.Success.SIMPLEX_COMMUNICATION;
}
}
@Override
public void handleSend(SendPacket sendPacket, PinpointSocket pinpointSocket) {
receive(sendPacket, pinpointSocket);
}
@Override
public void handleRequest(RequestPacket requestPacket, PinpointSocket pinpointSocket) {
requestResponse(requestPacket, pinpointSocket);
}
@Override
public void handlePing(PingPacket pingPacket, PinpointServer pinpointServer) {
recordPing(pingPacket, pinpointServer);
}
});
this.serverAcceptor.bind(configuration.getTcpListenIp(), configuration.getTcpListenPort());
}
use of com.navercorp.pinpoint.rpc.packet.PingPacket in project pinpoint by naver.
the class TcpDataSenderReconnectTest method serverAcceptorStart.
public PinpointServerAcceptor serverAcceptorStart() {
PinpointServerAcceptor serverAcceptor = new PinpointServerAcceptor();
serverAcceptor.setMessageListener(new ServerMessageListener() {
@Override
public void handleSend(SendPacket sendPacket, PinpointSocket pinpointSocket) {
logger.debug("handleSend packet:{}, remote:{}", sendPacket, pinpointSocket.getRemoteAddress());
send++;
}
@Override
public void handleRequest(RequestPacket requestPacket, PinpointSocket pinpointSocket) {
logger.debug("handleRequest packet:{}, remote:{}", requestPacket, pinpointSocket.getRemoteAddress());
}
@Override
public HandshakeResponseCode handleHandshake(Map properties) {
return HandshakeResponseType.Success.DUPLEX_COMMUNICATION;
}
@Override
public void handlePing(PingPacket pingPacket, PinpointServer pinpointServer) {
logger.debug("ping received {} {} ", pingPacket, pinpointServer);
}
});
serverAcceptor.bind(HOST, PORT);
return serverAcceptor;
}
use of com.navercorp.pinpoint.rpc.packet.PingPacket in project pinpoint by naver.
the class PinpointClientFactoryTest method pingInternal.
@Test
public void pingInternal() throws IOException, InterruptedException {
final CountDownLatch pingLatch = new CountDownLatch(1);
PinpointServerAcceptor serverAcceptor = PinpointRPCTestUtils.createPinpointServerFactory(bindPort, new PinpointRPCTestUtils.EchoServerListener() {
@Override
public void handlePing(PingPacket pingPacket, PinpointServer pinpointServer) {
pingLatch.countDown();
}
});
try {
PinpointClient client = clientFactory.connect("127.0.0.1", bindPort);
pingLatch.await();
PinpointRPCTestUtils.close(client);
} finally {
PinpointRPCTestUtils.close(serverAcceptor);
}
}
use of com.navercorp.pinpoint.rpc.packet.PingPacket in project pinpoint by naver.
the class PacketDecoder method decode.
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
if (buffer.readableBytes() < 2) {
return null;
}
buffer.markReaderIndex();
final short packetType = buffer.readShort();
switch(packetType) {
case PacketType.APPLICATION_SEND:
return readSend(packetType, buffer);
case PacketType.APPLICATION_REQUEST:
return readRequest(packetType, buffer);
case PacketType.APPLICATION_RESPONSE:
return readResponse(packetType, buffer);
case PacketType.APPLICATION_STREAM_CREATE:
return readStreamCreate(packetType, buffer);
case PacketType.APPLICATION_STREAM_CLOSE:
return readStreamClose(packetType, buffer);
case PacketType.APPLICATION_STREAM_CREATE_SUCCESS:
return readStreamCreateSuccess(packetType, buffer);
case PacketType.APPLICATION_STREAM_CREATE_FAIL:
return readStreamCreateFail(packetType, buffer);
case PacketType.APPLICATION_STREAM_RESPONSE:
return readStreamData(packetType, buffer);
case PacketType.APPLICATION_STREAM_PING:
return readStreamPing(packetType, buffer);
case PacketType.APPLICATION_STREAM_PONG:
return readStreamPong(packetType, buffer);
case PacketType.CONTROL_CLIENT_CLOSE:
return readControlClientClose(packetType, buffer);
case PacketType.CONTROL_SERVER_CLOSE:
return readControlServerClose(packetType, buffer);
case PacketType.CONTROL_PING:
PingPacket pingPacket = (PingPacket) readPing(packetType, buffer);
if (pingPacket == PingPacket.PING_PACKET) {
sendPong(channel);
// just drop ping
return null;
}
return pingPacket;
case PacketType.CONTROL_PONG:
logger.debug("receive pong. {}", channel);
readPong(packetType, buffer);
// just also drop pong.
return null;
case PacketType.CONTROL_HANDSHAKE:
return readEnableWorker(packetType, buffer);
case PacketType.CONTROL_HANDSHAKE_RESPONSE:
return readEnableWorkerConfirm(packetType, buffer);
}
logger.error("invalid packetType received. packetType:{}, channel:{}", packetType, channel);
channel.close();
return null;
}
Aggregations