Microsoft SQL Server 2008 R2 810-08234 User Manual

Product codes
810-08234
Page of 236
 
Application Development 
CHAPTER 8
 
153
The final step is to create a .NET assembly for the adapter. At minimum, the adapter 
includes a constructor, a Start() method, a Resume() method, and either a ProduceEvents() or 
ConsumeEvents() method, depending on whether you are developing an input adapter or an 
output adapter . You can see the general structure of the adapter class in the following code 
example:
public class TextFilePointInput : PointInputAdapter

   public TextFilePointInput(TextFileInputConfig configInfo,  
      CepEventType cepEventType) 
      { ... } 
 
   public override void Start() 
      { ... } 
 
   public override void Resume() 
      { ... } 
 
   private void ProduceEvents() 
      { ... } 
 
}
Using the constructor method for an untyped adapter, such as TextFilePointInput as in the 
example, you can pass the configuration parameters from the adapter factory and the event 
type object that passes from the query binding . The constructor also includes code to con-
nect to the event source and to map fields to the event payload. After the CEP server instan-
tiates the adapter, it invokes the Start() method, which generally calls the ProduceEvents() 
or ConsumeEvents()method to begin receiving streams . The Resume() method invokes the 
ProduceEvents() or ConsumeEvents() method again if the CEP server paused the streaming 
and confirms that the adapter is ready. 
The core transformation and queuing of events occurs in the ProduceEvents() method . This 
method iterates through either reading the events it is receiving from the source or writing 
events it is sending to the event consumer . It makes calls as necessary to push or pull events 
into or from the event stream using calls to Enqueue() or Dequeue() . Calls to Enqueue() and 
Dequeue() return the state of the adapter . If Enqueue() returns FULL or Dequeue() returns 
EMPTY, the adapter transitions to a suspended state and can no longer produce or consume 
events . When the adapter is ready to resume, it calls Ready(), which then causes the server to 
call Resume(), and the cycle of enqueuing and dequeuing begins again from the point in time 
at which the adapter was suspended .