All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.geode.management.internal.cli.domain.RegionInformation Maven / Gradle / Ivy

Go to download

Apache Geode provides a database-like consistency model, reliable transaction processing and a shared-nothing architecture to maintain very low latency performance with high concurrency processing

There is a newer version: 1.15.1
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
 * agreements. See the NOTICE file distributed with this work for additional information regarding
 * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance with the License. You may obtain a
 * copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package org.apache.geode.management.internal.cli.domain;

import org.apache.geode.cache.DataPolicy;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.Scope;

import java.io.Serializable;
import java.util.*;

/***
 * Gives the most basic common information of a region Used by the GetRegionsFunction for 'list
 * region' command since 7.0
 */
public class RegionInformation implements Serializable {

  private static final long serialVersionUID = 1L;
  protected String name;
  protected String path;
  protected Scope scope;
  protected DataPolicy dataPolicy;
  protected boolean isRoot;
  protected String parentRegion;

  private Set subRegionInformationSet = null;

  public RegionInformation(Region region, boolean recursive) {
    this.name = region.getFullPath().substring(1);
    this.path = region.getFullPath().substring(1);
    this.scope = region.getAttributes().getScope();
    this.dataPolicy = region.getAttributes().getDataPolicy();

    if (region.getParentRegion() == null) {
      this.isRoot = true;

      if (recursive) {
        Set> subRegions = region.subregions(recursive);
        subRegionInformationSet = getSubRegions(subRegions);
      }
    } else {
      this.isRoot = false;
      this.parentRegion = region.getParentRegion().getFullPath();
    }
  }

  private Set getSubRegions(Set> subRegions) {
    Set subRegionInformation = new HashSet();

    for (Region region : subRegions) {
      RegionInformation regionInformation = new RegionInformation(region, false);
      subRegionInformation.add(regionInformation);
    }

    return subRegionInformation;
  }

  public Set getSubRegionNames() {
    Set subRegionNames = new HashSet();

    if (subRegionInformationSet != null) {
      for (RegionInformation regInfo : subRegionInformationSet) {
        subRegionNames.add(regInfo.getName());
      }
    }

    return subRegionNames;
  }

  public String getName() {
    return name;
  }

  public String getPath() {
    return path;
  }

  public Scope getScope() {
    return scope;
  }

  public DataPolicy getDataPolicy() {
    return dataPolicy;
  }

  public Set getSubRegionInformation() {
    return subRegionInformationSet;
  }

  @Override
  public boolean equals(Object obj) {
    if (obj instanceof RegionInformation) {
      RegionInformation regionInfoObj = (RegionInformation) obj;
      return this.name.equals(regionInfoObj.getName()) && this.path.equals(regionInfoObj.getPath())
          && this.isRoot == regionInfoObj.isRoot
          && this.dataPolicy.equals(regionInfoObj.getDataPolicy())
          && this.scope.equals(regionInfoObj.getScope());
    } else {
      return false;
    }
  }

  @Override
  public int hashCode() {
    return this.name.hashCode() ^ this.path.hashCode() ^ this.dataPolicy.hashCode()
        ^ this.scope.hashCode();
  }

  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("\nName          :\t");
    sb.append(this.getName());
    sb.append("\nPath          :\t");
    sb.append(this.getPath());
    sb.append("\nScope         :\t");
    sb.append(this.getScope().toString());
    sb.append("\nData Policy   :\t");
    sb.append(this.getDataPolicy().toString());

    if (this.parentRegion != null) {
      sb.append("\nParent Region :\t");
      sb.append(this.parentRegion);
    }

    return sb.toString();
  }

  public String getSubRegionInfoAsString() {
    StringBuilder sb = new StringBuilder();
    if (this.isRoot) {

      for (RegionInformation regionInfo : this.subRegionInformationSet) {
        sb.append("\n");
        sb.append(regionInfo.getName());
      }
    }
    return sb.toString();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy