How to Implement a Custom Adapter Using Ant

Configuring Custom Adapters 14-7 } 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; break; } } } while if m_repeat 0 m_repeat--; } while s_logger.infoFileAdaptor + hashCode + stopped. + m_filePath; } public void setEventSenderStreamSender sender { m_eventSender = sender; } ... } Follow these guidelines when programming the adapter Java class; code snippets of the guidelines are shown in bold in the preceding example: ■ Import the interfaces and classes of the Oracle CEP API: import com.bea.wlevs.ede.api.StreamSender; import com.bea.wlevs.ede.api.StreamSource; import com.bea.wlevs.ede.api.RunnableBean; Because the adapter is an event source it must implement the StreamSource interface. If you want the adapter to run in a thread, also implement 14-8 Oracle Complex Event Processing Developers Guide RunnableBean. The StreamSender interface sends event types to the next component in your application network. For full details of these APIs, see Oracle Fusion Middleware Java API Reference for Oracle Complex Event Processing. ■ The adapter class must implement the StreamSource and RunnableBean interfaces because it is an event source and will run in its own thread: public class BusStopAdapter implements RunnableBean, StreamSource, StreamSink The StreamSource interface provides the StreamSender that you use to send events. ■ Because the adapter implements the RunnableBean interface, your adapter must then implement the run method: public void run {... This is where you should put the code that reads the incoming data, such as from a market feed, and convert it into an Oracle CEP event type, and then send the event to the next component in the network. Refer to the documentation of your data feed provider for details on how to read the incoming data. See Section 24.2.2.2, Accessing Third-Party JAR Files for information about ensuring you can access the vendor APIs if they are packaged in a third-party JAR file. In the Spatial example, the adapter itself generates the incoming data using the readLine protected method. This is just for illustrative purposes and is not a real-world scenario. For more information, see Chapter 2.1.4, Creating Oracle CEP Event Types . ■ Because your adapter implements StreamSource, you must implement the setEventSender method, which passes in the StreamSender that you use to send events: public void setEventSenderStreamSender sender { ... ■ If, as is typically the case, your adapter implements SuspendableBean, you must implement the suspend method that stops the adapter when, for example, the application is undeployed: public synchronized void suspend throws Exception { ...

14.2.2.2 Implementing a Custom Adapter as an Event Sink

The following sample code shows a Spring bean from HelloWorld application that acts as an event sink; see the explanation after the example for the code shown in bold: The following example shows the custom adapter class of the Spatial sample; see the explanation after the example for coding guidelines that correspond to the Java code in bold. package com.oracle.cep.sample.spatial; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.bea.wlevs.ede.api.EventProperty; import com.bea.wlevs.ede.api.EventRejectedException; import com.bea.wlevs.ede.api.EventType; import com.bea.wlevs.ede.api.EventTypeRepository;