001/*
002 * Copyright 2008-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2008-2024 Ping Identity Corporation
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020/*
021 * Copyright (C) 2008-2024 Ping Identity Corporation
022 *
023 * This program is free software; you can redistribute it and/or modify
024 * it under the terms of the GNU General Public License (GPLv2 only)
025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
026 * as published by the Free Software Foundation.
027 *
028 * This program is distributed in the hope that it will be useful,
029 * but WITHOUT ANY WARRANTY; without even the implied warranty of
030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
031 * GNU General Public License for more details.
032 *
033 * You should have received a copy of the GNU General Public License
034 * along with this program; if not, see <http://www.gnu.org/licenses>.
035 */
036package com.unboundid.ldap.sdk.unboundidds.monitors;
037
038
039
040import java.io.Serializable;
041
042import com.unboundid.util.NotMutable;
043import com.unboundid.util.NotNull;
044import com.unboundid.util.Nullable;
045import com.unboundid.util.ThreadSafety;
046import com.unboundid.util.ThreadSafetyLevel;
047
048
049
050/**
051 * This class provides a data structure that may be used to hold information
052 * about disk space information for a Directory Server component.
053 * <BR>
054 * <BLOCKQUOTE>
055 *   <B>NOTE:</B>  This class, and other classes within the
056 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
057 *   supported for use against Ping Identity, UnboundID, and
058 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
059 *   for proprietary functionality or for external specifications that are not
060 *   considered stable or mature enough to be guaranteed to work in an
061 *   interoperable way with other types of LDAP servers.
062 * </BLOCKQUOTE>
063 */
064@NotMutable()
065@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
066public final class DiskSpaceInfo
067       implements Serializable
068{
069  /**
070   * The serial version UID for this serializable class.
071   */
072  private static final long serialVersionUID = -7798824641501237274L;
073
074
075
076  // The number of total bytes at the specified path.
077  @Nullable private final Long totalBytes;
078
079  // The number of usable bytes at the specified path.
080  @Nullable private final Long usableBytes;
081
082  // The percentage of the total space that is usable.
083  @Nullable private final Long usablePercent;
084
085  // The name of the associated disk space consumer.
086  @Nullable private final String consumerName;
087
088  // The path in which the disk space is being consumed.
089  @Nullable private final String path;
090
091
092
093  /**
094   * Creates a new disk space info object with the provided information.
095   *
096   * @param  consumerName   The name of the server component which may consume
097   *                        disk space.
098   * @param  path           The path in which the server component may consume
099   *                        disk space.
100   * @param  totalBytes     The total amount of space in bytes on the volume
101   *                        that holds the specified path.
102   * @param  usableBytes    The amount of usable space in bytes on the volume
103   *                        that holds the specified path.
104   * @param  usablePercent  The percentage of the total space that is usable on
105   *                        the volume that holds the specified path.
106   *
107   * @deprecated  Use the constructor that takes a {@code Long} object for the
108   *              {@code usableBytes} parameter.
109   */
110  @Deprecated()
111  public DiskSpaceInfo(@Nullable final String consumerName,
112                       @Nullable final String path,
113                       @Nullable final Long totalBytes,
114                       @Nullable final Long usableBytes,
115                       final long usablePercent)
116  {
117    this(consumerName, path, totalBytes, usableBytes,
118         Long.valueOf(usablePercent));
119  }
120
121
122
123  /**
124   * Creates a new disk space info object with the provided information.
125   *
126   * @param  consumerName   The name of the server component which may consume
127   *                        disk space.
128   * @param  path           The path in which the server component may consume
129   *                        disk space.
130   * @param  totalBytes     The total amount of space in bytes on the volume
131   *                        that holds the specified path.
132   * @param  usableBytes    The amount of usable space in bytes on the volume
133   *                        that holds the specified path.
134   * @param  usablePercent  The percentage of the total space that is usable on
135   *                        the volume that holds the specified path.
136   */
137  public DiskSpaceInfo(@Nullable final String consumerName,
138                       @Nullable final String path,
139                       @Nullable final Long totalBytes,
140                       @Nullable final Long usableBytes,
141                       @Nullable final Long usablePercent)
142  {
143    this.consumerName  = consumerName;
144    this.path          = path;
145    this.totalBytes    = totalBytes;
146    this.usableBytes   = usableBytes;
147    this.usablePercent = usablePercent;
148  }
149
150
151
152  /**
153   * The name of the server component which may consume disk space.
154   *
155   * @return  The name of the server component which may consume disk space, or
156   *          {@code null} if that is not available.
157   */
158  @Nullable()
159  public String getConsumerName()
160  {
161    return consumerName;
162  }
163
164
165
166  /**
167   * Retrieves the path in which the server component may consume disk space.
168   *
169   * @return  The path in which the server component may consume disk space, or
170   *          {@code null} if that is not available.
171   */
172  @Nullable()
173  public String getPath()
174  {
175    return path;
176  }
177
178
179
180  /**
181   * Retrieves the total amount of space in bytes on the volume that holds the
182   * specified path.
183   *
184   * @return  The total amount of space in bytes on the volume that holds the
185   *          specified path, or {@code null} if that is not available.
186   */
187  @Nullable()
188  public Long getTotalBytes()
189  {
190    return totalBytes;
191  }
192
193
194
195  /**
196   * Retrieves the amount of usable free space in bytes on the volume that holds
197   * the specified path.
198   *
199   * @return  The total amount of usable free space in bytes on the volume that
200   *          holds the specified path, or {@code null} if that is not
201   *          available.
202   */
203  @Nullable()
204  public Long getUsableBytes()
205  {
206    return usableBytes;
207  }
208
209
210
211  /**
212   * Retrieves the percentage of the total space on the volume that holds the
213   * specified path which is free and usable by the Directory Server.
214   *
215   * @return  The percentage of the total space on the volume that holds the
216   *          specified path which is free and usable by the Directory Server.
217   */
218  @Nullable()
219  public Long getUsablePercent()
220  {
221    return usablePercent;
222  }
223
224
225
226  /**
227   * Retrieves a string representation of this disk space info object.
228   *
229   * @return  A string representation of this disk space info object.
230   */
231  @Override()
232  @NotNull()
233  public String toString()
234  {
235    final StringBuilder buffer = new StringBuilder();
236    toString(buffer);
237    return buffer.toString();
238  }
239
240
241
242  /**
243   * Appends a string representation of this disk space info object to the
244   * provided buffer.
245   *
246   * @param  buffer  The buffer to which the information should be appended.
247   */
248  public void toString(@NotNull final StringBuilder buffer)
249  {
250    buffer.append("DiskSpaceInfo(consumerName='");
251    buffer.append(consumerName);
252    buffer.append("', path='");
253    buffer.append(path);
254    buffer.append("', totalBytes=");
255    buffer.append(totalBytes);
256    buffer.append(", usableBytes=");
257    buffer.append(usableBytes);
258    buffer.append(", usablePercent=");
259    buffer.append(usablePercent);
260    buffer.append(')');
261  }
262}