001    /*
002     * Copyright 2008-2015 UnboundID Corp.
003     * All Rights Reserved.
004     */
005    /*
006     * Copyright (C) 2015 UnboundID Corp.
007     *
008     * This program is free software; you can redistribute it and/or modify
009     * it under the terms of the GNU General Public License (GPLv2 only)
010     * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011     * as published by the Free Software Foundation.
012     *
013     * This program is distributed in the hope that it will be useful,
014     * but WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016     * GNU General Public License for more details.
017     *
018     * You should have received a copy of the GNU General Public License
019     * along with this program; if not, see <http://www.gnu.org/licenses>.
020     */
021    package com.unboundid.ldap.sdk.unboundidds.monitors;
022    
023    
024    
025    import java.io.Serializable;
026    
027    import com.unboundid.util.NotMutable;
028    import com.unboundid.util.ThreadSafety;
029    import com.unboundid.util.ThreadSafetyLevel;
030    
031    
032    
033    /**
034     * <BLOCKQUOTE>
035     *   <B>NOTE:</B>  This class is part of the Commercial Edition of the UnboundID
036     *   LDAP SDK for Java.  It is not available for use in applications that
037     *   include only the Standard Edition of the LDAP SDK, and is not supported for
038     *   use in conjunction with non-UnboundID products.
039     * </BLOCKQUOTE>
040     * This class provides a data structure that may be used to hold information
041     * about disk space information for a Directory Server component.
042     */
043    @NotMutable()
044    @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
045    public final class DiskSpaceInfo
046           implements Serializable
047    {
048      /**
049       * The serial version UID for this serializable class.
050       */
051      private static final long serialVersionUID = -7798824641501237274L;
052    
053    
054    
055      // The number of total bytes at the specified path.
056      private final Long totalBytes;
057    
058      // The number of usable bytes at the specified path.
059      private final Long usableBytes;
060    
061      // The percentage of the total space that is usable.
062      private final Long usablePercent;
063    
064      // The name of the associated disk space consumer.
065      private final String consumerName;
066    
067      // The path in which the disk space is being consumed.
068      private final String path;
069    
070    
071    
072      /**
073       * Creates a new disk space info object with the provided information.
074       *
075       * @param  consumerName   The name of the server component which may consume
076       *                        disk space.
077       * @param  path           The path in which the server component may consume
078       *                        disk space.
079       * @param  totalBytes     The total amount of space in bytes on the volume
080       *                        that holds the specified path.
081       * @param  usableBytes    The amount of usable space in bytes on the volume
082       *                        that holds the specified path.
083       * @param  usablePercent  The percentage of the total space that is usable on
084       *                        the volume that holds the specified path.
085       */
086      public DiskSpaceInfo(final String consumerName, final String path,
087                           final Long totalBytes, final Long usableBytes,
088                           final long usablePercent)
089      {
090        this.consumerName  = consumerName;
091        this.path          = path;
092        this.totalBytes    = totalBytes;
093        this.usableBytes   = usableBytes;
094        this.usablePercent = usablePercent;
095      }
096    
097    
098    
099      /**
100       * The name of the server component which may consume disk space.
101       *
102       * @return  The name of the server component which may consume disk space, or
103       *          {@code null} if that is not available.
104       */
105      public String getConsumerName()
106      {
107        return consumerName;
108      }
109    
110    
111    
112      /**
113       * Retrieves the path in which the server component may consume disk space.
114       *
115       * @return  The path in which the server component may consume disk space, or
116       *          {@code null} if that is not available.
117       */
118      public String getPath()
119      {
120        return path;
121      }
122    
123    
124    
125      /**
126       * Retrieves the total amount of space in bytes on the volume that holds the
127       * specified path.
128       *
129       * @return  The total amount of space in bytes on the volume that holds the
130       *          specified path, or {@code null} if that is not available.
131       */
132      public Long getTotalBytes()
133      {
134        return totalBytes;
135      }
136    
137    
138    
139      /**
140       * Retrieves the amount of usable free space in bytes on the volume that holds
141       * the specified path.
142       *
143       * @return  The total amount of usable free space in bytes on the volume that
144       *          holds the specified path, or {@code null} if that is not
145       *          available.
146       */
147      public Long getUsableBytes()
148      {
149        return usableBytes;
150      }
151    
152    
153    
154      /**
155       * Retrieves the percentage of the total space on the volume that holds the
156       * specified path which is free and usable by the Directory Server.
157       *
158       * @return  The percentage of the total space on the volume that holds the
159       *          specified path which is free and usable by the Directory Server.
160       */
161      public Long getUsablePercent()
162      {
163        return usablePercent;
164      }
165    
166    
167    
168      /**
169       * Retrieves a string representation of this disk space info object.
170       *
171       * @return  A string representation of this disk space info object.
172       */
173      @Override()
174      public String toString()
175      {
176        final StringBuilder buffer = new StringBuilder();
177        toString(buffer);
178        return buffer.toString();
179      }
180    
181    
182    
183      /**
184       * Appends a string representation of this disk space info object to the
185       * provided buffer.
186       *
187       * @param  buffer  The buffer to which the information should be appended.
188       */
189      public void toString(final StringBuilder buffer)
190      {
191        buffer.append("DiskSpaceInfo(consumerName='");
192        buffer.append(consumerName);
193        buffer.append("', path='");
194        buffer.append(path);
195        buffer.append("', totalBytes=");
196        buffer.append(totalBytes);
197        buffer.append(", usableBytes=");
198        buffer.append(usableBytes);
199        buffer.append(", usablePercent=");
200        buffer.append(usablePercent);
201        buffer.append(')');
202      }
203    }