Skip to content

Commit

Permalink
Renamed TransportProtocol to Transport.
Browse files Browse the repository at this point in the history
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
  • Loading branch information
sbordet committed Feb 19, 2024
1 parent c6800e9 commit 6ef5ce9
Show file tree
Hide file tree
Showing 38 changed files with 270 additions and 270 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ The Jetty client libraries use the common I/O design described in xref:pg-arch-i
The common I/O components and concepts are used for all low-level transports.
The only partial exception is the xref:pg-client-io-arch-memory[memory transport], which is not based on network components; as such it does not need a `SelectorManager`, but it exposes `EndPoint` so that high-level protocols have a common interface to interact with the low-level transport.

The client-side abstraction for the low-level transport is `org.eclipse.jetty.io.TransportProtocol`.
The client-side abstraction for the low-level transport is `org.eclipse.jetty.io.Transport`.

`TransportProtocol` represents how high-level protocols can be transported; there is `TransportProtocol.TCP_IP` that represents communication over TCP, but also `TransportProtocol.TCPUnix` for Unix-Domain sockets, `QuicTransportProtocol` for QUIC and `MemoryTransportProtocol` for memory.
`Transport` represents how high-level protocols can be transported; there is `Transport.TCP_IP` that represents communication over TCP, but also `Transport.TCPUnix` for Unix-Domain sockets, `QuicTransport` for QUIC and `MemoryTransport` for memory.

Applications can specify the `TransportProtocol` to use for each request as described in xref:pg-client-http-api-protocol[this section].
Applications can specify the `Transport` to use for each request as described in xref:pg-client-http-api-protocol[this section].

When the `TransportProtocol` implementation uses the network, it delegates to `org.eclipse.jetty.io.ClientConnector`.
When the `Transport` implementation uses the network, it delegates to `org.eclipse.jetty.io.ClientConnector`.

`ClientConnector` primarily wraps `org.eclipse.jetty.io.SelectorManager` to provide network functionalities, and aggregates other four components:

Expand Down Expand Up @@ -109,17 +109,17 @@ link:https://openjdk.java.net/jeps/380[JEP 380] introduced Unix-Domain sockets s

`ClientConnector` handles Unix-Domain sockets exactly like it handles regular TCP sockets, so there is no additional configuration necessary -- Unix-Domain sockets are supported out-of-the-box.

Applications can specify the `TransportProtocol` to use for each request as described in xref:pg-client-http-api-protocol[this section].
Applications can specify the `Transport` to use for each request as described in xref:pg-client-http-api-protocol[this section].

[[pg-client-io-arch-memory]]
===== Memory Support

In addition to support communication between client and server via network or Unix-Domain, the Jetty client libraries also support communication between client and server via memory for intra-process communication.
This means that the client and server must be in the same JVM process.

This functionality is provided by `org.eclipse.jetty.server.MemoryTransportProtocol`, which does not delegate to `ClientConnector`, but instead delegates to the server-side `MemoryConnector` and its related classes.
This functionality is provided by `org.eclipse.jetty.server.MemoryTransport`, which does not delegate to `ClientConnector`, but instead delegates to the server-side `MemoryConnector` and its related classes.

Applications can specify the `TransportProtocol` to use for each request as described in xref:pg-client-http-api-protocol[this section].
Applications can specify the `Transport` to use for each request as described in xref:pg-client-http-api-protocol[this section].

[[pg-client-io-arch-protocol]]
==== Protocol Layer
Expand All @@ -132,7 +132,7 @@ On the client side, a `ClientConnectionFactory` implementation is the component

Applications may use `ClientConnector.connect(SocketAddress, Map<String, Object>)` to establish a TCP connection to the server, and must provide `ClientConnector` with the following information in the context map:

* A `TransportProtocol` instance that specifies the low-level transport to use.
* A `Transport` instance that specifies the low-level transport to use.
* A `ClientConnectionFactory` that creates `Connection` instances for the high-level protocol.
* A `Promise` that is notified when the connection creation succeeds or fails.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPCli
----

[[pg-client-http-api-protocol]]
===== Request `TransportProtocol`
===== Request `Transport`

The communication between client and server happens over a xref:pg-client-io-arch-transport[low-level transport], and applications can specify the low-level transport to use for each request.

Expand All @@ -298,5 +298,5 @@ This is a fancy example of how to mix HTTP versions and low-level transports:

[source,java,indent=0]
----
include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tag=mixedTransportProtocols]
include::../../{doc_code}/org/eclipse/jetty/docs/programming/client/http/HTTPClientDocs.java[tag=mixedTransports]
----
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ A connection may start by speaking one protocol, for example HTTP/1.1, but then

Two origins with the same `(scheme, host, port, tag)` but different `protocol` create two different destinations and therefore two different connection pools.

Finally, it is possible for a server to speak the same protocol over different xref:pg-client-io-arch-transport[low-level transports] (represented by `TransportProtocol`), for example TCP and Unix-Domain.
Finally, it is possible for a server to speak the same protocol over different xref:pg-client-io-arch-transport[low-level transports] (represented by `Transport`), for example TCP and Unix-Domain.

Two origins with the same `(scheme, host, port, tag, protocol)` but different low-level transports create two different destinations and therefore two different connection pools.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.eclipse.jetty.io.ClientConnector;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.SelectorManager;
import org.eclipse.jetty.io.TransportProtocol;
import org.eclipse.jetty.io.Transport;
import org.eclipse.jetty.io.ssl.SslClientConnectionFactory;
import org.eclipse.jetty.io.ssl.SslConnection;
import org.eclipse.jetty.util.BufferUtil;
Expand Down Expand Up @@ -143,8 +143,8 @@ public void onFillable()
int port = 8080;
SocketAddress address = new InetSocketAddress(host, port);

// The TransportProtocol instance.
TransportProtocol transportProtocol = TransportProtocol.TCP_IP;
// The Transport instance.
Transport transport = Transport.TCP_IP;

// The ClientConnectionFactory that creates CustomConnection instances.
ClientConnectionFactory connectionFactory = (endPoint, context) ->
Expand All @@ -158,7 +158,7 @@ public void onFillable()

// Populate the context with the mandatory keys to create and obtain connections.
Map<String, Object> context = new ConcurrentHashMap<>();
context.put(TransportProtocol.class.getName(), transportProtocol);
context.put(Transport.class.getName(), transport);
context.put(ClientConnector.CLIENT_CONNECTION_FACTORY_CONTEXT_KEY, connectionFactory);
context.put(ClientConnector.CONNECTION_PROMISE_CONTEXT_KEY, connectionPromise);
clientConnector.connect(address, context);
Expand Down Expand Up @@ -272,7 +272,7 @@ public void writeLine(String line, Callback callback)
CompletableFuture<TelnetConnection> connectionPromise = new Promise.Completable<>();

Map<String, Object> context = new HashMap<>();
context.put(TransportProtocol.class.getName(), TransportProtocol.TCP_IP);
context.put(Transport.class.getName(), Transport.TCP_IP);
context.put(ClientConnector.CLIENT_CONNECTION_FACTORY_CONTEXT_KEY, connectionFactory);
context.put(ClientConnector.CONNECTION_PROMISE_CONTEXT_KEY, connectionPromise);
clientConnector.connect(address, context);
Expand Down Expand Up @@ -397,7 +397,7 @@ public void writeLine(String line, Callback callback)
CompletableFuture<SslConnection> connectionPromise = new Promise.Completable<>();

Map<String, Object> context = new ConcurrentHashMap<>();
context.put(TransportProtocol.class.getName(), TransportProtocol.TCP_IP);
context.put(Transport.class.getName(), Transport.TCP_IP);
context.put(ClientConnector.CLIENT_CONNECTION_FACTORY_CONTEXT_KEY, connectionFactory);
context.put(ClientConnector.CONNECTION_PROMISE_CONTEXT_KEY, connectionPromise);
clientConnector.connect(address, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@
import org.eclipse.jetty.io.ClientConnectionFactory;
import org.eclipse.jetty.io.ClientConnector;
import org.eclipse.jetty.io.Content;
import org.eclipse.jetty.io.TransportProtocol;
import org.eclipse.jetty.io.Transport;
import org.eclipse.jetty.io.ssl.SslHandshakeListener;
import org.eclipse.jetty.quic.client.ClientQuicConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.MemoryConnector;
import org.eclipse.jetty.server.MemoryTransportProtocol;
import org.eclipse.jetty.server.MemoryTransport;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.component.LifeCycle;
Expand Down Expand Up @@ -1160,7 +1160,7 @@ public void unixDomain() throws Exception

ContentResponse response = httpClient.newRequest("jetty.org", 80)
// Specify that the request must be sent over Unix-Domain.
.transportProtocol(new TransportProtocol.TCPUnix(unixDomainPath))
.transport(new Transport.TCPUnix(unixDomainPath))
.send();
// end::unixDomain[]
}
Expand All @@ -1181,17 +1181,17 @@ public void memory() throws Exception
HttpClient httpClient = new HttpClient();
httpClient.start();

// Use the MemoryTransportProtocol to communicate with the server-side.
TransportProtocol transportProtocol = new MemoryTransportProtocol(memoryConnector);
// Use the MemoryTransport to communicate with the server-side.
Transport transport = new MemoryTransport(memoryConnector);

httpClient.newRequest("http://localhost/")
// Specify the TransportProtocol to use.
.transportProtocol(transportProtocol)
// Specify the Transport to use.
.transport(transport)
.send();
// end::memory[]
}

public void mixedTransportProtocols() throws Exception
public void mixedTransports() throws Exception
{
Path unixDomainPath = Path.of("/path/to/server.sock");

Expand All @@ -1212,19 +1212,19 @@ public void mixedTransportProtocols() throws Exception
HTTP3Client http3Client = new HTTP3Client(quicConfiguration, clientConnector);
ClientConnectionFactoryOverHTTP3.HTTP3 http3 = new ClientConnectionFactoryOverHTTP3.HTTP3(http3Client);

// tag::mixedTransportProtocols[]
// tag::mixedTransports[]
HttpClient httpClient = new HttpClient(new HttpClientTransportDynamic(clientConnector, http2, http1, http3));
httpClient.start();

// Make a TCP request to a 3rd party web application.
ContentResponse thirdPartyResponse = httpClient.newRequest("https://third-party.com/api")
// No need to specify the TransportProtocol, TCP will be used by default.
// No need to specify the Transport, TCP will be used by default.
.send();

// Upload the third party response content to a validation process.
ContentResponse validatedResponse = httpClient.newRequest("http://localhost/validate")
// The validation process is available via Unix-Domain.
.transportProtocol(new TransportProtocol.TCPUnix(unixDomainPath))
.transport(new Transport.TCPUnix(unixDomainPath))
.method(HttpMethod.POST)
.body(new BytesRequestContent(thirdPartyResponse.getContent()))
.send();
Expand All @@ -1233,10 +1233,10 @@ public void mixedTransportProtocols() throws Exception
// it to another web application in the same Jetty server.
ContentResponse response = httpClient.newRequest("http://localhost/process")
// The processing is in-memory.
.transportProtocol(new MemoryTransportProtocol(memoryConnector))
.transport(new MemoryTransport(memoryConnector))
.method(HttpMethod.POST)
.body(new BytesRequestContent(validatedResponse.getContent()))
.send();
// end::mixedTransportProtocols[]
// end::mixedTransports[]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.MemoryConnector;
import org.eclipse.jetty.server.MemoryTransportProtocol;
import org.eclipse.jetty.server.MemoryTransport;
import org.eclipse.jetty.server.NetworkConnector;
import org.eclipse.jetty.server.ProxyConnectionFactory;
import org.eclipse.jetty.server.Request;
Expand Down Expand Up @@ -266,8 +266,8 @@ public void memoryConnector() throws Exception
httpClient.start();

ContentResponse response = httpClient.newRequest("http://localhost/")
// Use the memory TransportProtocol to communicate with the server-side.
.transportProtocol(new MemoryTransportProtocol(connector))
// Use the memory Transport to communicate with the server-side.
.transport(new MemoryTransport(connector))
.send();
// end::memoryConnector[]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void connect(SocketAddress address, Map<String, Object> context)
Promise<Connection> promise = (Promise<Connection>)context.get(HTTP_CONNECTION_PROMISE_CONTEXT_KEY);
context.put(ClientConnector.CONNECTION_PROMISE_CONTEXT_KEY, Promise.from(ioConnection -> {}, promise::failed));
context.put(ClientConnector.CLIENT_CONNECTOR_CONTEXT_KEY, connector);
destination.getOrigin().getTransportProtocol().connect(address, context);
destination.getOrigin().getTransport().connect(address, context);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.ClientConnectionFactory;
import org.eclipse.jetty.io.ClientConnector;
import org.eclipse.jetty.io.TransportProtocol;
import org.eclipse.jetty.io.Transport;
import org.eclipse.jetty.io.ssl.SslClientConnectionFactory;
import org.eclipse.jetty.util.Fields;
import org.eclipse.jetty.util.Jetty;
Expand Down Expand Up @@ -468,16 +468,16 @@ public Origin createOrigin(Request request, Origin.Protocol protocol)
host = host.toLowerCase(Locale.ENGLISH);
int port = request.getPort();
port = normalizePort(scheme, port);
TransportProtocol transportProtocol = request.getTransportProtocol();
if (transportProtocol == null)
Transport transport = request.getTransport();
if (transport == null)
{
// Ask the ClientConnector for backwards compatibility
// until ClientConnector.Configurator is removed.
transportProtocol = connector.newTransportProtocol();
if (transportProtocol == null)
transportProtocol = TransportProtocol.TCP_IP;
transport = connector.newTransport();
if (transport == null)
transport = Transport.TCP_IP;
}
return new Origin(scheme, new Origin.Address(host, port), request.getTag(), protocol, transportProtocol);
return new Origin(scheme, new Origin.Address(host, port), request.getTag(), protocol, transport);
}

/**
Expand Down Expand Up @@ -540,10 +540,10 @@ public void newConnection(Destination destination, Promise<Connection> promise)
if (proxy != null)
origin = proxy.getOrigin();

TransportProtocol transportProtocol = origin.getTransportProtocol();
context.put(TransportProtocol.class.getName(), transportProtocol);
Transport transport = origin.getTransport();
context.put(Transport.class.getName(), transport);

if (transportProtocol.requiresDomainNamesResolution())
if (transport.requiresDomainNamesResolution())
{
Origin.Address address = origin.getAddress();
getSocketAddressResolver().resolve(address.getHost(), address.getPort(), new Promise<>()
Expand Down Expand Up @@ -574,14 +574,14 @@ public void failed(Throwable x)
connect(socketAddresses, nextIndex, context);
}
});
transport.connect((SocketAddress)socketAddresses.get(index), context);
HttpClient.this.transport.connect((SocketAddress)socketAddresses.get(index), context);
}
});
}
else
{
context.put(HttpClientTransport.HTTP_CONNECTION_PROMISE_CONTEXT_KEY, promise);
transport.connect(transportProtocol.getSocketAddress(), context);
this.transport.connect(transport.getSocketAddress(), context);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.eclipse.jetty.io.ClientConnectionFactory;
import org.eclipse.jetty.io.ClientConnector;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.TransportProtocol;
import org.eclipse.jetty.io.Transport;
import org.eclipse.jetty.util.Attachable;
import org.eclipse.jetty.util.Promise;
import org.eclipse.jetty.util.ssl.SslContextFactory;
Expand All @@ -54,7 +54,7 @@ public HttpProxy(Origin.Address address, boolean secure)

public HttpProxy(Origin.Address address, boolean secure, Origin.Protocol protocol)
{
this(new Origin(secure ? "https" : "http", address, null, protocol, TransportProtocol.TCP_IP), null);
this(new Origin(secure ? "https" : "http", address, null, protocol, Transport.TCP_IP), null);
}

public HttpProxy(Origin.Address address, SslContextFactory.Client sslContextFactory)
Expand All @@ -64,7 +64,7 @@ public HttpProxy(Origin.Address address, SslContextFactory.Client sslContextFact

public HttpProxy(Origin.Address address, SslContextFactory.Client sslContextFactory, Origin.Protocol protocol)
{
this(new Origin(sslContextFactory == null ? "http" : "https", address, null, protocol, TransportProtocol.TCP_IP), sslContextFactory);
this(new Origin(sslContextFactory == null ? "http" : "https", address, null, protocol, Transport.TCP_IP), sslContextFactory);
}

public HttpProxy(Origin origin, SslContextFactory.Client sslContextFactory)
Expand Down
Loading

0 comments on commit 6ef5ce9

Please sign in to comment.