1 package fr.in2p3.jsaga.impl.job.staging;
2
3 import org.ogf.saga.url.URL;
4 import org.ogf.saga.session.Session;
5 import org.ogf.saga.error.*;
6 import org.ogf.saga.namespace.Flags;
7 import org.ogf.saga.file.File;
8 import org.ogf.saga.file.FileFactory;
9
10
11
12
13
14
15
16
17
18
19
20
21
22 public abstract class AbstractDataStagingRemote extends AbstractDataStaging {
23 protected URL m_workerURL;
24
25 protected AbstractDataStagingRemote(URL localURL, URL workerURL, boolean append) {
26 super(localURL, append);
27 m_workerURL = workerURL;
28 }
29
30 public String getWorkerProtocol() {
31 return m_workerURL.getScheme();
32 }
33
34 protected void copy(Session session, URL sourceUrl, URL targetUrl) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, DoesNotExistException, TimeoutException, IncorrectStateException, NoSuccessException {
35 int append = (m_append ? Flags.APPEND : Flags.OVERWRITE).getValue();
36 try {
37 File file = FileFactory.createFile(JSAGA_FACTORY, session, sourceUrl, Flags.NONE.getValue());
38 try {
39 file.copy(targetUrl, append);
40 } finally {
41 file.close();
42 }
43 } catch (AlreadyExistsException e) {
44 throw new NoSuccessException(e);
45 } catch (IncorrectURLException e) {
46 throw new NoSuccessException(e);
47 }
48 }
49
50 public void cleanup(Session session) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, DoesNotExistException, TimeoutException, IncorrectStateException, NoSuccessException {
51 try {
52 File file = FileFactory.createFile(JSAGA_FACTORY, session, m_workerURL, Flags.NONE.getValue());
53 try {
54 file.remove();
55 } finally {
56 file.close();
57 }
58 } catch (AlreadyExistsException e) {
59 throw new NoSuccessException(e);
60 } catch (IncorrectURLException e) {
61 throw new NoSuccessException(e);
62 }
63 }
64 }