The instructions herein are meant to be used together with the remaining material on migrating. They provide an outline for moving an application to Esper 8.
Classpath Changes
Remove CGLib from classpath. Add the Esper compiler, common and runtime jar files and their dependencies.
Configuration Changes
Please see the document on migrating configuration XML and configuration code.
The following settings are for applications that allow subscribers and that rely on the Esper-7 global public visibilities.
The XML configuration is:
<esper-configuration xmlns="http://www.espertech.com/schema/esper">
<compiler>
<bytecode
allow-subscriber="true"
access-modifier-context="public"
access-modifier-event-type="public"
access-modifier-expression="public"
access-modifier-named-window="public"
access-modifier-script="public"
access-modifier-table="public"
access-modifier-variable="public"
bus-modifier-event-type="bus"/>
</compiler>
</esper-configuration>
The code for using the configuration API is:
Configuration configuration = new Configuration();
configuration.getCompiler().getByteCode().setAllowSubscriber(true);
configuration.getCompiler().getByteCode().setAccessModifiersPublic();
configuration.getCompiler().getByteCode().setBusModifierEventType(EventTypeBusModifier.BUS);
By setting the allow-subscriber flag your statement allows subscribers to receive results. Esper-7 allows subscribers by default.
By setting the default access modifiers to PUBLIC
all EPL-objects such as event types are publicly visible. Esper-7 has only public visibility.
By setting the bus-modifier for event types to BUS
your application can use send-event to send any type of event into the engine. Esper-7 has only bus visibility.
Remove Esper-related Imports from Classes
All package names have changed due to the refactoring into common, compiler and runtime. Please remove all Esper-related imports from the import section of each class.
Classes in com.espertech.esper.client
that were common to the compiler and runtime have been moved to com.espertech.esper.common.client
, for example EventBean
and EventType
.
Classes in com.espertech.esper.client
that were specific to the runtime have been moved to com.espertech.esper.runtime.client
.
Compile-Related Changes
Esper-8 uses a compiler for compiling an EPL module to byte code. The Esper-7 createEPL
method has been removed. You could use the utility method shown below for compiling. It returns you a Deployment
object. Use deployment.getStatements()
to obtain the EPStatement
instances.
Here is a method that can replace createEPL
calls of Esper-7:
public static EPDeployment compileDeploy(EPRuntime runtime, String epl) {
try {
// Obtain a copy of the engine configuration
Configuration configuration = runtime.getConfigurationDeepCopy();
// Build compiler arguments
CompilerArguments args = new CompilerArguments(configuration);
// Make the existing EPL objects available to the compiler
args.getPath().add(runtime.getRuntimePath());
// Compile
EPCompiled compiled = EPCompilerProvider.getCompiler().compile(epl, args);
// Return the deployment
return runtime.getDeploymentService().deploy(compiled);
}
catch (Exception ex) {
throw new RuntimeException(ex);
}
}
Here is how to use the method above:
EPDeployment deployment = compileDeploy(runtime, epl);
deployment.getStatements()[0].addListener(...);
Change Listener Code
The StatementAwareUpdateListener
interface has been removed. Instead the UpdateListener
interface was changed to match the StatementAwareUpdateListener
footprint.
Change Calls to the EPRuntime#sendEvent
method
The send-event and route-event methods were moved to the EPEventService
interface and were renamed to consistently account for the underlying event object
to be processed. All methods now also require the event type name as a parameter. The new methods are sendEventBean
, sendEventMap
, sendEventObjectArray
,
sendEventXMLDOM
and sendEventAvro
.
For example:
runtime.getEventService().sendEventBean(new MyEvent(...), "MyEvent");
Change Code That Advances Time
The TimerEvent
class is removed and the sendEvent
method can no longer be used to advance time. Use EPEventService#advanceTime(time)
and EPEventService#clockExternal()
instead.
Change Code That Uses the Runtime Configuration API
The ConfigurationOperations
interface has been removed. Instead use the Configuration
interface or respective service such as EPVariableService
.
The post Esper-8 Migrating Step-By-Step For Existing Applications appeared first on EsperTech.