|
Lines 43-48
Link Here
|
| 43 |
/** bundle's use count for this service */ |
43 |
/** bundle's use count for this service */ |
| 44 |
/* @GuardedBy("this") */ |
44 |
/* @GuardedBy("this") */ |
| 45 |
private int useCount; |
45 |
private int useCount; |
|
|
46 |
/** true if we are calling the factory getService method. Used to detect recursion. */ |
| 47 |
/* @GuardedBy("this") */ |
| 48 |
private boolean factoryInUse; |
| 46 |
|
49 |
|
| 47 |
/** Internal framework object. */ |
50 |
/** Internal framework object. */ |
| 48 |
|
51 |
|
|
Lines 56-61
Link Here
|
| 56 |
*/ |
59 |
*/ |
| 57 |
ServiceUse(BundleContextImpl context, ServiceRegistrationImpl<S> registration) { |
60 |
ServiceUse(BundleContextImpl context, ServiceRegistrationImpl<S> registration) { |
| 58 |
this.useCount = 0; |
61 |
this.useCount = 0; |
|
|
62 |
this.factoryInUse = false; |
| 59 |
S service = registration.getServiceObject(); |
63 |
S service = registration.getServiceObject(); |
| 60 |
if (service instanceof ServiceFactory<?>) { |
64 |
if (service instanceof ServiceFactory<?>) { |
| 61 |
@SuppressWarnings("unchecked") |
65 |
@SuppressWarnings("unchecked") |
|
Lines 116-121
Link Here
|
| 116 |
if (Debug.DEBUG_SERVICES) { |
120 |
if (Debug.DEBUG_SERVICES) { |
| 117 |
Debug.println("getService[factory=" + registration.getBundle() + "](" + context.getBundleImpl() + "," + registration + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
121 |
Debug.println("getService[factory=" + registration.getBundle() + "](" + context.getBundleImpl() + "," + registration + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| 118 |
} |
122 |
} |
|
|
123 |
// check for recursive call |
| 124 |
if (factoryInUse == true) { |
| 125 |
if (Debug.DEBUG_SERVICES) { |
| 126 |
Debug.println(factory + ".getService() recursively called."); //$NON-NLS-1$ |
| 127 |
} |
| 128 |
|
| 129 |
ServiceException se = new ServiceException(NLS.bind(Msg.SERVICE_FACTORY_RECURSION, factory.getClass().getName(), "getService"), ServiceException.FACTORY_RECURSION); //$NON-NLS-1$ |
| 130 |
context.getFramework().publishFrameworkEvent(FrameworkEvent.WARNING, registration.getBundle(), se); |
| 131 |
return null; |
| 132 |
} |
| 133 |
factoryInUse = true; |
| 119 |
final S service; |
134 |
final S service; |
| 120 |
try { |
135 |
try { |
| 121 |
service = AccessController.doPrivileged(new PrivilegedAction<S>() { |
136 |
service = AccessController.doPrivileged(new PrivilegedAction<S>() { |
|
Lines 133-138
Link Here
|
| 133 |
ServiceException se = new ServiceException(NLS.bind(Msg.SERVICE_FACTORY_EXCEPTION, factory.getClass().getName(), "getService"), ServiceException.FACTORY_EXCEPTION, t); //$NON-NLS-1$ |
148 |
ServiceException se = new ServiceException(NLS.bind(Msg.SERVICE_FACTORY_EXCEPTION, factory.getClass().getName(), "getService"), ServiceException.FACTORY_EXCEPTION, t); //$NON-NLS-1$ |
| 134 |
context.getFramework().publishFrameworkEvent(FrameworkEvent.ERROR, registration.getBundle(), se); |
149 |
context.getFramework().publishFrameworkEvent(FrameworkEvent.ERROR, registration.getBundle(), se); |
| 135 |
return null; |
150 |
return null; |
|
|
151 |
} finally { |
| 152 |
factoryInUse = false; |
| 136 |
} |
153 |
} |
| 137 |
|
154 |
|
| 138 |
if (service == null) { |
155 |
if (service == null) { |