diff --git a/dev/io.openliberty.netty.internal.impl/.classpath b/dev/io.openliberty.netty.internal.impl/.classpath index fe8401e205f1..8957be46ae91 100644 --- a/dev/io.openliberty.netty.internal.impl/.classpath +++ b/dev/io.openliberty.netty.internal.impl/.classpath @@ -1,8 +1,9 @@ - + + diff --git a/dev/io.openliberty.netty.internal.impl/bnd.bnd b/dev/io.openliberty.netty.internal.impl/bnd.bnd index b326edab780f..b90d236de6f1 100644 --- a/dev/io.openliberty.netty.internal.impl/bnd.bnd +++ b/dev/io.openliberty.netty.internal.impl/bnd.bnd @@ -22,7 +22,8 @@ WS-TraceGroup: Netty Export-Package: \ io.openliberty.netty.internal.impl, \ io.openliberty.netty.internal.tcp, \ - io.openliberty.netty.internal.udp + io.openliberty.netty.internal.udp, \ + io.openliberty.netty.internal.local Import-Package: \ com.ibm.ws.channelfw.internal.chains, \ @@ -31,10 +32,11 @@ Import-Package: \ io.openliberty.netty.internal.exception, \ ${defaultPackageImport} -# reuse the existing translated messages from the TCP Channel +# reuse the existing translated messages from the Channel Private-Package: \ com.ibm.ws.tcpchannel.internal.resources, \ - com.ibm.ws.udpchannel.internal.resources + com.ibm.ws.udpchannel.internal.resources, \ + com.ibm.ws.localchannel.internal.resources -dsannotations: \ io.openliberty.netty.internal.impl.NettyFrameworkImpl diff --git a/dev/io.openliberty.netty.internal.impl/src/io/openliberty/netty/internal/impl/NettyFrameworkImpl.java b/dev/io.openliberty.netty.internal.impl/src/io/openliberty/netty/internal/impl/NettyFrameworkImpl.java index 9b4758857c02..4d86664432cb 100644 --- a/dev/io.openliberty.netty.internal.impl/src/io/openliberty/netty/internal/impl/NettyFrameworkImpl.java +++ b/dev/io.openliberty.netty.internal.impl/src/io/openliberty/netty/internal/impl/NettyFrameworkImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2021, 2023 IBM Corporation and others. + * Copyright (c) 2021, 2025 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -61,6 +61,7 @@ import io.openliberty.netty.internal.tcp.TCPConfigurationImpl; import io.openliberty.netty.internal.tcp.TCPUtils; import io.openliberty.netty.internal.udp.UDPUtils; +import io.openliberty.netty.internal.local.LocalUtils; import com.ibm.websphere.channelfw.EndPointMgr; /** @@ -93,11 +94,11 @@ public class NettyFrameworkImpl implements ServerQuiesceListener, NettyFramework private CHFWBundle chfw; private volatile boolean isActive = false; - private ScheduledExecutorService scheduledExecutorService = null; + private ScheduledExecutorService scheduledExecutorService = null; - @Activate - protected void activate(ComponentContext context, Map config) { + @Activate + protected void activate(ComponentContext context, Map config) { // Ideally use the executor service provided by Liberty // Compared to channelfw, quiesce is hit every time because // connections are lazy cleaned on deactivate @@ -105,16 +106,16 @@ protected void activate(ComponentContext context, Map config) { // specify 0 for the "default" number of threads, // (java.lang.Runtime.availableProcessors() * 2) childGroup = new NioEventLoopGroup(0); - } + } - @Deactivate - protected void deactivate(ComponentContext context, Map properties) { + @Deactivate + protected void deactivate(ComponentContext context, Map properties) { if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) { Tr.event(this, tc, "Deactivate called", new Object[] {context, properties}); } EndPointMgrImpl.destroyEndpoints(); stopEventLoops(); - } + } @Modified protected void modified(ComponentContext context, Map config) { @@ -476,12 +477,23 @@ public BootstrapExtended createUDPBootstrapOutbound(Map options) return UDPUtils.createUDPBootstrapOutbound(this, options); } + + @Override + public ServerBootstrapExtended createLocalBootstrap(Map options) throws NettyException { + return LocalUtils.createLocalBootstrap(this, options); + } + + @Override + public BootstrapExtended createLocalBootstrapOutbound(Map options) throws NettyException { + return LocalUtils.createLocalBootstrapOutbound(this, options); + } + @Override public Channel start(ServerBootstrapExtended bootstrap, String inetHost, int inetPort, ChannelFutureListener bindListener) throws NettyException { return TCPUtils.start(this, bootstrap, inetHost, inetPort, bindListener); } - + @Override public Channel start(BootstrapExtended bootstrap, String inetHost, int inetPort, @@ -499,6 +511,7 @@ public Channel startOutbound(BootstrapExtended bootstrap, String inetHost, int i } } + @Override public ChannelFuture stop(Channel channel) { synchronized (activeChannelMap) { @@ -629,4 +642,5 @@ private void logChannelStopped(Channel channel) { public EndPointMgr getEndpointManager() { return EndPointMgrImpl.getRef(); } + } diff --git a/dev/io.openliberty.netty.internal.impl/src/io/openliberty/netty/internal/local/LocalUtils.java b/dev/io.openliberty.netty.internal.impl/src/io/openliberty/netty/internal/local/LocalUtils.java new file mode 100644 index 000000000000..40c6aa210269 --- /dev/null +++ b/dev/io.openliberty.netty.internal.impl/src/io/openliberty/netty/internal/local/LocalUtils.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2021, 2025 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package io.openliberty.netty.internal.local; + +import java.util.Map; +import com.ibm.websphere.ras.Tr; +import com.ibm.websphere.ras.TraceComponent; + +import io.netty.channel.Channel; +import io.netty.channel.local.LocalAddress; +import io.netty.channel.local.LocalChannel; +import io.netty.channel.local.LocalServerChannel; +import io.openliberty.netty.internal.BootstrapExtended; +import io.openliberty.netty.internal.ServerBootstrapExtended; +import io.openliberty.netty.internal.exception.NettyException; +import io.openliberty.netty.internal.impl.NettyFrameworkImpl; +import io.openliberty.netty.internal.impl.NettyConstants; + +public class LocalUtils { + + private static final TraceComponent tc = Tr.register(LocalUtils.class, NettyConstants.NETTY_TRACE_NAME, NettyConstants.BASE_BUNDLE); + + /** + * Create a {@link ServerBootstrapExtended} for local channels that are not + * based on host address/port addressing but can use {@link LocalAddress} + * + * @param framework + * @param channel class - this is the class of the channel that is added + * @param options + * @return the bootstrap to which a child handler can be added to deal with + * protocol specific tasks + * @throws NettyException + */ + public static ServerBootstrapExtended createLocalBootstrap(NettyFrameworkImpl framework, + Map options) throws NettyException { + + ServerBootstrapExtended bs = new ServerBootstrapExtended(); + bs.group(framework.getParentGroup(), framework.getChildGroup()); + bs.channel(LocalServerChannel.class); + return bs; + } + + + /** + * Create a {@link BootstrapExtended} for outbound local channels TODO GDH - not + * found where we will use this from yet in WOLA. + * + * @param framework + * @param channel class - this is the class of the channel that is added + * @param options + * @return + * @throws NettyException + */ + public static BootstrapExtended createLocalBootstrapOutbound(NettyFrameworkImpl framework, + Map options) throws NettyException { + + BootstrapExtended bs = new BootstrapExtended(); + bs.group(framework.getChildGroup()); + bs.channel(LocalChannel.class); + return bs; + } + + + /** + * + * @param channel + */ + public static void logChannelStopped(Channel channel) { + Tr.info(tc, "stopped" + channel.toString()); + } + + /** + * + * @param channel + */ + public static void logChannelStarted(Channel channel) { + Tr.info(tc, "started" + channel.toString()); + } +} diff --git a/dev/io.openliberty.netty.internal.impl/src/io/openliberty/netty/internal/local/package-info.java b/dev/io.openliberty.netty.internal.impl/src/io/openliberty/netty/internal/local/package-info.java new file mode 100644 index 000000000000..89a924c97e4f --- /dev/null +++ b/dev/io.openliberty.netty.internal.impl/src/io/openliberty/netty/internal/local/package-info.java @@ -0,0 +1,12 @@ +/******************************************************************************* + * Copyright (c) 2025 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +@org.osgi.annotation.versioning.Version("1.0") +package io.openliberty.netty.internal.local; + diff --git a/dev/io.openliberty.netty.internal/src/io/openliberty/netty/internal/NettyFramework.java b/dev/io.openliberty.netty.internal/src/io/openliberty/netty/internal/NettyFramework.java index 02cfb4865c6d..f5db9134422f 100644 --- a/dev/io.openliberty.netty.internal/src/io/openliberty/netty/internal/NettyFramework.java +++ b/dev/io.openliberty.netty.internal/src/io/openliberty/netty/internal/NettyFramework.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2021, 2023 IBM Corporation and others. + * Copyright (c) 2021, 2025 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -12,11 +12,10 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.Callable; -import java.util.concurrent.FutureTask; -import java.util.concurrent.atomic.AtomicBoolean; import com.ibm.websphere.channelfw.EndPointMgr; +import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; @@ -69,6 +68,40 @@ public interface NettyFramework { */ BootstrapExtended createUDPBootstrapOutbound(Map options) throws NettyException; + + + /** + * Create a local bootstrap: handles registering the correct EventLoopGroups, + * creating a LocalChannel, and implementing and configuration properties. + * This method is used by protocols that are based on local addresses rather + * than remote host and port. It adds in the common handlers that Liberty + * expects to add to a pipeline. The initializer will be used to add additional + * protocol specifix handlers. + * + * @param initializer - and initializer for a particular protocol channel + * that uses local addresses + * @param options + * @return BootstrapExtended + * @throws NettyException + */ + ServerBootstrapExtended createLocalBootstrap(Map options) + throws NettyException; + + /** + * Create a local bootstrap from Netty outbound: handles registering the + * correct EventLoopGroups, creating a LocalChannel, and implementing and + * configuration properties. + * + * @param initializer - an initializer for a particular protocol channel + * that uses localAddresses + * @param options + * @return BootstrapExtended + * @throws NettyException + */ + BootstrapExtended createLocalBootstrapOutbound(Map options) + throws NettyException; + + /** * Binds a ServerBootstrap to the given host and port, and registers the * ServerChannel with this framework @@ -109,6 +142,7 @@ Channel start(BootstrapExtended bootstrap, String inetHost, int inetPort, Channe Channel startOutbound(BootstrapExtended bootstrap, String inetHost, int inetPort, ChannelFutureListener bindListener) throws NettyException; + /** * Removes a Channel from the set of active Channels. If the Channel is not * already closed, then close will be invoked and its ChannelFuture will be