blob: 0fa3572c4ca426575633da5d6be3cf73a28fb918 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
/*******************************************************************************
* 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 com.ibm.oti.shared.Shared;
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;
/**
* The main plugin class to be used in the desktop.
*/
public class CachingServicePlugin implements BundleActivator {
public static boolean DEBUG;
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(final 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 ...");
final String name = ICachingService.class.getName();
// CachingServiceFactory factory = new CachingServiceFactory();
final 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(final BundleContext context) throws Exception {
}
private void loadOptions(final BundleContext context) {
// all this is only to get the application args
DebugOptions service = null;
final 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);
}
}
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
final 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 (final 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;
}
}
|