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

Commit 0d78cbb

Browse files
Marek PotociarPetr Bouda
authored andcommitted
HK2 Factory usage refactorings.
- Replaced injection of Factory with javax.inject.Provider where possible - Introduced SupplierFactory for use cases where Factory.dispose implementation is NO OP - Refactored all Factory implementations to extend SupplierFactory where possible - Removed some stale and unused Factory related utility classes and methods Change-Id: I0ab940d9a4d162d5d2e10450d87e3a6beadf7390 Signed-off-by: Marek Potociar <[email protected]>
1 parent b9a497f commit 0d78cbb

File tree

51 files changed

+471
-773
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+471
-773
lines changed

containers/glassfish/jersey-gf-ejb/src/main/java/org/glassfish/jersey/gf/ejb/internal/EjbComponentProvider.java

Lines changed: 22 additions & 21 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
@@ -40,11 +40,6 @@
4040

4141
package org.glassfish.jersey.gf.ejb.internal;
4242

43-
import com.sun.ejb.containers.BaseContainer;
44-
import com.sun.ejb.containers.EjbContainerUtil;
45-
import com.sun.ejb.containers.EjbContainerUtilImpl;
46-
import com.sun.enterprise.config.serverbeans.Application;
47-
import com.sun.enterprise.config.serverbeans.Applications;
4843
import java.lang.annotation.Annotation;
4944
import java.lang.reflect.InvocationHandler;
5045
import java.lang.reflect.InvocationTargetException;
@@ -64,27 +59,38 @@
6459
import java.util.concurrent.CopyOnWriteArrayList;
6560
import java.util.logging.Level;
6661
import java.util.logging.Logger;
62+
63+
import javax.ws.rs.ext.ExceptionMapper;
64+
6765
import javax.annotation.Priority;
6866
import javax.ejb.Local;
6967
import javax.ejb.Remote;
7068
import javax.inject.Singleton;
7169
import javax.naming.InitialContext;
7270
import javax.naming.NamingException;
73-
import javax.ws.rs.ext.ExceptionMapper;
74-
import org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl;
75-
import org.glassfish.ejb.deployment.descriptor.EjbDescriptor;
71+
72+
import org.glassfish.jersey.internal.inject.Injections;
73+
import org.glassfish.jersey.internal.inject.SupplierFactory;
74+
import org.glassfish.jersey.server.ApplicationHandler;
75+
import org.glassfish.jersey.server.model.Invocable;
76+
import org.glassfish.jersey.server.spi.ComponentProvider;
77+
import org.glassfish.jersey.server.spi.internal.ResourceMethodInvocationHandlerProvider;
78+
7679
import org.glassfish.hk2.api.DynamicConfiguration;
77-
import org.glassfish.hk2.api.Factory;
7880
import org.glassfish.hk2.api.ServiceLocator;
7981
import org.glassfish.hk2.utilities.binding.ServiceBindingBuilder;
82+
83+
import org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl;
84+
import org.glassfish.ejb.deployment.descriptor.EjbDescriptor;
8085
import org.glassfish.internal.data.ApplicationInfo;
8186
import org.glassfish.internal.data.ApplicationRegistry;
8287
import org.glassfish.internal.data.ModuleInfo;
83-
import org.glassfish.jersey.internal.inject.Injections;
84-
import org.glassfish.jersey.server.ApplicationHandler;
85-
import org.glassfish.jersey.server.model.Invocable;
86-
import org.glassfish.jersey.server.spi.ComponentProvider;
87-
import org.glassfish.jersey.server.spi.internal.ResourceMethodInvocationHandlerProvider;
88+
89+
import com.sun.ejb.containers.BaseContainer;
90+
import com.sun.ejb.containers.EjbContainerUtil;
91+
import com.sun.ejb.containers.EjbContainerUtilImpl;
92+
import com.sun.enterprise.config.serverbeans.Application;
93+
import com.sun.enterprise.config.serverbeans.Applications;
8894

8995
/**
9096
* EJB component provider.
@@ -106,7 +112,7 @@ public final class EjbComponentProvider implements ComponentProvider, ResourceMe
106112
/**
107113
* HK2 factory to provide EJB components obtained via JNDI lookup.
108114
*/
109-
private static class EjbFactory<T> implements Factory<T> {
115+
private static class EjbFactory<T> extends SupplierFactory<T> {
110116

111117
final InitialContext ctx;
112118
final Class<T> clazz;
@@ -123,11 +129,6 @@ public T provide() {
123129
}
124130
}
125131

126-
@Override
127-
public void dispose(T instance) {
128-
// do nothing
129-
}
130-
131132
public EjbFactory(Class<T> rawType, InitialContext ctx, EjbComponentProvider ejbProvider) {
132133
this.clazz = rawType;
133134
this.ctx = ctx;

containers/jersey-servlet-core/src/main/java/org/glassfish/jersey/servlet/WebComponent.java

Lines changed: 6 additions & 23 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-2016 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
@@ -78,6 +78,7 @@
7878
import org.glassfish.jersey.internal.ServiceFinderBinder;
7979
import org.glassfish.jersey.internal.inject.Providers;
8080
import org.glassfish.jersey.internal.inject.ReferencingFactory;
81+
import org.glassfish.jersey.internal.inject.SupplierFactory;
8182
import org.glassfish.jersey.internal.util.ReflectionHelper;
8283
import org.glassfish.jersey.internal.util.collection.Ref;
8384
import org.glassfish.jersey.internal.util.collection.Value;
@@ -106,7 +107,6 @@
106107
import org.glassfish.jersey.servlet.spi.FilterUrlMappingsProvider;
107108
import org.glassfish.jersey.uri.UriComponent;
108109

109-
import org.glassfish.hk2.api.Factory;
110110
import org.glassfish.hk2.api.ServiceLocator;
111111
import org.glassfish.hk2.api.TypeLiteral;
112112
import org.glassfish.hk2.utilities.binding.AbstractBinder;
@@ -235,30 +235,21 @@ protected void configure() {
235235
.to(new TypeLiteral<Ref<HttpServletResponse>>() {}).in(RequestScoped.class);
236236
}
237237

238-
bindFactory(new Factory<ServletContext>() {
238+
bindFactory(new SupplierFactory<ServletContext>() {
239239
@Override
240240
public ServletContext provide() {
241241
return webConfig.getServletContext();
242242
}
243-
244-
@Override
245-
public void dispose(final ServletContext instance) {
246-
//not used
247-
}
248243
}).to(ServletContext.class).in(Singleton.class);
249244

250245
final ServletConfig servletConfig = webConfig.getServletConfig();
251246
if (webConfig.getConfigType() == WebConfig.ConfigType.ServletConfig) {
252-
bindFactory(new Factory<ServletConfig>() {
247+
bindFactory(new SupplierFactory<ServletConfig>() {
253248
@Override
254249
public ServletConfig provide() {
255250
return servletConfig;
256251
}
257252

258-
@Override
259-
public void dispose(final ServletConfig instance) {
260-
//not used
261-
}
262253
}).to(ServletConfig.class).in(Singleton.class);
263254

264255
// @PersistenceUnit
@@ -272,29 +263,21 @@ public void dispose(final ServletConfig instance) {
272263
}
273264
}
274265
} else {
275-
bindFactory(new Factory<FilterConfig>() {
266+
bindFactory(new SupplierFactory<FilterConfig>() {
276267
@Override
277268
public FilterConfig provide() {
278269
return webConfig.getFilterConfig();
279270
}
280271

281-
@Override
282-
public void dispose(final FilterConfig instance) {
283-
//not used
284-
}
285272
}).to(FilterConfig.class).in(Singleton.class);
286273
}
287274

288-
bindFactory(new Factory<WebConfig>() {
275+
bindFactory(new SupplierFactory<WebConfig>() {
289276
@Override
290277
public WebConfig provide() {
291278
return webConfig;
292279
}
293280

294-
@Override
295-
public void dispose(final WebConfig instance) {
296-
//not used
297-
}
298281
}).to(WebConfig.class).in(Singleton.class);
299282

300283
install(new ServiceFinderBinder<>(AsyncContextDelegateProvider.class, applicationProperties, RuntimeType.SERVER));

core-client/src/main/java/org/glassfish/jersey/client/ClientBinder.java

Lines changed: 3 additions & 8 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
@@ -57,6 +57,7 @@
5757
import org.glassfish.jersey.internal.inject.ContextInjectionResolver;
5858
import org.glassfish.jersey.internal.inject.JerseyClassAnalyzer;
5959
import org.glassfish.jersey.internal.inject.ReferencingFactory;
60+
import org.glassfish.jersey.internal.inject.SupplierFactory;
6061
import org.glassfish.jersey.internal.spi.AutoDiscoverable;
6162
import org.glassfish.jersey.internal.util.collection.Ref;
6263
import org.glassfish.jersey.message.internal.MessageBodyFactory;
@@ -65,7 +66,6 @@
6566
import org.glassfish.jersey.process.internal.RequestScoped;
6667
import org.glassfish.jersey.spi.ExecutorServiceProvider;
6768

68-
import org.glassfish.hk2.api.Factory;
6969
import org.glassfish.hk2.api.TypeLiteral;
7070
import org.glassfish.hk2.utilities.binding.AbstractBinder;
7171

@@ -88,7 +88,7 @@ public RequestContextInjectionFactory(Provider<Ref<ClientRequest>> referenceFact
8888
}
8989
}
9090

91-
private static class PropertiesDelegateFactory implements Factory<PropertiesDelegate> {
91+
private static class PropertiesDelegateFactory extends SupplierFactory<PropertiesDelegate> {
9292

9393
private final Provider<ClientRequest> requestProvider;
9494

@@ -101,11 +101,6 @@ private PropertiesDelegateFactory(Provider<ClientRequest> requestProvider) {
101101
public PropertiesDelegate provide() {
102102
return requestProvider.get().getPropertiesDelegate();
103103
}
104-
105-
@Override
106-
public void dispose(PropertiesDelegate instance) {
107-
// do nothing
108-
}
109104
}
110105

111106
/**

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

Lines changed: 4 additions & 8 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
@@ -45,9 +45,10 @@
4545
import java.util.List;
4646
import java.util.Set;
4747

48+
import javax.ws.rs.core.Context;
49+
4850
import javax.inject.Inject;
4951
import javax.inject.Singleton;
50-
import javax.ws.rs.core.Context;
5152

5253
import org.glassfish.jersey.internal.util.ReflectionHelper;
5354
import org.glassfish.jersey.internal.util.collection.LazyValue;
@@ -130,16 +131,11 @@ public Object resolve(Injectee injectee, ServiceHandle<?> root) {
130131
}
131132

132133
private Factory asFactory(final ServiceHandle handle) {
133-
return new Factory() {
134+
return new SupplierFactory() {
134135
@Override
135136
public Object provide() {
136137
return handle.getService();
137138
}
138-
139-
@Override
140-
public void dispose(Object instance) {
141-
//not used
142-
}
143139
};
144140
}
145141

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

Lines changed: 1 addition & 29 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
@@ -39,8 +39,6 @@
3939
*/
4040
package org.glassfish.jersey.internal.inject;
4141

42-
import java.lang.annotation.Annotation;
43-
4442
import javax.ws.rs.WebApplicationException;
4543

4644
import org.glassfish.hk2.api.DynamicConfiguration;
@@ -213,32 +211,6 @@ public static void addBinding(final BindingBuilder<?> builder,
213211
BindingBuilderFactory.addBinding(builder, configuration, defaultLoader);
214212
}
215213

216-
/**
217-
* Get a new factory class-based service binding builder.
218-
*
219-
* @param <T> service type.
220-
* @param factoryType service factory class.
221-
* @param factoryScope factory scope.
222-
* @return initialized binding builder.
223-
*/
224-
public static <T> ServiceBindingBuilder<T> newFactoryBinder(
225-
final Class<? extends Factory<T>> factoryType, final Class<? extends Annotation> factoryScope) {
226-
return BindingBuilderFactory.newFactoryBinder(factoryType, factoryScope);
227-
}
228-
229-
/**
230-
* Get a new factory class-based service binding builder.
231-
*
232-
* The factory itself is bound in a {@link org.glassfish.hk2.api.PerLookup per-lookup} scope.
233-
*
234-
* @param <T> service type.
235-
* @param factoryType service factory class.
236-
* @return initialized binding builder.
237-
*/
238-
public static <T> ServiceBindingBuilder<T> newFactoryBinder(final Class<? extends Factory<T>> factoryType) {
239-
return BindingBuilderFactory.newFactoryBinder(factoryType);
240-
}
241-
242214
/**
243215
* Get a new factory instance-based service binding builder.
244216
*

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

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)