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.impl;
  
Defines the protocol used in support of group membership. API to Master ENSURE_NODE -> ENSURE_OK | FAIL REMOVE_MEMBER -> OK | FAIL TRANSFER_MASTER -> TRANSFER_OK | FAIL Monitor to Master GROUP_REQ -> GROUP | FAIL
 
 public class RepGroupProtocol extends TextProtocol {
 
     public static final String VERSION = "3";
 
     public static enum FailReason {
         DEFAULT, MEMBER_NOT_FOUND, IS_MASTER, IS_REPLICA, TRANSFER_FAIL;
     }
 
     /* The messages defined by this class. */
 
     public final MessageOp ENSURE_NODE =
         new MessageOp("ENREQ"EnsureNode.class);
     public final MessageOp ENSURE_OK =
         new MessageOp("ENRESP"EnsureOK.class);
     public final MessageOp REMOVE_MEMBER =
         new MessageOp("RMREQ"RemoveMember.class);
     public final MessageOp GROUP_REQ =
         new MessageOp("GREQ"GroupRequest.class);
     public final MessageOp GROUP_RESP =
         new MessageOp("GRESP"GroupResponse.class);
     public final MessageOp RGFAIL_RESP =
         new MessageOp("GRFAIL"Fail.class);
     public final MessageOp UPDATE_ADDRESS =
         new MessageOp("UPDADDR"UpdateAddress.class);
     public final MessageOp TRANSFER_MASTER =
         new MessageOp("TMASTER"TransferMaster.class);
     public final MessageOp TRANSFER_OK =
         new MessageOp("TMRESP"TransferOK.class);
 
     public RepGroupProtocol(String groupName,
                             NameIdPair nameIdPair,
                             RepImpl repImpl) {
 
         super(groupNamenameIdPairrepImpl);
 
         this.initializeMessageOps(new MessageOp[] {
                 ,
                 ,
                 ,
                 ,
                 ,
                 ,
                 ,
                 ,
                 
         });
 
         setTimeouts(repImpl,
                     .,
                     .);
     }
 
     private abstract class CommonRequest extends RequestMessage {
         private final String nodeName;
 
         public CommonRequest(String nodeName) {
             this. = nodeName;
         }
 
         public CommonRequest(String requestLineString[] tokens
             throws InvalidMessageException {
 
             super(requestLinetokens);
              = nextPayloadToken();
         }
 
         @Override
         protected String getMessagePrefix() {
             return ;
         }
 
         public String wireFormat() {
             return wireFormatPrefix() +  + ;
         }
 
         public String getNodeName() {
             return ;
        }
    }
    public class RemoveMember extends CommonRequest {
        public RemoveMember(String nodeName) {
            super(nodeName);
        }
        public RemoveMember(String requestLineString[] tokens)
            throws InvalidMessageException {
            super(requestLinetokens);
        }
        @Override
        public MessageOp getOp() {
            return ;
        }
    }
    public class TransferMaster extends RequestMessage {
        private final String nodeNameList;
        private final long timeout;
        private final boolean force;
        public TransferMaster(String nodeNameList,
                              long timeout,
                              boolean force) {
            super();
            this. = nodeNameList;
            this. = timeout;
            this. = force;
        }
        public TransferMaster(String requestLineString[] tokens)
            throws InvalidMessageException {
            super(requestLinetokens);
            this. = nextPayloadToken();
            this. = Long.parseLong(nextPayloadToken());
            this. = Boolean.parseBoolean(nextPayloadToken());
        }
        @Override
        public String wireFormat() {
            return wireFormatPrefix() +  +  +
                 +  +  + ;
        }
        @Override
        public MessageOp getOp() {
            return ;
        }
        public String getNodeNameList() {
            return ;
        }
        public long getTimeout() {
            return ;
        }
        public boolean getForceFlag() {
            return ;
        }
    }
    public class GroupRequest extends RequestMessage {
        public GroupRequest() {
        }
        public GroupRequest(String lineString[] tokens)
            throws InvalidMessageException {
            super(linetokens);
        }
        @Override
        public MessageOp getOp() {
           return ;
        }
        @Override
        protected String getMessagePrefix() {
            return ;
        }
        public String wireFormat() {
           return wireFormatPrefix();
        }
    }
    public class UpdateAddress extends CommonRequest {
        private final String newHostName;
        private final int newPort;
        public UpdateAddress(String nodeName
                             String newHostName
                             int newPort) {
            super(nodeName);
            this. = newHostName;
            this. = newPort;
        }
        public UpdateAddress(String requestLineString[] tokens
            throws InvalidMessageException {
            super(requestLinetokens);
            this. = nextPayloadToken();
            this. = new Integer(nextPayloadToken());
        }
        @Override
        public MessageOp getOp() {
            return ;
        }
        public String getNewHostName() {
            return ;
        }
        public int getNewPort() {
            return ;
        }
        @Override
        public String wireFormat() {
            return super.wireFormat() +  +  +  + 
                   ;
        }
    }
    public class EnsureNode extends RequestMessage {
        final RepNodeImpl node;
        public EnsureNode(RepNodeImpl node) {
            assert(node.getType() == .);
            this. = node;
        }
        public EnsureNode(String lineString[] tokens)
            throws InvalidMessageException {
            super(linetokens);
             = RepGroupImpl.hexDeserializeNode(nextPayloadToken());
        }
        public RepNodeImpl getNode() {
            return ;
        }
        @Override
        public MessageOp getOp() {
            return ;
        }
        @Override
        protected String getMessagePrefix() {
            return ;
        }
        public String wireFormat() {
            return wireFormatPrefix() +  +
                   RepGroupImpl.serializeHex();
        }
    }
    public class EnsureOK extends OK {
        private final NameIdPair nameIdPair;
        public EnsureOK(NameIdPair nameIdPair) {
            super();
            this. = nameIdPair;
        }
        public EnsureOK(String lineString[] tokens)
            throws InvalidMessageException {
            super(linetokens);
             = new NameIdPair(nextPayloadToken(),
                                        Integer.parseInt(nextPayloadToken()));
        }
        public NameIdPair getNameIdPair() {
            return ;
        }
        @Override
        public MessageOp getOp() {
            return ;
        }
        @Override
        public String wireFormat() {
            return wireFormatPrefix() +  +
                   .getName() +  +
                   Integer.toString(.getId());
        }
    }
    public class TransferOK extends OK {
        private final String winner;
        public TransferOK(String winner) {
            super();
            this. = winner;
        }
        public TransferOK(String lineString[] tokens)
            throws InvalidMessageException {
            super(linetokens);
             = nextPayloadToken();
        }
        public String getWinner() {
            return ;
        }
        @Override
        public MessageOp getOp() {
            return ;
        }
        @Override
        public String wireFormat() {
            return wireFormatPrefix() +  + ;
        }
    }
    public class GroupResponse extends ResponseMessage {
        final RepGroupImpl group;
        public GroupResponse(RepGroupImpl group) {
            this. = group;
        }
        public GroupResponse(String lineString[] tokens)
            throws InvalidMessageException {
            super(linetokens);
             = RepGroupImpl.deserializeHex
                (tokensgetCurrentTokenPosition()); 
        }
        public RepGroupImpl getGroup() {
            return ;
        }
        @Override
        public MessageOp getOp() {
            return ;
        }
        @Override
        protected String getMessagePrefix() {
            return ;
        }
        public String wireFormat() {
            return wireFormatPrefix() +  + .serializeHex();
        }
    }

    
Extends the class Fail, adding a reason code to distinguish amongst different types of failures.
    public class Fail extends TextProtocol.Fail {
        final FailReason reason;
        public Fail(FailReason reasonString message) {
            super(message);
            this. = reason;
        }
        public Fail(String lineString[] tokens)
            throws InvalidMessageException {
            super(linetokens);
             = FailReason.valueOf(nextPayloadToken());
        }
        @Override
        public MessageOp getOp() {
            return 
        }
        @Override
        public String wireFormat() {
            return super.wireFormat() +  + .toString();
        }
        public FailReason getReason() {
            return ;
        }
    }
New to GrepCode? Check out our FAQ X