Skip to content

Netty OLA changes in Netty Framework #31229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 17 commits into
base: netty-transport-http
Choose a base branch
from
Draft
3 changes: 2 additions & 1 deletion dev/io.openliberty.netty.internal.impl/.classpath
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test" output="bin_test"/>
<classpathentry kind="src" output="bin_test" path="test"/>
<classpathentry kind="con" path="aQute.bnd.classpath.container"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
</classpath>
8 changes: 5 additions & 3 deletions dev/io.openliberty.netty.internal.impl/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;

/**
Expand Down Expand Up @@ -93,28 +94,28 @@ 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<String, Object> config) {
@Activate
protected void activate(ComponentContext context, Map<String, Object> config) {
// Ideally use the executor service provided by Liberty
// Compared to channelfw, quiesce is hit every time because
// connections are lazy cleaned on deactivate
parentGroup = new NioEventLoopGroup(1);
// specify 0 for the "default" number of threads,
// (java.lang.Runtime.availableProcessors() * 2)
childGroup = new NioEventLoopGroup(0);
}
}

@Deactivate
protected void deactivate(ComponentContext context, Map<String, Object> properties) {
@Deactivate
protected void deactivate(ComponentContext context, Map<String, Object> 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<String, Object> config) {
Expand Down Expand Up @@ -476,12 +477,23 @@ public BootstrapExtended createUDPBootstrapOutbound(Map<String, Object> options)
return UDPUtils.createUDPBootstrapOutbound(this, options);
}


@Override
public ServerBootstrapExtended createLocalBootstrap(Map<String, Object> options) throws NettyException {
return LocalUtils.createLocalBootstrap(this, options);
}

@Override
public BootstrapExtended createLocalBootstrapOutbound(Map<String, Object> 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,
Expand All @@ -499,6 +511,7 @@ public Channel startOutbound(BootstrapExtended bootstrap, String inetHost, int i
}
}


@Override
public ChannelFuture stop(Channel channel) {
synchronized (activeChannelMap) {
Expand Down Expand Up @@ -629,4 +642,5 @@ private void logChannelStopped(Channel channel) {
public EndPointMgr getEndpointManager() {
return EndPointMgrImpl.getRef();
}

}
Original file line number Diff line number Diff line change
@@ -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<String, Object> 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<String, Object> 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());
}
}
Original file line number Diff line number Diff line change
@@ -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;

Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -69,6 +68,40 @@ public interface NettyFramework {
*/
BootstrapExtended createUDPBootstrapOutbound(Map<String, Object> 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<String, Object> 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<String, Object> options)
throws NettyException;


/**
* Binds a ServerBootstrap to the given host and port, and registers the
* ServerChannel with this framework
Expand Down Expand Up @@ -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
Expand Down