001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.namequeues;
019
020import org.apache.yetus.audience.InterfaceAudience;
021
022/**
023 * Base payload to be prepared by client to send various namedQueue events for in-memory ring buffer
024 * storage in either HMaster or RegionServer. e.g slowLog responses
025 */
026@InterfaceAudience.Private
027public class NamedQueuePayload {
028
029  public enum NamedQueueEvent {
030    SLOW_LOG(0),
031    BALANCE_DECISION(1),
032    BALANCE_REJECTION(2),
033    WAL_EVENT_TRACKER(3);
034
035    private final int value;
036
037    NamedQueueEvent(int i) {
038      this.value = i;
039    }
040
041    public static NamedQueueEvent getEventByOrdinal(int value) {
042      switch (value) {
043        case 0: {
044          return SLOW_LOG;
045        }
046        case 1: {
047          return BALANCE_DECISION;
048        }
049        case 2: {
050          return BALANCE_REJECTION;
051        }
052        case 3: {
053          return WAL_EVENT_TRACKER;
054        }
055        default: {
056          throw new IllegalArgumentException(
057            "NamedQueue event with ordinal " + value + " not defined");
058        }
059      }
060    }
061
062    public int getValue() {
063      return value;
064    }
065  }
066
067  private final NamedQueueEvent namedQueueEvent;
068
069  public NamedQueuePayload(int eventOrdinal) {
070    this.namedQueueEvent = NamedQueueEvent.getEventByOrdinal(eventOrdinal);
071  }
072
073  public NamedQueueEvent getNamedQueueEvent() {
074    return namedQueueEvent;
075  }
076
077}