Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / JAVA / classes / org / openafs / jafs / Cell.java
1 /*
2 * @(#)Cell.java 1.0 6/29/2001
3 *
4 * Copyright (c) 2001-2002 International Business Machines Corp.
5 * All rights reserved.
6 *
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
10 *
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.
22 */
23
24 package org.openafs.jafs;
25
26 import java.util.ArrayList;
27 import java.util.GregorianCalendar;
28 import java.util.Date;
29
30 /**
31 * An abstract representation of an AFS cell. It holds information about
32 * the cell, such as what users, groups, and servers exist in the cell.
33 * <BR><BR>
34 *
35 * Constructing a <code>Cell</code> object does not mean a new cell is
36 * created in the AFS file system -- on the contrary, a <code>Cell</code>
37 * object must be a representation of an already existing AFS cell. There
38 * is no way to create a new AFS cell through this API. See
39 * <a href="http://www.openafs.org">OpenAFS.org</a> for information on how
40 * to create a new cell.<BR><BR>
41 *
42 * The construction of a <code>Cell</code> object acts as an entry point
43 * for authentication into the AFS system. Thus, when you construct a
44 * <code>Cell</code>, you must pass in an authenticated <code>Token</code>
45 * of a user in the AFS cell that the <code>Cell</code> represents. You
46 * will be authenticated as the user represented by <code>token</code> and
47 * you will only be allowed to perform actions that the user is
48 * authorized to perform. You must construct a <code>Cell</code> before
49 * attempting to construct any other object in this package, since the
50 * other objects all require a <code>Cell</code> object on construction,
51 * either directly or indirectly.<BR><BR>
52 *
53 * Note that to successfully construct a <code>Cell</code> object, the
54 * code must be running on a machine with a running AFS client, and the
55 * cell this object is to represent must have an entry in the client's
56 * CellServDB file.<BR><BR>
57 *
58 * Each <code>Cell</code> object has its own individual set of
59 * <code>Server</code>s, <code>User</code>s, and <code>Group</code>s.
60 * This represents the properties and attributes of an actual AFS cell.
61 *
62 * If an error occurs during a method call, an
63 * <code>AFSException</code> will be thrown. This class is the Java
64 * equivalent of errors thrown by AFS; see {@link AFSException}
65 * for a complete description.<BR><BR>
66 *
67 * <!--Example of how to use class-->
68 * The following is a simple example of how to construct and use a
69 * <code>Cell</code> object. It shows how a <code>Cell</code> can be used to
70 * get an abstract representation of an AFS server, and how it can obtain an
71 * array of <code>User</code> objects, each of which is an abstract
72 * representation of an AFS user.<BR><BR>
73 *
74 * <PRE>
75 * import org.openafs.jafs.AFSException;
76 * import org.openafs.jafs.Cell;
77 * import org.openafs.jafs.Partition;
78 * import org.openafs.jafs.Server;
79 * import org.openafs.jafs.Token;
80 * import org.openafs.jafs.User;
81 * ...
82 * public class ...
83 * {
84 * ...
85 * private Cell cell;
86 * private Server server;
87 * private Token token;
88 * ...
89 * public static void main(String[] args) throws Exception
90 * {
91 * String username = arg[0];
92 * String password = arg[1];
93 * String cellName = arg[2];
94 * String serverName = arg[3];
95 *
96 * token = new Token(username, password, cellName);
97 * cell = new Cell(token);
98 * server = cell.getServer(serverName);
99 *
100 * User[] users = cell.getUsers();
101 * ...
102 * }
103 * ...
104 * }
105 * </PRE>
106 *
107 */
108 public class Cell implements java.io.Serializable
109 {
110 protected ArrayList users;
111 protected ArrayList userNames;
112 protected ArrayList groups;
113 protected ArrayList groupNames;
114 protected ArrayList servers;
115 protected ArrayList serverNames;
116
117 protected String name;
118 protected long cellHandle;
119 protected Token token;
120
121 protected int maxGroupID;
122 protected int maxUserID;
123
124 protected GregorianCalendar tokenExpiration;
125
126 protected boolean cachedInfo;
127
128 /**
129 * Constructs a new <CODE>Cell</CODE> object instance given
130 * the <code>Token</code> that should represents an authenticated user
131 * with administrative access. In order to get full access to the cell,
132 * it is best that the <code>Token</code> provided have administrative
133 * privileges.
134 *
135 * @param token the user's authenticated token
136 * @exception AFSException If an error occurs in the native code
137 */
138 public Cell( Token token )
139 throws AFSException
140 {
141 this.token = token;
142 this.name = token.getCellName();
143
144 cellHandle = getCellHandle( name, token.getHandle() );
145 //System.out.println("cellHandle: " + cellHandle);
146 users = null;
147 userNames = null;
148 groups = null;
149 groupNames = null;
150 servers = null;
151 serverNames = null;
152 cachedInfo = false;
153 tokenExpiration = null;
154 }
155
156 /**
157 * Constructs a new <CODE>Cell</CODE> object instance given
158 * the <code>Token</code> that should represents an authenticated user
159 * with administrative access. In order to get full access to the cell,
160 * it is best that the <code>Token</code> provided have administrative
161 * privileges.
162 *
163 * <P> This constructor is ideal for point-in-time representation and
164 * transient applications. It ensures all data member values are set
165 * and available without calling back to the filesystem at the first
166 * request for them. Use the {@link #refresh()} method to address any
167 * coherency concerns.
168 *
169 * @param token the user's authenticated token
170 * @param preloadAllMembers true will ensure all object members are
171 * set upon construction; otherwise members
172 * will be set upon access, which is the default
173 * behavior.
174 * @exception AFSException If an error occurs in the native code
175 * @see #refresh
176 */
177 public Cell( Token token, boolean preloadAllMembers )
178 throws AFSException
179 {
180 this(token);
181 if (preloadAllMembers) refresh(true);
182 }
183
184 /**
185 * Refreshes the properties of this Cell object instance with values
186 * from the AFS cell it represents. All properties that have been
187 * initialized and/or accessed will be renewed according to the values
188 * of the AFS cell this Cell object instance represents.
189 *
190 * <P>Since in most environments administrative changes can be administered
191 * from an AFS command-line program or an alternate GUI application, this
192 * method provides a means to refresh the Java object representation and
193 * thereby ascertain any possible modifications that may have been made
194 * from such alternate administrative programs. Using this method before
195 * an associated instance accessor will ensure the highest level of
196 * representative accuracy, accommodating changes made external to the
197 * Java application space. If administrative changes to the underlying AFS
198 * system are only allowed via this API, then the use of this method is
199 * unnecessary.
200 *
201 * @exception AFSException If an error occurs in the native code
202 */
203 public void refresh() throws AFSException
204 {
205 this.refresh(false);
206 }
207
208 /**
209 * Refreshes the properties of this Cell object instance with values
210 * from the AFS cell it represents. If <CODE>all</CODE> is <CODE>true</CODE>
211 * then <U>all</U> of the properties of this Cell object instance will be
212 * set, or renewed, according to the values of the AFS cell it represents,
213 * disregarding any previously set properties.
214 *
215 * <P> Thus, if <CODE>all</CODE> is <CODE>false</CODE> then properties that
216 * are currently set will be refreshed and properties that are not set will
217 * remain uninitialized. See {@link #refresh()} for more information.
218 *
219 * @param all if true set or renew all object properties; otherwise
220 * renew all set properties
221 * @exception AFSException If an error occurs in the native code
222 * @see #refresh()
223 */
224 protected void refresh(boolean all) throws AFSException
225 {
226 if( all || (users != null) ) {
227 refreshUsers();
228 }
229 if( all || (userNames != null) ) {
230 refreshUserNames();
231 }
232 if( all || (groups != null) ) {
233 refreshGroups();
234 }
235 if( all || (groupNames != null) ) {
236 refreshGroupNames();
237 }
238 if( all || (servers != null) ) {
239 refreshServers();
240 }
241 if( all || (serverNames != null) ) {
242 refreshServerNames();
243 }
244 if( all || cachedInfo ) {
245 refreshInfo();
246 }
247 }
248
249 /**
250 * Obtains the expiration time of the token being used by this
251 * <code>Cell</code> object. Does not actually refresh the token; that is,
252 * once a token is obtained, its expiration time will not change. This
253 * method is mostly for consistency with the other methods. It is mainly
254 * used for getting the token information once; after that, it need not
255 * be called again.
256 *
257 * @exception AFSException If an error occurs in the native code
258 */
259 private void refreshTokenExpiration() throws AFSException
260 {
261 long expTime;
262
263 expTime = token.getExpiration();
264
265 tokenExpiration = new GregorianCalendar();
266 long longTime = expTime*1000;
267 Date d = new Date( longTime );
268 tokenExpiration.setTime( d );
269 }
270
271 /**
272 * Sets all the information fields of this <code>Cell</code> object,
273 * such as max group and user ids, to trheir most current values.
274 *
275 * @exception AFSException If an error occurs in the native code
276 */
277 protected void refreshInfo() throws AFSException
278 {
279 maxGroupID = getMaxGroupID( cellHandle );
280 maxUserID = getMaxUserID( cellHandle );
281 cachedInfo = true;
282 }
283
284 /**
285 * Obtains the most current list of <code>User</code> objects of this cell.
286 * Finds all users that currently have a kas and/or pts entry for this cell.
287 *
288 * @exception AFSException If an error occurs in the native code
289 */
290 protected void refreshUsers() throws AFSException
291 {
292 User currUser;
293 users = new ArrayList();
294
295 // get kas entries
296 long iterationId = getKasUsersBegin( cellHandle );
297
298 currUser = new User( this );
299 boolean authorized = false;
300 int r = 1;
301 while( r != 0 ) {
302 try {
303 if (authorized) {
304 users.add( currUser );
305 currUser = new User( this );
306 }
307 r = getKasUsersNext( cellHandle, iterationId, currUser );
308 authorized = true;
309 } catch (AFSException e) {
310 System.err.println("ERROR Cell::refreshUsers():kas (User: "
311 + currUser.getName() + ") -> " + e.getMessage());
312 authorized = false;
313 //if (org.openafs.jafs.ErrorCodes.isPermissionDenied(e.getErrorCode()))
314 //r = 0;
315 }
316 }
317 getKasUsersDone( iterationId );
318
319 //take the union with the pts entries
320 iterationId = getPtsUsersBegin( cellHandle );
321 authorized = false;
322 r = 1;
323 while( r != 0 ) {
324 try {
325 if (authorized) {
326 if( !users.contains( currUser ) ) {
327 users.add( currUser );
328 }
329 currUser = new User( this );
330 }
331 r = getPtsOnlyUsersNext( cellHandle, iterationId, currUser );
332 authorized = true;
333 } catch (AFSException e) {
334 System.err.println("ERROR Cell::refreshUsers():pts (User: "
335 + currUser.getName() + ") -> " + e.getMessage());
336 authorized = false;
337 //if (org.openafs.jafs.ErrorCodes.isPermissionDenied(e.getErrorCode()))
338 // r = 0;
339 }
340 }
341 getPtsUsersDone( iterationId );
342
343 }
344
345 /**
346 * Obtains the most current list of user names of this cell. Finds
347 * all users that currently have a kas and/or pts entry for this cell.
348 *
349 * @exception AFSException If an error occurs in the native code
350 */
351 protected void refreshUserNames() throws AFSException
352 {
353 String currName;
354 userNames = new ArrayList();
355
356 // get kas entries
357 long iterationId = getKasUsersBegin( cellHandle );
358 while( ( currName = getKasUsersNextString( iterationId )) != null ) {
359 userNames.add( currName );
360 }
361 getKasUsersDone( iterationId );
362
363 //take the union with the pts entries
364 iterationId = Cell.getPtsUsersBegin( cellHandle );
365 while( ( currName = getPtsOnlyUsersNextString( iterationId, cellHandle ) )
366 != null ) {
367 if( !userNames.contains( currName ) ) {
368 userNames.add( currName );
369 }
370 }
371 getPtsUsersDone( iterationId );
372 }
373
374
375 /**
376 * Obtains the most current list of <code>Group</code> objects of this cell.
377 *
378 * @exception AFSException If an error occurs in the native code
379 */
380 protected void refreshGroups() throws AFSException
381 {
382 Group currGroup;
383
384 long iterationId = getGroupsBegin( cellHandle );
385
386 groups = new ArrayList();
387
388 currGroup = new Group( this );
389 boolean authorized = false;
390 int r = 1;
391 while( r != 0 ) {
392 try {
393 if (authorized) {
394 groups.add( currGroup );
395 currGroup = new Group( this );
396 }
397 r = getGroupsNext( cellHandle, iterationId, currGroup );
398 authorized = true;
399 } catch (AFSException e) {
400 e.printStackTrace();
401
402 // System.err.println("ERROR Cell::refreshGroups() (Group: "
403 // + currGroup.getName() + ") -> " + e.getMessage());
404 authorized = false;
405 //if (org.openafs.jafs.ErrorCodes.isPermissionDenied(e.getErrorCode()))
406 // r = 0;
407 }
408 }
409 Cell.getGroupsDone( iterationId );
410 }
411
412 /**
413 * Obtains the most current list of group names of this cell.
414 *
415 * @exception AFSException If an error occurs in the native code
416 */
417 protected void refreshGroupNames() throws AFSException
418 {
419 String currName;
420
421 long iterationId = getGroupsBegin( cellHandle );
422
423 groupNames = new ArrayList();
424 while( ( currName = getGroupsNextString( iterationId ) ) != null ) {
425 groupNames.add( currName );
426 }
427 getGroupsDone( iterationId );
428 }
429
430 /**
431 * Obtains the most current list of <code>Server</code> objects of this cell.
432 *
433 * @exception AFSException If an error occurs in the native code
434 */
435 protected void refreshServers() throws AFSException
436 {
437 Server currServer;
438
439 long iterationId = getServersBegin( cellHandle );
440
441 servers = new ArrayList();
442
443 currServer = new Server( this );
444 boolean authorized = false;
445 int r = 1;
446 while( r != 0 ) {
447 try {
448 if (authorized) {
449 //System.out.println("[Java] Cell::refreshServers() -> adding server: "
450 // + currServer.getName());
451 servers.add( currServer );
452 currServer = new Server( this );
453 }
454 r = getServersNext( cellHandle, iterationId, currServer );
455 //System.out.println("[Java] Cell::refreshServers() -> r: " + r);
456 authorized = true;
457 } catch (AFSException e) {
458 System.err.println("ERROR Cell::refreshServers() (Server: "
459 + currServer.getName() + ") -> " + e.getMessage());
460 authorized = false;
461 //if (e.getErrorCode() == org.openafs.jafs.ErrorCodes.PERMISSION_DENIED)
462 // r = 0;
463 }
464 }
465 getServersDone( iterationId );
466 }
467
468 /**
469 * Obtains the most current list of server names of this cell.
470 *
471 * @exception AFSException If an error occurs in the native code
472 */
473 protected void refreshServerNames()
474 throws AFSException
475 {
476 String currName;
477
478 long iterationId = getServersBegin( cellHandle );
479
480 serverNames = new ArrayList();
481 while( ( currName = getServersNextString( iterationId ) ) != null ) {
482 serverNames.add( currName );
483 }
484 getServersDone( iterationId );
485 }
486
487 /**
488 * Unauthenticates this </code>Token</code> object associated with this
489 * <code>Cell</code> and deletes all of its stored information. This
490 * method should only be called when this <code>Cell</code> or any of the
491 * objects constructed using this <code>Cell</code> will not be used
492 * anymore. Note that this does not delete the actual AFS cell that this
493 * <code>Cell</code> object represents; it merely closes the
494 * representation.
495 *
496 * @exception AFSException If an error occurs in the native code
497 */
498 public void close() throws AFSException
499 {
500 Cell.closeCell( cellHandle );
501 token.close();
502 users = null;
503 userNames = null;
504 groups = null;
505 groupNames = null;
506 servers = null;
507 serverNames = null;
508 cachedInfo = false;
509 tokenExpiration = null;
510 }
511
512 //////////////// ACCESSORS ////////////////////////
513
514 /**
515 * Retrieves the <CODE>User</CODE> object (which is an abstract
516 * representation of an actual AFS user) designated by <code>name</code>.
517 * If a user by that name does not actually exist in AFS in the cell
518 * represented by this object, an {@link AFSException} will be
519 * thrown.
520 *
521 * @exception AFSException If an error occurs in the native code
522 * @exception NullPointerException If <CODE>name</CODE> is
523 * <CODE>null</CODE>.
524 * @param name the name of the user to retrieve
525 * @return <CODE>User</CODE> designated by <code>name</code>.
526 */
527 public User getUser(String name) throws AFSException
528 {
529 if (name == null) throw new NullPointerException();
530 User user = new User(name, this);
531 return user;
532 }
533
534 /**
535 * Returns the total number of users who are registered with KAS and PTS,
536 * without duplicates. If a user has a KAS entry and not a PTS entry,
537 * it will still be counted. Conversely, if a user has a PTS entry and
538 * not KAS, it too will be counted. Effectively it is a non-duplicate
539 * union of KAS and PTS user entries.
540 *
541 * <P>If the total list of users or user names have already been
542 * collected (see {@link #getUsers()}), then the returning value will be
543 * calculated based upon the current list. Otherwise, KAS and PTS will be
544 * explicitly queried for the information.
545 *
546 * @exception AFSException If an error occurs in the native code
547 * @return a <code>User</code> array of the users of the cell.
548 * @see #getUsers()
549 * @see #getUserNames()
550 */
551 public int getUserCount() throws AFSException
552 {
553 if( users != null ) {
554 return users.size();
555 } else if( userNames != null ) {
556 return userNames.size();
557 } else {
558 int k = getKasUserCount(cellHandle);
559 int p = getPtsOnlyUserCount(cellHandle);
560 return k + p;
561 }
562 }
563
564 /**
565 * Retrieves an array containing all of the <code>User</code> objects
566 * associated with this <code>Cell</code>, each of which are an abstract
567 * representation of an actual user of the AFS cell. After this method
568 * is called once, it saves the array of <code>User</code>s and returns
569 * that saved array on subsequent calls, until the {@link #refresh()} method
570 * is called and a more current list is obtained.
571 *
572 * @exception AFSException If an error occurs in the native code
573 * @return a <code>User</code> array of the users of the cell.
574 */
575 public User[] getUsers() throws AFSException
576 {
577 if( users == null ) refreshUsers();
578 return (User[]) users.toArray( new User[users.size()] );
579 }
580
581 /**
582 * Returns an array containing a subset of the <code>User</code> objects
583 * associated with this <code>Cell</code>, each of which is an abstract
584 * representation of an actual AFS user of the AFS cell. The subset
585 * is a point-in-time list of users (<code>User</code> objects
586 * representing AFS users) starting at the complete array's index of
587 * <code>startIndex</code> and containing up to <code>length</code>
588 * elements.
589 *
590 * If <code>length</code> is larger than the number of remaining elements,
591 * respective to <code>startIndex</code>, then this method will
592 * ignore the remaining positions requested by <code>length</code> and
593 * return an array that contains the remaining number of elements found in
594 * this cell's complete array of users.
595 *
596 * <P>This method is especially useful when managing iterations of very
597 * large lists. {@link #getUserCount()} can be used to determine if
598 * iteration management is practical.
599 *
600 * <P>This method does not save the resulting data and therefore
601 * queries AFS for each call.
602 *
603 * <P><B>Note:</B> PTS-only users are collected before KAS users
604 * and therefore will always, if PTS-only users exist, be within the
605 * lowest range of this cell's complete list of users. PTS and KAS
606 * users are joined in a non-duplicating union and are consequently
607 * treated as a single list of users, thus <code>startIndex</code>
608 * does not necessarily indicate the first KAS user.
609 *
610 * <P><B>Example:</B> If there are more than 50,000 users within this cell
611 * then only render them in increments of 10,000.
612 * <PRE>
613 * ...
614 * User[] users;
615 * if (cell.getUserCount() > 50000) {
616 * int index = 0;
617 * int length = 10000;
618 * while (index < cell.getUserCount()) {
619 * users = cell.<B>getUsers</B>(index, length);
620 * for (int i = 0; i < users.length; i++) {
621 * ...
622 * }
623 * index += length;
624 * ...
625 * }
626 * } else {
627 * users = cell.getUsers();
628 * for (int i = 0; i < users.length; i++) {
629 * ...
630 * }
631 * }
632 * ...
633 * </PRE>
634 *
635 * @param startIndex the base zero index position at which the subset array
636 * should start from, relative to the complete list of
637 * elements present in AFS.
638 * @param length the number of elements that the subset should contain
639 * @return a subset array of users in this cell
640 * @exception AFSException If an error occurs in the native code
641 * @see #getUserCount()
642 * @see #getUserNames(int, int)
643 * @see #getUsers()
644 */
645 public User[] getUsers(int startIndex, int length) throws AFSException
646 {
647 User[] users = new User[length];
648 User currUser = new User( this );
649 int ptsOnlyCount = getPtsOnlyUserCount(cellHandle);
650 long iterationID = 0;
651 int indexPTS = 0;
652 int indexKAS = 0;
653
654 if (startIndex < ptsOnlyCount) {
655 int i = 0;
656 iterationID = getPtsUsersBegin(cellHandle);
657 while( getPtsOnlyUsersNext( cellHandle, iterationID, currUser ) != 0 &&
658 indexPTS < length )
659 {
660 if (i >= startIndex) {
661 users[indexPTS] = currUser;
662 currUser = new User( this );
663 indexPTS++;
664 }
665 }
666 getPtsUsersDone( iterationID );
667
668 if (indexPTS < length) {
669 startIndex = 0;
670 length -= indexPTS;
671 } else {
672 return users;
673 }
674 } else {
675 startIndex -= (ptsOnlyCount - 1);
676 }
677
678 iterationID = getKasUsersBeginAt( cellHandle, startIndex );
679 while( getKasUsersNext(cellHandle, iterationID, currUser ) != 0 &&
680 indexKAS < length )
681 {
682 users[indexKAS] = currUser;
683 currUser = new User( this );
684 indexKAS++;
685 }
686 getKasUsersDone( iterationID );
687
688 if (indexKAS < length) {
689 User[] u = new User[indexKAS + indexPTS];
690 System.arraycopy(users, 0, u, 0, u.length);
691 return u;
692 } else {
693 return users;
694 }
695 }
696
697 /**
698 * Retrieves an array containing all of the names of users
699 * associated with this <code>Cell</code>. After this method
700 * is called once, it saves the array of <code>String</code>s and returns
701 * that saved array on subsequent calls, until the {@link #refresh()} method
702 * is called and a more current list is obtained.
703 *
704 * <P>This method is especially useful when managing iterations of
705 * large lists. {@link #getUserCount()} can be used to determine if
706 * iteration management is practical. In comparison to {@link #getUsers()},
707 * this method has yielded an average performance advantage of approximately
708 * 82% at 10K users; this statistic, however, strictly compares the response
709 * time of each method and understands that the {@link #getUsers()} method
710 * will return an array of populated <code>User</code> objects, whereas this
711 * method will return an array of <code>String</code> names.
712 * <BR><BR>
713 *
714 * @return an <code>String</code> array of the user names of the cell.
715 * @exception AFSException If an error occurs in the native code
716 */
717 public String[] getUserNames() throws AFSException
718 {
719 if( userNames == null ) refreshUserNames();
720 return (String[]) userNames.toArray( new String[userNames.size()] );
721 }
722
723 /**
724 * Returns an array containing a subset of the names of users
725 * associated with this <code>Cell</code>. The subset
726 * is a point-in-time list of users (<code>String</code> names
727 * of AFS users) starting at the complete array's index of
728 * <code>startIndex</code> and containing up to <code>length</code>
729 * elements.
730 *
731 * If <code>length</code> is larger than the number of remaining elements,
732 * respective to <code>startIndex</code>, then this method will
733 * ignore the remaining positions requested by <code>length</code> and
734 * return an array that contains the remaining number of elements found in
735 * this cell's complete array of users.
736 *
737 * <P>This method is especially useful when managing iterations of very
738 * large lists. {@link #getUserCount()} can be used to determine if
739 * iteration management is practical.
740 *
741 * <P>This method does not save the resulting data and therefore
742 * queries AFS for each call.
743 *
744 * <P><B>Note:</B> PTS-only users are collected before KAS users
745 * and therefore will always, if PTS-only users exist, be within the
746 * lowest range of this cell's complete list of users. PTS and KAS
747 * users are joined in a non-duplicating union and are consequently
748 * treated as a single list of users, thus <code>startIndex</code>
749 * does not necessarily indicate the first KAS user.
750 *
751 * <P><B>Example:</B> If there are more than 50,000 users within this cell
752 * then only render them in increments of 10,000.
753 * <PRE>
754 * ...
755 * String[] users;
756 * if (cell.getUserCount() > 50000) {
757 * int index = 0;
758 * int length = 10000;
759 * while (index < cell.getUserCount()) {
760 * users = cell.<B>getUserNames</B>(index, length);
761 * for (int i = 0; i < users.length; i++) {
762 * ...
763 * }
764 * index += length;
765 * ...
766 * }
767 * } else {
768 * users = cell.getUserNames();
769 * for (int i = 0; i < users.length; i++) {
770 * ...
771 * }
772 * }
773 * ...
774 * </PRE>
775 *
776 * @param startIndex the base zero index position at which the subset array
777 * should start from, relative to the complete list of
778 * elements present in AFS.
779 * @param length the number of elements that the subset should contain
780 * @return a subset array of user names in this cell
781 * @exception AFSException If an error occurs in the native code
782 * @see #getUserCount()
783 * @see #getUserNames()
784 * @see #getUsers(int, int)
785 */
786 public String[] getUserNames(int startIndex, int length)
787 throws AFSException
788 {
789 String[] users = new String[length];
790 String currUser;
791 int ptsOnlyCount = getPtsOnlyUserCount(cellHandle);
792 long iterationID = 0;
793 int indexPTS = 0;
794 int indexKAS = 0;
795
796 if (startIndex < ptsOnlyCount) {
797 int i = 0;
798 iterationID = getPtsUsersBegin(cellHandle);
799 while( (currUser = getPtsOnlyUsersNextString( iterationID, cellHandle ))
800 != null && indexPTS < length ) {
801 if (i >= startIndex) {
802 users[indexPTS] = currUser;
803 indexPTS++;
804 }
805 }
806 getPtsUsersDone( iterationID );
807
808 if (indexPTS < length) {
809 startIndex = 0;
810 length -= indexPTS;
811 } else {
812 return users;
813 }
814 } else {
815 startIndex -= (ptsOnlyCount - 1);
816 }
817
818 iterationID = getKasUsersBeginAt( cellHandle, startIndex );
819 while( (currUser = getKasUsersNextString( iterationID )) != null &&
820 indexKAS < length ) {
821 users[indexKAS] = currUser;
822 indexKAS++;
823 }
824 getKasUsersDone( iterationID );
825
826 if (indexKAS < length) {
827 String[] u = new String[indexKAS + indexPTS];
828 System.arraycopy(users, 0, u, 0, u.length);
829 return u;
830 } else {
831 return users;
832 }
833 }
834
835 /**
836 * Retrieves the <CODE>Group</CODE> object (which is an abstract
837 * representation of an actual AFS group) designated by <code>name</code>.
838 * If a group by that name does not actually exist in AFS in the cell
839 * represented by this object, an {@link AFSException} will be
840 * thrown.
841 *
842 * @exception AFSException If an error occurs in the native code
843 * @exception NullPointerException If <CODE>name</CODE> is
844 * <CODE>null</CODE>.
845 * @param name the name of the group to retrieve
846 * @return <CODE>Group</CODE> designated by <code>name</code>.
847 */
848 public Group getGroup(String name) throws AFSException
849 {
850 if (name == null) throw new NullPointerException();
851 Group group = new Group(name, this);
852 group.refresh(true);
853 return group;
854 }
855
856 /**
857 * Returns the total number of groups associated with this Cell.
858 *
859 * <P>If the total list of groups or group names have already been
860 * collected (see {@link #getGroups()}), then the returning value will be
861 * calculated based upon the current list. Otherwise, PTS will be
862 * explicitly queried for the information.
863 *
864 * @exception AFSException If an error occurs in the native code
865 * @return a <code>User</code> array of the users of the cell.
866 * @see #getGroups()
867 * @see #getGroupNames()
868 */
869 public int getGroupCount() throws AFSException
870 {
871 if( groups != null ) {
872 return groups.size();
873 } else if( groupNames != null ) {
874 return groupNames.size();
875 } else {
876 return getGroupCount(cellHandle);
877 }
878 }
879
880 /**
881 * Retrieves an array containing all of the <code>Group</code> objects
882 * associated with this <code>Cell</code>, each of which are an abstract
883 * representation of an actual group of the AFS cell. After this method
884 * is called once, it saves the array of <code>Group</code>s and returns
885 * that saved array on subsequent calls, until the {@link #refresh()} method
886 * is called and a more current list is obtained.
887 *
888 * @exception AFSException If an error occurs in the native code
889 * @return a <code>Group</code> array of the groups of the cell.
890 */
891 public Group[] getGroups() throws AFSException
892 {
893 if( groups == null ) refreshGroups();
894 return (Group[]) groups.toArray( new Group[groups.size()] );
895 }
896
897 /**
898 * Returns an array containing a subset of the <code>Group</code> objects
899 * associated with this <code>Cell</code>, each of which is an abstract
900 * representation of an actual AFS group of the AFS cell. The subset
901 * is a point-in-time list of groups (<code>Group</code> objects
902 * representing AFS groups) starting at the complete array's index of
903 * <code>startIndex</code> and containing up to <code>length</code>
904 * elements.
905 *
906 * If <code>length</code> is larger than the number of remaining elements,
907 * respective to <code>startIndex</code>, then this method will
908 * ignore the remaining positions requested by <code>length</code> and
909 * return an array that contains the remaining number of elements found in
910 * this cell's complete array of groups.
911 *
912 * <P>This method is especially useful when managing iterations of very
913 * large lists. {@link #getGroupCount()} can be used to determine if
914 * iteration management is practical.
915 *
916 * <P>This method does not save the resulting data and therefore
917 * queries AFS for each call.
918 *
919 * <P><B>Example:</B> If there are more than 50,000 groups within this cell
920 * then only render them in increments of 10,000.
921 * <PRE>
922 * ...
923 * Group[] groups;
924 * if (cell.getGroupCount() > 50000) {
925 * int index = 0;
926 * int length = 10000;
927 * while (index < cell.getGroupCount()) {
928 * groups = cell.<B>getGroups</B>(index, length);
929 * for (int i = 0; i < groups.length; i++) {
930 * ...
931 * }
932 * index += length;
933 * ...
934 * }
935 * } else {
936 * groups = cell.getGroups();
937 * for (int i = 0; i < groups.length; i++) {
938 * ...
939 * }
940 * }
941 * ...
942 * </PRE>
943 *
944 * @param startIndex the base zero index position at which the subset array
945 * should start from, relative to the complete list of
946 * elements present in AFS.
947 * @param length the number of elements that the subset should contain
948 * @return a subset array of groups in this cell
949 * @exception AFSException If an error occurs in the native code
950 * @see #getGroupCount()
951 * @see #getGroupNames(int, int)
952 * @see #getGroups()
953 */
954 public Group[] getGroups(int startIndex, int length) throws AFSException
955 {
956 Group[] groups = new Group[length];
957 Group currGroup = new Group( this );
958 int i = 0;
959
960 long iterationID = getGroupsBeginAt( cellHandle, startIndex );
961
962 while( getGroupsNext( cellHandle, iterationID, currGroup ) != 0
963 && i < length ) {
964 groups[i] = currGroup;
965 currGroup = new Group( this );
966 i++;
967 }
968 getGroupsDone( iterationID );
969 if (i < length) {
970 Group[] v = new Group[i];
971 System.arraycopy(groups, 0, v, 0, i);
972 return v;
973 } else {
974 return groups;
975 }
976 }
977
978 /**
979 * Retrieves an array containing all of the names of groups
980 * associated with this <code>Cell</code>. After this method
981 * is called once, it saves the array of <code>String</code>s and returns
982 * that saved array on subsequent calls, until the {@link #refresh()} method
983 * is called and a more current list is obtained.
984 *
985 * @exception AFSException If an error occurs in the native code
986 * @return a <code>String</code> array of the group names of the cell.
987 */
988 public String[] getGroupNames() throws AFSException
989 {
990 if( groupNames == null ) refreshGroupNames();
991 return (String[]) groupNames.toArray( new String[groupNames.size()] );
992 }
993
994 /**
995 * Returns an array containing a subset of the names of groups
996 * associated with this <code>Cell</code>. The subset
997 * is a point-in-time list of groups (<code>String</code> names
998 * of AFS groups) starting at the complete array's index of
999 * <code>startIndex</code> and containing up to <code>length</code>
1000 * elements.
1001 *
1002 * If <code>length</code> is larger than the number of remaining elements,
1003 * respective to <code>startIndex</code>, then this method will
1004 * ignore the remaining positions requested by <code>length</code> and
1005 * return an array that contains the remaining number of elements found in
1006 * this cell's complete array of groups.
1007 *
1008 * <P>This method is especially useful when managing iterations of very
1009 * large lists. {@link #getGroupCount()} can be used to determine if
1010 * iteration management is practical.
1011 *
1012 * <P>This method does not save the resulting data and therefore
1013 * queries AFS for each call.
1014 *
1015 * <P><B>Example:</B> If there are more than 50,000 groups within this cell
1016 * then only render them in increments of 10,000.
1017 * <PRE>
1018 * ...
1019 * String[] groups;
1020 * if (cell.getGroupCount() > 50000) {
1021 * int index = 0;
1022 * int length = 10000;
1023 * while (index < cell.getGroupCount()) {
1024 * groups = cell.<B>getGroupNames</B>(index, length);
1025 * for (int i = 0; i < groups.length; i++) {
1026 * ...
1027 * }
1028 * index += length;
1029 * ...
1030 * }
1031 * } else {
1032 * groups = cell.getGroupNames();
1033 * for (int i = 0; i < groups.length; i++) {
1034 * ...
1035 * }
1036 * }
1037 * ...
1038 * </PRE>
1039 *
1040 * @param startIndex the base zero index position at which the subset array
1041 * should start from, relative to the complete list of
1042 * elements present in AFS.
1043 * @param length the number of elements that the subset should contain
1044 * @return a subset array of group names in this cell
1045 * @exception AFSException If an error occurs in the native code
1046 * @see #getGroupCount()
1047 * @see #getGroups(int, int)
1048 * @see #getGroupNames()
1049 */
1050 public String[] getGroupNames(int startIndex, int length)
1051 throws AFSException
1052 {
1053 String[] groups = new String[length];
1054 String currGroup;
1055 int i = 0;
1056
1057 long iterationID = getGroupsBeginAt( cellHandle, startIndex );
1058
1059 while( (currGroup = getGroupsNextString( iterationID )) != null &&
1060 i < length )
1061 {
1062 groups[i] = currGroup;
1063 i++;
1064 }
1065 getGroupsDone( iterationID );
1066 if (i < length) {
1067 String[] v = new String[i];
1068 System.arraycopy(groups, 0, v, 0, i);
1069 return v;
1070 } else {
1071 return groups;
1072 }
1073 }
1074
1075 /**
1076 * Retrieves the <CODE>Server</CODE> object (which is an abstract
1077 * representation of an actual AFS server) designated by <code>name</code>.
1078 * If a group by that name does not actually exist in AFS in the cell
1079 * represented by this object, an {@link AFSException} will be
1080 * thrown.
1081 *
1082 * @exception AFSException If an error occurs in the native code
1083 * @exception NullPointerException If <CODE>name</CODE> is
1084 * <CODE>null</CODE>.
1085 * @param name the name of the server to retrieve
1086 * @return <CODE>Server</CODE> designated by <code>name</code>.
1087 */
1088 public Server getServer(String name)
1089 throws AFSException
1090 {
1091 if (name == null) throw new NullPointerException();
1092 Server server = new Server(name, this);
1093 server.refresh(true);
1094 return server;
1095 }
1096
1097 /**
1098 * Returns the total number of servers associated with this Cell.
1099 *
1100 * <P>If the total list of servers or server names have already been
1101 * collected (see {@link #getServers()}), then the returning value will be
1102 * calculated based upon the current list. Otherwise, AFS will be
1103 * explicitly queried for the information.
1104 *
1105 * @exception AFSException If an error occurs in the native code
1106 * @return a <code>User</code> array of the users of the cell.
1107 * @see #getServers()
1108 * @see #getServerNames()
1109 */
1110 public int getServerCount() throws AFSException
1111 {
1112 if( servers != null ) {
1113 return servers.size();
1114 } else if( serverNames != null ) {
1115 return serverNames.size();
1116 } else {
1117 return getServerCount(cellHandle);
1118 }
1119 }
1120
1121 /**
1122 * Retrieves an array containing all of the <code>Server</code> objects
1123 * associated with this <code>Cell</code>, each of which are an abstract
1124 * representation of an actual server of the AFS cell. After this method
1125 * is called once, it saves the array of <code>Server</code>s and returns
1126 * that saved array on subsequent calls, until the {@link #refresh()} method
1127 * is called and a more current list is obtained.
1128 *
1129 * @exception AFSException If an error occurs in the native code
1130 * @return an <code>Server</code> array of the servers of the cell.
1131 */
1132 public Server[] getServers() throws AFSException
1133 {
1134 if ( servers == null ) refreshServers();
1135 return (Server[]) servers.toArray( new Server[servers.size()] );
1136 }
1137
1138 /**
1139 * Retrieves an array containing all of the names of servers
1140 * associated with this <code>Cell</code>. After this method
1141 * is called once, it saves the array of <code>String</code>s and returns
1142 * that saved array on subsequent calls, until the {@link #refresh()} method
1143 * is called and a more current list is obtained.
1144 *
1145 * @exception AFSException If an error occurs in the native code
1146 * @return a <code>String</code> array of the servers of the cell.
1147 */
1148 public String[] getServerNames() throws AFSException
1149 {
1150 if ( serverNames == null ) refreshServerNames();
1151 return (String[]) serverNames.toArray( new String[serverNames.size()] );
1152 }
1153
1154 /**
1155 * Returns the maximum group ID that's been used within the cell.
1156 * The next auto-assigned group ID will be one less (more negative)
1157 * than this amount. After this method is called once, it saves the
1158 * max group id and returns that id on subsequent calls, until the
1159 * {@link #refresh()} method is called and a more current id is obtained.
1160 *
1161 * @return an integer representing the maximum group ID
1162 * @exception AFSException If an error occurs in the native code
1163 */
1164 public int getMaxGroupID() throws AFSException
1165 {
1166 if( !cachedInfo ) refreshInfo();
1167 return maxGroupID;
1168
1169 }
1170
1171 /**
1172 * Returns the maximum user ID that's been used within the cell.
1173 * The next auto-assigned user ID will be one greater (more positive)
1174 * than this amount. After this method is called once, it saves the
1175 * max user id and returns that id on subsequent calls, until the
1176 * {@link #refresh()} method is called and a more current id is obtained.
1177 *
1178 * @return an integer representing the maximum user ID
1179 * @exception AFSException If an error occurs in the native code
1180 */
1181 public int getMaxUserID() throws AFSException
1182 {
1183 if( !cachedInfo ) refreshInfo();
1184 return maxUserID;
1185 }
1186
1187 /**
1188 * Returns the expiration time of the authentication token being used
1189 * by this <code>Cell</code> object. After this time, this
1190 * <code>Cell</code> object will no longer be authorized to perform
1191 * actions requiring administrative authority.
1192 *
1193 * @return expiration time of the token
1194 * @exception AFSException If an error occurs in the native code
1195 */
1196 public GregorianCalendar getTokenExpiration() throws AFSException
1197 {
1198 if( tokenExpiration == null ) refreshTokenExpiration();
1199 return tokenExpiration;
1200 }
1201
1202 /**
1203 * Returns the cell handle of this cell.
1204 *
1205 * @return the cell handle
1206 * @exception AFSException If an error occurs in the native code
1207 */
1208 public long getCellHandle() throws AFSException
1209 {
1210 return cellHandle;
1211 }
1212
1213 /**
1214 * Returns the name of this cell.
1215 *
1216 * @return the cell name
1217 */
1218 public String getName()
1219 {
1220 return name;
1221 }
1222
1223 /**
1224 * Sets the maximum group ID that's been used within the cell. The next
1225 * auto-assigned group ID will be one less (more negative) than this amount.
1226 *
1227 * @param maxID an integer representing the maximum group ID
1228 * @exception AFSException If an error occurs in the native code
1229 */
1230 public void setMaxGroupID( int maxID ) throws AFSException
1231 {
1232 setMaxGroupID( cellHandle, maxID );
1233 maxGroupID = maxID;
1234 }
1235
1236 /**
1237 * Sets the maximum user ID that's been used within the cell. The next
1238 * auto-assigned user ID will be one greater (more positive) than this
1239 * amount.
1240 *
1241 * @param maxID an integer representing the maximum user ID
1242 * @exception AFSException If an error occurs in the native code
1243 */
1244 public void setMaxUserID( int maxID ) throws AFSException
1245 {
1246 setMaxUserID( cellHandle, maxID );
1247 maxUserID = maxID;
1248 }
1249
1250 /////////////// information methods ////////////////////
1251
1252 /**
1253 * Returns a <code>String</code> representation of this <code>Cell</code>.
1254 * Contains the cell name followed by the names of its users and groups.
1255 *
1256 * @return a <code>String</code> representation of this <code>Cell</code>
1257 */
1258 public String getInfo()
1259 {
1260 String r = "Cell: " + name + "\n\n";
1261 try {
1262 r += "\tMax group ID: " + getMaxGroupID() + "\n";
1263 r += "\tMax user ID: " + getMaxUserID() + "\n";
1264 r += "\tToken expiration: " + getTokenExpiration().getTime() + "\n";
1265 } catch( AFSException e ) {
1266 return e.toString();
1267 }
1268
1269 String[] servs;
1270 String[] usrs;
1271 String[] grps;
1272 try {
1273 usrs = getUserNames();
1274 grps = getGroupNames();
1275 servs = getServerNames();
1276
1277 } catch( Exception e ) {
1278 return e.toString();
1279 }
1280
1281 r += "--Users--\n";
1282
1283 for( int i = 0; i < usrs.length; i++ ) {
1284
1285 r += usrs[i] + "\n";
1286 }
1287
1288 r += "\n--Groups--\n";
1289
1290 for( int i = 0; i < grps.length; i++ ) {
1291
1292 r += grps[i] + "\n";
1293 }
1294
1295 r += "\n--Servers--\n";
1296
1297 for( int i = 0; i < servs.length; i++ ) {
1298
1299 r += servs[i] + "\n";
1300 }
1301
1302 return r;
1303 }
1304
1305 /**
1306 * Returns a <code>String</code> containing the <code>String</code>
1307 * representations of all the users of this <code>Cell</code>.
1308 *
1309 * @return a <code>String</code> representation of the users
1310 * @see User#getInfo
1311 */
1312 public String getInfoUsers() throws AFSException
1313 {
1314 String r;
1315
1316 r = "Cell: " + name + "\n\n";
1317 r += "--Users--\n";
1318
1319 User usrs[] = getUsers();
1320 for( int i = 0; i < usrs.length; i++ ) {
1321 r += usrs[i].getInfo() + "\n";
1322 }
1323
1324 return r;
1325 }
1326
1327 /**
1328 * Returns a <code>String</code> containing the <code>String</code>
1329 * representations of all the groups of this <code>Cell</code>.
1330 *
1331 * @return a <code>String</code> representation of the groups
1332 * @see Group#getInfo
1333 */
1334 public String getInfoGroups() throws AFSException
1335 {
1336 String r;
1337
1338 r = "Cell: " + name + "\n\n";
1339 r += "--Groups--\n";
1340
1341 Group grps[] = getGroups();
1342 for( int i = 0; i < grps.length; i++ ) {
1343 r += grps[i].getInfo() + "\n";
1344 }
1345 return r;
1346 }
1347
1348 /**
1349 * Returns a <code>String</code> containing the <code>String</code>
1350 * representations of all the servers of this <code>Cell</code>.
1351 *
1352 * @return a <code>String</code> representation of the servers
1353 * @see Server#getInfo
1354 */
1355 public String getInfoServers()
1356 throws AFSException
1357 {
1358 String r;
1359 r = "Cell: " + name + "\n\n";
1360 r += "--Servers--\n";
1361 Server[] servs = getServers();
1362 for( int i = 0; i < servs.length; i++ ) {
1363 r += servs[i].getInfo() + "\n";
1364 }
1365 return r;
1366 }
1367
1368 /////////////// override methods ////////////////////
1369
1370 /**
1371 * Tests whether two <code>Cell</code> objects are equal, based on their
1372 * names. Does not test whether the objects are actually the same
1373 * representational instance of the AFS cell.
1374 *
1375 * @param otherCell the <code>Cell</code> to test
1376 * @return whether the specifed user is the same as this user
1377 */
1378 public boolean equals( Cell otherCell )
1379 {
1380 return name.equals( otherCell.getName() );
1381 }
1382
1383 /**
1384 * Returns the name of this <CODE>Cell</CODE>
1385 *
1386 * @return the name of this <CODE>Cell</CODE>
1387 */
1388 public String toString()
1389 {
1390 return name;
1391 }
1392
1393 /////////////// native methods Cell ////////////////////
1394
1395 /**
1396 * Returns the total number of KAS users belonging to the cell denoted
1397 * by <CODE>cellHandle</CODE>.
1398 *
1399 * @param cellHandle the handle of the cell to which the users belong
1400 * @return total count of KAS users
1401 * @exception AFSException If an error occurs in the native code
1402 * @see Cell#getCellHandle
1403 */
1404 protected static native int getKasUserCount( long cellHandle )
1405 throws AFSException;
1406
1407 /**
1408 * Begin the process of getting the kas users that belong to the cell.
1409 * Returns an iteration ID to be used by subsequent calls to
1410 * <code>getKasUsersNextString</code> (or <code>getKasUsersNext</code>)
1411 * and <code>getKasUsersDone</code>.
1412 *
1413 * @param cellHandle the handle of the cell to which the users belong
1414 * @see Cell#getCellHandle
1415 * @return an iteration ID
1416 * @exception AFSException If an error occurs in the native code
1417 */
1418 protected static native long getKasUsersBegin( long cellHandle )
1419 throws AFSException;
1420
1421 /**
1422 * Begin the process of getting the KAS users, starting at
1423 * <code>startIndex</code>, that belong to the cell.
1424 * Returns an iteration ID to be used by subsequent calls to
1425 * <code>getKasUsersNextString</code> (or <code>getKasUsersNext</code>)
1426 * and <code>getKasUsersDone</code>.
1427 *
1428 * @param cellHandle the handle of the cell to which the users belong
1429 * @param startIndex the starting base-zero index
1430 * @return an iteration ID
1431 * @exception AFSException If an error occurs in the native code
1432 * @see Cell#getCellHandle
1433 */
1434 protected static native long getKasUsersBeginAt( long cellHandle,
1435 int startIndex )
1436 throws AFSException;
1437
1438 /**
1439 * Returns the next kas user of the cell. Returns <code>null</code> if there
1440 * are no more users. Appends instance names to principal names as follows:
1441 * <i>principal</i>.<i>instance</i>
1442 *
1443 * @param iterationId the iteration ID of this iteration
1444 * @see Cell#getKasUsersBegin
1445 * @return the name of the next user of the cell
1446 * @exception AFSException If an error occurs in the native code
1447 */
1448 protected static native String getKasUsersNextString( long iterationId )
1449 throws AFSException;
1450
1451 /**
1452 * Fills the next kas user object of the cell. Returns 0 if there
1453 * are no more users, != 0 otherwise.
1454 *
1455 * @param cellHandle the handle of the cell to which the users belong
1456 * @see Cell#getCellHandle
1457 * @param iterationId the iteration ID of this iteration
1458 * @see Cell#getKasUsersBegin
1459 * @param theUser a User object to be populated with the values of
1460 * the next kas user
1461 * @return 0 if there are no more users, != 0 otherwise
1462 * @exception AFSException If an error occurs in the native code
1463 */
1464 protected static native int getKasUsersNext( long cellHandle,
1465 long iterationId,
1466 User theUser )
1467 throws AFSException;
1468
1469 /**
1470 * Signals that the iteration is complete and will not be accessed anymore.
1471 *
1472 * @param iterationId the iteration ID of this iteration
1473 * @see Cell#getKasUsersBegin
1474 * @exception AFSException If an error occurs in the native code
1475 */
1476 protected static native void getKasUsersDone( long iterationId )
1477 throws AFSException;
1478
1479 /**
1480 * Returns the total number of PTS users belonging to the cell denoted
1481 * by <CODE>cellHandle</CODE>.
1482 *
1483 * @param cellHandle the handle of the cell to which the users belong
1484 * @return total number of PTS users
1485 * @exception AFSException If an error occurs in the native code
1486 * @see Cell#getCellHandle
1487 */
1488 protected static native int getPtsUserCount( long cellHandle )
1489 throws AFSException;
1490
1491 /**
1492 * Returns the total number of PTS users, belonging to the cell denoted
1493 * by <CODE>cellHandle</CODE>, that are not in KAS.
1494 *
1495 * @param cellHandle the handle of the cell to which the users belong
1496 * @return total number of users that are in PTS and not KAS
1497 * @exception AFSException If an error occurs in the native code
1498 * @see Cell#getCellHandle
1499 */
1500 protected static native int getPtsOnlyUserCount( long cellHandle )
1501 throws AFSException;
1502
1503 /**
1504 * Begin the process of getting the pts users that belong to the cell.
1505 * Returns an iteration ID to be used by subsequent calls to
1506 * <code>getPtsUsersNextString</code> (or <code>getPtsUsersNext</code>)
1507 * and <code>getPtsUsersDone</code>.
1508 *
1509 * @param cellHandle the handle of the cell to which the users belong
1510 * @see Cell#getCellHandle
1511 * @return an iteration ID
1512 * @exception AFSException If an error occurs in the native code
1513 */
1514 protected static native long getPtsUsersBegin( long cellHandle )
1515 throws AFSException;
1516
1517 /**
1518 * Returns the next pts user of the cell. Returns <code>null</code> if
1519 * there are no more users.
1520 *
1521 * @param iterationId the iteration ID of this iteration
1522 * @see Cell#getPtsUsersBegin
1523 * @return the name of the next user of the cell
1524 * @exception AFSException If an error occurs in the native code
1525 */
1526 protected static native String getPtsUsersNextString( long iterationId )
1527 throws AFSException;
1528
1529 /**
1530 * Returns the next pts user (who is not a kas user) of the cell.
1531 * Returns <code>null</code> if there are no more users.
1532 *
1533 * @param iterationId the iteration ID of this iteration
1534 * @param cellHandle the cell handle to which these users will belong
1535 * @see Cell#getPtsUsersBegin
1536 * @return the name of the next pts user (not kas user) of the cell
1537 * @exception AFSException If an error occurs in the native code
1538 */
1539 protected static native String getPtsOnlyUsersNextString( long iterationId,
1540 long cellHandle )
1541 throws AFSException;
1542
1543 /**
1544 * Fills the next pts user object of the cell. Returns 0 if there
1545 * are no more users, != 0 otherwise.
1546 *
1547 * @param cellHandle the handle of the cell to which the users belong
1548 * @see Cell#getCellHandle
1549 * @param iterationId the iteration ID of this iteration
1550 * @see Cell#getPtsUsersBegin
1551 * @param theUser a User object to be populated with the values of
1552 * the next pts user
1553 * @return 0 if there are no more users, != 0 otherwise
1554 * @exception AFSException If an error occurs in the native code
1555 */
1556 protected static native int getPtsUsersNext( long cellHandle, long iterationId,
1557 User theUser )
1558 throws AFSException;
1559
1560 /**
1561 * Fills the next pts user (who does not have a kas entry) object of
1562 * the cell. Returns 0 if there are no more users, != 0 otherwise.
1563 *
1564 * @param cellHandle the handle of the cell to which the users belong
1565 * @see Cell#getCellHandle
1566 * @param iterationId the iteration ID of this iteration
1567 * @see Cell#getPtsUsersBegin
1568 * @param theUser a User object to be populated with the values of
1569 * the next pts (with no kas) user
1570 * @return 0 if there are no more users, != 0 otherwise
1571 * @exception AFSException If an error occurs in the native code
1572 */
1573 protected static native int getPtsOnlyUsersNext( long cellHandle,
1574 long iterationId,
1575 User theUser )
1576 throws AFSException;
1577
1578 /**
1579 * Signals that the iteration is complete and will not be accessed anymore.
1580 *
1581 * @param iterationId the iteration ID of this iteration
1582 * @see Cell#getPtsUsersBegin
1583 * @exception AFSException If an error occurs in the native code
1584 */
1585 protected static native void getPtsUsersDone( long iterationId )
1586 throws AFSException;
1587
1588 /**
1589 * Returns the total number of groups belonging to the cell denoted
1590 * by <CODE>cellHandle</CODE>.
1591 *
1592 * @param cellHandle the handle of the cell to which the groups belong
1593 * @return total number of groups
1594 * @exception AFSException If an error occurs in the native code
1595 * @see Cell#getCellHandle
1596 */
1597 protected static native int getGroupCount( long cellHandle )
1598 throws AFSException;
1599
1600 /**
1601 * Begin the process of getting the groups that belong to the cell. Returns
1602 * an iteration ID to be used by subsequent calls to
1603 * <code>getGroupsNextString</code> (or <code>getGroupsNext</code>) and
1604 * <code>getGroupsDone</code>.
1605 *
1606 * @param cellHandle the handle of the cell to which the groups belong
1607 * @see Cell#getCellHandle
1608 * @return an iteration ID
1609 * @exception AFSException If an error occurs in the native code
1610 */
1611 protected static native long getGroupsBegin( long cellHandle )
1612 throws AFSException;
1613
1614 /**
1615 * Begin the process of getting the groups that belong to the cell, starting
1616 * with element index <code>startIndex</code>. Returns an iteration ID to
1617 * be used by subsequent calls to <code>getGroupsNextString</code>
1618 * (or <code>getGroupsNext</code>) and <code>getGroupsDone</code>.
1619 *
1620 * @param cellHandle the handle of the cell to which the groups belong
1621 * @param startIndex the starting base-zero index
1622 * @return an iteration ID
1623 * @exception AFSException If an error occurs in the native code
1624 * @see Cell#getCellHandle
1625 */
1626 protected static native long getGroupsBeginAt( long cellHandle,
1627 int startIndex )
1628 throws AFSException;
1629
1630 /**
1631 * Returns the next group of the cell. Returns <code>null</code> if there
1632 * are no more groups.
1633 *
1634 * @param iterationId the iteration ID of this iteration
1635 * @see Cell#getGroupsBegin
1636 * @return the name of the next user of the cell
1637 * @exception AFSException If an error occurs in the native code
1638 */
1639 protected static native String getGroupsNextString( long iterationId )
1640 throws AFSException;
1641
1642 /**
1643 * Fills the next group object of the cell. Returns 0 if there
1644 * are no more groups, != 0 otherwise.
1645 *
1646 * @param cellHandle the handle of the cell to which the users belong
1647 * @see Cell#getCellHandle
1648 * @param iterationId the iteration ID of this iteration
1649 * @see Cell#getGroupsBegin
1650 * @param theGroup a Group object to be populated with the values of
1651 * the next group
1652 * @return 0 if there are no more users, != 0 otherwise
1653 * @exception AFSException If an error occurs in the native code
1654 */
1655 protected static native int getGroupsNext( long cellHandle, long iterationId,
1656 Group theGroup )
1657 throws AFSException;
1658
1659 /**
1660 * Signals that the iteration is complete and will not be accessed anymore.
1661 *
1662 * @param iterationId the iteration ID of this iteration
1663 * @see Cell#getGroupsBegin
1664 * @exception AFSException If an error occurs in the native code
1665 */
1666 protected static native void getGroupsDone( long iterationId )
1667 throws AFSException;
1668
1669 /**
1670 * Returns the total number of servers belonging to the cell denoted
1671 * by <CODE>cellHandle</CODE>.
1672 *
1673 * @param cellHandle the handle of the cell to which the servers belong
1674 * @return total number of servers
1675 * @exception AFSException If an error occurs in the native code
1676 * @see Cell#getCellHandle
1677 */
1678 protected static native int getServerCount( long cellHandle )
1679 throws AFSException;
1680
1681 /**
1682 * Begin the process of getting the servers in the cell. Returns
1683 * an iteration ID to be used by subsequent calls to
1684 * <code>getServersNextString</code> and <code>getServersDone</code>.
1685 *
1686 * @param cellHandle the handle of the cell to which the servers belong
1687 * @see Cell#getCellHandle
1688 * @return an iteration ID
1689 * @exception AFSException If an error occurs in the native code
1690 */
1691 protected static native long getServersBegin( long cellHandle )
1692 throws AFSException;
1693
1694 /**
1695 * Returns the next server of the cell. Returns <code>null</code> if there
1696 * are no more servers.
1697 *
1698 * @param iterationId the iteration ID of this iteration
1699 * @see Cell#getServersBegin
1700 * @return the name of the next server of the cell
1701 * @exception AFSException If an error occurs in the native code
1702 */
1703 protected static native String getServersNextString( long iterationId )
1704 throws AFSException;
1705
1706 /**
1707 * Fills the next server object of the cell. Returns 0 if there are no
1708 * more servers, != 0 otherwise.
1709 *
1710 * @param cellHandle the handle of the cell to which the users belong
1711 * @see Cell#getCellHandle
1712 * @param iterationId the iteration ID of this iteration
1713 * @param theServer a Server object to be populated with the values
1714 * of the next server
1715 * @see Cell#getServersBegin
1716 * @return 0 if there are no more servers, != 0 otherwise
1717 * @exception AFSException If an error occurs in the native code
1718 */
1719 protected static native int getServersNext( long cellHandle, long iterationId,
1720 Server theServer )
1721 throws AFSException;
1722
1723 /**
1724 * Signals that the iteration is complete and will not be accessed anymore.
1725 *
1726 * @param iterationId the iteration ID of this iteration
1727 * @see Cell#getServersBegin
1728 * @exception AFSException If an error occurs in the native code
1729 */
1730 protected static native void getServersDone( long iterationId )
1731 throws AFSException;
1732
1733 /**
1734 * Returns the name of the cell.
1735 *
1736 * @param cellHandle the handle of the cell to which the user belongs
1737 * @see Cell#getCellHandle
1738 * @return the name of the cell
1739 * @exception AFSException If an error occurs in the native code
1740 */
1741 protected static native String getCellName( long cellHandle )
1742 throws AFSException;
1743
1744 /**
1745 * Creates a mount point for a volume within the file system.
1746 *
1747 * @param cellHandle the handle of the cell to which the user belongs
1748 * @see Cell#getCellHandle
1749 * @param directory the full path of the place in the AFS file system
1750 * at which to mount the volume
1751 * @param volumeName the name of the volume to mount
1752 * @param readWrite whether or not this is to be a readwrite mount point
1753 * @param forceCheck whether or not to check if this volume name exists
1754 * @exception AFSException If an error occurs in the native code
1755 */
1756 protected static native void createMountPoint( long cellHandle,
1757 String directory,
1758 String volumeName,
1759 boolean readWrite,
1760 boolean forceCheck )
1761 throws AFSException;
1762
1763 /*
1764 * Sets an ACL for a given place in the AFS file system.
1765 *
1766 * @param directory the full path of the place in the AFS file system
1767 * for which to add an entry
1768 * @param username the name of the user or group for which to add an entry
1769 * @param read whether or not to allow read access to this user
1770 * @param write whether or not to allow write access to this user
1771 * @param lookup whether or not to allow lookup access to this user
1772 * @param delete whether or not to allow deletion access to this user
1773 * @param insert whether or not to allow insertion access to this user
1774 * @param lock whether or not to allow lock access to this user
1775 * @param admin whether or not to allow admin access to this user
1776 * @exception AFSException If an error occurs in the native code
1777 */
1778 public static native void setACL( String directory, String username,
1779 boolean read, boolean write,
1780 boolean lookup, boolean delete,
1781 boolean insert, boolean lock,
1782 boolean admin )
1783 throws AFSException;
1784
1785 /**
1786 * Gets the maximum group pts ID that's been used within a cell.
1787 * The next auto-assigned group ID will be one less (more negative)
1788 * than this value.
1789 *
1790 * @param cellHandle the handle of the cell to which the group belongs
1791 * @see Cell#getCellHandle
1792 * @return an integer reresenting the max group id in a cell
1793 * @exception AFSException If an error occurs in the native code
1794 */
1795 protected static native int getMaxGroupID( long cellHandle )
1796 throws AFSException;
1797
1798 /**
1799 * Sets the maximum group pts ID that's been used within a cell. The next
1800 * auto-assigned group ID will be one less (more negative) than this value.
1801 *
1802 * @param cellHandle the handle of the cell to which the group belongs
1803 * @see Cell#getCellHandle
1804 * @param maxID an integer reresenting the new max group id in a cell
1805 * @exception AFSException If an error occurs in the native code
1806 */
1807 protected static native void setMaxGroupID( long cellHandle, int maxID )
1808 throws AFSException;
1809
1810 /**
1811 * Gets the maximum user pts ID that's been used within a cell.
1812 * The next auto-assigned user ID will be one greater (more positive)
1813 * than this value.
1814 *
1815 * @param cellHandle the handle of the cell to which the user belongs
1816 * @see Cell#getCellHandle
1817 * @return an integer reresenting the max user id in a cell
1818 * @exception AFSException If an error occurs in the native code
1819 */
1820 protected static native int getMaxUserID( long cellHandle )
1821 throws AFSException;
1822
1823 /**
1824 * Sets the maximum user pts ID that's been used within a cell. The next
1825 * auto-assigned user ID will be one greater (more positive) than this value.
1826 *
1827 * @param cellHandle the handle of the cell to which the user belongs
1828 * @see Cell#getCellHandle
1829 * @param maxID an integer reresenting the new max user id in a cell
1830 * @exception AFSException If an error occurs in the native code
1831 */
1832 protected static native void setMaxUserID( long cellHandle, int maxID )
1833 throws AFSException;
1834
1835 /**
1836 * Reclaims all memory being saved by the cell portion of the native library.
1837 * This method should be called when no more <code>Cell</code> objects
1838 * are expected to be used.
1839 */
1840 protected static native void reclaimCellMemory();
1841
1842
1843 /////////////// native methods jafs_Cell ////////////////////
1844
1845 /**
1846 * Opens a cell for administrative use, based on the token provided.
1847 * Returns a cell handle to be used by other methods as a means of
1848 * authentication.
1849 *
1850 * @param cellName the name of the cell for which to get the handle
1851 * @param tokenHandle a token handle previously returned by a call to
1852 * {@link Token#getHandle}
1853 * @return a handle to the open cell
1854 * @exception AFSException If an error occurs in the native code
1855 * @see Token#getHandle
1856 */
1857 protected static native long getCellHandle( String cellName, long tokenHandle )
1858 throws AFSException;
1859
1860 /**
1861 * Closes the given currently open cell handle.
1862 *
1863 * @param cellHandle the cell handle to close
1864 * @exception AFSException If an error occurs in the native code
1865 */
1866 protected static native void closeCell( long cellHandle )
1867 throws AFSException;
1868 }
1869
1870
1871
1872
1873
1874
1875
1876