Implementing a Custom Adapter as an Event Source

Configuring Custom Adapters 14-9 import com.bea.wlevs.ede.api.RunnableBean; import com.bea.wlevs.ede.api.StreamSender; import com.bea.wlevs.ede.api.StreamSink; import com.bea.wlevs.ede.api.StreamSource; import com.bea.wlevs.util.Service; import java.lang.RuntimeException; import oracle.spatial.geometry.JGeometry; import com.oracle.cep.cartridge.spatial.Geometry; public class BusStopAdapter implements RunnableBean, StreamSource, StreamSink { private final static String APP_NAME = spatial_sample; ... private String m_eventTypeName; private EventType m_eventType; private StreamSender m_eventSender; ... public BusStopAdapter { super; } ... Servicefilter = EventTypeRepository.SERVICE_FILTER public void setEventTypeRepositoryEventTypeRepository etr { m_etr = etr; } public void setShowboolean b { m_show = b; } public void run { m_stopped = false; Need to store running thread so that it can be interrrupted in case of suspend. m_runningThread = Thread.currentThread; if m_etr == null { throw new RuntimeExceptionEventTypeRepoitory is not set; } m_eventType = m_etr.getEventTypem_eventTypeName; if m_eventType == null { throw new RuntimeExceptionEventType + m_eventType + is not found.; } s_logger.infofileSource + m_filePath; if m_initialDelay 0 { try { s_logger.infoSleeping for : + m_initialDelay; Thread.sleepm_initialDelay; } catch InterruptedException e { e.printStackTrace; } 14-10 Oracle Complex Event Processing Developers Guide } synchronized this { while m_start { try { this.wait; } catch InterruptedException e { } } } BufferedReader reader = null; System.out.printlnSending + m_eventType + from + m_filePath; while m_repeat = 0 m_stopped { try { s_logger.infoStarting fileSource + m_filePath; m_lineno = 0; reader = new BufferedReadernew FileReaderm_filePath; } catch Exception e { s_logger.warne.toString; m_stopped = true; break; } while isStopped { try { Object ev = null; ev = readLinereader; if ev == null { reader.close; break; } m_eventSender.sendInsertEventev; if m_show { System.out.printlnev.toString; } } catch Exception e { s_logger.fatalFailed to get tuple from + m_filePath + : + m_lineno + \n + e.toString + \n; m_stopped = true; break; } if m_sleep 0 { try { synchronized this { We need to save thread so that it can be interrupted in case of suspend. waitm_sleep; } } catch InterruptedException e { s_logger.warne; Configuring Custom Adapters 14-11 break; } } } while if m_repeat 0 m_repeat--; } while s_logger.infoFileAdaptor + hashCode + stopped. + m_filePath; } Override public void onInsertEventObject event throws EventRejectedException { if m_start { m_start = true; synchronized this { notify; } } } ... } The programming guidelines shown in the preceding example are as follows: ■ Your custom adapter must implement the com.bea.wlevs.ede.api.StreamSink interface: public class BusStopAdapter implements RunnableBean, StreamSource, StreamSink ■ The StreamSink interface has a single method that you must implement, onInsertEventjava.lang.Object, which is a callback method for receiving events. The parameter of the method is an Object that represents the actual event that the bean received from the component that sent it the event: public void onInsertEventObject event For complete API reference information about the Oracle CEP APIs described in this section, see the Oracle Fusion Middleware Java API Reference for Oracle Complex Event Processing.

14.2.3 Implementing a Custom Adapter Factory

Your adapter factory class must implement the com.bea.wlevs.ede.api.AdapterFactory interface, which has a single method, create, in which you code the creation of your specific adapter class. Event beans implement Factory. The following is a possible adapter factory class for the HelloWorld example: package com.bea.adapter.wlevs.example.helloworld; import com.bea.wlevs.ede.api.Adapter; import com.bea.wlevs.ede.api.AdapterFactory; public class HelloWorldAdapterFactory implements Factory { public HelloWorldAdapterFactory { } public synchronized Adapter create throws IllegalArgumentException { return new HelloWorldAdapter; } } For full details of these APIs, see the Oracle Fusion Middleware Java API Reference for Oracle Complex Event Processing. 14-12 Oracle Complex Event Processing Developers Guide

14.3 Passing Login Credentials from an Adapter to a Data Feed Provider

If your adapter accesses an external data feed, the adapter might need to pass login credentials username and password to the data feed for user authentication. The simplest, and least secure, way to do this is to hard-code the non-encrypted login credentials in your adapter Java code. However, this method does not allow you to encrypt the password or later change the login credentials without recompiling the adapter Java code. The following procedures describe a different method that takes these two issues into account. In the procedure, it is assumed that the username to access the data feed is juliet and the password is superSecret. You must decide whether you want the login credentials to be configured statically in the EPN assembly file, or dynamically by extending the configuration of the adapter. Configuring the credentials statically in the EPN assembly file is easier, but if the credentials later change you must restart the application for the update to the EPN assembly file to take place. Extending the adapter configuration allows you to change the credentials dynamically without restarting the application, but extending the configuration involves additional steps, such as creating an XSD file and compiling it into a JAXB object. This section describes: ■ Section 14.3.1, How to Pass Static Login Credentials to the Data Feed Provider ■ Section 14.3.2, How to Pass Dynamic Login Credentials to the Data Feed Provider ■ Section 14.3.3, How to Access Login Credentials From an Adapter at Runtime For more information, see Chapter 19, Extending Component Configuration .

14.3.1 How to Pass Static Login Credentials to the Data Feed Provider

This procedure describes how to pass login credentials that you configure statically in the EPN assembly file. To pass static credentials to the data feed provider: 1. Open a command window and set your environment as described in Setting Your Development Environment in the Oracle Complex Event Processing Getting Started. 2. Change to the directory that contains the EPN assembly file for your application. 3. Using your favorite XML editor, edit the EPN assembly file by updating the wlevs:adapter element that declares your adapter. In particular, add two instance properties that correspond to the username and password of the login credentials. For now, specify the cleartext password value; you will encrypt it in a later step. Also add a temporary password element whose value is the cleartext password. For example: wlevs:adapter id=myAdapter provider=myProvider wlevs:instance-property name=user value=juliet wlevs:instance-property name=password value=superSecret passwordsuperSecretpassword wlevs:adapter 4. Save the EPN assembly file.