Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Lippert2008-07-04 18:57:06 +0000
committerMartin Lippert2008-07-04 18:57:06 +0000
commit2f425920ab801b833bc8828a053d8adc1e427aa3 (patch)
tree92830ad0186a56d60ad3eb58cb71098ddc8787e6 /bundles/org.eclipse.equinox.weaving.caching.j9/src
parenta8ed43f1d037ff5a577f4c36d9876e874964b898 (diff)
downloadrt.equinox.bundles-2f425920ab801b833bc8828a053d8adc1e427aa3.tar.gz
rt.equinox.bundles-2f425920ab801b833bc8828a053d8adc1e427aa3.tar.xz
rt.equinox.bundles-2f425920ab801b833bc8828a053d8adc1e427aa3.zip
Bug 238730 - [aspects] rename bundles and start with new version numbering
Diffstat (limited to 'bundles/org.eclipse.equinox.weaving.caching.j9/src')
-rw-r--r--bundles/org.eclipse.equinox.weaving.caching.j9/src/org/eclipse/equinox/weaving/internal/caching/j9/CachingService.java97
-rw-r--r--bundles/org.eclipse.equinox.weaving.caching.j9/src/org/eclipse/equinox/weaving/internal/caching/j9/CachingServiceFactory.java30
-rw-r--r--bundles/org.eclipse.equinox.weaving.caching.j9/src/org/eclipse/equinox/weaving/internal/caching/j9/CachingServicePlugin.java110
3 files changed, 237 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.weaving.caching.j9/src/org/eclipse/equinox/weaving/internal/caching/j9/CachingService.java b/bundles/org.eclipse.equinox.weaving.caching.j9/src/org/eclipse/equinox/weaving/internal/caching/j9/CachingService.java
new file mode 100644
index 000000000..109c49a06
--- /dev/null
+++ b/bundles/org.eclipse.equinox.weaving.caching.j9/src/org/eclipse/equinox/weaving/internal/caching/j9/CachingService.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * David Knibb initial implementation
+ * Matthew Webster Eclipse 3.2 changes
+ *******************************************************************************/
+
+package org.eclipse.equinox.weaving.internal.caching.j9;
+
+import java.net.URL;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+import org.eclipse.equinox.service.weaving.ICachingService;
+import org.osgi.framework.Bundle;
+
+import com.ibm.oti.shared.HelperAlreadyDefinedException;
+import com.ibm.oti.shared.Shared;
+import com.ibm.oti.shared.SharedClassURLHelper;
+
+public class CachingService implements ICachingService {
+
+ private Bundle bundle;
+ private ClassLoader classLoader;
+ private String partition;
+ SharedClassURLHelper urlhelper;
+
+ public CachingService () {
+ if (CachingServicePlugin.DEBUG) System.out.println("- CachingService.<init>()");
+ }
+
+ public CachingService (ClassLoader loader, Bundle bundle, String key) {
+ if (CachingServicePlugin.DEBUG) System.out.println("> CachingService.<init>() bundle=" + bundle.getSymbolicName() + ", loader=" + loader + ", key='" + key + "'");
+ this.bundle = bundle;
+ this.classLoader = loader;
+ this.partition = hashNamespace(key);
+ try{
+ urlhelper = Shared.getSharedClassHelperFactory().getURLHelper(classLoader);
+ } catch (HelperAlreadyDefinedException e) {
+ e.printStackTrace();
+ }
+ if (CachingServicePlugin.DEBUG) System.out.println("< CachingService.<init>() partition='" + partition + "', urlhelper=" + urlhelper);
+ }
+
+ public ICachingService getInstance(ClassLoader classLoader, Bundle bundle, String key) {
+ return new CachingService(classLoader,bundle, key);
+ }
+
+ public byte[] findStoredClass(String namespace, URL sourceFileURL, String name) {
+ byte[] bytes = urlhelper.findSharedClass(partition, sourceFileURL, name);
+ if (CachingServicePlugin.DEBUG && bytes != null) System.out.println("- CachingService.findStoredClass() bundle=" + bundle.getSymbolicName() + ", name=" + name + ", url=" + sourceFileURL + ", bytes=" + bytes);
+ return bytes;
+ }
+
+ public boolean storeClass(String namespace, URL sourceFileURL, Class clazz, byte[] classbytes) {
+ boolean success = urlhelper.storeSharedClass(partition, sourceFileURL, clazz);
+ if (CachingServicePlugin.DEBUG && success) System.out.println("- CachingService.storeClass() bundle=" + bundle.getSymbolicName() + ", clazz=" + clazz + ", url=" + sourceFileURL);
+ return success;
+ }
+
+ /**
+ * Hash the shared class namespace using MD5
+ * @param keyToHash
+ * @return the MD5 version of the input string
+ */
+ public String hashNamespace(String namespace){
+ MessageDigest md = null;
+ try {
+ md = MessageDigest.getInstance("MD5");
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ }
+ byte[] bytes = md.digest(namespace.getBytes());
+ StringBuffer result = new StringBuffer();
+ for(int i=0; i<bytes.length; i++){
+ byte b = bytes[i];
+ int num;
+ if(b<0) {
+ num = b+256;
+ }else{
+ num=b;
+ }
+ String s = Integer.toHexString(num);
+ while (s.length()<2){
+ s = "0"+s;
+ }
+ result.append(s);
+ }
+ return new String(result);
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.weaving.caching.j9/src/org/eclipse/equinox/weaving/internal/caching/j9/CachingServiceFactory.java b/bundles/org.eclipse.equinox.weaving.caching.j9/src/org/eclipse/equinox/weaving/internal/caching/j9/CachingServiceFactory.java
new file mode 100644
index 000000000..c3c86db7d
--- /dev/null
+++ b/bundles/org.eclipse.equinox.weaving.caching.j9/src/org/eclipse/equinox/weaving/internal/caching/j9/CachingServiceFactory.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * David Knibb initial implementation
+ * Matthew Webster Eclipse 3.2 changes
+ *******************************************************************************/
+
+package org.eclipse.equinox.weaving.internal.caching.j9;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
+
+public class CachingServiceFactory implements ServiceFactory {
+
+ public Object getService(Bundle bundle, ServiceRegistration registration) {
+ return new CachingService();
+ }
+
+ public void ungetService(Bundle bundle, ServiceRegistration registration,
+ Object service) {
+
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.weaving.caching.j9/src/org/eclipse/equinox/weaving/internal/caching/j9/CachingServicePlugin.java b/bundles/org.eclipse.equinox.weaving.caching.j9/src/org/eclipse/equinox/weaving/internal/caching/j9/CachingServicePlugin.java
new file mode 100644
index 000000000..4009aeb82
--- /dev/null
+++ b/bundles/org.eclipse.equinox.weaving.caching.j9/src/org/eclipse/equinox/weaving/internal/caching/j9/CachingServicePlugin.java
@@ -0,0 +1,110 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * David Knibb initial implementation
+ * Matthew Webster Eclipse 3.2 changes
+ * Martin Lippert minor changes
+ *******************************************************************************/
+
+package org.eclipse.equinox.weaving.internal.caching.j9;
+
+import org.eclipse.equinox.service.weaving.ICachingService;
+import org.eclipse.osgi.service.debug.DebugOptions;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+import com.ibm.oti.shared.Shared;
+
+/**
+ * The main plugin class to be used in the desktop.
+ */
+public class CachingServicePlugin implements BundleActivator {
+
+ public static boolean verbose = Boolean.getBoolean("org.aspectj.osgi.verbose");
+
+ /**
+ * The constructor.
+ */
+ public CachingServicePlugin() {
+ }
+
+ /**
+ * This method is called upon plug-in activation
+ */
+ public void start(BundleContext context) throws Exception {
+ if (CachingServicePlugin.DEBUG) System.out.println("> CachingServicePlugin.start() context=" + context);
+
+ loadOptions(context);
+
+ //are we on J9?
+ if(shouldRegister()){
+ if (verbose) System.err.println("[org.aspectj.osgi.service.caching.j9] info starting J9 caching service ...");
+ String name = ICachingService.class.getName();
+// CachingServiceFactory factory = new CachingServiceFactory();
+ CachingService singleCachingService = new CachingService();
+ context.registerService(name,singleCachingService,null);
+// System.out.println("CachingServicePlugin.start() - registered cachingService");
+ }
+ else {
+ if (verbose) System.err.println("[org.aspectj.osgi.service.caching.j9] warning cannot start J9 caching service");
+ }
+
+ if (CachingServicePlugin.DEBUG) System.out.println("< CachingServicePlugin.start()");
+ }
+
+ /**
+ * This method is called when the plug-in is stopped
+ */
+ public void stop(BundleContext context) throws Exception {
+ }
+
+ private boolean shouldRegister(){
+ if (CachingServicePlugin.DEBUG) System.out.println("> CachingServicePlugin.shouldRegister()");
+
+ boolean enabled;
+ try{
+ Class.forName("com.ibm.oti.vm.VM"); //if this fails we are not on J9
+ boolean sharing = Shared.isSharingEnabled(); //if not using shared classes we want a different adaptor
+ if (CachingServicePlugin.DEBUG) System.out.println("- CachingServicePlugin.shouldRegister() sharing=" + sharing);
+
+ if(sharing) {
+ enabled = true;
+ }else{
+ enabled = false;
+ }
+ }
+ catch(ClassNotFoundException ex){
+ if (CachingServicePlugin.DEBUG) System.out.println("E CachingServicePlugin.shouldRegister() ex=" + ex);
+ //not on J9
+ enabled = false;
+ }
+
+ if (CachingServicePlugin.DEBUG) System.out.println("< CachingServicePlugin.shouldRegister() " + enabled);
+ return enabled;
+ }
+
+ private void loadOptions (BundleContext context) {
+ // all this is only to get the application args
+ DebugOptions service = null;
+ ServiceReference reference = context.getServiceReference(DebugOptions.class.getName());
+ if (reference != null)
+ service = (DebugOptions) context.getService(reference);
+ if (service == null)
+ return;
+ try {
+ DEBUG = service.getBooleanOption("org.aspectj.osgi.service.caching.j9/debug", false);
+ } finally {
+ // we have what we want - release the service
+ context.ungetService(reference);
+ }
+ }
+
+ public static boolean DEBUG;
+
+}

Back to the top