Writing a Script to Determine Receiver Use

If you are managing replications with IBM Db2 for i (AS400/iSeries) as a source database, you may want to identify which receivers are in use at any time so that unused receivers can be deleted. Syniti Data Replication provides a global script function called GetReceiversInUse so that you can identify all the receivers in use for replications using a specific connection to Db2. There are two ways you might use this function.

 1. Receiver Names are Auto-Generated with Sequential Names

The first (and simplest) approach can be applied when receiver names are sequentially autogenerated in the format <rec_prefix>nnn, where nnn is a sequential number. This occurs when the JRNRCV(*GEN) parameter is used in the change journal. If you run the function below, you obtain a list of receivers in use by Syniti DR under that connection.

GetReceiversInUse(ConnectionName, True, True)

Parameters:
- ConnectionName = Name of the IBM Db2 for i connection for which to retrieve the receivers in use
- IsSource = True if ConnectionName refers to a source connection, false otherwise
- OnlyActiveReplications = If true, retrieve only receivers used by active (Enabled) replications, and skip the disabled ones

The list of receivers returned is sorted by (in order): Journal Library, Journal Name, Receiver Library and Receiver Name. For instance, you could obtain these receivers as output:

          JRNLIB1.JOURNAL1     RECLIB1.RECV0003
         JRNLIB1.JOURNAL1     RECLIB1.RECV0004
         JRNLIB1.JOURNAL1     RECLIB1.RECV0005
         JRNLIB1.JOURNAL1     RECLIB1.RECV0006
         JRNLIB1.JOURNAL2     RECLIB2.RECV0015
         JRNLIB1.JOURNAL2     RECLIB2.RECV0016

Warning: The results from this function show only receivers in use by Syniti DR. Other receivers may be used by other applications. Do not remove receivers unless you have verified that they are not needed.

This result shows that, under JOURNAL1, you can remove RECLIB1.RECV001 and RECLIB1.RECV002 because they are not in use by Syniti DR; under JOURNAL2, you can remove RECLIB2.RECV0001 through RECLIB2.RECV0014 because they are not in use by Syniti DR.  

With this information, you could write a script function using the event LogReader_onReceiverChanged to detect the current list of receivers not in use and the run the command to remove them physically from the i(iSeries/AS400) system.

2. Receiver Names are NOT Sequentially Named

If sequential naming is not guaranteed, there is no way to detect if a receiver, based on its name, is in the receiver chain of one specific receiver. In this case, a script would need to store the receiver chain for each journal in a shared list in memory, but preferably in a file. For instance, the LogReader_onReceiverChanged event might return the previous and the new receiver:

JRNLIB1.JOURNAL1     RECLIB1.RECV_A       old receiver
JRNLIB1.JOURNAL1     RECLIB1.RECV_B        new receiver

Every time the receiver changes, its name needs to be stored in a list. At some point the list might look like this:

JRNLIB1.JOURNAL1     RECLIB1.RECV_A  
JRNLIB1.JOURNAL1     RECLIB1.RECV_B      
JRNLIB1.JOURNAL1     RECLIB1.RECV_C
JRNLIB1.JOURNAL1     RECLIB1.RECV_D  
JRNLIB1.JOURNAL1     RECLIB1.RECV_E
JRNLIB1.JOURNAL1     RECLIB1.RECV_F        

Notice that letters A through F have been used to simplify the sample, but the receivers could have any names. If at this point you run GetReceiversInUse and you find out that the first receiver in use is RECLIB1.RECV_C, you know that receivers RECLIB1.RECV_A and RECLIB1.RECV_B can be removed because they appear earlier in the list.