The following list suggests some common customizations in TCP adapter subclasses, in addition to implementing the methods that the adapter needs:
-
You can define a different value for InitialExpressions for the Terminators property.
To specify an ASCII character, use the ObjectScript function $CHAR (abbreviated to $C). The following example from EnsLib.TCP.TextLineInboundAdapterOpens in a new tab sets Terminators to the newline character (ASCII 10):
Property Terminators As %String [ InitialExpression = {$C(10)} ];
For more information about functions like $CHAR, see “ObjectScript Functions” in the ObjectScript Reference.
You can set Terminators to a single character or to a multi-character string. If you supply a string for the Terminators value, InterSystems IRIS uses the string as follows:
-
You can add properties and methods.
-
You can add and remove settings. See “Adding and Removing Settings” in the article “Programming in InterSystems IRIS” in Developing Productions.
-
If you need to require login credentials for the connection, simply add the property name Credentials to the SETTINGS list. The Credentials property is already defined as a %StringOpens in a new tab in the base class Ens.AdapterOpens in a new tab.
-
(For inbound adapters) You can also enforce a pool size of 1 by setting the parameter SINGLEPOOLJOB = 1:
/// Force a single listener job regardless of PoolSize setting
Parameter SINGLEPOOLJOB = 1;
Any subclass of this adapter class or a business service class that uses such an adapter class can use this parameter in its class code to better control the pool size.
-
You can implement the OnInit() callback method to perform any special setup actions or initialize any structures.
For inbound adapters, one of these actions might be to examine settings and initiate a connection between the adapter and the TCP client it will listen to, or to create any object properties that the adapter will use.
For outbound adapters, one of these actions might be to examine settings and open a socket to a port on the TCP listener.
-
For inbound adapters, you can implement the OnConnected() callback method.
Whenever a connection exists to the configured TCP client, the adapter calls OnConnected() to read a stream from the TCP data source. This read operation is controlled by adapter settings.
OnConnected() uses helper methods to parse the data.
Upon successfully reading data, OnConnected() calls the production framework’s ProcessInput() method to pass the received data stream to the associated business service. If this call returns an outbound stream, OnConnected() writes that data as a reply to the TCP client.
If no data is available to read from the TCP connection during the CallInterval time, OnConnected() returns without doing anything.