View Javadoc

1   package fr.in2p3.jsaga.impl.file;
2   
3   import fr.in2p3.jsaga.engine.factories.DataAdaptorFactory;
4   import fr.in2p3.jsaga.impl.AbstractSagaObjectImpl;
5   import org.ogf.saga.SagaObject;
6   import org.ogf.saga.error.*;
7   import org.ogf.saga.file.*;
8   import org.ogf.saga.session.Session;
9   import org.ogf.saga.task.Task;
10  import org.ogf.saga.task.TaskMode;
11  import org.ogf.saga.url.URL;
12  
13  /* ***************************************************
14  * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
15  * ***             http://cc.in2p3.fr/             ***
16  * ***************************************************
17  * File:   FileFactoryImpl
18  * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
19  * Date:   18 sept. 2007
20  * ***************************************************
21  * Description:                                      */
22  /**
23   *
24   */
25  public class FileFactoryImpl extends AbstractAsyncFileFactoryImpl {
26      public FileFactoryImpl(DataAdaptorFactory adaptorFactory) {
27          super(adaptorFactory);
28      }
29  
30      ///////////////////////////////////////// interface FileFactory /////////////////////////////////////////
31  
32      protected File doCreateFile(Session session, URL name, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
33          float timeout = this.getTimeout("createFile", name);
34          if (timeout == SagaObject.WAIT_FOREVER) {
35              return super.doCreateFileSync(session, name, flags);
36          } else {
37              try {
38                  return (File) this.getResult(super.doCreateFile(TaskMode.ASYNC, session, name, flags), timeout);
39              }
40              catch (IncorrectStateException e) {throw new NoSuccessException(e);}
41              catch (SagaIOException e) {throw new NoSuccessException(e);}
42          }
43      }
44  
45      protected FileInputStream doCreateFileInputStream(Session session, URL name) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
46          float timeout = this.getTimeout("createFileInputStream", name);
47          if (timeout == SagaObject.WAIT_FOREVER) {
48              return super.doCreateFileInputStreamSync(session, name);
49          } else {
50              try {
51                  return (FileInputStream) this.getResult(super.doCreateFileInputStream(TaskMode.ASYNC, session, name), timeout);
52              }
53              catch (IncorrectStateException e) {throw new NoSuccessException(e);}
54              catch (SagaIOException e) {throw new NoSuccessException(e);}
55          }
56      }
57  
58      protected FileOutputStream doCreateFileOutputStream(Session session, URL name, boolean append) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
59          float timeout = this.getTimeout("createFileOutputStream", name);
60          if (timeout == SagaObject.WAIT_FOREVER) {
61              return super.doCreateFileOutputStreamSync(session, name, append);
62          } else {
63              try {
64                  return (FileOutputStream) this.getResult(super.doCreateFileOutputStream(TaskMode.ASYNC, session, name, append), timeout);
65              }
66              catch (IncorrectStateException e) {throw new NoSuccessException(e);}
67              catch (SagaIOException e) {throw new NoSuccessException(e);}
68          }
69      }
70  
71      protected Directory doCreateDirectory(Session session, URL name, int flags) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, AlreadyExistsException, DoesNotExistException, TimeoutException, NoSuccessException {
72          float timeout = this.getTimeout("createDirectory", name);
73          if (timeout == SagaObject.WAIT_FOREVER) {
74              return super.doCreateDirectorySync(session, name, flags);
75          } else {
76              try {
77                  return (Directory) this.getResult(super.doCreateDirectory(TaskMode.ASYNC, session, name, flags), timeout);
78              }
79              catch (IncorrectStateException e) {throw new NoSuccessException(e);}
80              catch (SagaIOException e) {throw new NoSuccessException(e);}
81          }
82      }
83  
84      ////////////////////////////////////////// private methods //////////////////////////////////////////
85  
86      private float getTimeout(String methodName, URL url) throws NoSuccessException {
87          return AbstractSagaObjectImpl.getTimeout(FileFactory.class, methodName, url.getScheme());
88      }
89  
90      private Object getResult(Task task, float timeout)
91              throws NotImplementedException, IncorrectURLException,
92              AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException,
93              BadParameterException, IncorrectStateException, AlreadyExistsException, DoesNotExistException,
94              TimeoutException, NoSuccessException, SagaIOException
95      {
96          return AbstractSagaObjectImpl.getResult(task, timeout);
97      }
98  }