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 node state querying. Because this protocol has to transfer byte array between two nodes, so instead of using the former NodeStateProtocol, we introduce this new protocol which inherits from BinaryProtocol. Note: once we support active version update, we can use one protocol only. The message request sequence: NODE_STATE_REQ -> NODE_STATE_RESP
 
 public class BinaryNodeStateProtocol extends BinaryProtocol {
 
     public static final int VERSION = 1;
 
     /* The messages defined by this class. */
     public final static MessageOp BIN_NODE_STATE_REQ =
         new MessageOp((short) 1, BinaryNodeStateRequest.class);
     public final static MessageOp BIN_NODE_STATE_RESP =
         new MessageOp((short) 2, BinaryNodeStateResponse.class);
 
     public BinaryNodeStateProtocol(NameIdPair nameIdPair,
                                    RepImpl repImpl) {
 
         super(nameIdPairrepImpl);
 
         this.initializeMessageOps(new MessageOp[] {
                 
                  
         });
     }
 
     /* Message request the state of the specified node. */
     public class BinaryNodeStateRequest extends SimpleMessage {
         /* The name of the node whose status is requested. */
         private final String nodeName;
         /* The name of the group the node belongs to. */
         private final String groupName;
 
         public BinaryNodeStateRequest(String nodeNameString groupName) {
             super();
             this. = nodeName;
             this. = groupName;
         }
 
         public BinaryNodeStateRequest(ByteBuffer buffer) {
             super();
              = getString(buffer);
              = getString(buffer);
         }
 
         public String getNodeName() {
             return ;
         }
 
         public String getGroupName() {
             return ;
         }
 
         @Override
         public MessageOp getOp() {
             return ;
         }
 
         @Override
         public ByteBuffer wireFormat() {
            return wireFormat();
         }
     }
 
     /* Message return state of specified node. */
     public class BinaryNodeStateResponse extends SimpleMessage {
         /* The name of the node which requests the status. */
         private final String nodeName;
         /* The name of the group which this node joins. */
         private final String groupName;
         /* The name of the current master in the group. */
         private final String masterName;
         /* The JEVersion that this node runs. */
         private final JEVersion jeVersion;
         /* Time when this node joins the group. */
        private final long joinTime;
        /* The current state of this node. */
        private final State nodeState;
        /* The last commit VLSN on this node. */
        private final long commitVLSN;
        /* The last master commit VLSN known by this node. */
        private final long masterCommitVLSN;
        /* The number of running feeders on this node. */
        private final int activeFeeders;
        /* The log version of this node. */
        private final int logVersion;
        /* The state of the JE application, specified by users themselves. */
        private final byte[] appState;
        /* 
         * The system load of the node, it is serialized and deserialized in 
         * String format. 
         */
        private final double systemLoad;
        public BinaryNodeStateResponse(String nodeName
                                       String groupName,
                                       String masterName,
                                       JEVersion jeVersion,
                                       long joinTime,
                                       State nodeState,
                                       long commitVLSN,
                                       long masterCommitVLSN,
                                       int activeFeeders,
                                       int logVersion,
                                       byte[] appState,
                                       double systemLoad) {
            super();
            this. = nodeName;
            this. = groupName;
            this. = masterName;
            this. = jeVersion;
            this. = joinTime;
            this. = nodeState;
            this. = commitVLSN;
            this. = masterCommitVLSN;
            this. = activeFeeders;
            this. = logVersion;
            this. = appState;
            this. = systemLoad;
        }
        public BinaryNodeStateResponse(ByteBuffer buffer) {
            super();
             = getString(buffer);
             = getString(buffer);
             = getString(buffer);
             = new JEVersion(getString(buffer));
             = LogUtils.readLong(buffer);
             = getEnum(State.classbuffer);
             = LogUtils.readLong(buffer);
             = LogUtils.readLong(buffer);
             = LogUtils.readInt(buffer);
             = LogUtils.readInt(buffer);
             = getByteArray(buffer);
             = getDouble(buffer);
        }
        public String getNodeName() {
            return ;
        }
        public String getGroupName() {
            return ;
        }
        public String getMasterName() {
            return ;
        }
        public JEVersion getJEVersion() {
            return ;
        }
        public long getJoinTime() {
            return ;
        }
        public State getNodeState() {
            return ;
        }
        public long getCommitVLSN() { 
            return ;
        }
        public long getKnownMasterCommitVLSN() {
            return ;
        }
        public int getActiveFeeders() {
            return ;
        }
        public int getLogVersion() {
            return ;
        }
        public byte[] getAppState() {
            if (. == 0) {
                return null;
            }
            return ;
        }
        public double getSystemLoad() {
            return ;
        }
        @Override
        public MessageOp getOp() {
            return ;
        }
        @Override
        public ByteBuffer wireFormat() {
            /* 
             * If the appState is null, make a new zero byte array, since 
             * writing null byte array would cause a NPE, and a meaningful 
             * application state shouldn't be a zero length byte array. 
             */
            byte[] realAppState = ( == null ? new byte[0] : );
            return wireFormat(
                              ,
                              
                              .toString(),
                              
                              
                              
                              
                              
                              ,
                              realAppState,
                              );
        }
        /* Convert the response to the NodeState. */
        public NodeState convertToNodeState() {
            return new NodeState(,
                                 ,
                                 ,
                                 ,
                                 ,
                                 ,
                                 ,
                                 ,
                                 ,
                                 ,
                                 getAppState(),
                                 );
        }
    }
New to GrepCode? Check out our FAQ X