use of org.glassfish.jersey.internal.inject.ForeignDescriptor in project jersey by jersey.
the class RequestScopeTest method testMultipleGetInstanceCalls.
@Test
public void testMultipleGetInstanceCalls() throws Exception {
final RequestScope requestScope = new RequestScope();
assertNull(requestScope.suspendCurrent());
ForeignDescriptor inhab = ForeignDescriptor.wrap(new TestProvider("a"));
final Instance instance = requestScope.runInScope(new Callable<Instance>() {
@Override
public Instance call() throws Exception {
final Instance internalInstance = requestScope.suspendCurrent();
internalInstance.put(inhab, "1");
requestScope.suspendCurrent();
requestScope.suspendCurrent();
requestScope.suspendCurrent();
requestScope.suspendCurrent();
return internalInstance;
}
});
assertEquals("1", instance.get(inhab));
instance.release();
assertEquals("1", instance.get(inhab));
instance.release();
assertEquals("1", instance.get(inhab));
instance.release();
assertEquals("1", instance.get(inhab));
instance.release();
assertEquals("1", instance.get(inhab));
instance.release();
assertNull(instance.get(inhab));
}
use of org.glassfish.jersey.internal.inject.ForeignDescriptor in project jersey by jersey.
the class RequestScopeTest method testScopeWithCreatedInstance.
@Test
public void testScopeWithCreatedInstance() {
final RequestScope requestScope = new RequestScope();
assertNull(requestScope.suspendCurrent());
final Instance instance = requestScope.createInstance();
ForeignDescriptor inhab = ForeignDescriptor.wrap(new TestProvider("a"));
instance.put(inhab, "1");
requestScope.runInScope(instance, new Runnable() {
@Override
public void run() {
assertEquals("1", instance.get(inhab));
instance.release();
assertEquals("1", instance.get(inhab));
}
});
assertNull(instance.get(inhab));
}
use of org.glassfish.jersey.internal.inject.ForeignDescriptor in project jersey by jersey.
the class DelegatedInjectionValueSupplierProvider method getInjectee.
/**
* Creates a new object {@link Injectee} corresponding to the injecting point. The injectee contains basic information
* about the injection point types and {@link ForeignDescriptor} of the underlying DI provider to make delegated injection
* resolver as simple as possible.
*
* @param parameter jersey-like parameter corresponding to one resource-method's parameter.
* @return injectee instance as a source of the information about the injecting point.
*/
private Injectee getInjectee(Parameter parameter) {
InjecteeImpl injectee = new InjecteeImpl();
injectee.setRequiredType(parameter.getType());
injectee.setInjecteeClass(parameter.getRawType());
ForeignDescriptor proxyDescriptor = descriptorCache.apply(parameter);
if (proxyDescriptor != null) {
injectee.setInjecteeDescriptor(proxyDescriptor);
}
return injectee;
}
use of org.glassfish.jersey.internal.inject.ForeignDescriptor in project jersey by jersey.
the class HK2InjectionManager method createForeignDescriptor.
@Override
public ForeignDescriptor createForeignDescriptor(Binding binding) {
ForeignDescriptor foreignDescriptor = createAndTranslateForeignDescriptor(binding);
ActiveDescriptor<Object> activeDescriptor = ServiceLocatorUtilities.addOneDescriptor(locator, (Descriptor) foreignDescriptor.get(), false);
return ForeignDescriptor.wrap(activeDescriptor, activeDescriptor::dispose);
}
use of org.glassfish.jersey.internal.inject.ForeignDescriptor in project jersey by jersey.
the class RequestScopeTest method testScopeReleaseInsideScope.
@Test
public void testScopeReleaseInsideScope() {
final RequestScope requestScope = new RequestScope();
assertNull(requestScope.suspendCurrent());
final Instance instance = requestScope.createInstance();
ForeignDescriptor inhab = ForeignDescriptor.wrap(new TestProvider("a"));
instance.put(inhab, "1");
requestScope.runInScope(instance, new Runnable() {
@Override
public void run() {
final Instance internalInstance = requestScope.suspendCurrent();
assertEquals(internalInstance, instance);
assertEquals("1", instance.get(inhab));
instance.release();
assertEquals("1", instance.get(inhab));
}
});
assertEquals("1", instance.get(inhab));
instance.release();
assertNull(instance.get(inhab));
}
Aggregations