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 */
018
019package org.apache.hadoop.registry.client.types;
020
021
022import org.apache.hadoop.classification.InterfaceAudience;
023import org.apache.hadoop.classification.InterfaceStability;
024import org.codehaus.jackson.annotate.JsonIgnoreProperties;
025import org.codehaus.jackson.annotate.JsonProperty;
026
027/**
028 * Output of a <code>RegistryOperations.stat()</code> call
029 */
030@InterfaceAudience.Public
031@InterfaceStability.Evolving
032@JsonIgnoreProperties(ignoreUnknown = true)
033public final class RegistryPathStatus {
034
035  /**
036   * Short path in the registry to this entry
037   */
038  public final String path;
039
040  /**
041   * Timestamp
042   */
043  public final long time;
044
045  /**
046   * Entry size in bytes, as returned by the storage infrastructure.
047   * In zookeeper, even "empty" nodes have a non-zero size.
048   */
049  public final long size;
050
051  /**
052   * Number of child nodes
053   */
054  public final int children;
055
056  /**
057   * Construct an instance
058   * @param path full path
059   * @param time time
060   * @param size entry size
061   * @param children number of children
062   */
063  public RegistryPathStatus(
064      @JsonProperty("path") String path,
065      @JsonProperty("time") long time,
066      @JsonProperty("size") long size,
067      @JsonProperty("children") int children) {
068    this.path = path;
069    this.time = time;
070    this.size = size;
071    this.children = children;
072  }
073
074  /**
075   * Equality operator checks size, time and path of the entries.
076   * It does <i>not</i> check {@link #children}.
077   * @param other the other entry
078   * @return true if the entries are considered equal.
079   */
080  @Override
081  public boolean equals(Object other) {
082    if (this == other) {
083      return true;
084    }
085    if (other == null || getClass() != other.getClass()) {
086      return false;
087    }
088
089    RegistryPathStatus status = (RegistryPathStatus) other;
090
091    if (size != status.size) {
092      return false;
093    }
094    if (time != status.time) {
095      return false;
096    }
097    if (path != null ? !path.equals(status.path) : status.path != null) {
098      return false;
099    }
100    return true;
101  }
102
103  /**
104   * The hash code is derived from the path.
105   * @return hash code for storing the path in maps.
106   */
107  @Override
108  public int hashCode() {
109    return path != null ? path.hashCode() : 0;
110  }
111
112  @Override
113  public String toString() {
114    final StringBuilder sb =
115        new StringBuilder("RegistryPathStatus{");
116    sb.append("path='").append(path).append('\'');
117    sb.append(", time=").append(time);
118    sb.append(", size=").append(size);
119    sb.append(", children=").append(children);
120    sb.append('}');
121    return sb.toString();
122  }
123}