diff --git a/appserver/extras/embedded/all/pom.xml b/appserver/extras/embedded/all/pom.xml index a5659a2f9cc..ec6a4308f99 100644 --- a/appserver/extras/embedded/all/pom.xml +++ b/appserver/extras/embedded/all/pom.xml @@ -551,6 +551,11 @@ hk2-utils true + + org.glassfish.hk2 + hk2-extras + true + org.hibernate.validator hibernate-validator diff --git a/appserver/extras/embedded/web/pom.xml b/appserver/extras/embedded/web/pom.xml index 5e0898e1b55..579a9d65820 100644 --- a/appserver/extras/embedded/web/pom.xml +++ b/appserver/extras/embedded/web/pom.xml @@ -115,6 +115,11 @@ hk2-utils true + + org.glassfish.hk2 + hk2-extras + true + org.hibernate.validator hibernate-validator diff --git a/nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/adapter/JerseyContainerCommandService.java b/nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/adapter/JerseyContainerCommandService.java index 5de7f9a7c8f..a6af42fec5c 100644 --- a/nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/adapter/JerseyContainerCommandService.java +++ b/nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/adapter/JerseyContainerCommandService.java @@ -43,9 +43,9 @@ import org.glassfish.hk2.api.PostConstruct; import org.glassfish.hk2.api.ServiceLocator; import org.glassfish.hk2.api.TypeLiteral; +import org.glassfish.hk2.extras.ExtrasUtilities; import org.glassfish.hk2.utilities.Binder; import org.glassfish.hk2.utilities.binding.AbstractBinder; -import org.glassfish.hk2util.SimpleTopicDistributionService; import org.glassfish.internal.api.InternalSystemAdministrator; import org.glassfish.internal.api.ServerContext; import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer; @@ -142,12 +142,7 @@ private JerseyContainer getJerseyContainer(ResourceConfig config) { () -> this + ": Creating Jersey container for " + HttpHandler.class + " and " + config); final GrizzlyHttpContainer httpHandler = ContainerFactory.createContainer(GrizzlyHttpContainer.class, config); final ServiceLocator jerseyLocator = httpHandler.getApplicationHandler().getInjectionManager().getInstance(ServiceLocator.class); - /* - We enable a temporary distribution service until the HK2 Extras package is fixed so that we can enable - the topic distribution service provided by HK2. - */ - //ExtrasUtilities.enableTopicDistribution(jerseyLocator); - SimpleTopicDistributionService.enable(jerseyLocator); + ExtrasUtilities.enableTopicDistribution(jerseyLocator); return new JerseyContainer() { @Override public void service(Request request, Response response) throws Exception { diff --git a/nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/adapter/RestAdapter.java b/nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/adapter/RestAdapter.java index 441ea5acc69..1d1398754c2 100644 --- a/nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/adapter/RestAdapter.java +++ b/nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/adapter/RestAdapter.java @@ -59,9 +59,9 @@ import org.glassfish.hk2.api.PostConstruct; import org.glassfish.hk2.api.ServiceLocator; import org.glassfish.hk2.api.TypeLiteral; +import org.glassfish.hk2.extras.ExtrasUtilities; import org.glassfish.hk2.utilities.Binder; import org.glassfish.hk2.utilities.binding.AbstractBinder; -import org.glassfish.hk2util.SimpleTopicDistributionService; import org.glassfish.internal.api.AdminAccessController; import org.glassfish.internal.api.RemoteAdminAccessException; import org.glassfish.internal.api.ServerContext; @@ -282,12 +282,7 @@ private JerseyContainer getJerseyContainer(ResourceConfig config) { () -> this + ": Creating Jersey container for " + HttpHandler.class + " and " + config); final GrizzlyHttpContainer httpHandler = ContainerFactory.createContainer(GrizzlyHttpContainer.class, config); final ServiceLocator jerseyLocator = httpHandler.getApplicationHandler().getInjectionManager().getInstance(ServiceLocator.class); - /* - We enable a temporary distribution service until the HK2 Extras package is fixed so that we can enable - the topic distribution service provided by HK2. - */ - //ExtrasUtilities.enableTopicDistribution(jerseyLocator); - SimpleTopicDistributionService.enable(jerseyLocator); + ExtrasUtilities.enableTopicDistribution(jerseyLocator); return new JerseyContainer() { @Override public void service(Request request, Response response) throws Exception { diff --git a/nucleus/common/common-util/src/main/java/org/glassfish/hk2util/SimpleTopicDistributionService.java b/nucleus/common/common-util/src/main/java/org/glassfish/hk2util/SimpleTopicDistributionService.java deleted file mode 100644 index b2d9d51b56b..00000000000 --- a/nucleus/common/common-util/src/main/java/org/glassfish/hk2util/SimpleTopicDistributionService.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2024 Contributors to the Eclipse Foundation. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */package org.glassfish.hk2util; - -import static java.lang.System.Logger.Level.WARNING; - -import jakarta.inject.Inject; -import jakarta.inject.Named; -import jakarta.inject.Singleton; -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.lang.reflect.Parameter; -import java.util.Arrays; -import org.glassfish.hk2.api.IterableProvider; -import org.glassfish.hk2.api.ServiceLocator; -import org.glassfish.hk2.api.TypeLiteral; -import org.glassfish.hk2.api.messaging.MessageReceiver; -import org.glassfish.hk2.api.messaging.SubscribeTo; -import org.glassfish.hk2.api.messaging.Topic; -import org.glassfish.hk2.api.messaging.TopicDistributionService; -import org.glassfish.hk2.utilities.ServiceLocatorUtilities; -import org.jvnet.hk2.annotations.ContractsProvided; - -/** - * - * @author Ondro Mihalyi - */ -@Singleton -@Named(SimpleTopicDistributionService.NAME) -@ContractsProvided({TopicDistributionService.class}) -public class SimpleTopicDistributionService implements TopicDistributionService { - - public static final String NAME = "SimpleTopicDistributionService"; - - @Inject - private IterableProvider receivers; - - public static void enable(ServiceLocator locator) { - if (locator == null) { - throw new IllegalArgumentException(); - } - - if (locator.getService(SimpleTopicDistributionService.class, SimpleTopicDistributionService.NAME) != null) { - // Will not add it a second time - return; - } - - ServiceLocatorUtilities.addClasses(locator, true, SimpleTopicDistributionService.class); - } - - @Override - public void distributeMessage(Topic topic, Object message) { - receivers.ofType(new TypeLiteral() { - }.getType()) - .forEach(receiver -> { - Arrays.stream(receiver.getClass().getMethods()) - .filter(method -> { - final Parameter[] parameters = method.getParameters(); - return methodReturnsVoid(method) - && parameters.length == 1 - && method.getParameterTypes()[0].isInstance(message) - && containsSubscribeToAnnotation(parameters[0].getAnnotations()); - }) - .forEach(method -> { - try { - method.invoke(receiver, message); - } catch (Exception ex) { - System.getLogger(SimpleTopicDistributionService.class.getName()) - .log(WARNING, ex.getMessage(), ex); - } - }); - }); - } - - private static boolean methodReturnsVoid(Method method) { - return method.getReturnType().equals(Void.TYPE); - } - - private boolean containsSubscribeToAnnotation(Annotation[] annotations) { - for (Annotation annotation : annotations) { - if (SubscribeTo.class.isInstance(annotation)) { - return true; - } - } - return false; - } - -} diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishImpl.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishImpl.java index a4a88440d69..c35df8b8cd8 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishImpl.java +++ b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishImpl.java @@ -24,7 +24,7 @@ import org.glassfish.hk2.api.ServiceLocator; import java.util.Properties; -import org.glassfish.hk2util.SimpleTopicDistributionService; +import org.glassfish.hk2.extras.ExtrasUtilities; /** * @author Sanjeeb.Sahoo@Sun.COM @@ -43,8 +43,7 @@ public GlassFishImpl(ModuleStartup gfKernel, ServiceLocator habitat, Properties We enable a temporary distribution service until the HK2 Extras package is fixed so that we can enable the topic distribution service provided by HK2. */ - //ExtrasUtilities.enableTopicDistribution(habitat); - SimpleTopicDistributionService.enable(habitat); + ExtrasUtilities.enableTopicDistribution(habitat); configure(gfProps); }