axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chinth...@apache.org
Subject svn commit: r358018 - in /webservices/axis2/trunk/java/modules/core: src/org/apache/axis2/context/ src/org/apache/axis2/description/ src/org/apache/axis2/engine/ src/org/apache/axis2/transport/http/server/ src/org/apache/axis2/util/ webapp/
Date Tue, 20 Dec 2005 15:11:54 GMT
Author: chinthaka
Date: Tue Dec 20 07:11:31 2005
New Revision: 358018

URL: http://svn.apache.org/viewcvs?rev=358018&view=rev
Log:
- improving the code
- adding a TimerThread to garbage collect SGContext and ServiceContext. Yet to be completed.

Added:
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/SGContextGarbageCollector.java
Modified:
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/AbstractContext.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContext.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/OperationContext.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisServiceGroup.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/AxisConfiguration.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnectionThread.java
    webservices/axis2/trunk/java/modules/core/webapp/ViewContexts.jsp
    webservices/axis2/trunk/java/modules/core/webapp/viewServiceContext.jsp
    webservices/axis2/trunk/java/modules/core/webapp/viewServiceGroupContext.jsp

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/AbstractContext.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/AbstractContext.java?rev=358018&r1=358017&r2=358018&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/AbstractContext.java
(original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/AbstractContext.java
Tue Dec 20 07:11:31 2005
@@ -19,6 +19,7 @@
 
 import org.apache.axis2.client.Options;
 
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -27,6 +28,8 @@
  * This is the top most level of the Context hierachy and is a bag of properties.
  */
 public abstract class AbstractContext {
+    protected long lastTouchedTime;
+
     protected AbstractContext parent;
     protected Map properties;
 
@@ -108,5 +111,25 @@
      */
     public void setProperty(String key, Object value) {
         properties.put(key, value);
+    }
+
+    /**
+     * ServiceContext and ServiceGroupContext are not getting automatically garbage collected.
And there
+     * is no specific way for some one to go and make it garbage collectable.
+     * So the current solution is to make them time out. So the logic is that, there is a
timer task
+     * in each and every service group which will check for the last touched time. And if
it has not
+     * been touched for some time, the timer task will remove it from the memory.
+     * The touching logic happens like this. Whenever there is a call to addMessageContext
in the operationContext
+     * it will go and update operationCOntext -> serviceContext -> serviceGroupContext.
+     */
+    protected void touch() {
+        lastTouchedTime = new Date().getTime();
+        if (parent != null) {
+            parent.touch();
+        }
+    }
+
+    public long getLastTouchedTime() {
+        return lastTouchedTime;
     }
 }

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContext.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContext.java?rev=358018&r1=358017&r2=358018&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContext.java
(original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContext.java
Tue Dec 20 07:11:31 2005
@@ -20,14 +20,16 @@
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.description.AxisServiceGroup;
 import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.util.SGContextGarbageCollector;
 import org.apache.axis2.util.UUIDGenerator;
 import org.apache.axis2.util.threadpool.ThreadFactory;
 import org.apache.axis2.util.threadpool.ThreadPool;
 
-import javax.xml.namespace.QName;
 import java.io.File;
 import java.util.HashMap;
+import java.util.Hashtable;
 import java.util.Map;
+import java.util.Timer;
 
 /**
  * This contains all the configuration information for Axis2.
@@ -39,8 +41,8 @@
      * <code>OperationContext</code> mapping.
      */
     private final Map operationContextMap = new HashMap();
-    private final Map serviceContextMap = new HashMap();
-    private final Map serviceGroupContextMap = new HashMap();
+    private final Map serviceContextMap = new Hashtable();
+    private Hashtable serviceGroupContextMap = new Hashtable();
     private transient AxisConfiguration axisConfiguration;
     private File rootDir;
     private transient ThreadFactory threadPool;
@@ -48,6 +50,15 @@
     public ConfigurationContext(AxisConfiguration axisConfiguration) {
         super(null);
         this.axisConfiguration = axisConfiguration;
+        startTimerTaskToTimeOutSGCtxt();
+    }
+
+    private void startTimerTaskToTimeOutSGCtxt() {
+        int delay = 5000;   // delay for 5 sec.
+        int period = 3000;  // repeat every 3 sec.
+        Timer timer = new Timer();
+
+        timer.schedule(new SGContextGarbageCollector(serviceGroupContextMap, 5 * 1000), delay,
period);
     }
 
     protected void finalize() throws Throwable {
@@ -127,15 +138,7 @@
         this.operationContextMap.put(messageID, mepContext);
     }
 
-    /**
-     * Registers a ServiceContext with a given service ID.
-     */
-    public synchronized void registerServiceContext(String serviceInstanceID,
-                                                    ServiceContext serviceContext) {
-        this.serviceContextMap.put(serviceInstanceID, serviceContext);
-    }
-
-    public void registerServiceGroupContext(ServiceGroupContext serviceGroupContext) {
+    public synchronized void registerServiceGroupContext(ServiceGroupContext serviceGroupContext)
{
         String id = serviceGroupContext.getId();
 
         if (serviceGroupContextMap.get(id) == null) {
@@ -144,10 +147,6 @@
         }
     }
 
-    public synchronized void removeService(QName name) {
-        serviceContextMap.remove(name);
-    }
-
     public AxisConfiguration getAxisConfiguration() {
         return axisConfiguration;
     }
@@ -201,8 +200,8 @@
      *
      * @return Returns hashmap of ServiceGroupContexts.
      */
-    public HashMap getServiceGroupContexts() {
-        return (HashMap) serviceGroupContextMap;
+    public Hashtable getServiceGroupContexts() {
+        return serviceGroupContextMap;
     }
 
     /**

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/OperationContext.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/OperationContext.java?rev=358018&r1=358017&r2=358018&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/OperationContext.java
(original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/OperationContext.java
Tue Dec 20 07:11:31 2005
@@ -80,11 +80,13 @@
      *
      * @param msgContext
      */
-    public synchronized void addMessageContext(MessageContext msgContext) throws AxisFault
{
+    public void addMessageContext(MessageContext msgContext) throws AxisFault {
         if (axisOperation != null) {
             axisOperation.addMessageContext(msgContext, this);
+            touch();
         }
     }
+
 
     /**
      * Removes the pointers to this <code>OperationContext</code> in the

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisServiceGroup.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisServiceGroup.java?rev=358018&r1=358017&r2=358018&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisServiceGroup.java
(original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisServiceGroup.java
Tue Dec 20 07:11:31 2005
@@ -92,7 +92,7 @@
         paramInclude.addParameter(param);
     }
 
-    public synchronized void addService(AxisService service) throws AxisFault {
+    public void addService(AxisService service) throws AxisFault {
         service.setParent(this);
 
         AxisConfiguration axisConfig = getParent();
@@ -165,7 +165,7 @@
         }
     }
 
-    public synchronized void removeService(QName name) throws AxisFault {
+    public void removeService(QName name) throws AxisFault {
         AxisService service = getService(name);
 
         if (service != null) {

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/AxisConfiguration.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/AxisConfiguration.java?rev=358018&r1=358017&r2=358018&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/AxisConfiguration.java
(original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/AxisConfiguration.java
Tue Dec 20 07:11:31 2005
@@ -21,16 +21,7 @@
 import org.apache.axis2.deployment.DeploymentEngine;
 import org.apache.axis2.deployment.repository.util.ArchiveReader;
 import org.apache.axis2.deployment.util.PhasesInfo;
-import org.apache.axis2.description.AxisService;
-import org.apache.axis2.description.AxisServiceGroup;
-import org.apache.axis2.description.HandlerDescription;
-import org.apache.axis2.description.ModuleConfiguration;
-import org.apache.axis2.description.ModuleDescription;
-import org.apache.axis2.description.Parameter;
-import org.apache.axis2.description.ParameterInclude;
-import org.apache.axis2.description.ParameterIncludeImpl;
-import org.apache.axis2.description.TransportInDescription;
-import org.apache.axis2.description.TransportOutDescription;
+import org.apache.axis2.description.*;
 import org.apache.axis2.om.OMElement;
 import org.apache.axis2.util.HostConfiguration;
 import org.apache.commons.logging.Log;
@@ -126,7 +117,7 @@
      * @param module
      * @throws AxisFault
      */
-    public synchronized void addModule(ModuleDescription module) throws AxisFault {
+    public void addModule(ModuleDescription module) throws AxisFault {
         module.setParent(this);
         modules.put(module.getName(), module);
     }
@@ -172,7 +163,7 @@
         addServiceGroup(axisServiceGroup);
     }
 
-    public void addServiceGroup(AxisServiceGroup axisServiceGroup) throws AxisFault {
+    public synchronized void addServiceGroup(AxisServiceGroup axisServiceGroup) throws AxisFault
{
         Iterator services = axisServiceGroup.getServices();
 
         axisServiceGroup.setParent(this);
@@ -213,7 +204,7 @@
      * @param transport
      * @throws AxisFault
      */
-    public synchronized void addTransportIn(TransportInDescription transport) throws AxisFault
{
+    public void addTransportIn(TransportInDescription transport) throws AxisFault {
         transportsIn.put(transport.getName(), transport);
     }
 
@@ -223,7 +214,7 @@
      * @param transport
      * @throws AxisFault
      */
-    public synchronized void addTransportOut(TransportOutDescription transport) throws AxisFault
{
+    public void addTransportOut(TransportOutDescription transport) throws AxisFault {
         transportsOut.put(transport.getName(), transport);
     }
 

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnectionThread.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnectionThread.java?rev=358018&r1=358017&r2=358018&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnectionThread.java
(original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnectionThread.java
Tue Dec 20 07:11:31 2005
@@ -40,7 +40,7 @@
  * Simple HTTP connection thread.
  */
 public class SimpleConnectionThread implements Runnable {
-    private static final Log LOG =
+    private static final Log log =
             LogFactory.getLog(SimpleConnectionThread.class);
     public static final String DEFAULT_CONTENT_CHARSET = "ISO-8859-1";
     private SimpleHttpServerConnection conn = null;
@@ -51,7 +51,7 @@
 
     public SimpleConnectionThread(final String name, final SimpleHttpServerConnection conn,
                                   final SimpleConnSet connpool, final HttpRequestHandler
handler)
-            throws IOException {
+            {
 
         // super(tg, name);
         if (conn == null) {
@@ -100,10 +100,11 @@
                 }
             } while (this.conn.isKeepAlive());
         } catch (InterruptedIOException e) {
+            log.error("Can not run SimpleConnectionThread ", e);
         }
         catch (IOException e) {
-            if (!this.stopped && !Thread.interrupted() && LOG.isDebugEnabled())
{
-                LOG.debug("[" + this.name + "] I/O error: " + e.getMessage());
+            if (!this.stopped && !Thread.interrupted() && log.isDebugEnabled())
{
+                log.debug("[" + this.name + "] I/O error: " + e.getMessage());
             }
         } finally {
             destroy();

Added: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/SGContextGarbageCollector.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/SGContextGarbageCollector.java?rev=358018&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/SGContextGarbageCollector.java
(added)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/SGContextGarbageCollector.java
Tue Dec 20 07:11:31 2005
@@ -0,0 +1,50 @@
+package org.apache.axis2.util;
+
+import org.apache.axis2.context.ServiceGroupContext;
+
+import java.util.Date;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.TimerTask;
+
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * @author : Eran Chinthaka (chinthaka@apache.org)
+ */
+
+public class SGContextGarbageCollector extends TimerTask {
+
+    private Hashtable serviceGroupContextMap;
+    private long timeOutInterval;
+
+    public SGContextGarbageCollector(Hashtable serviceGroupContextMap, long timeOutInterval)
{
+        this.serviceGroupContextMap = serviceGroupContextMap;
+        this.timeOutInterval = timeOutInterval;
+    }
+
+    public void run() {
+        long currentTime = new Date().getTime();
+        Iterator sgCtxtMapKeyIter = serviceGroupContextMap.keySet().iterator();
+        while (sgCtxtMapKeyIter.hasNext()) {
+            String sgCtxtId = (String) sgCtxtMapKeyIter.next();
+            ServiceGroupContext serviceGroupContext = (ServiceGroupContext) serviceGroupContextMap.get(sgCtxtId);
+            if ((currentTime - serviceGroupContext.getLastTouchedTime()) > timeOutInterval)
{
+
+                serviceGroupContextMap.remove(sgCtxtId);
+            }
+        }
+    }
+}

Modified: webservices/axis2/trunk/java/modules/core/webapp/ViewContexts.jsp
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/webapp/ViewContexts.jsp?rev=358018&r1=358017&r2=358018&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/webapp/ViewContexts.jsp (original)
+++ webservices/axis2/trunk/java/modules/core/webapp/ViewContexts.jsp Tue Dec 20 07:11:31
2005
@@ -2,7 +2,7 @@
 <%@ page import="org.apache.axis2.context.ConfigurationContext"%>
 <%@ page import="org.apache.axis2.context.ServiceContext"%>
 <%@ page import="org.apache.axis2.context.ServiceGroupContext"%>
-<%@ page import="java.util.HashMap"%>
+<%@ page import="java.util.Hashtable"%>
 <%@ page import="java.util.Iterator"%>
 <%--
   Created by IntelliJ IDEA.
@@ -18,7 +18,7 @@
     ConfigurationContext configContext = (ConfigurationContext)request.getSession().getAttribute(
             Constants.CONFIG_CONTEXT);
 
-    HashMap serviceGroupContextsMap = configContext.getServiceGroupContexts();
+    Hashtable serviceGroupContextsMap = configContext.getServiceGroupContexts();
     Iterator serviceGroupContext = serviceGroupContextsMap.keySet().iterator();
     if(serviceGroupContextsMap.size() >0){
     %>

Modified: webservices/axis2/trunk/java/modules/core/webapp/viewServiceContext.jsp
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/webapp/viewServiceContext.jsp?rev=358018&r1=358017&r2=358018&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/webapp/viewServiceContext.jsp (original)
+++ webservices/axis2/trunk/java/modules/core/webapp/viewServiceContext.jsp Tue Dec 20 07:11:31
2005
@@ -2,7 +2,7 @@
 <%@ page import="org.apache.axis2.context.ConfigurationContext" %>
 <%@ page import="org.apache.axis2.context.ServiceContext" %>
 <%@ page import="org.apache.axis2.context.ServiceGroupContext" %>
-<%@ page import="java.util.HashMap" %>
+<%@ page import="java.util.Hashtable" %>
 <%@ page import="java.util.Iterator" %>
 <%@ page import="java.util.Map" %>
 <%--
@@ -18,7 +18,7 @@
 <h1>Runing Context hierachy</h1>
 <%
     ConfigurationContext configContext = (ConfigurationContext) request.getSession().getAttribute(Constants.CONFIG_CONTEXT);
-    HashMap serviceGroupContextsMap = configContext.getServiceGroupContexts();
+    Hashtable serviceGroupContextsMap = configContext.getServiceGroupContexts();
     String type = request.getParameter("TYPE");
     String sgID = request.getParameter("PID");
     String ID = request.getParameter("ID");

Modified: webservices/axis2/trunk/java/modules/core/webapp/viewServiceGroupContext.jsp
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/webapp/viewServiceGroupContext.jsp?rev=358018&r1=358017&r2=358018&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/webapp/viewServiceGroupContext.jsp (original)
+++ webservices/axis2/trunk/java/modules/core/webapp/viewServiceGroupContext.jsp Tue Dec 20
07:11:31 2005
@@ -1,7 +1,7 @@
 <%@ page import="org.apache.axis2.Constants"%>
 <%@ page import="org.apache.axis2.context.ConfigurationContext"%>
 <%@ page import="org.apache.axis2.context.ServiceGroupContext"%>
-<%@ page import="java.util.HashMap"%>
+<%@ page import="java.util.Hashtable"%>
 <%@ page import="java.util.Iterator"%>
 <%@ page import="java.util.Map"%>
 <%--
@@ -16,7 +16,7 @@
 <h1>Runing Context hierachy</h1>
 <%
     ConfigurationContext configContext = (ConfigurationContext)request.getSession().getAttribute(Constants.CONFIG_CONTEXT);
-    HashMap serviceGroupContextsMap = configContext.getServiceGroupContexts();
+    Hashtable serviceGroupContextsMap = configContext.getServiceGroupContexts();
     String type = request.getParameter("TYPE");
     String sgID = request.getParameter("ID");
     ServiceGroupContext sgContext = (ServiceGroupContext)serviceGroupContextsMap.get(sgID);



Mime
View raw message