Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Changed the way PipelineNotification is loaded.
Browse files Browse the repository at this point in the history
  • Loading branch information
user1 committed Oct 16, 2020
1 parent 02d414d commit 0da22d0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 40 deletions.
3 changes: 1 addition & 2 deletions mule4-agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>co.elastic.apm</groupId>
<artifactId>mule4-agent</artifactId>
<version>0.0.4</version>
<version>0.1.0</version>
<name>Elastic Mule 4 APM agent</name>
<description>Elastic Mule 4 APM agent</description>
<packaging>jar</packaging>
Expand Down Expand Up @@ -100,7 +100,6 @@
<groupId>co.elastic.apm</groupId>
<artifactId>elastic-apm-agent</artifactId>
<version>${elastic-apm.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>co.elastic.apm</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
import org.mule.runtime.api.artifact.Registry;
import org.mule.runtime.api.interception.ProcessorInterceptor;
import org.mule.runtime.api.interception.ProcessorInterceptorFactory;
import org.mule.runtime.api.notification.PipelineMessageNotification;
import org.mule.runtime.api.notification.PipelineMessageNotificationListener;
import org.mule.runtime.core.api.context.notification.ServerNotificationManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/*
* This is ProcessorInterceptorFactory API to intercept flow step execution.
Expand All @@ -19,43 +14,10 @@ public class MuleProcessorInterceptorFactory implements ProcessorInterceptorFact
@Inject
private Registry registry;

private Logger logger = LoggerFactory.getLogger(MuleProcessorInterceptorFactory.class);

/*
* Creation of flow interceptors is done with a byproduct of only-once instantiation of flow listeners.
*/
@Override
public ProcessorInterceptor get() {
ApmHandler apmHandler = registry.lookupByType(ApmHandler.class).get();

setupPipelineListener(apmHandler);

return new MuleProcessorInterceptor(apmHandler);
}

// Setup a singleton flow event listener once.
// TODO: find a away to do it in the tracer.xml
private void setupPipelineListener(ApmHandler apmHandler) {
ServerNotificationManager notificationManager = registry.lookupByType(ServerNotificationManager.class).get();

// Register only once, check if hasn't been registered before.
synchronized (notificationManager) {
if (notificationManager.getListeners().stream()
.anyMatch(x -> x.getListener().getClass() == ApmPipelineNotificationListener.class))
return;
}

ApmPipelineNotificationListener apmPipelineNotificationListener = new ApmPipelineNotificationListener(
apmHandler);

// Enable notifications
notificationManager.setNotificationDynamic(true);
notificationManager.addInterfaceToType(PipelineMessageNotificationListener.class,
PipelineMessageNotification.class);

notificationManager.addListener(apmPipelineNotificationListener);

logger.debug("Created Elastic APM event lifecycle listeners");
}

}
7 changes: 7 additions & 0 deletions mule4-agent/src/main/resources/tracer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@
<object name="_muleProcessorInterceptorFactory"
class="co.elastic.apm.mule4.agent.MuleProcessorInterceptorFactory" />

<object doc:name="Object" name="_apmPipelineNotifications" class="co.elastic.apm.mule4.agent.ApmPipelineNotificationListener" />

<notifications>
<notification event="PIPELINE-MESSAGE"/>
<notification-listener ref="_apmPipelineNotifications" />
</notifications>

</mule>
7 changes: 7 additions & 0 deletions mule4-agent/src/test/resources/test-tracer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@
<object name="_muleProcessorInterceptorFactory"
class="co.elastic.apm.mule4.agent.MuleProcessorInterceptorFactory" />

<object doc:name="Object" name="_apmPipelineNotifications" class="co.elastic.apm.mule4.agent.ApmPipelineNotificationListener" />

<notifications>
<notification event="PIPELINE-MESSAGE"/>
<notification-listener ref="_apmPipelineNotifications" />
</notifications>

</mule>

0 comments on commit 0da22d0

Please sign in to comment.