View Javadoc

1   /*
2    * Copyright (c) 2005 The University of Reading
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    * 1. Redistributions of source code must retain the above copyright
9    *    notice, this list of conditions and the following disclaimer.
10   * 2. Redistributions in binary form must reproduce the above copyright
11   *    notice, this list of conditions and the following disclaimer in the
12   *    documentation and/or other materials provided with the distribution.
13   * 3. Neither the name of the University of Reading, nor the names of the
14   *    authors or contributors may be used to endorse or promote products
15   *    derived from this software without specific prior written permission.
16   * 
17   * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18   * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20   * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21   * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27   */
28  
29  package uk.ac.rdg.resc.jstyx.client;
30  
31  import org.apache.mina.common.ByteBuffer;
32  
33  import uk.ac.rdg.resc.jstyx.types.DirEntry;
34  import uk.ac.rdg.resc.jstyx.messages.TwriteMessage;
35  import uk.ac.rdg.resc.jstyx.messages.TreadMessage;
36  
37  /***
38   * Convenience class that provides empty implementations for all the methods in
39   * CStyxFileChangeListener.
40   *
41   * @author Jon Blower
42   * $Revision: 373 $
43   * $Date: 2005-08-31 09:15:57 +0100 (Wed, 31 Aug 2005) $
44   * $Log$
45   * Revision 1.9  2005/08/31 08:15:57  jonblower
46   * Corrections to comments
47   *
48   * Revision 1.8  2005/07/28 16:38:58  jonblower
49   * Added material to comments
50   *
51   * Revision 1.7  2005/06/20 17:20:43  jonblower
52   * Added download() and downloadAsync() to CStyxFile
53   *
54   * Revision 1.6  2005/05/25 16:57:07  jonblower
55   * Added fileCreated() event
56   *
57   * Revision 1.5  2005/05/12 14:20:55  jonblower
58   * Changed dataSent() method to dataWritten() (more accurate name)
59   *
60   * Revision 1.4  2005/05/12 08:00:34  jonblower
61   * Added getChildrenAsync() to CStyxFile and childrenFound() to CStyxFileChangeListener
62   *
63   * Revision 1.3  2005/03/19 21:46:58  jonblower
64   * Further fixes relating to releasing ByteBuffers
65   *
66   * Revision 1.2  2005/03/16 17:55:52  jonblower
67   * Replaced use of java.nio.ByteBuffer with MINA's ByteBuffer to minimise copying of buffers
68   *
69   * Revision 1.1.1.1  2005/02/16 18:58:17  jonblower
70   * Initial import
71   *
72   */
73  public class CStyxFileChangeAdapter implements CStyxFileChangeListener
74  {
75      
76      /***
77       * Called when the file has been opened.
78       * @param file The file that has been opened
79       * @param mode The mode with which the file was opened
80       */
81      public void fileOpen(CStyxFile file, int mode){}
82      
83      /***
84       * Called when the file has been created.
85       * @param file The file that has been created
86       * @param mode The mode with which the file was created
87       */
88      public void fileCreated(CStyxFile file, int mode){}
89      
90      /***
91       * Called when new data have been read from the file (after the Rread message
92       * arrives). Note that the offset of the file (i.e. the file position) will
93       * not have changed before this method is called.  It is up to clients to 
94       * update the offset of the file if required (e.g.
95       * <code>file.setOffset(offset + data.remaining())</code>).
96       *
97       * After this method is finished, the ByteBuffer will automatically be returned to the pool.
98       * If you want to delay this happening, call data.acquire() within this
99       * method.  Then when you no longer need the data in the buffer, call 
100      * data.release().
101      *
102      * @param file The CStyxFile containing the data
103      * @param tReadMsg The original TreadMessage that was sent (contains the offset,
104      * tag etc of the message)
105      * @param data The new data that have been read from the file
106      */
107     public void dataArrived(CStyxFile file, TreadMessage tReadMsg, ByteBuffer data){}
108     
109     /***
110      * Called when data have been written to the file (after the Rwrite message
111      * arrives). Note that the offset of the file (i.e. the file position) will
112      * not have changed before this method is called.  It is up to clients to 
113      * update the offset of the file if required (e.g.
114      * <code>file.setOffset(offset + data.remaining())</code>).
115      * @param file The CStyxFile containing the data
116      * @param tWriteMsg The TwriteMessage that caused this event to be fired
117      */
118     public void dataWritten(CStyxFile file, TwriteMessage tWriteMsg){}
119     
120     /***
121      * Called when an Rerror message arrives
122      * @param file the CStyxFile from which the error originated
123      * @param message the error message
124      */
125     public void error(CStyxFile file, String message){}
126     
127     /***
128      * Called after the stat of a file (permissions etc) has been changed.
129      * Actually, this is called after an Rstat message arrives; it does not
130      * necessarily mean that the stat has changed.
131      */
132     public void statChanged(CStyxFile file, DirEntry newDirEntry){}
133     
134     /***
135      * Called after a successful read on a directory. (Result of a call to
136      * CStyxFile.getChildrenAsync()).  All the dirEntries of the children will
137      * have been set, so it is safe to call getDirEntry() on any of the children
138      * without worrying about the method blocking.
139      */
140     public void childrenFound(CStyxFile file, CStyxFile[] children){}
141     
142     /***
143      * Called after a file has been successfully uploaded
144      * @param targetFile The file to which we have written
145      */
146     public void uploadComplete(CStyxFile targetFile) {}
147     
148     /***
149      * Called after a file has been successfully downloaded
150      * @param sourceFile The file from which the data have been downloaded.
151      */
152     public void downloadComplete(CStyxFile sourceFile) {}
153     
154 }