Developing Apama Applications > Developing Correlator Plug-ins > Writing Correlator Plug-ins in Java > Sample plug-ins in Java > A plug-in in Java that subscribes to receive events
A plug-in in Java that subscribes to receive events
This sample shows how a plug-in subscribes to receive events sent on a particular channel. This sample is comparable to the similar C and C++ subscription plug-in samples.
The Java code for the SubscribePlugin class contains the public static createHandler method. (Methods that will be called from EPL code need to be public and static.)
import com.apama.epl.plugin.Correlator;
import com.apama.epl.plugin.EventHandler;
 
/** Demonstrates a plugin subscribing to channels to receive events */
 
public class SubscribePlugin
{
public static class SubscribeHandler implements EventHandler
{
public void handleEvent(String event, String channel)
{
System.out.println("Got event "+event+" on channel "+channel);
}
}
public static Object createHandler(String channel)
{
SubscribeHandler h = new SubscribeHandler();
Correlator.subscribe(h, new String[] { channel });
return h;
}
}
The deployment descriptor file contains the following <plugin> stanza that illustrates how to specify the plug-in.
<application-classes>
<plugin>
<plugin-name>SubscribePlugin</plugin-name>
<plugin-class>SubscribePlugin</plugin-class>
<description>A test plugin</description>
</plugin>
</application-classes>
The EPL code imports the plug-in and calls the createHandler() method.
event A {
string str;
}
 
monitor SubscribePluginTest
{
// Load the plugin
import "SubscribePlugin" as subscribe_plugin;
 
action onload {
chunk handler := subscribe_plugin.createHandler("SampleChannel");
send A("Hello World") to "SampleChannel";
}
}
Copyright © 2013-2015 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG.