airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From patanac...@apache.org
Subject svn commit: r1182073 - /incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/GFacService.java
Date Tue, 11 Oct 2011 20:22:56 GMT
Author: patanachai
Date: Tue Oct 11 20:22:56 2011
New Revision: 1182073

URL: http://svn.apache.org/viewvc?rev=1182073&view=rev
Log:
Enable Dynamic Phase adding in GFac instead of using axis2.xml

Modified:
    incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/GFacService.java

Modified: incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/GFacService.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/GFacService.java?rev=1182073&r1=1182072&r2=1182073&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/GFacService.java
(original)
+++ incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/GFacService.java
Tue Oct 11 20:22:56 2011
@@ -22,30 +22,28 @@
 package org.apache.airavata.services.gfac.axis2;
 
 import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
 import java.net.URL;
-import java.util.*;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
 
 import javax.jcr.Credentials;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryFactory;
 import javax.jcr.SimpleCredentials;
-import javax.security.auth.login.Configuration;
-import javax.servlet.ServletContext;
 
-import org.apache.airavata.core.gfac.services.GenericService;
 import org.apache.airavata.registry.api.Registry;
 import org.apache.airavata.registry.api.impl.JCRRegistry;
+import org.apache.airavata.services.gfac.axis2.dispatchers.GFacURIBasedDispatcher;
 import org.apache.airavata.services.gfac.axis2.handlers.AmazonSecurityHandler;
 import org.apache.airavata.services.gfac.axis2.handlers.MyProxySecurityHandler;
 import org.apache.airavata.services.gfac.axis2.util.WSConstants;
-import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.deployment.WarBasedAxisConfigurator;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.TransportInDescription;
 import org.apache.axis2.engine.AxisConfiguration;
-import org.apache.axis2.engine.AxisConfigurator;
 import org.apache.axis2.engine.Phase;
 import org.apache.axis2.engine.ServiceLifeCycle;
 import org.apache.axis2.util.Utils;
@@ -53,13 +51,17 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class GFacService implements ServiceLifeCycle {
-    
+
     private static final Logger log = LoggerFactory.getLogger(GFacService.class);
 
     public static final String CONFIGURATION_CONTEXT_REGISTRY = "registry";
+    public static final String GFAC_URL = "GFacURL";
 
     public static final String SECURITY_CONTEXT = "security_context";
+    
     public static final String REPOSITORY_PROPERTIES = "repository.properties";
+    
+    public static final int GFAC_URL_UPDATE_INTERVAL = 1000 * 60 * 60 * 3;
 
     /*
      * Properties for JCR
@@ -67,31 +69,32 @@ public class GFacService implements Serv
     public static final String JCR_CLASS = "jcr.class";
     public static final String JCR_USER = "jcr.user";
     public static final String JCR_PASS = "jcr.pass";
+    
+    /*
+     * Heart beat thread
+     */
+    private Thread thread;    
 
-    public static GenericService service;
-    public static final int GFAC_URL_UPDATE_INTERVAL = 1000 * 60 * 60 * 3;
-    public ConfigurationContext context;
-    public GFacThread thread;
-    public static final String GFAC_URL = "GFacURL";
-
-    public void startUp(ConfigurationContext configctx, AxisService service){
-        this.context = configctx;
+    public void startUp(ConfigurationContext configctx, AxisService service) {
         AxisConfiguration config = null;
-        configctx.getAxisConfiguration().getTransportsIn().get("http").getParameter("port");
         List<Phase> phases = null;
         config = service.getAxisConfiguration();
         phases = config.getInFlowPhases();
 
-        initializeRepository(configctx);
-
+        /*
+         * Add dispatcher and security handler to inFlowPhases
+         */
         for (Iterator<Phase> iterator = phases.iterator(); iterator.hasNext();) {
             Phase phase = (Phase) iterator.next();
             if ("Security".equals(phase.getPhaseName())) {
                 phase.addHandler(new MyProxySecurityHandler());
                 phase.addHandler(new AmazonSecurityHandler());
-                return;
+            } else if ("Dispatch".equals(phase.getPhaseName())) {
+                phase.addHandler(new GFacURIBasedDispatcher(), 0);
             }
         }
+
+        initializeRepository(configctx);
     }
 
     private void initializeRepository(ConfigurationContext context) {
@@ -109,18 +112,23 @@ public class GFacService implements Serv
 
             Registry registry = new JCRRegistry(repository, credentials);
             String localAddress = Utils.getIpAddress(context.getAxisConfiguration());
-            TransportInDescription transportInDescription = context.getAxisConfiguration().getTransportsIn().get("http");
-            if(transportInDescription != null && transportInDescription.getParameter("port")
!= null){
-                port = (String)transportInDescription.getParameter("port").getValue();
-            }else{
+            TransportInDescription transportInDescription = context.getAxisConfiguration().getTransportsIn()
+                    .get("http");
+            if (transportInDescription != null && transportInDescription.getParameter("port")
!= null) {
+                port = (String) transportInDescription.getParameter("port").getValue();
+            } else {
                 port = map.get("port");
             }
             localAddress = "http://" + localAddress + ":" + port;
-            localAddress = localAddress + "/" +
-                    context.getContextRoot() + "/" + context.getServicePath() + "/" + WSConstants.GFAC_SERVICE_NAME;
-            System.out.println(localAddress);
+            localAddress = localAddress + "/" + context.getContextRoot() + "/" + context.getServicePath()
+ "/"
+                    + WSConstants.GFAC_SERVICE_NAME;
+            log.debug("GFAC_ADDRESS:" + localAddress);
             context.setProperty(CONFIGURATION_CONTEXT_REGISTRY, registry);
             context.setProperty(GFAC_URL, localAddress);
+            
+            /*
+             * Heart beat message to registry
+             */
             thread = new GFacThread(context);
             thread.start();
         } catch (Exception e) {
@@ -132,7 +140,7 @@ public class GFacService implements Serv
         Registry registry = (JCRRegistry) configctx.getProperty(CONFIGURATION_CONTEXT_REGISTRY);
         String gfacURL = (String) configctx.getProperty(GFAC_URL);
         registry.deleteGFacDescriptor(gfacURL);
-            thread.interrupt();
+        thread.interrupt();
         try {
             thread.join();
         } catch (InterruptedException e) {
@@ -140,70 +148,25 @@ public class GFacService implements Serv
         }
     }
 
-
-//
-//    private String getTomcatPort(ConfigurationContext context) {
-//        String port = null;
-//        Object obj = context.getProperty("transport.http.servletContext");
-//        try {
-//            Field field = context.getProperty("transport.http.servletContext").getClass().getDeclaredField("context");
-//            field.setAccessible(true);
-//            obj = field.get(obj);
-//            field = obj.getClass().getDeclaredField("context");
-//            field.setAccessible(true);
-//            obj = field.get(obj);
-//            field = obj.getClass().getSuperclass().getDeclaredField("listeners");
-//            field.setAccessible(true);
-//            ArrayList list = (ArrayList) field.get(obj);
-//            for(int i=0;i<list.size();i++){
-//                obj = list.get(i);
-//                field = obj.getClass().getDeclaredField("connector");
-//                field.setAccessible(true);
-//                obj = field.get(obj);
-//                field = obj.getClass().getDeclaredField("scheme");
-//                field.setAccessible(true);
-//                String scheme = (String)field.get(obj);
-//                if("http".equals(scheme)){
-//                    field = obj.getClass().getDeclaredField("port");
-//                    field.setAccessible(true);
-//                    port = Integer.toString(field.getInt(obj));
-//                    break;
-//                }
-//            }
-//        } catch (NoSuchFieldException e) {
-//            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
-//        } catch (IllegalAccessException e) {
-//            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
-//        }
-//        return port;
-//    }
-//
-//    private Object getNextObject(Object obj,String fieldName){
-//        try {
-//            Field field = obj.getClass().getDeclaredField(fieldName);
-//            fi
-//        } catch (NoSuchFieldException e) {
-//            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
-//        }
-//    }
-    class GFacThread extends Thread{
+    class GFacThread extends Thread {
         private ConfigurationContext context = null;
 
-        GFacThread(ConfigurationContext context){
+        GFacThread(ConfigurationContext context) {
             this.context = context;
         }
+
         public void run() {
-        try {
-            while (true) {
-                Registry registry = (Registry) this.context.getProperty(CONFIGURATION_CONTEXT_REGISTRY);
-                String localAddress = (String) this.context.getProperty(GFAC_URL);
-                registry.saveGFacDescriptor(localAddress);
-                log.info("Updated the GFac URL in to Repository");
-                Thread.sleep(GFAC_URL_UPDATE_INTERVAL);
+            try {
+                while (true) {
+                    Registry registry = (Registry) this.context.getProperty(CONFIGURATION_CONTEXT_REGISTRY);
+                    String localAddress = (String) this.context.getProperty(GFAC_URL);
+                    registry.saveGFacDescriptor(localAddress);
+                    log.info("Updated the GFac URL in to Repository");
+                    Thread.sleep(GFAC_URL_UPDATE_INTERVAL);
+                }
+            } catch (InterruptedException e) {
+                log.info("GFacURL update thread is interrupted");
             }
-        } catch (InterruptedException e) {
-            log.info("GFacURL update thread is interrupted");
         }
     }
-    }
 }



Mime
View raw message