Monitoring server availability

The connection object CclConn has three methods which can be used to determine the availability of the server connection that it represents:
status
requests the status (that is, the availability) of the server.
changed
requests notification of any change in this status.
cancel
requests cancellation of a changed request.

The example described below shows how server availability can be monitored in a Client application that is busy doing something else.

Here is a subclass of the flow class designed for use with server status calls. The reply handler implementation prints the server name and its newly-changed status; it ignores the returned communication area. Next, it issues a changed server request so that the next server status change will be received. The reply handler will be called every time the availability of the server changes.
class ChgFlow : public CclFlow {
public:
       ChgFlow( Ccl::Sync stype ) : CclFlow( stype ) {}
  void handleReply( CclBuf* ) {
         CclConn* ccon = connection();
         cout << ccon-> serverName() << " is "
              << ccon-> serverStatusText() << endl;
         ChgFlow* sflow = new ChgFlow( Ccl::async );
         ccon-> changed( *sflow );
         }
  };
The main Client application iterates through all the servers listed in the CICS® Transaction Gateway Initialization file. For each one, an asynchronous status request call is issued. The Client application continues with whatever else it has to do.
int numservs = myeci.serverCount();
CclConn* pcon;
ChgFlow* pflo;
for ( int i = 1; i <= numservs ; i++ ) {
  pcon = new CclConn( myeci.serverName( i ) );
  pflo = new ChgFlow( Ccl::async );
  pcon-> status( *pflo );
  }
  …
The output produced could look something like this:
PROD1    is unavailable
DEVTSERV is unavailable
PROD1    is available
Initially, both servers are unavailable because the ECI Client application is not running. It starts, and after a while makes contact with one of the servers.