ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r792104 - in /incubator/ace/trunk/webui/src/org/apache/ace/server: SessionConstants.java SessionFramework.java SessionListener.java
Date Wed, 08 Jul 2009 11:49:45 GMT
Author: marrs
Date: Wed Jul  8 11:49:45 2009
New Revision: 792104

URL: http://svn.apache.org/viewvc?rev=792104&view=rev
Log:
ACE-29 working on session management for web clients, embedding a private framework instance
in each client session

Added:
    incubator/ace/trunk/webui/src/org/apache/ace/server/SessionConstants.java   (with props)
    incubator/ace/trunk/webui/src/org/apache/ace/server/SessionFramework.java   (with props)
    incubator/ace/trunk/webui/src/org/apache/ace/server/SessionListener.java   (with props)

Added: incubator/ace/trunk/webui/src/org/apache/ace/server/SessionConstants.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/webui/src/org/apache/ace/server/SessionConstants.java?rev=792104&view=auto
==============================================================================
--- incubator/ace/trunk/webui/src/org/apache/ace/server/SessionConstants.java (added)
+++ incubator/ace/trunk/webui/src/org/apache/ace/server/SessionConstants.java Wed Jul  8 11:49:45
2009
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.ace.server;
+
+/**
+ * Constants for keys that are used to store objects in a
+ * session.
+ */
+public interface SessionConstants {
+    /** OSGi framework with session specific client bundles. */
+    public static final String FRAMEWORK = "fw";
+    
+    /** Cache directory of the OSGi framework. */
+    public static final String CACHEDIR = "cd";
+}

Propchange: incubator/ace/trunk/webui/src/org/apache/ace/server/SessionConstants.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/ace/trunk/webui/src/org/apache/ace/server/SessionFramework.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/webui/src/org/apache/ace/server/SessionFramework.java?rev=792104&view=auto
==============================================================================
--- incubator/ace/trunk/webui/src/org/apache/ace/server/SessionFramework.java (added)
+++ incubator/ace/trunk/webui/src/org/apache/ace/server/SessionFramework.java Wed Jul  8 11:49:45
2009
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.ace.server;
+
+import java.io.File;
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpSession;
+
+import org.osgi.framework.Bundle;
+
+/**
+ * Provides access to a client session specific framework
+ * instance.
+ */
+public class SessionFramework {
+    public static Bundle getFramework(HttpSession session, File baseDir) throws Exception
{
+        Bundle fw = (Bundle) session.getAttribute(SessionConstants.FRAMEWORK);
+        if (fw == null) {
+            try {
+                Map configMap = new HashMap();
+                configMap.put("org.osgi.framework.system.packages.extra", "my.package.one,
my.package.two");
+                configMap.put("org.osgi.framework.storage.clean", "true");
+                configMap.put("felix.cache.rootdir", new File(baseDir, "caches"));
+                String cacheDirName = "cache_" + session.getId();
+                configMap.put("org.osgi.framework.storage", cacheDirName);
+    
+                String systemBundlesList = 
+                    "file:bundle/org.apache.felix.shell-1.2.0.jar " + 
+                    "file:bundle/org.apache.felix.shell.tui-1.2.0.jar";
+                configMap.put("felix.auto.start.1", systemBundlesList);
+
+                List bundles = new ArrayList();
+                
+                Class autoActivatorClass = Class.forName("org.apache.felix.main.AutoActivator");
+                Constructor autoActivatorConstructor = autoActivatorClass.getConstructor(new
Class[] { Map.class });
+                Object autoActivator = autoActivatorConstructor.newInstance(new Object[]
{ configMap });
+                
+                bundles.add(autoActivator);
+                
+                configMap.put("felix.systembundle.activators", bundles);
+    
+                Class felixClass = Class.forName("org.apache.felix.framework.Felix");
+                Constructor felixConstructor = felixClass.getConstructor(new Class[] { Map.class
});
+                Bundle felix = (Bundle) felixConstructor.newInstance(new Object[] { configMap
});
+                felix.start();
+                session.setAttribute(SessionConstants.FRAMEWORK, felix);
+                session.setAttribute(SessionConstants.CACHEDIR, cacheDirName);
+                return felix;
+            }
+            catch (Exception error) {
+                throw error;
+            }
+        }
+        return fw;
+    }
+}

Propchange: incubator/ace/trunk/webui/src/org/apache/ace/server/SessionFramework.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/ace/trunk/webui/src/org/apache/ace/server/SessionListener.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/webui/src/org/apache/ace/server/SessionListener.java?rev=792104&view=auto
==============================================================================
--- incubator/ace/trunk/webui/src/org/apache/ace/server/SessionListener.java (added)
+++ incubator/ace/trunk/webui/src/org/apache/ace/server/SessionListener.java Wed Jul  8 11:49:45
2009
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.ace.server;
+
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+
+/**
+ * Listener that examines sessions that are destroyed and stops an embedded
+ * framework stored in <code>SessionConstants.FRAMEWORK</code> if present.
+ */
+public class SessionListener implements HttpSessionListener {
+    public void sessionCreated(HttpSessionEvent se) {
+    }
+
+    public void sessionDestroyed(HttpSessionEvent se) {
+        HttpSession session = se.getSession();
+        if (session != null) {
+            Bundle framework = (Bundle) session.getAttribute(SessionConstants.FRAMEWORK);
+            if (framework != null) {
+                try {
+                    framework.stop();
+                }
+                catch (BundleException e) {
+                    // not much we can do if this fails
+                }
+            }
+        }
+    }
+}

Propchange: incubator/ace/trunk/webui/src/org/apache/ace/server/SessionListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message