Skip to content
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

Netty transport http chain interface legacy enabled #30559

Open
wants to merge 6 commits into
base: netty-transport-http
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dev/com.ibm.ws.transport.http/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ Export-Package: \
com.ibm.ws.http.netty.inbound,\
com.ibm.ws.http.netty,\
io.openliberty.http.netty*,\
io.openliberty.http.ext
io.openliberty.http.ext,\
io.openliberty.http.channel

Import-Package: \
!com.ibm.ws.http.logging.source,\
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2023 IBM Corporation and others.
* Copyright (c) 2011, 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 @@ -48,10 +48,8 @@
import com.ibm.websphere.ras.annotation.Trivial;
import com.ibm.ws.ffdc.annotation.FFDCIgnore;
import com.ibm.ws.http.dispatcher.internal.HttpDispatcher;
import com.ibm.ws.http.internal.HttpChain.ChainState;
import com.ibm.ws.http.logging.internal.AccessLogger;
import com.ibm.ws.http.logging.internal.DisabledLogger;
import com.ibm.ws.http.netty.NettyChain;
import com.ibm.ws.kernel.launch.service.PauseableComponent;
import com.ibm.ws.kernel.launch.service.PauseableComponentException;
import com.ibm.ws.kernel.productinfo.ProductInfo;
Expand All @@ -71,6 +69,10 @@

import io.openliberty.checkpoint.spi.CheckpointHook;
import io.openliberty.checkpoint.spi.CheckpointPhase;
import io.openliberty.http.channel.Chain;
import io.openliberty.http.channel.ChainState;
import io.openliberty.http.channel.LegacyHttpChain;
import io.openliberty.http.netty.channel.NettyHttpChain;
import io.openliberty.netty.internal.NettyFramework;
import io.openliberty.netty.internal.impl.NettyConstants;
import io.openliberty.netty.internal.tls.NettyTlsProvider;
Expand Down Expand Up @@ -169,10 +171,10 @@ public String get() {
*/
protected volatile OnError onError = OnError.WARN;

private final HttpChain httpChain = new HttpChain(this, false);
private final HttpChain httpSecureChain = new HttpChain(this, true);
private final NettyChain nettyChain = new NettyChain(this, false);
private final NettyChain nettySecureChain = new NettyChain(this, true);
private final LegacyHttpChain httpChain = new LegacyHttpChain(this, false);
private final LegacyHttpChain httpSecureChain = new LegacyHttpChain(this, true);
private final NettyHttpChain nettyChain = new NettyHttpChain(this, false);
private final NettyHttpChain nettySecureChain = new NettyHttpChain(this, true);

private final AtomicReference<AccessLog> accessLogger = new AtomicReference<AccessLog>(DisabledLogger.getRef());

Expand Down Expand Up @@ -208,7 +210,7 @@ public void run() {
synchronized (actionLock) {
// Always allow stops.
if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
Tr.debug(this, tc, "EndpointAction: stopping chains " + HttpEndpointImpl.this, httpChain, httpSecureChain);
Tr.debug(this, tc, "EndpointAction: stopping chains " + HttpEndpointImpl.this, getCurrentHttpChain(), getCurrentHttpsChain());

getCurrentHttpChain().stop();
getCurrentHttpsChain().stop();
Expand All @@ -223,7 +225,7 @@ public void run() {
synchronized (actionLock) {
// Always allow stops.
if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
Tr.debug(this, tc, "EndpointAction: stopping https chain " + HttpEndpointImpl.this, httpSecureChain);
Tr.debug(this, tc, "EndpointAction: stopping https chain " + HttpEndpointImpl.this, getCurrentHttpsChain());

getCurrentHttpsChain().stop();
}
Expand Down Expand Up @@ -307,22 +309,21 @@ protected void activate(ComponentContext ctx, Map<String, Object> config) {
MetatypeUtils.parseBoolean(config, NettyConstants.USE_NETTY, config.get(NettyConstants.USE_NETTY), true);


useNetty = false; //FORCE for testing legacy chains

initializeChains();


modified(config);

}

private void initializeChains() {
if(useNetty) {
nettyChain.initNettyChain(name, netty);
nettySecureChain.initNettyChain(name, netty);
nettyChain.init(name, netty);
nettySecureChain.init(name, netty);

}else {
httpChain.init(name, cid, chfw);
httpSecureChain.init(name, cid, chfw);
httpChain.init(name, chfw);
httpSecureChain.init(name, chfw);
}
}

Expand Down Expand Up @@ -485,12 +486,12 @@ private synchronized void switchChains(boolean switchToNetty) {


if(switchToNetty) {
nettyChain.initNettyChain(name, netty);
nettySecureChain.initNettyChain(name, netty);
nettyChain.init(name, netty);
nettySecureChain.init(name, netty);

} else {
httpChain.init(name, cid, chfw);
httpSecureChain.init(name, cid, chfw);
httpChain.init(name, chfw);
httpSecureChain.init(name, chfw);
}

if(httpPort >=0) {
Expand Down Expand Up @@ -583,19 +584,19 @@ public void processHttpChainWork(boolean enableEndpoint, boolean isPause) {

private void logChainStates(){
if(TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()){
HttpChain httpChain = getCurrentHttpChain();
HttpChain httpsChain = getCurrentHttpsChain();
Chain httpChain = getCurrentHttpChain();
Chain httpsChain = getCurrentHttpsChain();

Tr.debug(this, tc, "Chain states after resume - HTTP: " + ChainState.printState(httpChain.getChainState())
+ ", HTTPS: " + ChainState.printState(httpsChain.getChainState()));
Tr.debug(this, tc, "Chain states after resume - HTTP: " + httpChain.state()
+ ", HTTPS: " + httpsChain.state());
}
}

public String getEventTopic() {
return topicString;
}

OnError onError() {
public OnError onError() {
return onError;
}

Expand All @@ -606,7 +607,7 @@ OnError onError() {
* OSGi framework.
*/
@FFDCIgnore(Exception.class)
final void shutdownFramework() {
public final void shutdownFramework() {
Tr.audit(tc, "httpChain.error.shutdown", name);

try {
Expand Down Expand Up @@ -647,15 +648,15 @@ public Supplier<String> getResolvedHostNameSupplier() {
* or not yet listening
*/
public int getListeningHttpPort() {
return useNetty ? nettyChain.getActivePort(): httpChain.getActivePort();
return useNetty ? nettyChain.activePort(): httpChain.activePort();
}

/**
* @return active https port, or -1 if the port is unconfigured,
* or not yet listening
*/
public int getListeningSecureHttpPort() {
return useNetty ? nettySecureChain.getActivePort(): httpSecureChain.getActivePort();
return useNetty ? nettySecureChain.activePort(): httpSecureChain.activePort();
}

public String getProtocolVersion() {
Expand Down Expand Up @@ -1318,7 +1319,7 @@ public void pause() throws PauseableComponentException {

// Check the state of the HTTP chains. The expectation is that the HTTP chains' states are NOT STARTED
// (UNITIALIZED, DESTROYED, QUIESCED or STOPPED).
if (getCurrentHttpChain().getChainState() == ChainState.STARTED.val || getCurrentHttpsChain().getChainState() == ChainState.STARTED.val) {
if (getCurrentHttpChain().state().get() == ChainState.STARTED || getCurrentHttpsChain().state().get() == ChainState.STARTED) {
throw new PauseableComponentException("The request to pause HTTP endpoint " + name + " did not complete successfully.");
}
} catch (Throwable t) {
Expand Down Expand Up @@ -1361,28 +1362,28 @@ private void verifyResumedChainStates() throws PauseableComponentException {
Tr.entry(this, tc, "verifyResumedChainStates");
}

HttpChain httpChain = getCurrentHttpChain();
HttpChain httpsChain = getCurrentHttpsChain();
Chain httpChain = getCurrentHttpChain();
Chain httpsChain = getCurrentHttpsChain();

int httpChainState = ChainState.UNINITIALIZED.val;
int httpsChainState = ChainState.UNINITIALIZED.val;
ChainState httpChainState = ChainState.INITIALIZED;
ChainState httpsChainState = ChainState.UNINITIALIZED;

long startTime = System.currentTimeMillis();
long timeout = 10000; // TODO - testing with ten seconds, but probably want this to be more aggressive

while (System.currentTimeMillis() - startTime < timeout) {
httpChainState = httpChain.getChainState();
httpsChainState = httpsChain.getChainState();
httpChainState = httpChain.state().get();
httpsChainState = httpsChain.state().get();

boolean isValid =
(httpChainState == ChainState.STARTED.val && httpsChainState == ChainState.UNINITIALIZED.val) ||
(httpChainState == ChainState.UNINITIALIZED.val && httpsChainState == ChainState.STARTED.val) ||
(httpChainState == ChainState.STARTED.val && httpsChainState == ChainState.STARTED.val);
(httpChainState == ChainState.STARTED && httpsChainState == ChainState.UNINITIALIZED) ||
(httpChainState == ChainState.UNINITIALIZED && httpsChainState == ChainState.STARTED) ||
(httpChainState == ChainState.STARTED && httpsChainState == ChainState.STARTED);

if (isValid) {
if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
Tr.debug(this, tc, "Chain states verified successfully - HTTP: " + ChainState.printState(httpChainState)
+ ", HTTPS: " + ChainState.printState(httpsChainState));
Tr.debug(this, tc, "Chain states verified successfully - HTTP: " + httpChainState
+ ", HTTPS: " + httpsChainState);
}
if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
Tr.exit(this, tc, "verifyResumedChainStates");
Expand All @@ -1407,8 +1408,8 @@ private void verifyResumedChainStates() throws PauseableComponentException {
". HTTPSChain: " + httpsChain.toString());

if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
Tr.debug(this, tc, "Chain states after resume - HTTP: " + ChainState.printState(httpChainState)
+ ", HTTPS: " + ChainState.printState(httpsChainState));
Tr.debug(this, tc, "Chain states after resume - HTTP: " + httpChainState
+ ", HTTPS: " + httpsChainState);
}

if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
Expand Down Expand Up @@ -1464,11 +1465,11 @@ public boolean isPaused() {
if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
Tr.debug(this, tc, "endpoint and chain data: " + HttpEndpointImpl.this, httpChain, httpSecureChain);

int httpChainState = getCurrentHttpChain().getChainState();
int httpsChainState = getCurrentHttpsChain().getChainState();
ChainState httpChainState = getCurrentHttpChain().state().get();
ChainState httpsChainState = getCurrentHttpsChain().state().get();

// Return true if any of these states apply: UNITIALIZED, DESTROYED, QUIESCED or STOPPED.
return (httpChainState != ChainState.STARTED.val && httpsChainState != ChainState.STARTED.val);
return (httpChainState != ChainState.STARTED && httpsChainState != ChainState.STARTED);
}

/** {@inheritDoc} */
Expand All @@ -1482,10 +1483,10 @@ public HashMap<String, String> getExtendedInfo() {
return info;
}

private synchronized HttpChain getCurrentHttpChain() {
private synchronized Chain getCurrentHttpChain() {
return useNetty ? nettyChain: httpChain;
}
private synchronized HttpChain getCurrentHttpsChain() {
private synchronized Chain getCurrentHttpsChain() {
return useNetty ? nettySecureChain: httpSecureChain;
}

Expand Down
Loading