ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1448029 - in /ace/trunk: org.apache.ace.client.repository.impl/ org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/impl/ org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/ org.apache.ace.webui.vaadin/src/o...
Date Wed, 20 Feb 2013 08:06:06 GMT
Author: marrs
Date: Wed Feb 20 08:06:06 2013
New Revision: 1448029

URL: http://svn.apache.org/r1448029
Log:
ACE-318 Fixed the cleanup of sessions and their services. Added a 'sessions' shell command
to see the open sessions.

Modified:
    ace/trunk/org.apache.ace.client.repository.impl/bnd.bnd
    ace/trunk/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/impl/Activator.java
    ace/trunk/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/impl/RepositoryAdminImpl.java
    ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinClient.java
    ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinServlet.java
    ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/component/MainActionToolbar.java

Modified: ace/trunk/org.apache.ace.client.repository.impl/bnd.bnd
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository.impl/bnd.bnd?rev=1448029&r1=1448028&r2=1448029&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository.impl/bnd.bnd (original)
+++ ace/trunk/org.apache.ace.client.repository.impl/bnd.bnd Wed Feb 20 08:06:06 2013
@@ -5,6 +5,7 @@
 	xpp3;version=1.1.4,\
 	xstream;version=1.2.2,\
 	org.apache.felix.dependencymanager,\
+	org.apache.felix.gogo.runtime,\
 	org.apache.ace.log;version=latest,\
 	org.apache.ace.connectionfactory;version=latest,\
 	org.apache.ace.client.repository.api;version=latest,\

Modified: ace/trunk/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/impl/Activator.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/impl/Activator.java?rev=1448029&r1=1448028&r2=1448029&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/impl/Activator.java
(original)
+++ ace/trunk/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/impl/Activator.java
Wed Feb 20 08:06:06 2013
@@ -24,6 +24,8 @@ import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
 
 import org.apache.ace.client.repository.RepositoryAdmin;
 import org.apache.ace.client.repository.SessionFactory;
@@ -45,6 +47,7 @@ import org.apache.ace.server.log.store.L
 import org.apache.felix.dm.Component;
 import org.apache.felix.dm.DependencyActivatorBase;
 import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.service.command.CommandProcessor;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.service.event.EventAdmin;
@@ -69,12 +72,32 @@ public class Activator extends Dependenc
     @Override
     public synchronized void init(BundleContext context, DependencyManager manager) throws
Exception {
         m_dependencyManager = manager;
+        
+        Properties props = new Properties();
+        props.put(CommandProcessor.COMMAND_SCOPE, "clientrepo");
+        props.put(CommandProcessor.COMMAND_FUNCTION, new String[] { "sessions" });
+        
         manager.add(createComponent()
-            .setInterface(SessionFactory.class.getName(), null)
+            .setInterface(SessionFactory.class.getName(), props)
             .setImplementation(this)
         );
     }
 
+    /** Shell command to show the active sessions. */
+    public void sessions() {
+        synchronized (m_sessions) {
+        	if (m_sessions.isEmpty()) {
+        		System.out.println("No sessions.");
+        	}
+        	else {
+        		System.out.println("Sessions:");
+        		for (Entry<String, SessionData> session : m_sessions.entrySet()) {
+        			System.out.println(" * " + session.getKey());
+        		}
+        	}
+        }
+    }
+    
     /**
      * {@inheritDoc}
      */

Modified: ace/trunk/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/impl/RepositoryAdminImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/impl/RepositoryAdminImpl.java?rev=1448029&r1=1448028&r2=1448029&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/impl/RepositoryAdminImpl.java
(original)
+++ ace/trunk/org.apache.ace.client.repository.impl/src/org/apache/ace/client/repository/impl/RepositoryAdminImpl.java
Wed Feb 20 08:06:06 2013
@@ -401,9 +401,13 @@ public class RepositoryAdminImpl impleme
     }
     
     public void deleteLocal() {
-        for (RepositorySet set : m_repositorySets) {
-            set.deleteLocal();
-        }
+    	synchronized (m_lock) {
+    		if (m_user != null && m_repositorySets != null) {
+    			for (RepositorySet set : m_repositorySets) {
+    				set.deleteLocal();
+    			}
+    		}
+    	}
     }
 
     private boolean loggedIn() {

Modified: ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinClient.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinClient.java?rev=1448029&r1=1448028&r2=1448029&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinClient.java
(original)
+++ ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinClient.java
Wed Feb 20 08:06:06 2013
@@ -23,6 +23,7 @@ import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -76,6 +77,7 @@ import com.vaadin.event.dd.DropHandler;
 import com.vaadin.event.dd.TargetDetails;
 import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
 import com.vaadin.event.dd.acceptcriteria.Or;
+import com.vaadin.service.ApplicationContext;
 import com.vaadin.ui.AbstractSelect.AbstractSelectTargetDetails;
 import com.vaadin.ui.AbstractSelect.VerticalLocationIs;
 import com.vaadin.ui.Button;
@@ -109,7 +111,7 @@ public class VaadinClient extends com.va
 
     private static final long serialVersionUID = 1L;
 
-    private static long SESSION_ID = 12345;
+    private static long SESSION_ID = 1;
 
     private static String targetRepo = "target";
     private static String shopRepo = "shop";
@@ -118,7 +120,6 @@ public class VaadinClient extends com.va
     private static String endpoint = "/repository";
 
     private volatile AuthenticationService m_authenticationService;
-    private volatile DependencyManager m_manager;
     private volatile BundleContext m_context;
     private volatile SessionFactory m_sessionFactory;
     private volatile UserAdmin m_userAdmin;
@@ -156,6 +157,9 @@ public class VaadinClient extends com.va
     private final AtomicBoolean m_dependenciesResolved = new AtomicBoolean(false);
 
     private ProgressIndicator m_progress;
+    private DependencyManager m_manager;
+	private Component m_component;
+	private final List<Component> m_eventHandlers = new ArrayList<Component>();
 
     // basic session ID generator
     private static long generateSessionID() {
@@ -184,13 +188,15 @@ public class VaadinClient extends com.va
 
     /**
      * Creates a new {@link VaadinClient} instance.
+     * @param m_manager2 
      * 
      * @param aceHost the hostname where the management service can be reached;
      * @param obrUrl the URL of the OBR to use;
      * @param useAuth <code>true</code> to use authentication, <code>false</code>
to disable authentication;
      * @param userName the hardcoded username to use when authentication is disabled.
      */
-    public VaadinClient(URL aceHost, URL obrUrl, boolean useAuth, String userName) {
+    public VaadinClient(DependencyManager manager, URL aceHost, URL obrUrl, boolean useAuth,
String userName) {
+    	m_manager = manager;
         try {
             m_repository = new URL(aceHost, endpoint);
         }
@@ -205,9 +211,44 @@ public class VaadinClient extends com.va
             throw new IllegalArgumentException("Need a valid user name when no authentication
is used!");
         }
     }
+    
+    @Override
+    public void start(URL applicationUrl, Properties applicationProperties, ApplicationContext
context) {
+        m_component = m_manager.createComponent()
+            .setImplementation(this)
+            .setCallbacks("setupDependencies", "start", "stop", "destroyDependencies")
+            .add(m_manager.createServiceDependency()
+                .setService(SessionFactory.class)
+                .setRequired(true)
+            )
+            .add(m_manager.createServiceDependency()
+                .setService(UserAdmin.class)
+                .setRequired(true)
+            )
+            .add(m_manager.createServiceDependency()
+                .setService(AuthenticationService.class)
+                .setRequired(m_useAuth)
+            )
+            .add(m_manager.createServiceDependency()
+                .setService(LogService.class)
+                .setRequired(false)
+            );
+		m_manager.add(m_component);
+    	super.start(applicationUrl, applicationProperties, context);
+    }
+    
+    @Override
+    public void close() {
+    	if (isRunning()) {
+	        m_admin.deleteLocal();
+	        cleanupListeners();
+	        m_manager.remove(m_component);
+	        super.close();
+    	}
+    }
 
     public void setupDependencies(Component component) {
-        m_sessionID = "" + generateSessionID();
+        m_sessionID = "web-" + generateSessionID();
         File dir = m_context.getDataFile(m_sessionID);
         dir.mkdir();
         m_sessionDir = dir;
@@ -522,10 +563,24 @@ public class VaadinClient extends com.va
         Properties props = new Properties();
         props.put(EventConstants.EVENT_TOPIC, topics);
         props.put(EventConstants.EVENT_FILTER, "(" + SessionFactory.SERVICE_SID + "=" + m_sessionID
+ ")");
-        m_manager.add(
-            m_manager.createComponent()
-                .setInterface(EventHandler.class.getName(), props)
-                .setImplementation(implementation));
+        Component component = m_manager.createComponent()
+		    .setInterface(EventHandler.class.getName(), props)
+		    .setImplementation(implementation);
+        synchronized (m_eventHandlers) {
+        	m_eventHandlers.add(component);
+        }
+		m_manager.add(component);
+    }
+    
+    private void cleanupListeners() {
+    	Component[] components;
+        synchronized (m_eventHandlers) {
+			components = m_eventHandlers.toArray(new Component[m_eventHandlers.size()]);
+			m_eventHandlers.clear();
+        }
+        for (Component component : components) {
+        	m_manager.remove(component);
+        }
     }
 
     /**
@@ -936,12 +991,6 @@ public class VaadinClient extends com.va
         return m_statefulTargetRepository.get(name);
     }
 
-    @Override
-    public void close() {
-        m_admin.deleteLocal();
-        super.close();
-    }
-
     private void showAddArtifactDialog() {
         final AddArtifactWindow window = new AddArtifactWindow(m_sessionDir, m_obrUrl) {
             @Override

Modified: ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinServlet.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinServlet.java?rev=1448029&r1=1448028&r2=1448029&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinServlet.java
(original)
+++ ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinServlet.java
Wed Feb 20 08:06:06 2013
@@ -39,7 +39,7 @@ import com.vaadin.terminal.gwt.server.Ab
 import com.vaadin.terminal.gwt.server.WebApplicationContext;
 
 public class VaadinServlet extends AbstractApplicationServlet implements ManagedService {
-    private static final int SESSION_TIMEOUT = 120; // in seconds (so 120 = 2 minutes)
+    private static final int SESSION_TIMEOUT = 30; // in seconds (so 120 = 2 minutes)
 
 	private static final long serialVersionUID = 1L;
     
@@ -68,28 +68,7 @@ public class VaadinServlet extends Abstr
 
     @Override
     protected Application getNewApplication(HttpServletRequest request)	throws ServletException
{
-        Application application = new VaadinClient(m_aceHost, m_obrUrl, m_useAuth, m_userName);
-        m_manager.add(m_manager.createComponent()
-            .setImplementation(application)
-            .setCallbacks("setupDependencies", "start", "stop", "destroyDependencies")
-            .add(m_manager.createServiceDependency()
-                .setService(SessionFactory.class)
-                .setRequired(true)
-            )
-            .add(m_manager.createServiceDependency()
-                .setService(UserAdmin.class)
-                .setRequired(true)
-            )
-            .add(m_manager.createServiceDependency()
-                .setService(AuthenticationService.class)
-                .setRequired(m_useAuth)
-            )
-            .add(m_manager.createServiceDependency()
-                .setService(LogService.class)
-                .setRequired(false)
-            )
-        );
-        return application;
+        return new VaadinClient(m_manager, m_aceHost, m_obrUrl, m_useAuth, m_userName);
     }
     
     @Override

Modified: ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/component/MainActionToolbar.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/component/MainActionToolbar.java?rev=1448029&r1=1448028&r2=1448029&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/component/MainActionToolbar.java
(original)
+++ ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/component/MainActionToolbar.java
Wed Feb 20 08:06:06 2013
@@ -300,17 +300,19 @@ public abstract class MainActionToolbar 
         setWidth("100%");
         setSpacing(true);
         
-        m_manager.add(m_manager.createComponent()
-            .setImplementation(this)
-            .add(m_manager.createServiceDependency()
-                .setService(UIExtensionFactory.class, "(" + UIExtensionFactory.EXTENSION_POINT_KEY
+ "=" + UIExtensionFactory.EXTENSION_POINT_VALUE_MENU + ")")
-                .setCallbacks("add", "remove")
-            )
-        );
-
         initComponent();
     }
     
+    public void init(org.apache.felix.dm.Component component) {
+    	DependencyManager dm = component.getDependencyManager();
+    	component.add(dm.createServiceDependency()
+            .setService(UIExtensionFactory.class, "(" + UIExtensionFactory.EXTENSION_POINT_KEY
+ "=" + UIExtensionFactory.EXTENSION_POINT_VALUE_MENU + ")")
+            .setCallbacks("add", "remove")
+            .setRequired(false)
+            .setInstanceBound(true)
+        );
+    }
+    
     public void add(ServiceReference ref, UIExtensionFactory factory) {
         m_extensions.put(ref, factory);
     }



Mime
View raw message