Oracle® CEP IDE Developer's Guide for Eclipse Release 11gR1 (11.1.1) Part Number E14301-02 |
|
|
View PDF |
This section contains information on the following subjects:
Oracle CEP metadata annotations are used to access the configuration of an Oracle CEP component. Oracle CEP offers the following annotations:
For more information, see:
You use the following annotations to specify the methods of an adapter Java implementation that handle various stages of the adapter's lifecyle: when its configuration is prepared, when the configuration is activated, and when the adapter is terminated due to an exception:
Use the com.bea.wlevs.util.Service annotation to specify the method of a component that is injected with an OSGi service reference.
Use the following annotations to configure resource access at design time and the corresponding deployment XML to override this configuration at deploy time:
javax.annotation.Resource
For more information, see Section 1.6, "Configuring Oracle CEP Resource Access".
The @Activate
annotation is one of the adapter lifecycle annotations that you use in the Java file that implements your custom adapter to explicitly specify the methods that Oracle CEP uses to send configuration information to the adapter.
Oracle CEP calls methods marked with the @Activate
annotation after, and if, the server has called and successfully executed all the methods marked with the @Prepare
annotation. You typically use the @Activate
method to actually get the adapter's configuration data to use in the rest of the adapter implementation.
The method you annotate with this annotation must have the following signature:
public void methodName(AdapterConfigObject adapterConfig)
where methodName
refers to the name you give the method and AdapterConfigObject
refers to the Java representation of the adapter's configuration XML file which is deployed with the application. The type of this class is com.bea.wlevs.configuration.application.DefaultAdapterConfig
by default; if, however, you have extended the configuration of the adapter, then the type is whatever have specified in the XSD that describes the extended XML file. For example, in the HelloWorld sample, the type is com.bea.wlevs.adapter.example.helloworld.HelloWorldAdapterConfig
.
At run time, Oracle CEP automatically creates an instance of this class, populates it with data from the actual XML file, and passes the instance to the adapter. The adapter methods annotated with the adapter lifecycle annotations can then use the class to get information about the adapter's configuration.
This metadata annotation does not have any attributes.
Example G-1 shows how to use the @Activate
annotation in the adapter component of the HelloWorld example; only relevant code is shown:
Example G-1 @Activate Annotation
package com.bea.wlevs.adapter.example.helloworld; ... import com.bea.wlevs.configuration.Activate; import com.bea.wlevs.ede.api.RunnableBean; import com.bea.wlevs.ede.api.StreamSender; import com.bea.wlevs.ede.api.StreamSource; import com.bea.wlevs.event.example.helloworld.HelloWorldEvent; public class HelloWorldAdapter implements RunnableBean, StreamSource { ... @Activate public void activateAdapter(HelloWorldAdapterConfig adapterConfig) { this.message = adapterConfig.getMessage(); } ... }
The com.bea.wlevs.adapter.example.helloworld.HelloWorldAdapterConfig
class is a Java represenation of the adapter's configuration XML file. In the HelloWorld example, the configuration has been extended; this means a custom XSD file describes the XML file. Example G-2 shows this XSD file also specifies the fully qualified name of the resulting Java configuration object, as shown in bold:
Example G-2 HelloWorldAdapterConfig
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns="http://www.bea.com/ns/wlevs/example/helloworld" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:wlevs="http://www.bea.com/ns/wlevs/config/application" targetNamespace="http://www.bea.com/ns/wlevs/example/helloworld" elementFormDefault="unqualified" attributeFormDefault="unqualified" jxb:extensionBindingPrefixes="xjc" jxb:version="1.0"> <xs:annotation> <xs:appinfo> <jxb:schemaBindings> <jxb:package name="com.bea.wlevs.adapter.example.helloworld"/> </jxb:schemaBindings> </xs:appinfo> </xs:annotation> <xs:import namespace="http://www.bea.com/ns/wlevs/config/application" schemaLocation="wlevs_application_config.xsd"/> <xs:element name="config"> <xs:complexType> <xs:choice maxOccurs="unbounded"> <xs:element name="adapter" type="HelloWorldAdapterConfig"/> <xs:element name="processor" type="wlevs:DefaultProcessorConfig"/> <xs:element name="channel" type="wlevs:DefaultStreamConfig" /> </xs:choice> </xs:complexType> </xs:element> <xs:complexType name="HelloWorldAdapterConfig"> <xs:complexContent> <xs:extension base="wlevs:AdapterConfig"> <xs:sequence> <xs:element name="message" type="xs:string"/> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> </xs:schema>
Oracle CEP automatically creates an instance of this class when the application is deployed. For example, the adapter section of the helloworldAdapter
configuration file is as follows:
<?xml version="1.0" encoding="UTF-8"?> <helloworld:config ... <adapter> <name>helloworldAdapter</name> <message>HelloWorld - the current time is:</message> </adapter> </helloworld:config>
In the Java code of the adapter above, the activateAdapter
method is annotated with the @Activate
annotation. The method uses the getMessage
method of the configuration object to get the value of the message
property set in the adapter's configuration XML file. In this case, the value is HelloWorld - the current time is:
. This value can then be used in the main part of the adapter implementation file.
The @Prepare
annotation is one of the adapter lifecycle annotations that you use in the Java file that implements your custom adapter to explicitly specify the methods that Oracle CEP uses to send configuration information to the adapter.
Oracle CEP calls the method annotated with @Prepare
whenever a component's state has been updated by a particular configuration change.
The method you annotate with this annotation must have the following signature:
public void methodName(AdapterConfigObject adapterConfig)
where methodName
refers to the name you give the method and AdapterConfigObject
refers to the Java represenation of the adapter's configuration XML file which is deployed with the application. The type of this class is com.bea.wlevs.configuration.application.DefaultAdapterConfig
by default; if, however, you have extended the configuration of the adapter, then the type is whatever have specified in the XSD that describes the extended XML file. For example, in the HelloWorld sample, the type is com.bea.wlevs.adapter.example.helloworld.HelloWorldAdapterConfig
.
At run time, Oracle CEP automatically creates an instance of this class, populates it with data from the actual XML file, and passes the instance to the adapter. The adapter methods annotated with the adapter lifecycle annotations can then use the class to get information about the adapter's configuration.
This metadata annotation does not have any attributes.
Example G-3, from the adapter component of the HelloWorld example, shows how to use the @Prepare
annotation; only relevant code is shown:
Example G-3 @Prepare Annotation
package com.bea.wlevs.adapter.example.helloworld; ... import com.bea.wlevs.configuration.Prepare; import com.bea.wlevs.ede.api.RunnableBean; import com.bea.wlevs.ede.api.StreamSender; import com.bea.wlevs.ede.api.StreamSource; import com.bea.wlevs.event.example.helloworld.HelloWorldEvent; public class HelloWorldAdapter implements RunnableBean, StreamSource { ... @Prepare public void checkConfiguration(HelloWorldAdapterConfig adapterConfig) { if (adapterConfig.getMessage() == null || adapterConfig.getMessage().length() == 0) { throw new RuntimeException("invalid message: " + message); } } ... }
The com.bea.wlevs.adapter.example.helloworld.HelloWorldAdapterConfig
class is a Java represenation of the adapter's configuration XML file; Oracle CEP automatically creates an instance of this class when the application is deployed. In the HelloWorld example, the adapter configuration has been extended. See the example in Appendix G, "com.bea.wlevs.configuration.Activate" for additional details.
In the Java code of the adapter above, the checkConfiguration
method is annotated with the @Prepare
annotation, which means this method is called when the adapter's configuration changes in some way. The example further shows that the method checks to make sure that the message
property of the adapter's configuration (set in the extended adapter configuration file) is not null or empty; if it is, then the method throws an exception.
The @Rollback
annotation is one of the adapter lifecycle annotations that you use in the Java file that implements your custom adapter to explicitly specify the methods that Oracle CEP uses to send configuration information to the adapter.
Oracle CEP calls the method annotated with @Rollback
whenever a component whose @Prepare
method was called but threw an exception. The server calls the @Rollback
method for each component for which this is true.
The method you annotate with this annotation must have the following signature:
public void methodName(AdapterConfigObject adapterConfig)
where methodName
refers to the name you give the method and AdapterConfigObject
refers to the Java represenation of the adapter's configuration XML file which is deployed with the application. The type of this class is com.bea.wlevs.configuration.application.DefaultAdapterConfig
by default; if, however, you have extended the configuration of the adapter, then the type is whatever have specified in the XSD that describes the extended XML file. For example, in the HelloWorld sample, the type is com.bea.wlevs.adapter.example.helloworld.HelloWorldAdapterConfig
.
At run time, Oracle CEP automatically creates an instance of this class, populates it with data from the actual XML file, and passes the instance to the adapter. The adapter methods annotated with the adapter lifecycle annotations can then use the class to get information about the adapter's configuration.
This metadata annotation does not have any attributes.
Example G-4, sample code from the adapter component of the HelloWorld example, shows how to use the @Rollback
annotation; only relevant code is shown:
Example G-4 @Rollback Annotation
package com.bea.wlevs.adapter.example.helloworld; ... import com.bea.wlevs.configuration.Rollback; import com.bea.wlevs.ede.api.RunnableBean; import com.bea.wlevs.ede.api.StreamSender; import com.bea.wlevs.ede.api.StreamSource; import com.bea.wlevs.event.example.helloworld.HelloWorldEvent; public class HelloWorldAdapter implements RunnableBean, StreamSource { ... @Rollback public void rejectConfigurationChange(HelloWorldAdapterConfig adapterConfig) { }
The com.bea.wlevs.adapter.example.helloworld.HelloWorldAdapterConfig
class is a Java represenation of the adapter's configuration XML file; Oracle CEP automatically creates an instance of this class when the application is deployed. In the HelloWorld example, the adapter configuration has been extended. See the example in Appendix G, "com.bea.wlevs.configuration.Activate" for additional details.
In the example, the rejectConfigurationChange
method is annotated with the @Rollback
annotation, which means this is the method that is called if the @Prepare
method threw an exception. In the example above, nothing actually happens.
Specifies that the annotated method, typically a JavaBean setter method, requires an OSGi service reference.
Table G-1 describes the attributes of the com.bea.wlevs.util.Service
JWS annotation.
Table G-1 Attributes of the com.bea.wlevs.util.Service JWS Annotation Tag
Name | Description | Data Type | Required? |
---|---|---|---|
|
The name of the bean that backs the injected service. May be null. |
|
No. |
|
Valid values for this attribute are:
Default value is |
|
No. |
|
Valid values for this attribute are:
Default value is |
|
No. |
|
Timeout for service resolution in milliseconds. Default value is 30000. |
|
No. |
|
Interface (or class) of the service to be injected Default value is |
|
No. |
|
Specifies the filter used to narrow service matches. Value may be |
|
No. |
Example G-5 shows how to use the @Service
annotation.
Example G-5 @Service Annotation
@Service(filter = "(Name=StockDs)") public void setDataSourceService(DataSourceService dss) { initStockTable(dss.getDataSource()); }
For another example, see Section 1.5.6, "Accessing the Event Type Repository".