Dynamic Resource Names Static Resource Injection

1-24 Oracle Complex Event Processing Developers Guide To override design time configuration at deploy time, you use Oracle CEP assembly file XML as Example 1–15 shows. Example 1–14 Static Resource Injection Using Dynamic Resource Names: Annotations import javax.annotation.Resource; public class SimpleBean implements EventBean { ... Resource name=trade-datasource public void setDataSource DataSource dataSource{ this.dataSource = dataSource; } } Example 1–15 Static Resource Injection Using Dynamic Resource Names: XML wlevs:event-bean id=simpleBean class=...SimpleBean wlevs:resource property=dataSource name=trade-datasource wlevs:event-bean

1.4.2 Dynamic Resource Injection

Dynamic resource injection refers to the injection of resources dynamically while the component is active in response to a dynamic configuration change using Spring container method injection. To configure dynamic resource injection at design time, you use the standard javax.annotation.Resource annotation as Example 1–16 shows. Example 1–16 Dynamic Resource Injection: Annotations import javax.annotations.Resource; public class SimpleBean implements EventBean { ... Resource trade-datasource public abstract DataSource getDataSource ; ... } The component calls the getDataSource method at run time whenever it needs to retrieve a new instance of the resource that the resource name trade-datasource refers to. Typically, the component calls the getDataSource method during the Prepare or Activate methods when dynamic configuration changes are handled. For more information see: ■ Section I.2, com.bea.wlevs.configuration.Activate ■ Section I.3, com.bea.wlevs.configuration.Prepare Another strategy is to always call the getDataSource prior to using the data source. That is, the application code does not store a reference to the data source as a field in the component.

1.4.3 Dynamic Resource Lookup Using JNDI

Oracle CEP supports the use of JNDI to look up resources dynamically as Example 1–17 . Overview of Creating Oracle CEP Applications 1-25 Example 1–17 Dynamic Resource Lookup Using JNDI import javax.naming.InitialContext; public class SimpleBean implements EventBean { ... public abstract void getDataSource throws Exception { InitialContext initialContext= new InitialContext ; return initialContext.lookup StockDs”; } } In Example 1–17 , the JNDI name StockDs must exactly match the name of the data source in the Oracle CEP server config.xml file as Example 1–8 shows.

1.4.4 Understanding Resource Name Resolution

Oracle CEP server resolves resource names by examining the naming scopes that Table 1–1 lists. Each naming scope contains a set of unique names. The name resolution behavior is specific to a naming scope. Some naming scopes resolve names by simple matching. Other scopes resolve names by mapping the name used to do the lookup into a new name. Once a name is mapped, lookup proceeds recursively beginning with the current scope.

1.5 Next Steps

After you have programmed all components of your application and created their configuration XML files: ■ Assemble all the components into a deployable OSGi bundle. This step also includes creating the MANIFEST.MF file that describes the bundle. See Section 24.2, Assembling an Oracle CEP Application. ■ Start Oracle CEP. See: – Section 5.3.1, How to Start a Local Oracle CEP Server – Section 5.3.2, How to Stop a Local Oracle CEP Server Note: You must disable security when starting the Oracle CEP server in order to use JNDI. Oracle does not recommend the use of JNDI for this reason. For more information, see Configuring Security for Oracle CEP in the Oracle Complex Event Processing Administrators Guide. Table 1–1 Resource Name Resolution Naming Scope Contents Resolution Behavior Component The property names of the component’s custom configuration Mapping Application The names of the configuration elements in the application configuration files Matching Server The names of the configuration elements in the server configuration file Matching JNDI The names registered in the servers JNDI registry Matching