com.ibm.di.server
Class ReconnectRuleEngine

java.lang.Object
  extended by com.ibm.di.server.ReconnectRuleEngine

public class ReconnectRuleEngine
extends Object

This class decides what to do when a connector raises an error. Possible actions are to attempt a reconnect or leave the error unhandled and let further mechanisms process it.

The class makes decisions based on configured rules. Each rule describes what should be done when an error occurs. Each rule applies to certain connectors and certain errors. In a rule the connectors are described by their base Java class and their name in the current configuration. (there are match-all options for both the class and the name of the connector). A rule describes applicable errors by their base Java class and a regular expression that matches their messages (the regular expression is optional).

The reconnect engine holds two collections of rules: in-built rules and user-defined rules.

The in-built rules are defined in an '.inf' file in the jar file of the corresponding connector. They are specific to that connector class. In order to preserver the reconnect behaviour, which existed before the introduction of ReconnectRuleEngine, when the engine is created, it implicitly adds to the in-built rules rules, which prescribe to attempt reconnect on all IOException-s and all CommunicationException-s.

The user defined rules reside in an external text file.


Field Summary
static int ERROR
          the situation is a fatal error which no reconnect could fix
static String ERROR_STRING
           
static int INVALID_RECONNECT_ACTION
           
static int RECONNECT
          reconnect should be attempted to fix the error situation
static char RECONNECT_RULE_PARTS_DELIMETER
          the delimeter of the parts of a rule in the config file
static String RECONNECT_STRING
           
 
Constructor Summary
ReconnectRuleEngine(Log log)
          Constructor, which loads the in-built rules and the user-defined rules.
 
Method Summary
 int getReconnectChoice(Class connectorClass, String connectorName, Throwable error)
           This method prescribes a response action for a given error situation.
 void loadRules(String userDefinedRulesFilePath, MetamergeConfig sysConfig)
          Loads the in-built and the user-defined rules.
static String rulesToTextInUserDefinedRuleFormat(String connectorClassName, Object rulesConfig)
          Parses the in-built reconnect rules for a given connector and transforms them to a text in the format for user-defined rules (each rule resides on a single line).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INVALID_RECONNECT_ACTION

public static final int INVALID_RECONNECT_ACTION
See Also:
Constant Field Values

ERROR

public static final int ERROR
the situation is a fatal error which no reconnect could fix

See Also:
Constant Field Values

RECONNECT

public static final int RECONNECT
reconnect should be attempted to fix the error situation

See Also:
Constant Field Values

RECONNECT_RULE_PARTS_DELIMETER

public static final char RECONNECT_RULE_PARTS_DELIMETER
the delimeter of the parts of a rule in the config file

See Also:
Constant Field Values

ERROR_STRING

public static final String ERROR_STRING
See Also:
Constant Field Values

RECONNECT_STRING

public static final String RECONNECT_STRING
See Also:
Constant Field Values
Constructor Detail

ReconnectRuleEngine

public ReconnectRuleEngine(Log log)
Constructor, which loads the in-built rules and the user-defined rules.

Parameters:
log - a log object to be used during the lifetime of the engine
Method Detail

loadRules

public void loadRules(String userDefinedRulesFilePath,
                      MetamergeConfig sysConfig)
               throws Exception
Loads the in-built and the user-defined rules.

Parameters:
userDefinedRulesFilePath - the file with user-defined rules
sysConfig - system configuration object, which has the in-built rules of all connectors
Throws:
Exception - problem while parsing the confgured rules ClassNotFoundException problem while loading an exception/connector class, specified in a rule

getReconnectChoice

public int getReconnectChoice(Class connectorClass,
                              String connectorName,
                              Throwable error)

This method prescribes a response action for a given error situation.

First searches the user-defined rules and if no matching rule is found, the method searches the in-built rules. If a rule cannot be found in either collection, the default action (ERROR) is prescribed.

When a collection (in-built or user-defined) is searched for a matching rule, first is sought a match for the error itself. If no match is found for the error and the error has a specified cause (getCause() returns non-null) then a match for the cause is searched. Only when both searched fail, another collection of rules is considered.

Parameters:
connectorClass - the Java class of the connector, which raised the error
connectorName - the name of the connector as it is specified in the configuration file of the solution
error - the error object
Returns:
the prescribed action - it is one of the following: ERROR or RECONNECT

rulesToTextInUserDefinedRuleFormat

public static String rulesToTextInUserDefinedRuleFormat(String connectorClassName,
                                                        Object rulesConfig)
                                                 throws Exception
Parses the in-built reconnect rules for a given connector and transforms them to a text in the format for user-defined rules (each rule resides on a single line).

Parameters:
connectorClassName - the fully qualified name of the Java class of the connector
rulesConfig - the configuration structure which holds the in-built reconnect rules of the connector (it is supposed to be a list of maps)
Returns:
all rules as text in user-defined rules format
Throws:
problem - with the reconnect rules
Exception