Search in sources :

Example 11 with ActiveMQConnection

use of org.apache.activemq.ActiveMQConnection in project pinpoint by naver.

the class ActiveMQMessageProducerSendInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args);
    }
    if (!validate(target, args)) {
        return;
    }
    Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    try {
        SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        recorder.recordApi(descriptor);
        if (throwable == null) {
            ActiveMQDestination destination = (ActiveMQDestination) args[0];
            // This annotation indicates the uri to which the call is made
            recorder.recordAttribute(AnnotationKey.MESSAGE_QUEUE_URI, destination.getQualifiedName());
            // DestinationId is used to render the virtual queue node.
            // We choose the queue/topic name as the logical name of the queue node.
            recorder.recordDestinationId(destination.getPhysicalName());
            ActiveMQSession session = ((ActiveMQSessionGetter) target)._$PINPOINT$_getActiveMQSession();
            ActiveMQConnection connection = session.getConnection();
            Transport transport = getRootTransport(((TransportGetter) connection)._$PINPOINT$_getTransport());
            Socket socket = ((SocketGetter) transport)._$PINPOINT$_getSocket();
            SocketAddress remoteSocketAddress = socket.getRemoteSocketAddress();
            String remoteAddress = ActiveMQClientUtils.getEndPoint(remoteSocketAddress);
            // Producer's endPoint should be the socket address of where the producer is actually connected to.
            recorder.recordEndPoint(remoteAddress);
            recorder.recordAttribute(ActiveMQClientConstants.ACTIVEMQ_BROKER_URL, remoteAddress);
        } else {
            recorder.recordException(throwable);
        }
    } catch (Throwable t) {
        logger.warn("AFTER error. Cause:{}", t.getMessage(), t);
    } finally {
        trace.traceBlockEnd();
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) ActiveMQSessionGetter(com.navercorp.pinpoint.plugin.activemq.client.field.getter.ActiveMQSessionGetter) ActiveMQSession(org.apache.activemq.ActiveMQSession) SocketGetter(com.navercorp.pinpoint.plugin.activemq.client.field.getter.SocketGetter) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) ActiveMQConnection(org.apache.activemq.ActiveMQConnection) Transport(org.apache.activemq.transport.Transport) SocketAddress(java.net.SocketAddress) Socket(java.net.Socket) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 12 with ActiveMQConnection

use of org.apache.activemq.ActiveMQConnection in project tomee by apache.

the class ActiveMQResourceAdapter method makeConnection.

@Override
public ActiveMQConnection makeConnection(final MessageActivationSpec activationSpec) throws JMSException {
    if (TomEEMessageActivationSpec.class.isInstance(activationSpec)) {
        final TomEEMessageActivationSpec s = TomEEMessageActivationSpec.class.cast(activationSpec);
        if (s.getConnectionFactoryLookup() != null) {
            try {
                final Object lookup = SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext().lookup("openejb:Resource/" + s.getConnectionFactoryLookup());
                if (!ActiveMQConnectionFactory.class.isInstance(lookup)) {
                    final org.apache.activemq.ra.ActiveMQConnectionFactory connectionFactory = org.apache.activemq.ra.ActiveMQConnectionFactory.class.cast(lookup);
                    Connection connection = connectionFactory.createConnection();
                    if (Proxy.isProxyClass(connection.getClass())) {
                        // not great, we should find a better want without bypassing ra layer
                        final InvocationHandler invocationHandler = Proxy.getInvocationHandler(connection);
                        if (AutoConnectionTracker.ConnectionInvocationHandler.class.isInstance(invocationHandler)) {
                            final Object handle = Reflections.get(invocationHandler, "handle");
                            if (TomEEManagedConnectionProxy.class.isInstance(handle)) {
                                final ActiveMQManagedConnection c = ActiveMQManagedConnection.class.cast(Reflections.get(handle, "connection"));
                                final ActiveMQConnection physicalConnection = ActiveMQConnection.class.cast(Reflections.get(c, "physicalConnection"));
                                final RedeliveryPolicy redeliveryPolicy = activationSpec.redeliveryPolicy();
                                if (redeliveryPolicy != null) {
                                    physicalConnection.setRedeliveryPolicy(redeliveryPolicy);
                                }
                                return physicalConnection;
                            }
                        }
                    }
                    /*
                        final RedeliveryPolicy redeliveryPolicy = activationSpec.redeliveryPolicy();
                        if (redeliveryPolicy != null) {
                            physicalConnection.setRedeliveryPolicy(redeliveryPolicy);
                        }
                        */
                    return null;
                }
            } catch (final ClassCastException cce) {
                throw new java.lang.IllegalStateException(cce);
            } catch (final NamingException e) {
                throw new IllegalArgumentException(e);
            }
        }
    }
    return super.makeConnection(activationSpec);
}
Also used : ActiveMQConnection(org.apache.activemq.ActiveMQConnection) Connection(javax.jms.Connection) ActiveMQManagedConnection(org.apache.activemq.ra.ActiveMQManagedConnection) ActiveMQManagedConnection(org.apache.activemq.ra.ActiveMQManagedConnection) ActiveMQConnection(org.apache.activemq.ActiveMQConnection) InvocationHandler(java.lang.reflect.InvocationHandler) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) RedeliveryPolicy(org.apache.activemq.RedeliveryPolicy) NamingException(javax.naming.NamingException) AutoConnectionTracker(org.apache.openejb.resource.AutoConnectionTracker)

Aggregations

ActiveMQConnection (org.apache.activemq.ActiveMQConnection)12 Test (org.junit.Test)5 SocketGetter (com.navercorp.pinpoint.plugin.activemq.client.field.getter.SocketGetter)4 Transport (org.apache.activemq.transport.Transport)4 ActiveMQSessionGetter (com.navercorp.pinpoint.plugin.activemq.client.field.getter.ActiveMQSessionGetter)2 TransportGetter (com.navercorp.pinpoint.plugin.activemq.client.field.getter.TransportGetter)2 Socket (java.net.Socket)2 SocketAddress (java.net.SocketAddress)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)2 ActiveMQSession (org.apache.activemq.ActiveMQSession)2 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)2 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)1 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Connection (javax.jms.Connection)1 NamingException (javax.naming.NamingException)1 RedeliveryPolicy (org.apache.activemq.RedeliveryPolicy)1 ActiveMQMessage (org.apache.activemq.command.ActiveMQMessage)1