2 * @(#)Volume.java 1.0 6/29/2001
4 * Copyright (c) 2001 International Business Machines Corp.
7 * This software has been released under the terms of the IBM Public
8 * License. For details, see the LICENSE file in the top-level source
9 * directory or online at http://www.openafs.org/dl/license10.html
11 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
12 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
13 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
14 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
15 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
16 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
17 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
18 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
19 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
20 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 package org
.openafs
.jafs
;
26 import java
.util
.GregorianCalendar
;
27 import java
.util
.Date
;
28 import java
.io
.Serializable
;
31 * An abstract representation of an AFS volume. It holds information about
32 * the server, such as what its quota is.
35 * Constructing an instance of a <code>Volume</code> does not mean an actual
36 * AFS partition is created on a partition -- usually a <code>Volume</code>
37 * object is a representation of an already existing AFS volume. If,
38 * however, the <code>Volume</code> is constructed with the name of a
39 * volume that does not exist in the cell to which the provided
40 * <code>Partition</code> belongs, a new AFS volume with that name can be
41 * created on that partition by calling the {@link #create(int)} method. If
42 * such a volume does already exist when this method is called, an exception
43 * will be thrown.<BR><BR>
45 * <!--Example of how to use class-->
46 * The following is a simple example of how to construct and use a
47 * <code>Volume</code> object. This example obtains the list of
48 * <code>Volume</code> objects residing on a particular partition, and prints
49 * out the name and id of each one.<BR><BR>
52 * import org.openafs.jafs.Cell;
53 * import org.openafs.jafs.AFSException;
54 * import org.openafs.jafs.Partition;
55 * import org.openafs.jafs.Server;
56 * import org.openafs.jafs.Volume;
62 * private Server server;
63 * private Partition partition;
65 * public static void main(String[] args) throws Exception
67 * String username = arg[0];
68 * String password = arg[1];
69 * String cellName = arg[2];
70 * String serverName = arg[3];
71 * String partitionName = arg[4];
73 * token = new Token(username, password, cellName);
74 * cell = new Cell(token);
75 * server = cell.getServer(serverName);
76 * partition = cell.getPartition(partitionName);
78 * System.out.println("Volumes in Partition " + partition.getName() + ":");
79 * Volume[] volumes = partition.getVolumes();
80 * for (int i = 0; i < volumes.length; i++) {
81 * System.out.println(" -> " + volumes[i] + ": " + volumes[i].getID());
89 public class Volume
implements Serializable
, Comparable
92 * Read-write volume type
94 public static final int VOLUME_TYPE_READ_WRITE
= 0;
96 * Read-only volume type
98 public static final int VOLUME_TYPE_READ_ONLY
= 1;
102 public static final int VOLUME_TYPE_BACKUP
= 2;
105 * Status/disposition ok
107 public static final int VOLUME_OK
= 0;
109 * Status/disposition salvage
111 public static final int VOLUME_SALVAGE
= 1;
113 * Status/disposition no vnode
115 public static final int VOLUME_NO_VNODE
= 2;
117 * Status/disposition no volume
119 public static final int VOLUME_NO_VOL
= 3;
121 * Status/disposition volume exists
123 public static final int VOLUME_VOL_EXISTS
= 4;
125 * Status/disposition no service
127 public static final int VOLUME_NO_SERVICE
= 5;
129 * Status/disposition offline
131 public static final int VOLUME_OFFLINE
= 6;
133 * Status/disposition online
135 public static final int VOLUME_ONLINE
= 7;
137 * Status/disposition disk full
139 public static final int VOLUME_DISK_FULL
= 8;
141 * Status/disposition over quota
143 public static final int VOLUME_OVER_QUOTA
= 9;
145 * Status/disposition busy
147 public static final int VOLUME_BUSY
= 10;
149 * Status/disposition moved
151 public static final int VOLUME_MOVED
= 11;
154 protected Server server
;
155 protected Partition partition
;
157 protected String name
;
160 protected int readWriteID
;
161 protected int readOnlyID
;
162 protected int backupID
;
164 protected long creationDate
;
165 protected long lastAccessDate
;
166 protected long lastUpdateDate
;
167 protected long lastBackupDate
;
168 protected long copyCreationDate
;
170 protected int accessesSinceMidnight
;
171 protected int fileCount
;
172 protected int maxQuota
;
173 protected int currentSize
;
174 protected int status
;
175 protected int disposition
;
178 protected GregorianCalendar creationDateCal
;
179 protected GregorianCalendar lastUpdateDateCal
;
180 protected GregorianCalendar copyCreationDateCal
;
182 protected boolean cachedInfo
;
185 * Constructs a new <CODE>Volume</CODE> object instance given the name of
186 * the AFS volume and the AFS cell, represented by <CODE>partition</CODE>,
187 * to which it belongs. This does not actually
188 * create a new AFS volume, it just represents one.
189 * If <code>name</code> is not an actual AFS volume, exceptions
190 * will be thrown during subsequent method invocations on this
191 * object, unless the {@link #create(int)} method is explicitly called
194 * @param name the name of the volume to represent
195 * @param partition the partition on which the volume resides
196 * @exception AFSException If an error occurs in the native code
198 public Volume( String name
, Partition partition
) throws AFSException
200 this.partition
= partition
;
201 this.server
= partition
.getServer();
202 this.cell
= server
.getCell();
205 creationDateCal
= null;
206 lastUpdateDateCal
= null;
207 copyCreationDateCal
= null;
214 * Constructs a new <CODE>Volume</CODE> object instance given the name of
215 * the AFS volume and the AFS partition, represented by
216 * <CODE>partition</CODE>, to which it belongs. This does not actually
217 * create a new AFS volume, it just represents one.
218 * If <code>name</code> is not an actual AFS volume, exceptions
219 * will be thrown during subsequent method invocations on this
220 * object, unless the {@link #create(int)} method is explicitly called
221 * to create it. Note that if the volume doesn't exist and
222 * <code>preloadAllMembers</code> is true, an exception will be thrown.
224 * <P> This constructor is ideal for point-in-time representation and
225 * transient applications. It ensures all data member values are set
226 * and available without calling back to the filesystem at the first request
227 * for them. Use the {@link #refresh()} method to address any coherency
230 * @param name the name of the volume to represent
231 * @param partition the partition on which the volume resides.
232 * @param preloadAllMembers true will ensure all object members are set
233 * upon construction; otherwise members will be
234 * set upon access, which is the default behavior.
235 * @exception AFSException If an error occurs in the native code
238 public Volume( String name
, Partition partition
, boolean preloadAllMembers
)
241 this(name
, partition
);
242 if (preloadAllMembers
) refresh(true);
246 * Creates a blank <code>Volume</code> given the cell to which the volume
247 * belongs, the server on which the partition resides, and
248 * the partition on which the volume resides. This blank
249 * object can then be passed into other methods to fill out its properties.
251 * @exception AFSException If an error occurs in the native code
252 * @param cell the cell to which the server belongs.
253 * @param server the server on which the partition resides
254 * @param partition the partition on which the volume resides
256 Volume( Partition partition
) throws AFSException
258 this( null, partition
);
261 /*-------------------------------------------------------------------------*/
264 * Refreshes the properties of this Volume object instance with values from
265 * the AFS volume it represents. All properties that have been initialized
266 * and/or accessed will be renewed according to the values of the AFS volume
267 * this Volume object instance represents.
269 * <P>Since in most environments administrative changes can be administered
270 * from an AFS command-line program or an alternate GUI application, this
271 * method provides a means to refresh the Java object representation and
272 * thereby ascertain any possible modifications that may have been made
273 * from such alternate administrative programs. Using this method before
274 * an associated instance accessor will ensure the highest level of
275 * representative accuracy, accommodating changes made external to the
276 * Java application space. If administrative changes to the underlying AFS
277 * system are only allowed via this API, then the use of this method is
280 * @exception AFSException If an error occurs in the native code
282 public void refresh() throws AFSException
288 * Refreshes the properties of this Volume object instance with values from
289 * the AFS volume it represents. If <CODE>all</CODE> is <CODE>true</CODE>
290 * then <U>all</U> of the properties of this Volume object instance will be
291 * set, or renewed, according to the values of the AFS volume it represents,
292 * disregarding any previously set properties.
294 * <P> Thus, if <CODE>all</CODE> is <CODE>false</CODE> then properties that
295 * are currently set will be refreshed and properties that are not set will
296 * remain uninitialized. See {@link #refresh()} for more information.
298 * @param all if true set or renew all object properties; otherwise renew
300 * @exception AFSException If an error occurs in the native code
303 protected void refresh(boolean all
) throws AFSException
305 if (all
|| cachedInfo
) refreshInfo();
309 * Refreshes the information fields of this <code>Volume</code> to reflect
310 * the current state of the AFS volume. These include the last update time,
313 * @exception AFSException If an error occurs in the native code
315 protected void refreshInfo() throws AFSException
317 getVolumeInfo( cell
.getCellHandle(), server
.getVosHandle(),
318 partition
.getID(), getID(), this );
320 creationDateCal
= null;
321 lastUpdateDateCal
= null;
322 copyCreationDateCal
= null;
326 * Creates a new volume on the server and partition given upon construction.
328 * @param quota the quota for the volume in K, 0 indicates an unlimited
331 * @exception AFSException If an error occurs in the native code
333 public void create( int quota
) throws AFSException
335 id
= create( cell
.getCellHandle(), server
.getVosHandle(),
336 partition
.getID(), name
, quota
);
341 * Creates a backup volume for this volume.
343 * @return the <code>Volume</code> object representation for the
344 * backup volume that was created
345 * @exception AFSException If an error occurs in the native code
347 public Volume
createBackup( ) throws AFSException
349 createBackupVolume( cell
.getCellHandle(), getID() );
350 return new Volume( name
+ ".backup", partition
);
354 * Creates a readonly site for this volume on the specified server and
355 * partition. Automatically releases the volume.
357 * @param sitePartition the partition on which the readonly volume is
360 * @return the <code>Volume</code> representation for the
361 * read-only volume that was created
362 * @exception AFSException If an error occurs in the native code
364 public Volume
createReadOnly( Partition sitePartition
)
367 Server siteServer
= sitePartition
.getServer();
368 createReadOnlyVolume( cell
.getCellHandle(), siteServer
.getVosHandle(),
369 sitePartition
.getID(), getID() );
371 return new Volume( name
+ ".readonly", sitePartition
);
375 * Deletes the volume from the cell.
377 * @exception AFSException If an error occurs in the native code
379 public void delete() throws AFSException
381 delete( cell
.getCellHandle(), server
.getVosHandle(), partition
.getID(),
384 creationDateCal
= null;
385 lastUpdateDateCal
= null;
386 copyCreationDateCal
= null;
393 * Releases this volume, which updates the read-only copies of it.
395 * <P> This method will force a complete release; a complete release updates
396 * all read-only sites even if the VLDB entry has a flag.
398 * @exception AFSException If an error occurs in the native code
400 public void release() throws AFSException
402 this.release( true );
406 * Releases this volume, which updates the read-only copies of it.
408 * @param forceComplete whether or not to force a complete release;
409 * a complete release updates all read-only sites
410 * even if the VLDB entry has a flag
411 * @exception AFSException If an error occurs in the native code
413 public void release( boolean forceComplete
) throws AFSException
415 release( cell
.getCellHandle(), getID(), forceComplete
);
419 * Dumps this volume to a file. If you use the dumpSince argument you will
420 * create an incremental dump, but you can leave it <code>null</code>
423 * @param fileName the path name of the file on the client machine to
424 * which to dump this volume
425 * @param dumpSince dump only files that have been modified more recently
427 * @exception AFSException If an error occurs in the native code
429 public void dump( String fileName
, GregorianCalendar dumpSince
)
433 if ( dumpSince
!= null ) {
434 startTime
= (int) ((dumpSince
.getTime().getTime())/((long) 1000));
436 dump( cell
.getCellHandle(), server
.getVosHandle(), partition
.getID(),
437 getID(), startTime
, fileName
);
441 * Dumps this volume to a file. Creates a full dump.
443 * @param fileName the path name of the file to which to dump this volume
444 * @exception AFSException If an error occurs in the native code
446 public void dump( String fileName
) throws AFSException
448 this.dump( fileName
, null );
452 * Restores a file to this volume. Note that this does not have to be an
453 * existing volume in order to be restored - you may create a
454 * <code>Volume</code> as a volume that doesn't yet exist and then restore
455 * a file to it. Or you can restore over an existing volume. If a new
456 * volume is being created with this method, the id will be automatically
459 * @param fileName the path name of the file on the client machine from
460 * which to restore this volume
461 * @param incremental if true, restores an incremental dump over an
463 * @exception AFSException If an error occurs in the native code
465 public void restore( String fileName
, boolean incremental
)
468 restore( fileName
, incremental
, 0 );
472 * Restores a file to this volume. Note that this does not have to be an
473 * existing volume in order to be restored - you may create a
474 * <code>Volume</code> as a volume that doesn't yet exist and then restore
475 * a file to it. Or you can restore over an existing volume.
477 * @param fileName the path name of the file on the client machine from
478 * which to restore this volume
479 * @param incremental if true, restores an incremental dump over an
481 * @param id the id to assign this volume
482 * @exception AFSException If an error occurs in the native code
484 public void restore( String fileName
, boolean incremental
, int id
)
487 restore( cell
.getCellHandle(), server
.getVosHandle(), partition
.getID(),
488 id
, name
, fileName
, incremental
);
492 * Mounts this volume, bringing it online and making it accessible.
494 * @exception AFSException If an error occurs in the native code
496 public void mount( ) throws AFSException
498 mount( server
.getVosHandle(), partition
.getID(), getID(), 0, true );
502 * Unmounts this volume, bringing it offline and making it inaccessible.
504 * @exception AFSException If an error occurs in the native code
506 public void unmount( ) throws AFSException
508 unmount( server
.getVosHandle(), partition
.getID(), getID() );
512 * Locks the VLDB enrty for this volume
514 * @exception AFSException If an error occurs in the native code
516 public void lock( ) throws AFSException
518 lock( cell
.getCellHandle(), getID() );
522 * Unlocks the VLDB entry for this volume
524 * @exception AFSException If an error occurs in the native code
526 public void unlock( ) throws AFSException
528 unlock( cell
.getCellHandle(), getID() );
532 * Moves this volume to the specified partition (which indirectly
533 * specifies a new server, as well). Caution: This will remove any backup
534 * volumes at the original site.
536 * @param newPartition the partition to which to move the volume
538 * @exception AFSException If an error occurs in the native code
540 public void moveTo( Partition newPartition
) throws AFSException
542 Server newServer
= newPartition
.getServer();
543 move( cell
.getCellHandle(), server
.getVosHandle(), partition
.getID(),
544 newServer
.getVosHandle(), newPartition
.getID(), getID() );
547 partition
= newPartition
;
551 * Renames this volume.
553 * @param newName the new name for this volume
554 * @exception AFSException If an error occurs in the native code
556 public void rename( String newName
) throws AFSException
558 rename( cell
.getCellHandle(), getID(), newName
);
563 * Salvages (restores consistency to) this volume. Uses default values for
564 * most salvager options in order to simplify the API.
566 * @exception AFSException If an error occurs in the native code
568 public void salvage() throws AFSException
570 Server
.salvage( cell
.getCellHandle(), server
.getBosHandle(),
571 partition
.getName(), name
, 4, null, null, false, false,
572 false, false, false, false );
576 * Creates a read-write mount point for this volume. Does not ensure the
577 * volume already exists.
579 * @param directory the name of the directory where this volume
581 * @exception AFSException If an error occurs in the native code
583 public void createMountPoint( String directory
) throws AFSException
585 createMountPoint(directory
, true);
589 * Creates a mount point for this volume. Does not ensure the volume
592 * @param directory the name of the directory where this volume should be
594 * @param readWrite whether or not this mount point should be read-write
595 * @exception AFSException If an error occurs in the native code
597 public void createMountPoint( String directory
, boolean readWrite
)
600 Cell
.createMountPoint( cell
.getCellHandle(), directory
, getName(),
604 //////////////// accessors: ////////////////////////
607 * Returns the name of this volume.
609 * @return the name of this volume
611 public String
getName()
617 * Returns this volume's hosting partition.
619 * @return this volume's partition
621 public Partition
getPartition()
627 * Returns the id of this volume.
629 * @exception AFSException If an error occurs in the native code
630 * @return the id of this volume
632 public int getID() throws AFSException
634 if( id
== -1 && name
!= null ) {
636 if( name
.endsWith( "backup" ) ) {
637 type
= VOLUME_TYPE_BACKUP
;
638 nameNoSuffix
= name
.substring( 0, name
.lastIndexOf( '.' ) );
639 } else if( name
.endsWith( "readonly" ) ) {
640 type
= VOLUME_TYPE_READ_ONLY
;
641 nameNoSuffix
= name
.substring( 0, name
.lastIndexOf( '.' ) );
643 type
= VOLUME_TYPE_READ_WRITE
;
646 id
= translateNameToID( cell
.getCellHandle(),
647 nameNoSuffix
, type
);
653 * Returns the read-write ID of this volume
655 * @exception AFSException If an error occurs in the native code
656 * @return the read-write id
658 public int getReadWriteID() throws AFSException
667 * Returns the read-only ID of this volume
669 * @exception AFSException If an error occurs in the native code
670 * @return the read-only id
672 public int getReadOnlyID() throws AFSException
681 * Returns the backup ID of this volume
683 * @exception AFSException If an error occurs in the native code
684 * @return the backup id
686 public int getBackupID() throws AFSException
695 * Returns the date the volume was created
697 * @return the date the volume was created
698 * @exception AFSException If an error occurs in the native code
700 public GregorianCalendar
getCreationDate() throws AFSException
705 if( creationDateCal
== null ) {
706 // make it into a date . . .
707 creationDateCal
= new GregorianCalendar();
708 Date d
= new Date( creationDate
*1000 );
709 creationDateCal
.setTime( d
);
711 return creationDateCal
;
715 * Returns the date the volume was last updated.
716 * After this method is called once, it saves the date
717 * and returns that date on subsequent calls,
718 * until the {@link #refresh()} method is called and a more current
721 * @return the date the volume was last updated
722 * @exception AFSException If an error occurs in the native code
724 public GregorianCalendar
getLastUpdateDate() throws AFSException
729 if( lastUpdateDateCal
== null ) {
730 // make it into a date . . .
731 lastUpdateDateCal
= new GregorianCalendar();
732 Date d
= new Date( lastUpdateDate
*1000 );
733 lastUpdateDateCal
.setTime( d
);
735 return lastUpdateDateCal
;
739 * Returns the date the volume was copied.
740 * After this method is called once, it saves the date
741 * and returns that date on subsequent calls,
742 * until the {@link #refresh()} method is called and a more current
745 * @return the date the volume was copied
746 * @exception AFSException If an error occurs in the native code
748 public GregorianCalendar
getCopyCreationDate() throws AFSException
753 if( copyCreationDateCal
== null ) {
754 // make it into a date . . .
755 copyCreationDateCal
= new GregorianCalendar();
756 Date d
= new Date( copyCreationDate
*1000 );
757 copyCreationDateCal
.setTime( d
);
759 return copyCreationDateCal
;
763 * Returns the number of accesses since midnight.
764 * After this method is called once, it saves the value
765 * and returns that value on subsequent calls,
766 * until the {@link #refresh()} method is called and a more current
769 * @exception AFSException If an error occurs in the native code
770 * @return the number of accesses since midnight
772 public int getAccessesSinceMidnight() throws AFSException
777 return accessesSinceMidnight
;
781 * Returns file count.
782 * After this method is called once, it saves the value
783 * and returns that value on subsequent calls,
784 * until the {@link #refresh()} method is called and a more current
787 * @exception AFSException If an error occurs in the native code
788 * @return the file count
790 public int getFileCount() throws AFSException
799 * Returns current volume size in K.
800 * After this method is called once, it saves the value
801 * and returns that value on subsequent calls,
802 * until the {@link #refresh()} method is called and a more current
805 * @exception AFSException If an error occurs in the native code
806 * @return the current volume size in K
808 public int getCurrentSize() throws AFSException
810 if( !cachedInfo
) refreshInfo();
815 * Returns the difference between quota and current volume size (in K).
817 * <P> Please note: the product of this method is <U>not</U> saved.
819 * @exception AFSException If an error occurs in the native code
820 * @return the current free space in K
822 public int getTotalFreeSpace() throws AFSException
824 if ( !cachedInfo
) refreshInfo();
825 return (maxQuota
- currentSize
);
829 * Returns this volume's quota, expressed in kilobyte blocks (1024
830 * kilobyte blocks equal one megabyte). After this method is called once,
831 * it saves the value and returns that value on subsequent calls,
832 * until the {@link #refresh()} method is called and a more current
835 * <P><B>Note:</B> A quota value of zero, "0", grants an unlimited quota
836 * in AFS. Consequently, to avoid delusion this method will throw an
837 * {@link AFSException} if the returning value is zero.
839 * @exception AFSException If an error occurs in the native code or
840 * this volume's quota is configured as
842 * @return the volume quota in K
843 * @see #isQuotaUnlimited()
845 public int getQuota() throws AFSException
847 if ( !cachedInfo
) refreshInfo();
849 throw new AFSException("Volume with id " + id
+
850 " has an unlimited quota configured.", 0);
856 * Tests whether this volume's quota is configured as unlimited.
858 * <P>After this method is called once, it saves the value and returns
859 * that value on subsequent calls, until the {@link #refresh()}
860 * method is called and a more current value is obtained.
862 * @exception AFSException If an error occurs in the native code
863 * @return <CODE>true</CODE> if this volume's quota is configured as
864 * unlimited; otherwise <CODE>false</CODE>.
867 public boolean isQuotaUnlimited() throws AFSException
869 if ( !cachedInfo
) refreshInfo();
870 return (maxQuota
== 0);
874 * Returns volume status. Possible values are:<ul>
875 * <li>{@link #VOLUME_OK}</li>
876 * <li>{@link #VOLUME_SALVAGE}</li>
877 * <li>{@link #VOLUME_NO_VNODE}</li>
878 * <li>{@link #VOLUME_NO_VOL}</li>
879 * <li>{@link #VOLUME_VOL_EXISTS}</li>
880 * <li>{@link #VOLUME_NO_SERVICE}</li>
881 * <li>{@link #VOLUME_OFFLINE}</li>
882 * <li>{@link #VOLUME_ONLINE}</li>
883 * <li>{@link #VOLUME_DISK_FULL}</li>
884 * <li>{@link #VOLUME_OVER_QUOTA}</li>
885 * <li>{@link #VOLUME_BUSY}</li>
886 * <li>{@link #VOLUME_MOVED}</li></ul>
887 * Typical value is VOLUME_OK.
888 * After this method is called once, it saves the value
889 * and returns that value on subsequent calls,
890 * until the {@link #refresh()} method is called and a more current
893 * @exception AFSException If an error occurs in the native code
894 * @return volume status
896 public int getStatus() throws AFSException
898 if( !cachedInfo
) refreshInfo();
903 * Returns volume disposition. Possible values are:<ul>
904 * <li>{@link #VOLUME_OK}</li>
905 * <li>{@link #VOLUME_SALVAGE}</li>
906 * <li>{@link #VOLUME_NO_VNODE}</li>
907 * <li>{@link #VOLUME_NO_VOL}</li>
908 * <li>{@link #VOLUME_VOL_EXISTS}</li>
909 * <li>{@link #VOLUME_NO_SERVICE}</li>
910 * <li>{@link #VOLUME_OFFLINE}</li>
911 * <li>{@link #VOLUME_ONLINE}</li>
912 * <li>{@link #VOLUME_DISK_FULL}</li>
913 * <li>{@link #VOLUME_OVER_QUOTA}</li>
914 * <li>{@link #VOLUME_BUSY}</li>
915 * <li>{@link #VOLUME_MOVED}</li></ul>
916 * Typical value is VOLUME_ONLINE.
917 * After this method is called once, it saves the value
918 * and returns that value on subsequent calls,
919 * until the {@link #refresh()} method is called and a more current
922 * @exception AFSException If an error occurs in the native code
923 * @return volume disposition
925 public int getDisposition() throws AFSException
927 if( !cachedInfo
) refreshInfo();
932 * Returns volume type. Possible values are:<ul>
933 * <li>{@link #VOLUME_TYPE_READ_WRITE}</li>
934 * <li>{@link #VOLUME_TYPE_READ_ONLY}</li>
935 * <li>{@link #VOLUME_TYPE_BACKUP}</li></ul>
937 * @exception AFSException If an error occurs in the native code
938 * @return volume type
940 public int getType() throws AFSException
942 if( !cachedInfo
) refreshInfo();
946 //////////////// mutators: ////////////////////////
949 * Sets quota of volume, 0 denotes an unlimited quota.
951 * @exception AFSException If an error occurs in the native code
952 * @param quota the new volume quota in K (0 for unlimited)
954 public void setQuota( int quota
) throws AFSException
956 this.changeQuota( cell
.getCellHandle(), server
.getVosHandle(),
957 partition
.getID(), getID(), quota
);
961 /////////////// custom information methods ////////////////////
964 * Returns a <code>String</code> representation of this <code>Volume</code>.
965 * Contains the information fields.
967 * @return a <code>String</code> representation of the <code>Volume</code>
969 public String
getInfo()
973 r
= "Volume: " + name
+ "\tid: " + getID() + "\n";
975 r
+= "\tread-write id: " + getReadWriteID() + "\tread-only id: "
976 + getReadOnlyID() + "\n";
977 r
+= "\tbackup id: " + getBackupID() + "\n";
979 r
+= "\tcreation date: " + getCreationDate().getTime() + "\n";
980 r
+= "\tlast update date: " + getLastUpdateDate().getTime() + "\n";
981 r
+= "\tcopy creation date: " + getCopyCreationDate().getTime() + "\n";
982 r
+= "\taccesses since midnight: " + getAccessesSinceMidnight() + "\n";
983 r
+= "\tfile count: " + getFileCount() + "\n";
984 r
+= "\tcurrent size: " + getCurrentSize() + " K\tquota: " +
987 switch( getStatus() ) {
995 r
+= "\tdisposition: ";
996 switch( getDisposition() ) {
1001 r
+= "OTHER - " + getDisposition();
1006 switch( getType() ) {
1007 case VOLUME_TYPE_READ_WRITE
:
1010 case VOLUME_TYPE_READ_ONLY
:
1013 case VOLUME_TYPE_BACKUP
:
1021 } catch( Exception e
) {
1022 return e
.toString();
1027 /////////////// custom override methods ////////////////////
1030 * Compares two Volume objects respective to their names and does not
1031 * factor any other attribute. Alphabetic case is significant in
1034 * @param volume The Volume object to be compared to this Volume
1037 * @return Zero if the argument is equal to this Volume's name, a
1038 * value less than zero if this Volume's name is
1039 * lexicographically less than the argument, or a value greater
1040 * than zero if this Volume's name is lexicographically
1041 * greater than the argument
1043 public int compareTo(Volume volume
)
1045 return this.getName().compareTo(volume
.getName());
1049 * Comparable interface method.
1051 * @see #compareTo(Volume)
1053 public int compareTo(Object obj
)
1055 return compareTo((Volume
)obj
);
1059 * Tests whether two <code>Volume</code> objects are equal, based on their
1060 * names and hosting partition.
1062 * @param otherVolume the Volume to test
1063 * @return whether the specifed Volume is the same as this Volume
1065 public boolean equals( Volume otherVolume
)
1067 return ( name
.equals(otherVolume
.getName()) ) &&
1068 ( this.getPartition().equals(otherVolume
.getPartition()) );
1072 * Returns the name of this <CODE>Volume</CODE>
1074 * @return the name of this <CODE>Volume</CODE>
1076 public String
toString()
1082 /////////////// native methods ////////////////////
1085 * Fills in the information fields of the provided <code>Volume</code>.
1087 * @param cellHandle the handle of the cell to which the volume belongs
1088 * @see Cell#getCellHandle
1089 * @param serverHandle the vos handle of the server on which the volume
1091 * @see Server#getVosServerHandle
1092 * @param partition the numeric id of the partition on which the volume
1094 * @param volId the numeric id of the volume for which to get the info
1095 * @param theVolume the {@link Volume Volume} object in which to fill in
1097 * @exception AFSException If an error occurs in the native code
1099 protected static native void getVolumeInfo( long cellHandle
, long serverHandle
,
1100 int partition
, int volId
,
1102 throws AFSException
;
1105 * Creates a volume on a particular partition.
1107 * @param cellHandle the handle of the cell in which to create the volume
1108 * @see Cell#getCellHandle
1109 * @param serverHandle the vos handle of the server on which to create
1111 * @see Server#getVosServerHandle
1112 * @param partition the numeric id of the partition on which to create
1114 * @param volumeName the name of the volume to create
1115 * @param quota the amount of space (in KB) to set as this volume's quota
1116 * @return the numeric ID assigned to the volume
1117 * @exception AFSException If an error occurs in the native code
1119 protected static native int create( long cellHandle
, long serverHandle
,
1120 int partition
, String volumeName
,
1122 throws AFSException
;
1125 * Deletes a volume from a particular partition.
1127 * @param cellHandle the handle of the cell in which to delete the volume
1128 * @see Cell#getCellHandle
1129 * @param serverHandle the vos handle of the server from which to delete
1131 * @see Server#getVosServerHandle
1132 * @param partition the numeric id of the partition from which to delete
1134 * @param volId the numeric id of the volume to delete
1135 * @exception AFSException If an error occurs in the native code
1137 protected static native void delete( long cellHandle
, long serverHandle
,
1138 int partition
, int volId
)
1139 throws AFSException
;
1142 * Creates a backup volume for the specified regular volume.
1144 * @param cellHandle the handle of the cell to which the volume belongs
1145 * @param volId the numeric id of the volume for which to create a backup
1147 * @see Cell#getCellHandle
1149 protected static native void createBackupVolume( long cellHandle
, int volId
)
1150 throws AFSException
;
1153 * Creates a read-only volume for the specified regular volume.
1155 * @param cellHandle the handle of the cell to which the volume belongs
1156 * @param serverHandle the vos handle of the server on which the read-only
1157 * volume is to reside
1158 * @see Server#getVosServerHandle
1159 * @param partition the numeric id of the partition on which the read-only
1161 * @param volId the numeric id of the volume for which to create a read-only volume
1162 * @see Cell#getCellHandle
1164 protected static native void createReadOnlyVolume( long cellHandle
,
1166 int partition
, int volId
)
1167 throws AFSException
;
1170 * Deletes a read-only volume for the specified regular volume.
1172 * @param cellHandle the handle of the cell to which the volume belongs
1173 * @param serverHandle the vos handle of the server on which the read-only
1175 * @see Server#getVosServerHandle
1176 * @param partition the numeric id of the partition on which the read-only
1178 * @param volId the numeric read-write id of the volume for which to
1179 * delete the read-only volume
1180 * @see Cell#getCellHandle
1182 protected static native void deleteReadOnlyVolume( long cellHandle
,
1184 int partition
, int volId
)
1185 throws AFSException
;
1188 * Changes the quota of the specified volume.
1190 * @param cellHandle the handle of the cell to which the volume belongs
1191 * @see Cell#getCellHandle
1192 * @param serverHandle the vos handle of the server on which the volume
1194 * @see Server#getVosServerHandle
1195 * @param partition the numeric id of the partition on which the volume
1197 * @param volId the numeric id of the volume for which to change the quota
1198 * @param newQuota the new quota (in KB) to assign the volume
1199 * @exception AFSException If an error occurs in the native code
1201 protected static native void changeQuota( long cellHandle
, long serverHandle
,
1202 int partition
, int volId
,
1204 throws AFSException
;
1207 * Move the specified volume to a different site.
1209 * @param cellHandle the handle of the cell to which the volume belongs
1210 * @see Cell#getCellHandle
1211 * @param fromServerHandle the vos handle of the server on which the volume
1213 * @see Server#getVosServerHandle
1214 * @param fromPartition the numeric id of the partition on which the volume
1216 * @param toServerHandle the vos handle of the server to which the volume
1218 * @param toPartition the numeric id of the partition to which the volume
1220 * @param volId the numeric id of the volume to move
1221 * @exception AFSException If an error occurs in the native code
1223 protected static native void move( long cellHandle
, long fromServerHandle
,
1224 int fromPartition
, long toServerHandle
,
1225 int toPartition
, int volId
)
1226 throws AFSException
;
1229 * Releases the specified volume that has readonly volume sites.
1231 * @param cellHandle the handle of the cell to which the volume belongs
1232 * @param volId the numeric id of the volume to release
1233 * @param forceComplete whether or not to force a complete release
1234 * @see Cell#getCellHandle
1236 protected static native void release( long cellHandle
, int volId
,
1237 boolean forceComplete
)
1238 throws AFSException
;
1241 * Dumps the specified volume to a file.
1243 * @param cellHandle the handle of the cell to which the volume belongs
1244 * @see Cell#getCellHandle
1245 * @param serverHandle the vos handle of the server on which the volume
1247 * @see Server#getVosServerHandle
1248 * @param partition the numeric id of the partition on which the
1250 * @param volId the numeric id of the volume to dump
1251 * @param startTime files with a modification time >= to this time will
1253 * @param dumpFile the full path of the file to which to dump
1254 * @exception AFSException If an error occurs in the native code
1256 protected static native void dump( long cellHandle
, long serverHandle
,
1257 int partition
, int volId
, int startTime
,
1259 throws AFSException
;
1262 * Restores the specified volume from a dump file.
1264 * @param cellHandle the handle of the cell to which the volume belongs
1265 * @see Cell#getCellHandle
1266 * @param serverHandle the vos handle of the server on which the volume is
1268 * @see Server#getVosServerHandle
1269 * @param partition the numeric id of the partition on which the volume is
1271 * @param volId the numeric id to assign the restored volume (can be 0)
1272 * @param volumeName the name of the volume to restore as
1273 * @param dumpFile the full path of the dump file from which to restore
1274 * @param incremental if true, restores an incremental dump over an existing
1275 * volume (server and partition values must correctly
1276 * indicate the current position of the existing volume),
1277 * otherwise restores a full dump
1278 * @exception AFSException If an error occurs in the native code
1280 protected static native void restore( long cellHandle
, long serverHandle
,
1281 int partition
, int volId
,
1282 String volumeName
, String dumpFile
,
1283 boolean incremental
)
1284 throws AFSException
;
1287 * Renames the specified read-write volume.
1289 * @param cellHandle the handle of the cell to which the volume belongs
1290 * @see Cell#getCellHandle
1291 * @param volId the numeric id of the read-write volume to rename
1292 * @param newVolumeName the new name for the volume
1293 * @exception AFSException If an error occurs in the native code
1295 protected static native void rename( long cellHandle
, int volId
,
1296 String newVolumeName
)
1297 throws AFSException
;
1300 * "Mounts" the specified volume, bringing it online.
1302 * @param serverHandle the vos handle of the server on which the volume
1304 * @see Server#getVosServerHandle
1305 * @param partition the numeric id of the partition on which the volume
1307 * @param volId the numeric id of the volume to bring online
1308 * @param sleepTime ? (not sure what this is yet, possibly a time to wait
1309 * before brining it online)
1310 * @param offline ? (not sure what this is either, probably the current
1311 * status of the volume -- busy or offline)
1312 * @exception AFSException If an error occurs in the native code
1314 protected static native void mount( long serverHandle
, int partition
,
1315 int volId
, int sleepTime
,
1317 throws AFSException
;
1320 * "Unmounts" the specified volume, bringing it offline.
1322 * @param serverHandle the vos handle of the server on which the volume
1324 * @see Server#getVosServerHandle
1325 * @param partition the numeric id of the partition on which the volume
1327 * @param volId the numeric id of the volume to bring offline
1328 * @exception AFSException If an error occurs in the native code
1330 protected static native void unmount( long serverHandle
, int partition
,
1332 throws AFSException
;
1335 * Locks the VLDB entry specified volume
1337 * @param cellHandle the handle of the cell on which the volume resides
1338 * @see Cell#getCellHandle
1339 * @param volId the numeric id of the volume to lock
1340 * @exception AFSException If an error occurs in the native code
1342 protected static native void lock( long cellHandle
, int volId
)
1343 throws AFSException
;
1346 * Unlocks the VLDB entry of the specified volume
1348 * @param cellHandle the handle of the cell on which the volume resides
1349 * @see Cell#getCellHandle
1350 * @param volId the numeric id of the volume to unlock
1351 * @exception AFSException If an error occurs in the native code
1353 protected static native void unlock( long cellHandle
, int volId
)
1354 throws AFSException
;
1357 * Translates a volume name into a volume id
1359 * @param cellHandle the handle of the cell to which the volume belongs
1360 * @see Cell#getCellHandle
1361 * @param name the name of the volume in question, cannot end in backup or
1363 * @param type the type of volume: read-write, read-only, or backup.
1364 * Acceptable values are:<ul>
1365 * <li>{@link #VOLUME_TYPE_READ_WRITE}</li>
1366 * <li>{@link #VOLUME_TYPE_READ_ONLY}</li>
1367 * <li>{@link #VOLUME_TYPE_BACKUP}</li></ul>
1368 * @return the id of the volume in question
1369 * @exception AFSException If an error occurs in the native code
1371 protected static native int translateNameToID( long cellHandle
, String name
,
1373 throws AFSException
;
1376 * Reclaims all memory being saved by the volume portion of the native
1377 * library. This method should be called when no more <code>Volume</code>
1378 * objects are expected to be used.
1380 protected static native void reclaimVolumeMemory();