1 package fr.in2p3.jsaga.impl.resource;
2
3 import fr.in2p3.jsaga.engine.factories.ResourceAdaptorFactory;
4 import fr.in2p3.jsaga.impl.AbstractSagaObjectImpl;
5 import org.ogf.saga.SagaObject;
6 import org.ogf.saga.error.*;
7 import org.ogf.saga.job.JobFactory;
8 import org.ogf.saga.resource.manager.ResourceManager;
9 import org.ogf.saga.session.Session;
10 import org.ogf.saga.task.Task;
11 import org.ogf.saga.task.TaskMode;
12 import org.ogf.saga.url.URL;
13
14
15
16
17
18 public class ResourceFactoryImpl extends AbstractAsyncResourceFactoryImpl {
19
20 public ResourceFactoryImpl(ResourceAdaptorFactory adaptorFactory) {
21 super(adaptorFactory);
22 }
23
24 protected ResourceManager doCreateResourceManager(Session session, URL rm) throws NotImplementedException, BadParameterException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, TimeoutException, NoSuccessException {
25 float timeout = this.getTimeout("createResourceManager", rm);
26 if (timeout == SagaObject.WAIT_FOREVER) {
27 return super.doCreateManagerSync(session, rm);
28 } else {
29 try {
30 return (ResourceManager) this.getResult(super.doCreateResourceManager(TaskMode.ASYNC, session, rm), timeout);
31 }
32 catch (IncorrectStateException e) {throw new NoSuccessException(e);}
33 catch (PermissionDeniedException e) {throw new NoSuccessException(e);}
34 catch (AlreadyExistsException e) {throw new NoSuccessException(e);}
35 catch (DoesNotExistException e) {throw new NoSuccessException(e);}
36 catch (SagaIOException e) {throw new NoSuccessException(e);}
37 }
38 }
39
40
41
42 private float getTimeout(String methodName, URL rm) throws NoSuccessException {
43 return AbstractSagaObjectImpl.getTimeout(JobFactory.class, methodName, rm.getScheme());
44 }
45
46 private Object getResult(Task task, float timeout)
47 throws NotImplementedException, IncorrectURLException,
48 AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException,
49 BadParameterException, IncorrectStateException, AlreadyExistsException, DoesNotExistException,
50 TimeoutException, NoSuccessException, SagaIOException
51 {
52 return AbstractSagaObjectImpl.getResult(task, timeout);
53 }
54 }