10.07.2015 Views

Using TCP Adapters with Ensemble - InterSystems Documentation

Using TCP Adapters with Ensemble - InterSystems Documentation

Using TCP Adapters with Ensemble - InterSystems Documentation

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Using</strong> the <strong>TCP</strong> Counted Inbound Adapter• Choose EnsLib.<strong>TCP</strong>.CountedInboundAdapter from the drop-down list.• Click Finish.The result is a template class like the following:Class Dev.Test.NewService1Extends Ens.BusinessService [ ProcedureBlock ]{Parameter ADAPTER = "EnsLib.<strong>TCP</strong>.CountedInboundAdapter";Method OnProcessInput(pInput As %RegisteredObject,pOutput As %RegisteredObject) As %Status{Quit $$$ERROR($$$NotImplemented)}}2. Implement the OnProcessInput() method in your new business service class. This is the method that uses the inputdata gathered by the EnsLib.<strong>TCP</strong>.CountedInboundAdapter.You can implement the OnProcessInput() method by replacing the following line in the template class <strong>with</strong> your owncode:Quit $$$ERROR($$$NotImplemented)Your OnProcessInput() method must know the types of incoming and outgoing data for communicating <strong>with</strong> theEnsLib.<strong>TCP</strong>.CountedInboundAdapter. However, the New Business Service Wizard specifies both types in theOnProcessInput() method signature as the generic object type %RegisteredObject.<strong>InterSystems</strong> suggests that, as your first action in coding the new business service, you change each OnProcessInput()argument to its specific type passed from the adapter:Method OnProcessInput(pInput As %Library.GlobalCharacterStream,Output pOutput As %Library.AbstractStream) As %StatusWhere:• pInput is of type %Library.GlobalCharacterStream and contains the incoming data stream that the <strong>TCP</strong> client hasdirected to the adapter.• pOutput is of type %Library.AbstractStream and contains any response that the business service might provide tothe <strong>TCP</strong> client.Keep in mind that the method must quit by returning a %Status object. See the code sample in the next section,“Sample Business Service Class Code.”3. Optionally, you may implement the OnConnect() callback method in your business service class.OnConnect() is available for a <strong>TCP</strong> inbound adapter to call back to its associated business service. If present in thebusiness service, this method is called each time the <strong>TCP</strong> inbound adapter establishes a new connection to or from aremote system.If you add an OnConnect() method to your business service class, it must have the following signature:Method OnConnect(pTimeout As %Numeric) As %StatusImplement an OnConnect() method in your business service if you need to take some action each time a new connectionis established, for example to send a logon sequence or a handshake token. The timeout argument is automaticallyprovided by the <strong>TCP</strong> inbound adapter. It takes its value from the ReadTimeout adapter setting. For details aboutReadTimeout, see “Adapter Settings.”Returning an error status from OnConnect() causes the new connection to fail and be disconnected. If an untrappedexception occurs <strong>with</strong>in OnConnect(), the adapter catches it and continues as if OnConnect() were not implemented.8 <strong>Using</strong> <strong>TCP</strong> <strong>Adapters</strong> <strong>with</strong> <strong>Ensemble</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!