Custom Adapters as Event Sources Custom Adapters as Event Sinks

14-6 Oracle Complex Event Processing Developers Guide 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; } } 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; 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