Search in sources :

Example 1 with PinpointSocketException

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

the class RequestManager method register.

public ChannelWriteFailListenableFuture<ResponseMessage> register(RequestPacket requestPacket, long timeoutMillis) {
    // shutdown check
    final int requestId = getNextRequestId();
    requestPacket.setRequestId(requestId);
    final ChannelWriteFailListenableFuture<ResponseMessage> future = new ChannelWriteFailListenableFuture<ResponseMessage>(timeoutMillis);
    final DefaultFuture old = this.requestMap.put(requestId, future);
    if (old != null) {
        throw new PinpointSocketException("unexpected error. old future exist:" + old + " id:" + requestId);
    }
    // when future fails, put a handle in order to remove a failed future in the requestMap.
    FailureEventHandler removeTable = createFailureEventHandler(requestId);
    future.setFailureEventHandler(removeTable);
    addTimeoutTask(timeoutMillis, future);
    return future;
}
Also used : FailureEventHandler(com.navercorp.pinpoint.rpc.FailureEventHandler) PinpointSocketException(com.navercorp.pinpoint.rpc.PinpointSocketException) ResponseMessage(com.navercorp.pinpoint.rpc.ResponseMessage) ChannelWriteFailListenableFuture(com.navercorp.pinpoint.rpc.ChannelWriteFailListenableFuture) DefaultFuture(com.navercorp.pinpoint.rpc.DefaultFuture)

Example 2 with PinpointSocketException

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

the class RequestManager method addTimeoutTask.

private void addTimeoutTask(long timeoutMillis, DefaultFuture future) {
    if (future == null) {
        throw new NullPointerException("future");
    }
    try {
        Timeout timeout = timer.newTimeout(future, timeoutMillis, TimeUnit.MILLISECONDS);
        future.setTimeout(timeout);
    } catch (IllegalStateException e) {
        // this case is that timer has been shutdown. That maybe just means that socket has been closed.
        future.setFailure(new PinpointSocketException("socket closed"));
    }
}
Also used : Timeout(org.jboss.netty.util.Timeout) PinpointSocketException(com.navercorp.pinpoint.rpc.PinpointSocketException)

Example 3 with PinpointSocketException

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

the class ReconnectTest method scheduledConnectStateTest.

@Test
public void scheduledConnectStateTest() {
    PinpointClient client = clientFactory.scheduledConnect("localhost", bindPort);
    client.send(new byte[10]);
    try {
        Future future = client.sendAsync(new byte[10]);
        future.await();
        future.getResult();
        Assert.fail();
    } catch (PinpointSocketException e) {
    }
    try {
        client.sendSync(new byte[10]);
        Assert.fail();
    } catch (PinpointSocketException e) {
    }
    try {
        PinpointRPCTestUtils.request(client, new byte[10]);
        Assert.fail();
    } catch (PinpointSocketException e) {
    }
    PinpointRPCTestUtils.close(client);
}
Also used : PinpointSocketException(com.navercorp.pinpoint.rpc.PinpointSocketException) Future(com.navercorp.pinpoint.rpc.Future)

Example 4 with PinpointSocketException

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

the class ClientFactoryUtils method createPinpointClient.

public static PinpointClient createPinpointClient(InetSocketAddress connectAddress, PinpointClientFactory clientFactory) {
    PinpointClient pinpointClient = null;
    for (int i = 0; i < 3; i++) {
        try {
            pinpointClient = clientFactory.connect(connectAddress);
            LOGGER.info("tcp connect success. remote:{}", connectAddress);
            return pinpointClient;
        } catch (PinpointSocketException e) {
            LOGGER.warn("tcp connect fail. remote:{} try reconnect, retryCount:{}", connectAddress, i);
        }
    }
    LOGGER.warn("change background tcp connect mode remote:{} ", connectAddress);
    pinpointClient = clientFactory.scheduledConnect(connectAddress);
    return pinpointClient;
}
Also used : PinpointClient(com.navercorp.pinpoint.rpc.client.PinpointClient) PinpointSocketException(com.navercorp.pinpoint.rpc.PinpointSocketException)

Example 5 with PinpointSocketException

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

the class NioUDPDataSender method sendPacket.

protected void sendPacket(Object message) {
    if (closed) {
        throw new PinpointSocketException("NioUDPDataSender already closed.");
    }
    if (message instanceof TBase) {
        byteBufferOutputStream.clear();
        final TBase dto = (TBase) message;
        try {
            serializer.serialize(dto, byteBufferOutputStream);
        } catch (TException e) {
            throw new PinpointSocketException("Serialize " + dto + " failed. Error:" + e.getMessage(), e);
        }
        ByteBuffer byteBuffer = byteBufferOutputStream.getByteBuffer();
        int bufferSize = byteBuffer.remaining();
        try {
            datagramChannel.write(byteBuffer);
        } catch (IOException e) {
            final Thread currentThread = Thread.currentThread();
            if (currentThread.isInterrupted()) {
                logger.warn("{} thread interrupted.", currentThread.getName());
                throw new PinpointSocketException(currentThread.getName() + " thread interrupted.", e);
            } else {
                throw new PinpointSocketException("packet send error. size:" + bufferSize + ", " + dto, e);
            }
        }
    } else {
        logger.warn("sendPacket fail. invalid type:{}", message != null ? message.getClass() : null);
        return;
    }
}
Also used : TException(org.apache.thrift.TException) PinpointSocketException(com.navercorp.pinpoint.rpc.PinpointSocketException) TBase(org.apache.thrift.TBase) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Aggregations

PinpointSocketException (com.navercorp.pinpoint.rpc.PinpointSocketException)7 DefaultFuture (com.navercorp.pinpoint.rpc.DefaultFuture)3 ResponseMessage (com.navercorp.pinpoint.rpc.ResponseMessage)2 ChannelWriteFailListenableFuture (com.navercorp.pinpoint.rpc.ChannelWriteFailListenableFuture)1 FailureEventHandler (com.navercorp.pinpoint.rpc.FailureEventHandler)1 Future (com.navercorp.pinpoint.rpc.Future)1 PinpointClient (com.navercorp.pinpoint.rpc.client.PinpointClient)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 TBase (org.apache.thrift.TBase)1 TException (org.apache.thrift.TException)1 Timeout (org.jboss.netty.util.Timeout)1