Return-Path:
Delivered-To: apmail-incubator-felix-commits-archive@www.apache.org
Received: (qmail 46632 invoked from network); 10 Aug 2006 22:16:52 -0000
Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199)
by minotaur.apache.org with SMTP; 10 Aug 2006 22:16:52 -0000
Received: (qmail 31979 invoked by uid 500); 10 Aug 2006 22:16:51 -0000
Delivered-To: apmail-incubator-felix-commits-archive@incubator.apache.org
Received: (qmail 31961 invoked by uid 500); 10 Aug 2006 22:16:51 -0000
Mailing-List: contact felix-commits-help@incubator.apache.org; run by ezmlm
Precedence: bulk
List-Help:
List-Unsubscribe:
List-Post:
List-Id:
Reply-To: felix-dev@incubator.apache.org
Delivered-To: mailing list felix-commits@incubator.apache.org
Received: (qmail 31913 invoked by uid 99); 10 Aug 2006 22:16:51 -0000
Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49)
by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Aug 2006 15:16:51 -0700
X-ASF-Spam-Status: No, hits=-9.4 required=10.0
tests=ALL_TRUSTED,NO_REAL_NAME
X-Spam-Check-By: apache.org
Received-SPF: pass (asf.osuosl.org: local policy)
Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113)
by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Aug 2006 15:16:41 -0700
Received: by eris.apache.org (Postfix, from userid 65534)
id 0EC8D1A9822; Thu, 10 Aug 2006 15:16:14 -0700 (PDT)
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: svn commit: r430562 [3/6] - in
/incubator/felix/sandbox/santillan/org.apache.felix.jmood: ./ src/
src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/felix/ src/main/java/org/apache/felix/jmood/
src/main/java/...
Date: Thu, 10 Aug 2006 22:16:02 -0000
To: felix-commits@incubator.apache.org
From: santillan@apache.org
X-Mailer: svnmailer-1.0.8
Message-Id: <20060810221615.0EC8D1A9822@eris.apache.org>
X-Virus-Checked: Checked by ClamAV on apache.org
X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N
Added: incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/core/instrumentation/BundleInfo.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/core/instrumentation/BundleInfo.java?rev=430562&view=auto
==============================================================================
--- incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/core/instrumentation/BundleInfo.java (added)
+++ incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/core/instrumentation/BundleInfo.java Thu Aug 10 15:15:58 2006
@@ -0,0 +1,171 @@
+/*
+ * Copyright 2005 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.
+ *
+ */
+
+package org.apache.felix.jmood.core.instrumentation;
+
+import java.io.Serializable;
+import java.util.Hashtable;
+public class BundleInfo implements Serializable {
+
+ //mgmt attributes
+ private int startLevel;
+ private String state;
+ private ServiceInfo[] registeredServices;
+ private ServiceInfo[] servicesInUse;
+ private Hashtable headers;
+ private long bundleId;
+ private PackageInfo[] exportedPackages;
+ private PackageInfo[] importedPackages;
+ private BundleInfo[] fragments;
+ private BundleInfo[] hosts;
+ private BundleInfo[] requiredBundles;
+ private BundleInfo[] requiringBundles;
+ private long lastModified;
+ private String symbolicName;
+ //private String version; //Included in the headers except for required bundles
+ private boolean bundlePersistentlyStarted;
+ private boolean removalPending;
+ private boolean required;
+ private boolean fragment;
+// private R4Permission[] permissions;//TODO This should include conditional permz as well as regular ones
+// private R4Configuration[] configurations; //TODO
+
+ public BundleInfo() {
+ }
+
+
+ ////////////GETTERS'n'SETTERS////////////////////////
+ public boolean isFragment() {
+ return fragment;
+ }
+
+
+ protected void setFragment(boolean fragment) {
+ this.fragment = fragment;
+ }
+
+
+ public long getLastModified() {
+ return lastModified;
+ }
+
+
+ protected void setLastModified(long lastModified) {
+ this.lastModified = lastModified;
+ }
+
+
+ public boolean isRequired() {
+ return required;
+ }
+
+
+ protected void setRequired(boolean required) {
+ this.required = required;
+ }
+ public long getBundleId() {
+ return bundleId;
+ }
+ protected void setBundleId(long bundleId) {
+ this.bundleId = bundleId;
+ }
+ public boolean isBundlePersistentlyStarted() {
+ return bundlePersistentlyStarted;
+ }
+ protected void setBundlePersistentlyStarted(boolean bundlePersistentlyStarted) {
+ this.bundlePersistentlyStarted = bundlePersistentlyStarted;
+ }
+ public PackageInfo[] getExportedPackages() {
+ return exportedPackages;
+ }
+ protected void setExportedPackages(PackageInfo[] exportedPackages) {
+ this.exportedPackages = exportedPackages;
+ }
+ public BundleInfo[] getFragments() {
+ return fragments;
+ }
+ protected void setFragments(BundleInfo[] fragments) {
+ this.fragments = fragments;
+ }
+ public Hashtable getHeaders() {
+ return headers;
+ }
+ protected void setHeaders(Hashtable headers) {
+ this.headers = headers;
+ }
+ public BundleInfo[] getHosts() {
+ return hosts;
+ }
+ protected void setHosts(BundleInfo[] hosts) {
+ this.hosts = hosts;
+ }
+ public PackageInfo[] getImportedPackages() {
+ return importedPackages;
+ }
+ protected void setImportedPackages(PackageInfo[] importedPackages) {
+ this.importedPackages = importedPackages;
+ }
+ public ServiceInfo[] getRegisteredServices() {
+ return registeredServices;
+ }
+ protected void setRegisteredServices(ServiceInfo[] registeredServices) {
+ this.registeredServices = registeredServices;
+ }
+ public boolean isRemovalPending() {
+ return removalPending;
+ }
+ protected void setRemovalPending(boolean removalPending) {
+ this.removalPending = removalPending;
+ }
+ public BundleInfo[] getRequiredBundles() {
+ return requiredBundles;
+ }
+ protected void setRequiredBundles(BundleInfo[] requiredBundles) {
+ this.requiredBundles = requiredBundles;
+ }
+ public BundleInfo[] getRequiringBundles() {
+ return requiringBundles;
+ }
+ protected void setRequiringBundles(BundleInfo[] requiringBundles) {
+ this.requiringBundles = requiringBundles;
+ }
+ public ServiceInfo[] getServicesInUse() {
+ return servicesInUse;
+ }
+ protected void setServicesInUse(ServiceInfo[] servicesInUse) {
+ this.servicesInUse = servicesInUse;
+ }
+ public int getStartLevel() {
+ return startLevel;
+ }
+ protected void setStartLevel(int startLevel) {
+ this.startLevel = startLevel;
+ }
+ public String getState() {
+ return state;
+ }
+ protected void setState(String state) {
+ this.state = state;
+ }
+ public String getSymbolicName() {
+ return symbolicName;
+ }
+ protected void setSymbolicName(String symbolicName) {
+ this.symbolicName = symbolicName;
+ }
+
+}
Added: incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/core/instrumentation/FrameworkSnapshot.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/core/instrumentation/FrameworkSnapshot.java?rev=430562&view=auto
==============================================================================
--- incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/core/instrumentation/FrameworkSnapshot.java (added)
+++ incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/core/instrumentation/FrameworkSnapshot.java Thu Aug 10 15:15:58 2006
@@ -0,0 +1,245 @@
+/*
+ * Copyright 2005 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.
+ *
+ */
+
+package org.apache.felix.jmood.core.instrumentation;
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import org.apache.felix.jmood.AgentContext;
+import org.apache.felix.jmood.core.ServiceNotAvailableException;
+import org.apache.felix.jmood.utils.InstrumentationSupport;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.packageadmin.ExportedPackage;
+
+public class FrameworkSnapshot {
+ private Hashtable bundles = new Hashtable(); //
+
+ private Hashtable services = new Hashtable();//
+
+ private Hashtable packages = new Hashtable();//
+
+ private AgentContext ac;
+
+ private long timestamp;
+
+ public FrameworkSnapshot(AgentContext ac) {
+ super();
+ this.ac = ac;
+ this.populate();
+ }
+
+ public long getShotTime() {
+ return timestamp;
+ }
+
+ public void refreshSnapshot() {
+ bundles = new Hashtable();
+ services = new Hashtable();
+ packages = new Hashtable();
+ this.populate();
+ ac.debug("factory-bundles found: " + bundles.size());
+ ac.debug("factory-services found: " + services.size());
+ ac.debug("factory-packages found: " + packages.size());
+
+ }
+
+ public BundleInfo[] getAllBundles() {
+ Enumeration b = bundles.elements();
+ BundleInfo[] binfo = new BundleInfo[bundles.size()];
+ for (int i = 0; i < binfo.length; i++) {
+ binfo[i] = (BundleInfo) b.nextElement();
+ }
+ return binfo;
+ }
+
+ public ServiceInfo[] getAllServiceInfo() {
+ Enumeration s = services.elements();
+ ServiceInfo[] sinfo = new ServiceInfo[services.size()];
+ for (int i = 0; i < sinfo.length; i++) {
+ sinfo[i] = (ServiceInfo) s.nextElement();
+ }
+ return sinfo;
+ }
+
+ public PackageInfo[] getAllPackageInfo() {
+ Enumeration p = packages.elements();
+ PackageInfo[] pinfo = new PackageInfo[packages.size()];
+ for (int i = 0; i < pinfo.length; i++) {
+ pinfo[i] = (PackageInfo) p.nextElement();
+ }
+ return pinfo;
+ }
+
+ // ///////////PRIVATE METHODS//////////////////////////
+
+ private void populate() {
+ Bundle[] bundles = ac.getBundleContext().getBundles();
+ BundleInfo[] binfo = new BundleInfo[bundles.length];
+ for (int i = 0; i < binfo.length; i++) {
+ binfo[i] = getBundleInfo(bundles[i]);
+ }
+ this.timestamp = System.currentTimeMillis();
+ }
+
+private BundleInfo getBundleInfo(Bundle bundle) {
+ if (bundle==null) return null;
+ ac.debug("creating R4 bundleinfo: "+bundle.getSymbolicName());
+ Long key = new Long(bundle.getBundleId());
+ if (bundles.containsKey(key))
+ return (BundleInfo) bundles.get(key);
+ BundleInfo b = new BundleInfo();
+ b.setBundleId(bundle.getBundleId());
+ bundles.put(key, b);
+ try{
+ b.setFragments(this.getFragments(bundle));
+ b.setHeaders(InstrumentationSupport.getHashtable(bundle.getHeaders()));
+ b.setLastModified(bundle.getLastModified());
+ b.setRegisteredServices(this.getSvcsInfo(bundle.getRegisteredServices()));
+ b.setBundlePersistentlyStarted(InstrumentationSupport.isBundlePersistentlyStarted(bundle, ac));
+ b.setStartLevel(InstrumentationSupport.getBundleStartLevel(bundle, ac));
+ b.setExportedPackages(this.getPkgInfo(InstrumentationSupport.getExportedPackages(bundle, ac)));
+ b.setFragment(InstrumentationSupport.isFragment(bundle, ac));
+ b.setRequired(InstrumentationSupport.isBundleRequired(bundle, ac));
+ b.setRemovalPending(InstrumentationSupport.isRequiredBundleRemovalPending(bundle, ac));
+ b.setRequiredBundles(this.getBundleDependencies(bundle));
+ b.setRequiringBundles(this.getBInfos(InstrumentationSupport.getRequiringBundles(bundle, ac)));
+ b.setImportedPackages(this.getImportedPackages(bundle));
+ }catch(ServiceNotAvailableException sae){
+ //Not needed, since they are default values, placed for clarity
+ b.setBundlePersistentlyStarted(false);
+ b.setStartLevel(-1);
+ b.setExportedPackages(null);
+ b.setFragment(false);
+ b.setRequired(false);
+ b.setRemovalPending(false);
+ b.setRequiredBundles(null);
+ b.setRequiringBundles(null);
+ b.setImportedPackages(null);
+ ac.warning(sae.getMessage());
+ }
+ b.setServicesInUse(this.getSvcsInfo(bundle.getServicesInUse()));
+ b.setState(InstrumentationSupport.getState(bundle.getState()));
+ b.setSymbolicName(bundle.getSymbolicName());
+ return b;
+ } private ServiceInfo getServiceInfo(ServiceReference svc) {
+ if (svc == null)
+ return null;
+ ac.debug("Creating R4service for service id "
+ + svc.getProperty(Constants.SERVICE_ID));
+ Long key = (Long) svc.getProperty(Constants.SERVICE_ID);
+ if (services.containsKey(key))
+ return (ServiceInfo) services.get(key);
+ ServiceInfo s = new ServiceInfo();
+ services.put(key, s);
+
+ // now we set the atts
+ s.setBundle(this.getBundleInfo(svc.getBundle()));
+ Bundle[] using = svc.getUsingBundles();
+ if (using != null) {
+ BundleInfo[] r4Using = new BundleInfo[using.length];
+ for (int i = 0; i < r4Using.length; i++) {
+ r4Using[i] = getBundleInfo(using[i]);
+ }
+ s.setUsingBundles(r4Using);
+ }
+ Hashtable props = new Hashtable();//
+ String[] keys=svc.getPropertyKeys();
+ for (int i=0; iFor each BundleInfo, this method returns the symbolic name String, which we define as the concatenation of
+ * the getSymbolicName of the Bundle interface and the bundle version as specified
+ * in the bundle header. Both parts are divided by a semicolon. An example would be:
+ *
+ * com.acme.foo;1.0.0
+ *
+ * @param bundles The Bundle array to be converted
+ * @return The String array
+ * @see org.osgi.framework.Bundle#getSymbolicName()
+ */
+ public static String[] getSymbolicNames(Bundle[] bundles) {
+ if(bundles==null) return null;
+ String[] names=new String[bundles.length];
+ for (int i = 0; i < names.length; i++) {
+ names[i]=getSymbolicName(bundles[i]);
+ }
+ return names;
+ }
+ public static String getSymbolicName(Bundle bundle){
+ return bundle.getSymbolicName()+";"+bundle.getHeaders().get(Constants.BUNDLE_VERSION);
+
+ }
+
+ /**
+ *
+ *
+ * OSGi exported packages can be uniquely identified by the tuple (packageName, packageVersion).
+ * This methods returns a String array representing those packages with the following syntax:
+ *
+ *
+ * packageName;packageVersion
+ *
+ * where packageName is as returned by the method getName() and packageVersion as returned by the method getVersion()
+ * in package admin's ExportedPackage class.
+ *
+ * @param packages The ExportedPackage array to be converted
+ * @return The String array
+ * @see org.osgi.service.packageadmin.ExportedPackage
+ */
+ public static String[] getPackageNames(ExportedPackage[] packages) {
+ if (packages==null) return null;
+ String[] names=new String[packages.length];
+ for (int i = 0; i < names.length; i++) {
+ names[i]=getPackageName(packages[i]);
+ }
+ return names;
+
+ }
+ public static String getPackageName(ExportedPackage pkg) {
+ return pkg.getName()+";"+pkg.getVersion().toString();
+ }
+
+
+ /**
+ *
+ * OSGi Services can be registered under more than one interface (objectClass in
+ * the spec). Services have a mandatory unique service id (as defined in the SERVICE_ID property of the org.osgi.framework.Constants interface), during their lifetime (i.e, until they are
+ * garbage collected). To show this information in a consistent way, we use the following String representation
+ * of the service:
+ *
+ * where objectClass1..objectClassN are the elements of the mandatory objectClass array
+ * included in the service property dictionary (and set by the framework at registration time. The property name is defined in org.osgi.framework.Constants#OBJECTCLASS
+ *