Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * See the file LICENSE for redistribution information.
   * Copyright (c) 2002, 2013 Oracle and/or its affiliates.  All rights reserved.
Class used by a node to track changes in Master Status. It's updated by the Listener. It represents the abstract notion that the notion of the current Replica Group is definitive and is always in advance of the notion of a master at each node. A node is typically playing catch up as it tries to bring its view in line with that of the group.
 public class MasterStatus implements Cloneable {
     /* This node's identity */
     private final NameIdPair nameIdPair;
     /* The current master resulting from election notifications */
     private InetSocketAddress groupMaster = null;
     /* The node ID used to identify the master. */
      * The Master as implemented by the Node. It can lag the groupMaster
      * as the node tries to catch up.
     private InetSocketAddress nodeMaster = null;
     private NameIdPair nodeMasterNameId = .;
     public MasterStatus(NameIdPair nameIdPair) {
         this. = nameIdPair;

Returns a read-only snapshot of the object.
     public synchronized Object clone() {
         try {
             return super.clone();
         } catch (CloneNotSupportedException e) {
         return null;

Returns true if it's the master from the Group's perspective
     public synchronized boolean isGroupMaster() {
         boolean isGroupMaster = .getId() == .getId();
         /* Assertion failure indicates inconsistent use of node ID. */
         assert(!isGroupMaster ||
                (.getId() == .getId()));
         return isGroupMaster;

Returns true if it's the master from the node's localized perspective
     public synchronized boolean isNodeMaster() {
         return .getId() == .getId();
     public synchronized void setGroupMaster(InetSocketAddress newGroupMaster,
                                             NameIdPair newGroupMasterNameId) {
          = newGroupMaster;
          = newGroupMasterNameId;

Predicate to determine whether the group and node have a consistent notion of the Master.

false if the node does not know of a Master, or the group Master is different from the node's notion the master.
     public synchronized boolean inSync() {
         return !.hasNullId() &&
                (.getId() == .getId());
     public synchronized void unSync() {
          = null;
          = .;

An assertion form of the above. By combining the check and exception generation in an atomic operation, it provides for an accurate exception message.

    public synchronized void assertSync()
        throws MasterSyncException {
        if (!inSync()) {
            throw new MasterSyncException();

Syncs to the group master
    public synchronized void sync() {
         = ;

Returns the Node's current idea of the Master. It may be "out of sync" with the Group's notion of the Master
    public synchronized InetSocketAddress getNodeMaster() {
        return ;
    public synchronized NameIdPair getNodeMasterNameId() {
        return ;
    public synchronized NameIdPair getGroupMasterNameId() {
        return ;
    public class MasterSyncException extends Exception {
        private final NameIdPair savedGroupMasterId;
        private final NameIdPair savedNodeMasterId;
        MasterSyncException () {
             = MasterStatus.this.getGroupMasterNameId();
             = MasterStatus.this.getNodeMasterNameId();
        public String getMessage() {
            return "Master change. Node master id: " +  +
            " Group master id: " + ;
New to GrepCode? Check out our FAQ X