Package org.eclipse.jetty.server
Class MemoryConnector
java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.ContainerLifeCycle
org.eclipse.jetty.server.AbstractConnector
org.eclipse.jetty.server.MemoryConnector
- All Implemented Interfaces:
Connector
,Container
,Destroyable
,Dumpable
,Dumpable.DumpableContainer
,Graceful
,LifeCycle
A server Connector
that allows clients to communicate via memory.
Typical usage on the server-side:
Server server = new Server();
MemoryConnector memoryConnector = new MemoryConnector(server, new HttpConnectionFactory());
server.addConnector(memoryConnector);
server.start();
Typical usage on the client-side:
// Connect to the server and get the local, client-side, EndPoint.
EndPoint clientEndPoint = memoryConnector.connect().getLocalEndPoint();
// Be ready to read responses.
Callback readCallback = ...;
clientEndPoint.fillInterested(readCallback);
// Write a request to the server.
ByteBuffer request = StandardCharsets.UTF_8.encode("""
GET / HTTP/1.1
Host: localhost
""");
Callback.Completable writeCallback = new Callback.Completable();
clientEndPoint.write(writeCallback, request);
-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopException
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
Container.InheritedListener, Container.Listener
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Graceful
Graceful.Shutdown, Graceful.ThrowingRunnable
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
LifeCycle.Listener
-
Field Summary
-
Constructor Summary
ConstructorDescriptionMemoryConnector
(Server server, Executor executor, Scheduler scheduler, ByteBufferPool bufferPool, ConnectionFactory... factories) MemoryConnector
(Server server, ConnectionFactory... factories) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
accept
(int acceptorID) connect()
Client-side applications use this method to connect to the server and obtain aEndPoint.Pipe
.protected void
doStart()
Starts the managed lifecycle beans in the order they were added.protected void
doStop()
Stops the managed lifecycle beans in the reverse order they were added.Get the underlying socket, channel, buffer etc.Methods inherited from class org.eclipse.jetty.server.AbstractConnector
addConnectionFactory, addFirstConnectionFactory, addIfAbsentConnectionFactory, clearConnectionFactories, getAcceptorPriorityDelta, getAcceptors, getByteBufferPool, getConnectedEndPoints, getConnectionFactories, getConnectionFactory, getConnectionFactory, getDefaultConnectionFactory, getDefaultProtocol, getExecutor, getIdleTimeout, getName, getProtocols, getScheduler, getServer, getShutdownIdleTimeout, handleAcceptFailure, interruptAcceptors, isAccepting, isShutdown, join, join, onEndPointClosed, onEndPointOpened, removeConnectionFactory, setAccepting, setAcceptorPriorityDelta, setConnectionFactories, setDefaultProtocol, setIdleTimeout, setName, setShutdownIdleTimeout, shutdown, toString
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, installBean, installBean, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeans
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.jetty.util.component.Container
addBean, addBean, addEventListener, getBean, getBeans, getBeans, getCachedBeans, getContainedBeans, getEventListeners, isManaged, manage, removeBean, removeEventListener, unmanage
Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpable
Methods inherited from interface org.eclipse.jetty.util.component.LifeCycle
addEventListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, start, stop
-
Constructor Details
-
MemoryConnector
-
MemoryConnector
public MemoryConnector(Server server, Executor executor, Scheduler scheduler, ByteBufferPool bufferPool, ConnectionFactory... factories)
-
-
Method Details
-
doStart
Description copied from class:ContainerLifeCycle
Starts the managed lifecycle beans in the order they were added.- Overrides:
doStart
in classAbstractConnector
- Throws:
AbstractLifeCycle.StopException
- If thrown, the lifecycle will immediately be stopped.Exception
- If there was a problem starting. Will cause a transition to FAILED state
-
doStop
Description copied from class:ContainerLifeCycle
Stops the managed lifecycle beans in the reverse order they were added.- Overrides:
doStop
in classAbstractConnector
- Throws:
Exception
- If there was a problem stopping. Will cause a transition to FAILED state
-
getTransport
Description copied from interface:Connector
Get the underlying socket, channel, buffer etc. for the connector..- Returns:
- the underlying socket, channel, buffer etc. for the connector.
-
accept
- Specified by:
accept
in classAbstractConnector
- Throws:
IOException
InterruptedException
-
connect
Client-side applications use this method to connect to the server and obtain a
EndPoint.Pipe
.Client-side applications should then use
EndPoint.Pipe.getLocalEndPoint()
to access the client-sideEndPoint
to write requests bytes to the server and read response bytes.- Returns:
- a
EndPoint.Pipe
representing the connection between client and server
-
getLocalSocketAddress
- Returns:
- the local
SocketAddress
of this connector
-