View Javadoc

1   package fr.in2p3.jsaga.impl.file;
2   
3   import fr.in2p3.jsaga.adaptor.data.DataAdaptor;
4   import fr.in2p3.jsaga.impl.namespace.AbstractNSDirectoryImpl;
5   import fr.in2p3.jsaga.impl.namespace.AbstractNSEntryImpl;
6   import org.ogf.saga.buffer.Buffer;
7   import org.ogf.saga.error.*;
8   import org.ogf.saga.file.*;
9   import org.ogf.saga.session.Session;
10  import org.ogf.saga.task.TaskMode;
11  import org.ogf.saga.url.URL;
12  
13  import java.util.List;
14  
15  /* ***************************************************
16  * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
17  * ***             http://cc.in2p3.fr/             ***
18  * ***************************************************
19  * File:   FileImpl
20  * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
21  * Date:   18 sept. 2007
22  * ***************************************************
23  * Description:                                      */
24  /**
25   *
26   */
27  public class FileImpl extends AbstractAsyncFileImpl implements File {
28      /** constructor for factory */
29      public FileImpl(Session session, URL url, DataAdaptor adaptor, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
30          super(session, url, adaptor, flags);
31      }
32  
33      /** constructor for NSDirectory.open() */
34      public FileImpl(AbstractNSDirectoryImpl dir, URL relativeUrl, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
35          super(dir, relativeUrl, flags);
36      }
37  
38      /** constructor for NSEntry.openAbsolute() */
39      public FileImpl(AbstractNSEntryImpl entry, String absolutePath, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
40          super(entry, absolutePath, flags);
41      }
42  
43      //////////////////////////////////////////// interface File ////////////////////////////////////////////
44  
45      public long getSize() throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, IncorrectStateException, TimeoutException, NoSuccessException {
46          float timeout = this.getTimeout("getSize");
47          if (timeout == WAIT_FOREVER) {
48              return super.getSizeSync();
49          } else {
50              try {
51                  return (Long) getResult(super.getSize(TaskMode.ASYNC), timeout);
52              }
53              catch (IncorrectURLException e) {throw new NoSuccessException(e);}
54              catch (BadParameterException e) {throw new NoSuccessException(e);}
55              catch (AlreadyExistsException e) {throw new NoSuccessException(e);}
56              catch (DoesNotExistException e) {throw new NoSuccessException(e);}
57              catch (SagaIOException e) {throw new NoSuccessException(e);}
58          }
59      }
60  
61      public int read(Buffer buffer, int len) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, TimeoutException, NoSuccessException, SagaIOException {
62          float timeout = this.getTimeout("read");
63          if (timeout == WAIT_FOREVER) {
64              return super.readSync(buffer, len);
65          } else {
66              try {
67                  return (Integer) getResult(super.read(TaskMode.ASYNC, buffer, len), timeout);
68              }
69              catch (IncorrectURLException e) {throw new NoSuccessException(e);}
70              catch (AlreadyExistsException e) {throw new NoSuccessException(e);}
71              catch (DoesNotExistException e) {throw new NoSuccessException(e);}
72          }
73      }
74  
75      public int read(Buffer buffer, int offset, int len) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, TimeoutException, NoSuccessException, SagaIOException {
76          float timeout = this.getTimeout("read");
77          if (timeout == WAIT_FOREVER) {
78              return super.readSync(buffer, offset, len);
79          } else {
80              try {
81                  return (Integer) getResult(super.read(TaskMode.ASYNC, buffer, offset, len), timeout);
82              }
83              catch (IncorrectURLException e) {throw new NoSuccessException(e);}
84              catch (AlreadyExistsException e) {throw new NoSuccessException(e);}
85              catch (DoesNotExistException e) {throw new NoSuccessException(e);}
86          }
87      }
88  
89      public int read(Buffer buffer) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, TimeoutException, NoSuccessException, SagaIOException {
90          float timeout = this.getTimeout("read");
91          if (timeout == WAIT_FOREVER) {
92              return super.readSync(buffer);
93          } else {
94              try {
95                  return (Integer) getResult(super.read(TaskMode.ASYNC, buffer), timeout);
96              }
97              catch (IncorrectURLException e) {throw new NoSuccessException(e);}
98              catch (AlreadyExistsException e) {throw new NoSuccessException(e);}
99              catch (DoesNotExistException e) {throw new NoSuccessException(e);}
100         }
101     }
102 
103     public int write(Buffer buffer, int offset, int len) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, TimeoutException, NoSuccessException, SagaIOException {
104         float timeout = this.getTimeout("write");
105         if (timeout == WAIT_FOREVER) {
106             return super.writeSync(buffer, offset, len);
107         } else {
108             try {
109                 return (Integer) getResult(super.write(TaskMode.ASYNC, buffer, offset, len), timeout);
110             }
111             catch (IncorrectURLException e) {throw new NoSuccessException(e);}
112             catch (AlreadyExistsException e) {throw new NoSuccessException(e);}
113             catch (DoesNotExistException e) {throw new NoSuccessException(e);}
114         }
115     }
116 
117     public int write(Buffer buffer, int len) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, TimeoutException, NoSuccessException, SagaIOException {
118         float timeout = this.getTimeout("write");
119         if (timeout == WAIT_FOREVER) {
120             return super.writeSync(buffer, len);
121         } else {
122             try {
123                 return (Integer) getResult(super.write(TaskMode.ASYNC, buffer, len), timeout);
124             }
125             catch (IncorrectURLException e) {throw new NoSuccessException(e);}
126             catch (AlreadyExistsException e) {throw new NoSuccessException(e);}
127             catch (DoesNotExistException e) {throw new NoSuccessException(e);}
128         }
129     }
130 
131     public int write(Buffer buffer) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, TimeoutException, NoSuccessException, SagaIOException {
132         float timeout = this.getTimeout("write");
133         if (timeout == WAIT_FOREVER) {
134             return super.writeSync(buffer);
135         } else {
136             try {
137                 return (Integer) getResult(super.write(TaskMode.ASYNC, buffer), timeout);
138             }
139             catch (IncorrectURLException e) {throw new NoSuccessException(e);}
140             catch (AlreadyExistsException e) {throw new NoSuccessException(e);}
141             catch (DoesNotExistException e) {throw new NoSuccessException(e);}
142         }
143     }
144 
145     public long seek(long offset, SeekMode whence) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, IncorrectStateException, TimeoutException, NoSuccessException, SagaIOException {
146         float timeout = this.getTimeout("seek");
147         if (timeout == WAIT_FOREVER) {
148             return super.seekSync(offset, whence);
149         } else {
150             try {
151                 return (Long) getResult(super.seek(TaskMode.ASYNC, offset, whence), timeout);
152             }
153             catch (IncorrectURLException e) {throw new NoSuccessException(e);}
154             catch (BadParameterException e) {throw new NoSuccessException(e);}
155             catch (AlreadyExistsException e) {throw new NoSuccessException(e);}
156             catch (DoesNotExistException e) {throw new NoSuccessException(e);}
157         }
158     }
159 
160     public void readV(IOVec[] iovecs) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, TimeoutException, NoSuccessException, SagaIOException {
161         float timeout = this.getTimeout("readV");
162         if (timeout == WAIT_FOREVER) {
163             super.readVSync(iovecs);
164         } else {
165             try {
166                 getResult(super.readV(TaskMode.ASYNC, iovecs), timeout);
167             }
168             catch (IncorrectURLException e) {throw new NoSuccessException(e);}
169             catch (AlreadyExistsException e) {throw new NoSuccessException(e);}
170             catch (DoesNotExistException e) {throw new NoSuccessException(e);}
171         }
172     }
173 
174     public void writeV(IOVec[] iovecs) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, TimeoutException, NoSuccessException, SagaIOException {
175         float timeout = this.getTimeout("writeV");
176         if (timeout == WAIT_FOREVER) {
177             super.writeVSync(iovecs);
178         } else {
179             try {
180                 getResult(super.writeV(TaskMode.ASYNC, iovecs), timeout);
181             }
182             catch (IncorrectURLException e) {throw new NoSuccessException(e);}
183             catch (AlreadyExistsException e) {throw new NoSuccessException(e);}
184             catch (DoesNotExistException e) {throw new NoSuccessException(e);}
185         }
186     }
187 
188     public int sizeP(String pattern) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, IncorrectStateException, PermissionDeniedException, BadParameterException, TimeoutException, NoSuccessException {
189         float timeout = this.getTimeout("sizeP");
190         if (timeout == WAIT_FOREVER) {
191             return super.sizePSync(pattern);
192         } else {
193             try {
194                 return (Integer) getResult(super.sizeP(TaskMode.ASYNC, pattern), timeout);
195             }
196             catch (IncorrectURLException e) {throw new NoSuccessException(e);}
197             catch (AlreadyExistsException e) {throw new NoSuccessException(e);}
198             catch (DoesNotExistException e) {throw new NoSuccessException(e);}
199             catch (SagaIOException e) {throw new NoSuccessException(e);}
200         }
201     }
202 
203     public int readP(String pattern, Buffer buffer) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, TimeoutException, NoSuccessException, SagaIOException {
204         float timeout = this.getTimeout("readP");
205         if (timeout == WAIT_FOREVER) {
206             return super.readPSync(pattern, buffer);
207         } else {
208             try {
209                 return (Integer) getResult(super.readP(TaskMode.ASYNC, pattern, buffer), timeout);
210             }
211             catch (IncorrectURLException e) {throw new NoSuccessException(e);}
212             catch (AlreadyExistsException e) {throw new NoSuccessException(e);}
213             catch (DoesNotExistException e) {throw new NoSuccessException(e);}
214         }
215     }
216 
217     public int writeP(String pattern, Buffer buffer) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, TimeoutException, NoSuccessException, SagaIOException {
218         float timeout = this.getTimeout("writeP");
219         if (timeout == WAIT_FOREVER) {
220             return super.writePSync(pattern, buffer);
221         } else {
222             try {
223                 return (Integer) getResult(super.writeP(TaskMode.ASYNC, pattern, buffer), timeout);
224             }
225             catch (IncorrectURLException e) {throw new NoSuccessException(e);}
226             catch (AlreadyExistsException e) {throw new NoSuccessException(e);}
227             catch (DoesNotExistException e) {throw new NoSuccessException(e);}
228         }
229     }
230 
231     public List<String> modesE() throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, IncorrectStateException, TimeoutException, NoSuccessException {
232         float timeout = this.getTimeout("modesE");
233         if (timeout == WAIT_FOREVER) {
234             return super.modesESync();
235         } else {
236             try {
237                 return (List<String>) getResult(super.modesE(TaskMode.ASYNC), timeout);
238             }
239             catch (IncorrectURLException e) {throw new NoSuccessException(e);}
240             catch (BadParameterException e) {throw new NoSuccessException(e);}
241             catch (AlreadyExistsException e) {throw new NoSuccessException(e);}
242             catch (DoesNotExistException e) {throw new NoSuccessException(e);}
243             catch (SagaIOException e) {throw new NoSuccessException(e);}
244         }
245     }
246 
247     public int sizeE(String emode, String spec) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, IncorrectStateException, PermissionDeniedException, BadParameterException, TimeoutException, NoSuccessException {
248         float timeout = this.getTimeout("sizeE");
249         if (timeout == WAIT_FOREVER) {
250             return super.sizeESync(emode, spec);
251         } else {
252             try {
253                 return (Integer) getResult(super.sizeE(TaskMode.ASYNC, emode, spec), timeout);
254             }
255             catch (IncorrectURLException e) {throw new NoSuccessException(e);}
256             catch (AlreadyExistsException e) {throw new NoSuccessException(e);}
257             catch (DoesNotExistException e) {throw new NoSuccessException(e);}
258             catch (SagaIOException e) {throw new NoSuccessException(e);}
259         }
260     }
261 
262     public int readE(String emode, String spec, Buffer buffer) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, TimeoutException, NoSuccessException, SagaIOException {
263         float timeout = this.getTimeout("readE");
264         if (timeout == WAIT_FOREVER) {
265             return super.readESync(emode, spec, buffer);
266         } else {
267             try {
268                 return (Integer) getResult(super.readE(TaskMode.ASYNC, emode, spec, buffer), timeout);
269             }
270             catch (IncorrectURLException e) {throw new NoSuccessException(e);}
271             catch (AlreadyExistsException e) {throw new NoSuccessException(e);}
272             catch (DoesNotExistException e) {throw new NoSuccessException(e);}
273         }
274     }
275 
276     public int writeE(String emode, String spec, Buffer buffer) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, IncorrectStateException, TimeoutException, NoSuccessException, SagaIOException {
277         float timeout = this.getTimeout("writeE");
278         if (timeout == WAIT_FOREVER) {
279             return super.writeESync(emode, spec, buffer);
280         } else {
281             try {
282                 return (Integer) getResult(super.writeE(TaskMode.ASYNC, emode, spec, buffer), timeout);
283             }
284             catch (IncorrectURLException e) {throw new NoSuccessException(e);}
285             catch (AlreadyExistsException e) {throw new NoSuccessException(e);}
286             catch (DoesNotExistException e) {throw new NoSuccessException(e);}
287         }
288     }
289 
290     ////////////////////////////////////////// private methods //////////////////////////////////////////
291 
292     private float getTimeout(String methodName) throws NoSuccessException {
293         return getTimeout(File.class, methodName, m_url.getScheme());
294     }
295 }