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.
   *
   */
  package com.sleepycat.je.rep.monitor;
  

Hidden:
For internal use only. Defines the protocol used by the Monitor to keep informed about group changes, and a node joins/leaves the group. The Master uses the protocol to inform all Monitors about group change and node join/leave change. GCHG -> no response expected from the monitor. JoinGroup -> no response expected from the monitor. LeaveGroup -> no response expected from the monitor.
 
 public class Protocol extends TextProtocol {
 
     static public final String VERSION = "1.0";
 
     /* The messages defined by this class. */
     public final MessageOp GROUP_CHANGE_REQ =
         new MessageOp("GCHG"GroupChange.class);
 
     public final MessageOp JOIN_GROUP_REQ =
         new MessageOp("JG"JoinGroup.class);
 
     public final MessageOp LEAVE_GROUP_REQ =
         new MessageOp("LG"LeaveGroup.class);
 
     public Protocol(String groupNameNameIdPair nameIdPairRepImpl repImpl) {
         super(groupNamenameIdPairrepImpl);
 
         initializeMessageOps(new MessageOp[] { 
             
             
              
         });
 
         setTimeouts(repImpl,
                     .,
                     .);
     }
 
     private abstract class ChangeEvent extends RequestMessage {
         /* Name of node which this change event happens on. */
         private final String nodeName;
 
         public ChangeEvent(String nodeName) {
             this. = nodeName;
         }
 
         public ChangeEvent(String lineString[] tokens
             throws InvalidMessageException {
 
             super(linetokens);
              = nextPayloadToken();
         }
 
         public String getNodeName() {
             return ;
         }
 
         @Override
         protected String getMessagePrefix() {
             return ;
         }
 
         public String wireFormat() {
             return wireFormatPrefix() +  +  + ;
         }
     }
 
     public class GroupChange extends ChangeEvent {
         private final RepGroupImpl group;
         /* Represents it's a ADD or REMOVE change event. */
         private final GroupChangeType opType;
 
         public GroupChange(RepGroupImpl group
                            String nodeName
                            GroupChangeType opType) {
             super(nodeName);
             this. = group;
             this. = opType;
         }
 
         public GroupChange(String lineString[] tokens)
            throws InvalidMessageException {
            super(linetokens);
             = GroupChangeType.valueOf(nextPayloadToken());
             = RepGroupImpl.deserializeHex
                (tokensgetCurrentTokenPosition());
        }
        public RepGroupImpl getGroup() {
            return ;
        }
        public GroupChangeType getOpType() {
            return ;
        }
        @Override
        public MessageOp getOp() {
            return ;
        }
        public String wireFormat() {
            return super.wireFormat() + 
                   .toString() +  +
                   .serializeHex();
        }
    }
    private abstract class MemberEvent extends ChangeEvent {
        private final String masterName;
        private final long joinTime;
        public MemberEvent(String nodeNameString masterNamelong joinTime) {
            super(nodeName);
            this. = masterName;
            this. = joinTime;
        }
        public MemberEvent(String lineString[] tokens)
            throws InvalidMessageException {
            super(linetokens);
             = nextPayloadToken();
             = Long.parseLong(nextPayloadToken());
        }
        public long getJoinTime() {
            return ;
        }
        public String getMasterName() {
            return ;
        }
        public String wireFormat() {
            return super.wireFormat() + 
                    +  +
                   Long.toString(); 
        }
    }
    /* Represents the event that a node joins the group. */
    public class JoinGroup extends MemberEvent {
        public JoinGroup(String nodeNameString masterNamelong joinTime) {
            super(nodeNamemasterNamejoinTime);
        }
        public JoinGroup(String lineString[] tokens
            throws InvalidMessageException {
            super(linetokens);
        }
        @Override
        public MessageOp getOp() {
            return ;
        }
    }
    /* Represents the event that a node leaves the group. */
    public class LeaveGroup extends MemberEvent {
        private final LeaveReason leaveReason;
        private final long leaveTime;
        public LeaveGroup(String nodeName,
                          String masterName
                          LeaveReason leaveReason
                          long joinTime
                          long leaveTime) {
            super(nodeNamemasterNamejoinTime);
            this. = leaveReason;
            this. = leaveTime;
        }
        public LeaveGroup(String lineString[] tokens)
            throws InvalidMessageException {
            super(linetokens);
             = LeaveReason.valueOf(nextPayloadToken());
             = Long.parseLong(nextPayloadToken());
        }
        public LeaveReason getLeaveReason() {
            return ;
        }
        public long getLeaveTime() {
            return ;
        }
        @Override
        public MessageOp getOp() {
            return ;
        }
        public String wireFormat() {
            return super.wireFormat() +  + 
                   .toString() +  + 
                   Long.toString();
        }
    }
New to GrepCode? Check out our FAQ X