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, org.eclipse.jetty.util.component.Container, org.eclipse.jetty.util.component.Destroyable, org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.util.component.Dumpable.DumpableContainer, org.eclipse.jetty.util.component.Graceful, org.eclipse.jetty.util.component.LifeCycle

public class MemoryConnector extends AbstractConnector

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);
 
  • Constructor Details

    • MemoryConnector

      public MemoryConnector(Server server, ConnectionFactory... factories)
    • MemoryConnector

      public MemoryConnector(Server server, Executor executor, org.eclipse.jetty.util.thread.Scheduler scheduler, org.eclipse.jetty.io.ByteBufferPool bufferPool, ConnectionFactory... factories)
  • Method Details

    • doStart

      protected void doStart() throws Exception
      Overrides:
      doStart in class AbstractConnector
      Throws:
      Exception
    • doStop

      protected void doStop() throws Exception
      Overrides:
      doStop in class AbstractConnector
      Throws:
      Exception
    • getTransport

      public Object 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

      protected void accept(int acceptorID) throws IOException, InterruptedException
      Specified by:
      accept in class AbstractConnector
      Throws:
      IOException
      InterruptedException
    • connect

      public org.eclipse.jetty.io.EndPoint.Pipe 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-side EndPoint to write requests bytes to the server and read response bytes.

      Returns:
      a EndPoint.Pipe representing the connection between client and server
    • getLocalSocketAddress

      public SocketAddress getLocalSocketAddress()
      Returns:
      the local SocketAddress of this connector