Search in sources :

Example 1 with ForeignDescriptor

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));
}
Also used : Instance(org.glassfish.jersey.process.internal.RequestScope.Instance) ForeignDescriptor(org.glassfish.jersey.internal.inject.ForeignDescriptor) Test(org.junit.Test)

Example 2 with ForeignDescriptor

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));
}
Also used : Instance(org.glassfish.jersey.process.internal.RequestScope.Instance) ForeignDescriptor(org.glassfish.jersey.internal.inject.ForeignDescriptor) Test(org.junit.Test)

Example 3 with ForeignDescriptor

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;
}
Also used : InjecteeImpl(org.glassfish.jersey.internal.inject.InjecteeImpl) ForeignDescriptor(org.glassfish.jersey.internal.inject.ForeignDescriptor)

Example 4 with ForeignDescriptor

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);
}
Also used : ForeignDescriptor(org.glassfish.jersey.internal.inject.ForeignDescriptor)

Example 5 with ForeignDescriptor

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));
}
Also used : Instance(org.glassfish.jersey.process.internal.RequestScope.Instance) ForeignDescriptor(org.glassfish.jersey.internal.inject.ForeignDescriptor) Test(org.junit.Test)

Aggregations

ForeignDescriptor (org.glassfish.jersey.internal.inject.ForeignDescriptor)7 Instance (org.glassfish.jersey.process.internal.RequestScope.Instance)5 Test (org.junit.Test)5 Callable (java.util.concurrent.Callable)1 InjecteeImpl (org.glassfish.jersey.internal.inject.InjecteeImpl)1