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;
019
020import java.util.Iterator;
021import java.util.List;
022import java.util.Optional;
023import org.apache.yetus.audience.InterfaceAudience;
024
025/**
026 * An extended version of Cell that allows CPs manipulate Tags.
027 */
028// Added by HBASE-19092 to expose Tags to CPs (history server) w/o exposing ExtendedCell.
029// Why is this in hbase-common and not in hbase-server where it is used?
030// RawCell is an odd name for a class that is only for CPs that want to manipulate Tags on
031// server-side only w/o exposing ExtendedCell -- super rare, super exotic.
032@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
033public interface RawCell extends Cell {
034  static final int MAX_TAGS_LENGTH = (2 * Short.MAX_VALUE) + 1;
035
036  /**
037   * Allows cloning the tags in the cell to a new byte[]
038   * @return the byte[] having the tags
039   */
040  default byte[] cloneTags() {
041    return PrivateCellUtil.cloneTags(this);
042  }
043
044  /**
045   * Creates a list of tags in the current cell
046   * @return a list of tags
047   */
048  default Iterator<Tag> getTags() {
049    return PrivateCellUtil.tagsIterator(this);
050  }
051
052  /**
053   * Returns the specific tag of the given type
054   * @param type the type of the tag
055   * @return the specific tag if available or null
056   */
057  default Optional<Tag> getTag(byte type) {
058    return PrivateCellUtil.getTag(this, type);
059  }
060
061  /**
062   * Check the length of tags. If it is invalid, throw IllegalArgumentException
063   * @param tagsLength the given length of tags
064   * @throws IllegalArgumentException if tagslength is invalid
065   */
066  public static void checkForTagsLength(int tagsLength) {
067    if (tagsLength > MAX_TAGS_LENGTH) {
068      throw new IllegalArgumentException("tagslength " + tagsLength + " > " + MAX_TAGS_LENGTH);
069    }
070  }
071
072  /** Returns A new cell which is having the extra tags also added to it. */
073  public static Cell createCell(Cell cell, List<Tag> tags) {
074    return PrivateCellUtil.createCell(cell, tags);
075  }
076}