Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit 853cc83

Browse files
author
Petr Bouda
committed
Replace HK2 PerLookup by Jersey PerLookup.
Change-Id: Id7648aeb5fd42b4c982a4d6a9e20a296c61add1d
1 parent 4fd1481 commit 853cc83

File tree

16 files changed

+100
-45
lines changed

16 files changed

+100
-45
lines changed

core-common/src/main/java/org/glassfish/jersey/hk2/Hk2Helper.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.glassfish.jersey.internal.inject.DisposableSupplier;
5555
import org.glassfish.jersey.internal.inject.InjectionResolverBinding;
5656
import org.glassfish.jersey.internal.inject.InstanceBinding;
57+
import org.glassfish.jersey.internal.inject.PerLookup;
5758
import org.glassfish.jersey.internal.inject.SupplierClassBinding;
5859
import org.glassfish.jersey.internal.inject.SupplierInstanceBinding;
5960

@@ -232,7 +233,7 @@ private static void bindSupplierClassBinding(ServiceLocator locator, SupplierCla
232233
}
233234
});
234235
binding.getQualifiers().forEach(supplierBuilder::qualifiedBy);
235-
supplierBuilder.in(binding.getSupplierScope());
236+
supplierBuilder.in(replaceScope(binding.getSupplierScope()));
236237
binder.bind(supplierBuilder);
237238

238239
// Register wrapper for factory functionality, wrapper automatically call service locator which is able to retrieve
@@ -257,7 +258,7 @@ private static void setupSupplierFactoryBridge(Binding<?, ?> binding, ServiceBin
257258
builder.named(binding.getName());
258259
binding.getContracts().forEach(builder::to);
259260
binding.getQualifiers().forEach(builder::qualifiedBy);
260-
builder.in(binding.getScope());
261+
builder.in(replaceScope(binding.getScope()));
261262

262263
if (binding.getRank() != null) {
263264
builder.ranked(binding.getRank());
@@ -277,7 +278,7 @@ static ActiveDescriptor<?> translateToActiveDescriptor(ClassBinding<?> desc) {
277278
.analyzeWith(desc.getAnalyzer());
278279

279280
if (desc.getScope() != null) {
280-
binding.in(desc.getScope());
281+
binding.in(replaceScope(desc.getScope()));
281282
}
282283

283284
if (desc.getRank() != null) {
@@ -402,4 +403,11 @@ protected void configure() {
402403
}
403404
};
404405
}
406+
407+
private static Class<? extends Annotation> replaceScope(Class<? extends Annotation> scope) {
408+
if (scope == PerLookup.class) {
409+
return org.glassfish.hk2.api.PerLookup.class;
410+
}
411+
return scope;
412+
}
405413
}

core-common/src/main/java/org/glassfish/jersey/internal/JaxrsProviders.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,11 @@
5353
import javax.inject.Provider;
5454

5555
import org.glassfish.jersey.internal.inject.AbstractBinder;
56+
import org.glassfish.jersey.internal.inject.PerLookup;
5657
import org.glassfish.jersey.message.MessageBodyWorkers;
5758
import org.glassfish.jersey.spi.ContextResolvers;
5859
import org.glassfish.jersey.spi.ExceptionMappers;
5960

60-
import org.glassfish.hk2.api.PerLookup;
61-
6261
/**
6362
* Jersey implementation of JAX-RS {@link javax.ws.rs.ext.Providers} contract.
6463
*
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* http://glassfish.java.net/public/CDDL+GPL_1_1.html
12+
* or packager/legal/LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at packager/legal/LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
41+
package org.glassfish.jersey.internal.inject;
42+
43+
import java.lang.annotation.Documented;
44+
import java.lang.annotation.Retention;
45+
import java.lang.annotation.Target;
46+
47+
import javax.inject.Scope;
48+
49+
import static java.lang.annotation.ElementType.METHOD;
50+
import static java.lang.annotation.ElementType.TYPE;
51+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
52+
53+
/**
54+
* PerLookup is the scope for objects that are created every time they are looked up. PerLookup objects
55+
* will be destroyed whenever a service containing them is destroyed.
56+
*
57+
* @author John Wells (john.wells at oracle.com)
58+
*/
59+
@Documented
60+
@Retention(RUNTIME)
61+
@Scope
62+
@Target({ TYPE, METHOD })
63+
public @interface PerLookup {
64+
}

core-common/src/main/java/org/glassfish/jersey/internal/inject/ProviderBinder.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@
5959
import org.glassfish.jersey.model.ContractProvider;
6060
import org.glassfish.jersey.model.internal.ComponentBag;
6161

62-
import org.glassfish.hk2.api.PerLookup;
63-
6462
/**
6563
* Class used for registration of the custom providers into injection manager.
6664
* <p>

core-common/src/test/java/org/glassfish/jersey/internal/inject/ReferencingFactoryTest.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@
5252

5353
import org.glassfish.jersey.internal.util.collection.Ref;
5454

55-
import org.glassfish.hk2.api.PerLookup;
56-
5755
import org.junit.Test;
5856
import static org.junit.Assert.assertSame;
5957

@@ -120,14 +118,14 @@ public ListOfStringReferencingFactory(Provider<Ref<List<String>>> referenceFacto
120118

121119
@Override
122120
protected void configure() {
123-
bindFactory(FooReferencingFactory.class).to(Foo.class).in(PerLookup.class);
124-
bindFactory(ReferencingFactory.<Foo>referenceFactory()).to(new GenericType<Ref<Foo>>() {}).in(Singleton.class);
121+
bindFactory(FooReferencingFactory.class).to(Foo.class);
122+
bindFactory(ReferencingFactory.referenceFactory()).to(new GenericType<Ref<Foo>>() {}).in(Singleton.class);
125123

126-
bindFactory(ListOfIntegerReferencingFactory.class).to(new GenericType<List<Integer>>() {}).in(PerLookup.class);
127-
bindFactory(ReferencingFactory.<List<Integer>>referenceFactory()).to(new GenericType<Ref<List<Integer>>>() {
124+
bindFactory(ListOfIntegerReferencingFactory.class).to(new GenericType<List<Integer>>() {});
125+
bindFactory(ReferencingFactory.referenceFactory()).to(new GenericType<Ref<List<Integer>>>() {
128126
}).in(Singleton.class);
129127

130-
bindFactory(ListOfStringReferencingFactory.class).to(new GenericType<List<String>>() {}).in(PerLookup.class);
128+
bindFactory(ListOfStringReferencingFactory.class).to(new GenericType<List<String>>() {});
131129
bindFactory(ReferencingFactory.referenceFactory(expectedStrings)).to(new GenericType<Ref<List<String>>>() {
132130
}).in(Singleton.class);
133131
}

core-server/src/main/java/org/glassfish/jersey/server/internal/ProcessingProviders.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@
6262
import org.glassfish.jersey.model.internal.RankedComparator;
6363
import org.glassfish.jersey.model.internal.RankedProvider;
6464

65-
import org.glassfish.hk2.api.PerLookup;
66-
6765
/**
6866
* Injectable encapsulating class containing processing providers like filters, interceptors,
6967
* name bound providers, dynamic features.
@@ -337,7 +335,7 @@ public static class Binder extends AbstractBinder {
337335
@Override
338336
protected void configure() {
339337

340-
bindFactory(ProcessingProvidersReferencingFactory.class).to(ProcessingProviders.class).in(PerLookup.class);
338+
bindFactory(ProcessingProvidersReferencingFactory.class).to(ProcessingProviders.class);
341339
bindFactory(ReferencingFactory.<ProcessingProviders>referenceFactory())
342340
.to(new GenericType<Ref<ProcessingProviders>>() {
343341
}).in(Singleton.class);

core-server/src/main/java/org/glassfish/jersey/server/internal/monitoring/MonitoringFeature.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@
6161
import org.glassfish.jersey.server.monitoring.MonitoringStatistics;
6262
import org.glassfish.jersey.server.monitoring.MonitoringStatisticsListener;
6363

64-
import org.glassfish.hk2.api.PerLookup;
65-
6664
/**
6765
* Feature that enables calculating of {@link MonitoringStatistics monitoring statistics} and
6866
* optionally also enables exposure of monitoring MBeans.
@@ -138,7 +136,7 @@ protected void configure() {
138136
.in(Singleton.class);
139137

140138
bindFactory(ApplicationInfoInjectionFactory.class)
141-
.to(ApplicationInfo.class).in(PerLookup.class);
139+
.to(ApplicationInfo.class);
142140
}
143141
});
144142
}
@@ -152,7 +150,7 @@ protected void configure() {
152150
.to(new GenericType<Ref<MonitoringStatistics>>() { })
153151
.in(Singleton.class);
154152

155-
bindFactory(StatisticsInjectionFactory.class).to(MonitoringStatistics.class).in(PerLookup.class);
153+
bindFactory(StatisticsInjectionFactory.class).to(MonitoringStatistics.class);
156154

157155
bind(StatisticsListener.class).to(MonitoringStatisticsListener.class).in(Singleton.class);
158156
}

core-server/src/main/java/org/glassfish/jersey/server/model/InvocableValidator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2012-2015 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -47,11 +47,10 @@
4747
import javax.inject.Singleton;
4848

4949
import org.glassfish.jersey.internal.Errors;
50+
import org.glassfish.jersey.internal.inject.PerLookup;
5051
import org.glassfish.jersey.internal.inject.Providers;
5152
import org.glassfish.jersey.server.internal.LocalizationMessages;
5253

53-
import org.glassfish.hk2.api.PerLookup;
54-
5554
/**
5655
* Validator ensuring that {@link Invocable invocable} and {@link HandlerConstructor constructor} is correctly defined (for
5756
* example correctly annotated with scope annotation). This validator is stateful and therefore new instance must be created

core-server/src/test/java/org/glassfish/jersey/server/internal/inject/ActiveBindingBindingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import javax.inject.Singleton;
5656

5757
import org.glassfish.jersey.internal.inject.InjectionManager;
58+
import org.glassfish.jersey.internal.inject.PerLookup;
5859
import org.glassfish.jersey.internal.util.collection.Ref;
5960
import org.glassfish.jersey.process.internal.RequestScoped;
6061
import org.glassfish.jersey.server.ContainerResponse;
@@ -64,7 +65,6 @@
6465

6566
import org.glassfish.hk2.api.DescriptorType;
6667
import org.glassfish.hk2.api.DescriptorVisibility;
67-
import org.glassfish.hk2.api.PerLookup;
6868
import org.glassfish.hk2.api.ServiceHandle;
6969
import org.glassfish.hk2.utilities.AbstractActiveDescriptor;
7070
import org.glassfish.hk2.utilities.binding.AbstractBinder;

core-server/src/test/java/org/glassfish/jersey/server/model/ValidatorTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import org.glassfish.jersey.internal.Errors;
7676
import org.glassfish.jersey.internal.inject.AbstractBinder;
7777
import org.glassfish.jersey.internal.inject.InjectionManager;
78+
import org.glassfish.jersey.internal.inject.PerLookup;
7879
import org.glassfish.jersey.internal.util.Producer;
7980
import org.glassfish.jersey.model.internal.CommonConfig;
8081
import org.glassfish.jersey.model.internal.ComponentBag;
@@ -87,8 +88,6 @@
8788
import org.glassfish.jersey.server.ServerProperties;
8889
import org.glassfish.jersey.server.model.internal.ModelErrors;
8990

90-
import org.glassfish.hk2.api.PerLookup;
91-
9291
import org.junit.Ignore;
9392
import org.junit.Test;
9493
import static org.junit.Assert.assertEquals;

0 commit comments

Comments
 (0)