Ejemplo n.º 1
0
 /**
  * Creates a monitor instance using the config object. The <code>monitorConfig</code> must be
  * initialized with the following configuration properties:
  *
  * <ul>
  *   <li>The <code>GroupName</code> of the replication group being monitored.
  *   <li>The (group wide) unique <code>NodeName</code> associated with this monitor node.
  *   <li>The <code>NodeType</code> must be set to <code>NodeType.Monitor</code>
  *   <li>The <code>NodeHost</code> identifying the hostname and port on which the monitor can be
  *       contacted.
  *   <li>The <code>HelperHosts</code> identifying the list of helpers the monitor can contact to
  *       register itself so it can receive notifications from the group when there is a change in
  *       masters.
  * </ul>
  *
  * @param monitorConfig contains the monitor configuration initialized as described above.
  * @throws IllegalArgumentException if an invalid parameter is specified.
  */
 public Monitor(ReplicationConfig monitorConfig) {
   if (!monitorConfig.getNodeType().equals(NodeType.MONITOR)) {
     throw new IllegalArgumentException(
         "The configured node type was: "
             + monitorConfig.getNodeType()
             + " instead of: "
             + NodeType.MONITOR);
   }
   String groupName = monitorConfig.getGroupName();
   if (groupName == null) {
     throw new IllegalArgumentException("Missing group name");
   }
   nameIdPair = new NameIdPair(monitorConfig.getNodeName());
   String nodeHost = monitorConfig.getNodeHostPort();
   if (nodeHost == null) {
     throw new IllegalArgumentException("Missing nodeHost");
   }
   this.monitorConfig = monitorConfig.clone();
   repGroupAdmin = new ReplicationGroupAdmin(groupName, monitorConfig.getHelperSockets());
   logger = LoggerUtils.getLoggerFormatterNeeded(getClass());
   formatter = new ReplicationFormatter(nameIdPair);
 }