geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwo...@apache.org
Subject svn commit: r1075629 - in /geronimo/server/branches/3.0-M2/plugins/console/osgi-portlets/src/main: java/org/apache/geronimo/console/portlet/BundlesPortlet.java webapp/WEB-INF/view/BundlesView.jsp
Date Tue, 01 Mar 2011 02:54:19 GMT
Author: rwonly
Date: Tue Mar  1 02:54:19 2011
New Revision: 1075629

URL: http://svn.apache.org/viewvc?rev=1075629&view=rev
Log:
GERONIMO-5774 osgi portlet improvements (refactor the refresh status codes)

Modified:
    geronimo/server/branches/3.0-M2/plugins/console/osgi-portlets/src/main/java/org/apache/geronimo/console/portlet/BundlesPortlet.java
    geronimo/server/branches/3.0-M2/plugins/console/osgi-portlets/src/main/webapp/WEB-INF/view/BundlesView.jsp

Modified: geronimo/server/branches/3.0-M2/plugins/console/osgi-portlets/src/main/java/org/apache/geronimo/console/portlet/BundlesPortlet.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-M2/plugins/console/osgi-portlets/src/main/java/org/apache/geronimo/console/portlet/BundlesPortlet.java?rev=1075629&r1=1075628&r2=1075629&view=diff
==============================================================================
--- geronimo/server/branches/3.0-M2/plugins/console/osgi-portlets/src/main/java/org/apache/geronimo/console/portlet/BundlesPortlet.java
(original)
+++ geronimo/server/branches/3.0-M2/plugins/console/osgi-portlets/src/main/java/org/apache/geronimo/console/portlet/BundlesPortlet.java
Tue Mar  1 02:54:19 2011
@@ -74,10 +74,7 @@ public class BundlesPortlet extends Gene
     private PortletRequestDispatcher maximizedView;
     private PortletRequestDispatcher helpView;
 
-    
-    BundleContext bundleContext = null;
-    StartLevel startLevelService = null;
-    
+   
     public void init(PortletConfig portletConfig) throws PortletException {
         super.init(portletConfig);
         normalView = portletConfig.getPortletContext().getRequestDispatcher(NORMALVIEW_JSP);
@@ -97,13 +94,6 @@ public class BundlesPortlet extends Gene
     
     protected void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws
IOException,
             PortletException {
-
-        //get bundleContext
-        bundleContext = (BundleContext) renderRequest.getPortletSession().getPortletContext().getAttribute("osgi-bundlecontext");
-        
-        //get the StartLeval object
-        ServiceReference startLevelRef = bundleContext.getServiceReference(StartLevel.class.getCanonicalName());
-        startLevelService = (StartLevel) bundleContext.getService(startLevelRef);
         
         if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) {
             return;
@@ -124,6 +114,14 @@ public class BundlesPortlet extends Gene
 
     private void doBundlesView(RenderRequest request, RenderResponse response) {
 
+        //get bundleContext
+        BundleContext bundleContext = (BundleContext) request.getPortletSession().getPortletContext().getAttribute("osgi-bundlecontext");
+        
+        //get the StartLeval object
+        ServiceReference startLevelRef = bundleContext.getServiceReference(StartLevel.class.getCanonicalName());
+        StartLevel startLevelService = (StartLevel) bundleContext.getService(startLevelRef);
+        
+        //get all bundles
         Bundle[] bundles = bundleContext.getBundles();
 
         // list contains bundles converted from Bundle objects
@@ -132,7 +130,7 @@ public class BundlesPortlet extends Gene
         
         // convert Bundle to OSGiBundle
         for (Bundle bundle : bundles) {
-            if (!checkSysBundle(bundle)){
+            if (!checkSysBundle(bundle, startLevelService)){
                 OSGiBundle osgiBundle = new OSGiBundle(bundle);
                 OSGiBundleList.add(osgiBundle);
             }
@@ -143,11 +141,13 @@ public class BundlesPortlet extends Gene
             request.setAttribute("GridJSONObject", grid);
         } catch (JSONException e) {
             e.printStackTrace();
+        } finally {
+            bundleContext.ungetService(startLevelRef);
         }
 
     }
     
-    private boolean checkSysBundle(Bundle bundle){
+    private boolean checkSysBundle(Bundle bundle, StartLevel startLevelService){
         
         // check start level
         if (startLevelService!=null && startLevelService.getBundleStartLevel(bundle)
<= 50){ //config.properties set karaf.systemBundlesStartLevel=50
@@ -219,7 +219,7 @@ public class BundlesPortlet extends Gene
 
     public void serveResource(ResourceRequest request, ResourceResponse response) throws
PortletException, IOException {
         
-        bundleContext = (BundleContext) request.getPortletSession().getPortletContext().getAttribute("osgi-bundlecontext");
+        BundleContext bundleContext = (BundleContext) request.getPortletSession().getPortletContext().getAttribute("osgi-bundlecontext");
         
         String resourceId = request.getResourceID();
   
@@ -277,7 +277,11 @@ public class BundlesPortlet extends Gene
                 } else if (action.equals("refresh")){
                     // prepare response
                     resultItem.put("id", id);
-                    resultItem.put("state", OSGiBundle.getStateName(bundleContext.getBundle(id).getState()));
+                    if (bundleContext.getBundle(id)!=null){
+                        resultItem.put("state", OSGiBundle.getStateName(bundleContext.getBundle(id).getState()));
+                    } else {
+                        resultItem.put("state", OSGiBundle.getStateName(Bundle.UNINSTALLED));
+                    }
                 }   
                 
                 PrintWriter writer = response.getWriter();
@@ -287,7 +291,7 @@ public class BundlesPortlet extends Gene
                 e.printStackTrace();
             } catch (BundleException e) {
                 e.printStackTrace();
-            }catch (InterruptedException e) {
+            } catch (InterruptedException e) {
                 e.printStackTrace();
             }
             
@@ -311,12 +315,8 @@ public class BundlesPortlet extends Gene
             ServiceReference reference = bundle.getBundleContext().getServiceReference(PackageAdmin.class.getName());
             try {
                 
-               
                 PackageAdmin packageAdmin = (PackageAdmin) bundle.getBundleContext().getService(reference);
                 
-
-                
-                
                 //importing
                 Set<PackageBundlePair> importingPairs =  getImportingPairs(packageAdmin,
bundle);
 
@@ -376,6 +376,10 @@ public class BundlesPortlet extends Gene
             
         } else if (resourceId.equals("showSysBundles")) {
             
+            //get the StartLeval object
+            ServiceReference startLevelRef = bundleContext.getServiceReference(StartLevel.class.getCanonicalName());
+            StartLevel startLevelService = (StartLevel) bundleContext.getService(startLevelRef);
+            
             Bundle[] bundles = bundleContext.getBundles();
 
             // list contains bundles converted from Bundle objects
@@ -384,7 +388,7 @@ public class BundlesPortlet extends Gene
             
             // convert Bundle to OSGiBundle
             for (Bundle bundle : bundles) {
-                if (checkSysBundle(bundle)){
+                if (checkSysBundle(bundle, startLevelService)){
                     OSGiBundle osgiBundle = new OSGiBundle(bundle);
                     OSGiBundleList.add(osgiBundle);
                 }
@@ -396,6 +400,8 @@ public class BundlesPortlet extends Gene
                 writer.print(grid);
             } catch (JSONException e) {
                 e.printStackTrace();
+            } finally{
+                bundleContext.ungetService(startLevelRef);
             }
             
             

Modified: geronimo/server/branches/3.0-M2/plugins/console/osgi-portlets/src/main/webapp/WEB-INF/view/BundlesView.jsp
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-M2/plugins/console/osgi-portlets/src/main/webapp/WEB-INF/view/BundlesView.jsp?rev=1075629&r1=1075628&r2=1075629&view=diff
==============================================================================
--- geronimo/server/branches/3.0-M2/plugins/console/osgi-portlets/src/main/webapp/WEB-INF/view/BundlesView.jsp
(original)
+++ geronimo/server/branches/3.0-M2/plugins/console/osgi-portlets/src/main/webapp/WEB-INF/view/BundlesView.jsp
Tue Mar  1 02:54:19 2011
@@ -154,15 +154,16 @@ function hideLoadingDIV(){
     							dijit.byId("usrBundlesGrid").store.setValue(item,"state","Unknown");
     						}
     					});
-    				}else if(updatedItem.state == "Uninstalled") {
+    				}else if(updatedItem.state == "Uninstalled") { // uninstall action results; refresh
action may also go here
+        				// should show a msg
     					dijit.byId("usrBundlesGrid").store.fetchItemByIdentity({
     						identity:updatedItem.id,
     						onItem:function(item){
     							dijit.byId("usrBundlesGrid").store.deleteItem(item);
     						}
     					});
-    				}else { // start/stop/refresh action results
-        				//todo: refresh when the status is Unknown but bundle is uninstalled.
+    				}else { // start or stop action results; refresh action may also go here
+        				// should show a msg
     					dijit.byId("usrBundlesGrid").store.fetchItemByIdentity({
     						identity:updatedItem.id,
     						onItem:function(item){
@@ -412,9 +413,7 @@ This portlet shows the general user bund
 				</div>
 			</td>
 			
-	        
-	    
-			
+
 		</tr> 
 	</table>
 	



Mime
View raw message