incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mnutt...@apache.org
Subject svn commit: r899240 - in /incubator/aries/trunk/application/application-runtime/src/main: java/org/apache/aries/application/runtime/ java/org/apache/aries/application/runtime/impl/ resources/ resources/OSGI-INF/ resources/OSGI-INF/blueprint/
Date Thu, 14 Jan 2010 15:31:48 GMT
Author: mnuttall
Date: Thu Jan 14 15:31:47 2010
New Revision: 899240

URL: http://svn.apache.org/viewvc?rev=899240&view=rev
Log:
ARIES-89: Implement application support: Very basic runtime support

Added:
    incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/
    incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextImpl.java
      - copied, changed from r899234, incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/ApplicationContextImpl.java
    incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextManagerImpl.java
      - copied, changed from r899234, incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/ApplicationContextManagerImpl.java
    incubator/aries/trunk/application/application-runtime/src/main/resources/
    incubator/aries/trunk/application/application-runtime/src/main/resources/OSGI-INF/
    incubator/aries/trunk/application/application-runtime/src/main/resources/OSGI-INF/blueprint/
    incubator/aries/trunk/application/application-runtime/src/main/resources/OSGI-INF/blueprint/app-context-management.xml
Removed:
    incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/ApplicationContextImpl.java
    incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/ApplicationContextManagerImpl.java

Copied: incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextImpl.java
(from r899234, incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/ApplicationContextImpl.java)
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextImpl.java?p2=incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextImpl.java&p1=incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/ApplicationContextImpl.java&r1=899234&r2=899240&rev=899240&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/ApplicationContextImpl.java
(original)
+++ incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextImpl.java
Thu Jan 14 15:31:47 2010
@@ -17,39 +17,72 @@
  * under the License.
  */
 
-package org.apache.aries.application.runtime;
+package org.apache.aries.application.runtime.impl;
 
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
 import java.util.Set;
 
 import org.apache.aries.application.management.ApplicationContext;
 import org.apache.aries.application.management.AriesApplication;
+import org.apache.aries.application.management.BundleInfo;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
 
 public class ApplicationContextImpl implements ApplicationContext {
+  
+  private AriesApplication _application;
+  private Map<BundleInfo, Bundle> _bundles;
+  private ApplicationState _state;
+  private BundleContext _bundleContext;
+  
+  public ApplicationContextImpl (BundleContext b, AriesApplication app) { 
+    _application = app;
+    _bundles = new HashMap<BundleInfo, Bundle>();
+    _state = ApplicationState.INSTALLED;
+  }
 
   public AriesApplication getApplication() {
-    // TODO Auto-generated method stub
-    return null;
+    return _application;
   }
-
+  
   public Set<Bundle> getApplicationContent() {
-    // TODO Auto-generated method stub
-    return null;
-  }
+    Set<Bundle> result = new HashSet<Bundle>();
+    for (Map.Entry<BundleInfo, Bundle> entry : _bundles.entrySet()) { 
+      result.add (entry.getValue());
+    }
+    return result;
+  } 
 
   public ApplicationState getApplicationState() {
-    // TODO Auto-generated method stub
-    return null;
+    return _state;
   }
 
-  public void start() {
-    // TODO Auto-generated method stub
-    
+  public void start() throws BundleException {
+    Set<BundleInfo> bundleInfo = _application.getBundleInfo();
+    for (BundleInfo bi : bundleInfo) { 
+      // TODO: proper synchronisation!
+      if (_bundles.containsKey(bi)) { 
+        Bundle b = _bundles.get(bi);
+        if (b.getState() != Bundle.ACTIVE) { 
+          b.start();
+        }
+      } else { 
+        Bundle b = _bundleContext.installBundle(bi.getLocation()); 
+        b.start();
+        _bundles.put(bi, b);
+      }
+    }
+    _state = ApplicationState.ACTIVE;
   }
 
-  public void stop() {
-    // TODO Auto-generated method stub
-    
-  } 
-  
+  public void stop() throws BundleException {
+    for (Map.Entry<BundleInfo, Bundle> entry : _bundles.entrySet()) { 
+      Bundle b = entry.getValue();
+      b.stop();
+    }
+    _state = ApplicationState.RESOLVED;
+  }
 }

Copied: incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextManagerImpl.java
(from r899234, incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/ApplicationContextManagerImpl.java)
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextManagerImpl.java?p2=incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextManagerImpl.java&p1=incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/ApplicationContextManagerImpl.java&r1=899234&r2=899240&rev=899240&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/ApplicationContextManagerImpl.java
(original)
+++ incubator/aries/trunk/application/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextManagerImpl.java
Thu Jan 14 15:31:47 2010
@@ -17,24 +17,52 @@
  * under the License.
  */
 
-package org.apache.aries.application.runtime;
+package org.apache.aries.application.runtime.impl;
 
+import java.util.HashSet;
+import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 
 import org.apache.aries.application.management.ApplicationContext;
 import org.apache.aries.application.management.ApplicationContextManager;
 import org.apache.aries.application.management.AriesApplication;
+import org.osgi.framework.BundleContext;
 
 public class ApplicationContextManagerImpl implements ApplicationContextManager {
 
+  ConcurrentMap<AriesApplication, ApplicationContext> _appToContextMap;
+  BundleContext _bundleContext;
+  
+  public ApplicationContextManagerImpl () { 
+    _appToContextMap = new ConcurrentHashMap<AriesApplication, ApplicationContext>();
+  }
+  
+  public void setBundleContext (BundleContext b) { 
+    _bundleContext = b;
+  }
+  
   public ApplicationContext getApplicationContext(AriesApplication app) {
-    // TODO Auto-generated method stub
-    return null;
+    ApplicationContext result;
+    if (_appToContextMap.containsKey(app)) { 
+      result = _appToContextMap.get(app);
+    } else { 
+      result = new ApplicationContextImpl (_bundleContext, app);
+      ApplicationContext previous = _appToContextMap.putIfAbsent(app, result);
+      if (previous != null) { 
+        result = previous;
+      }
+    }
+    return result;
   }
 
   public Set<ApplicationContext> getApplicationContexts() {
-    // TODO Auto-generated method stub
-    return null;
+    Set<ApplicationContext> result = new HashSet<ApplicationContext>();
+    for (Map.Entry<AriesApplication, ApplicationContext> entry: _appToContextMap.entrySet())
{
+      result.add (entry.getValue());
+    }
+    return result;
   }
 
 }

Added: incubator/aries/trunk/application/application-runtime/src/main/resources/OSGI-INF/blueprint/app-context-management.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-runtime/src/main/resources/OSGI-INF/blueprint/app-context-management.xml?rev=899240&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-runtime/src/main/resources/OSGI-INF/blueprint/app-context-management.xml
(added)
+++ incubator/aries/trunk/application/application-runtime/src/main/resources/OSGI-INF/blueprint/app-context-management.xml
Thu Jan 14 15:31:47 2010
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+  
+  <bean id="app-context-manager" class="org.apache.aries.application.runtime.impl.ApplicationContextManagerImpl"
scope="singleton" activation="lazy">
+    <property name="bundleContext" ref="blueprintBundleContext"/>
+  </bean>
+   
+  <service interface="org.apache.aries.application.management.pplicationContextManager"
ref="app-context-manager" />
+  
+</blueprint>



Mime
View raw message