View Javadoc

1   package fr.in2p3.jsaga.adaptor;
2   
3   import fr.in2p3.jsaga.adaptor.base.defaults.Default;
4   import fr.in2p3.jsaga.adaptor.base.usage.Usage;
5   import fr.in2p3.jsaga.adaptor.security.SecurityCredential;
6   import org.ogf.saga.error.*;
7   
8   import java.util.Map;
9   
10  /* ***************************************************
11   * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
12   * ***             http://cc.in2p3.fr/             ***
13   * ***************************************************
14   * File:   WaitForEverAdaptorAbstract
15   * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
16   * Date:   28 mai 2009
17   * ***************************************************
18   * Description:                                      */
19  /**
20   *
21   */
22  public abstract class WaitForEverAdaptorAbstract implements ClientAdaptor {
23      private static boolean s_isHanging = false;
24  
25      public Usage getUsage() {
26          return null;
27      }
28      public Default[] getDefaults(Map attributes) throws IncorrectStateException {
29          return null;
30      }
31      public int getDefaultPort() {
32          return NO_PORT;
33      }
34      public Class[] getSupportedSecurityCredentialClasses() {
35          return null;
36      }
37      public void setSecurityCredential(SecurityCredential credential) {
38          // do nothing
39      }
40  
41      public void connect(String userInfo, String host, int port, String basePath, Map attributes) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, BadParameterException, TimeoutException, NoSuccessException {
42          mayHang(attributes);
43      }
44      public void disconnect() throws NoSuccessException {
45          // do nothing
46      }
47  
48      public static void hang() {
49          try {
50              // set isHanging
51              s_isHanging = true;
52  
53              // hang
54              for (;;) {
55                  Thread.currentThread().sleep(100);
56              }
57          } catch (InterruptedException e) {/*ignore*/}
58      }
59      public static boolean isHanging() {
60          // save result
61          boolean ret = s_isHanging;
62  
63          // reset
64          s_isHanging = false;
65  
66          // return
67          return ret;
68      }
69      protected static void mayHang(Map attributes) {
70          if (attributes.containsKey("hangatconnect")) {
71              hang();
72          }
73      }
74      protected static void mayHang(String additionalArgs) {
75          if ("hangatconnect".equals(additionalArgs)) {
76              hang();
77          }
78      }
79  }