public interface MessageTransport
MessageTransport.open(URI, MessageEndpoint) method with
the server URI.
Usage example:
class RoutedServer implementsMessageEndpoint{ private finalMessageEndpointremoteEndpoint; private finalOutputStreamrouterOut = getRouterOutputStream(); private finalWritableByteChannelrouterOutChannel; RoutedServer(MessageEndpointremoteEndpoint) { this.remoteEndpoint = remoteEndpoint; this.routerOutChannel =Channels.newChannel(routerOut); newThread(() -> { try { runInputLoop(); } catch (IOExceptionex) { } }).start(); } @Overridepublic void sendText(Stringtext) throwsIOException{ routerOut.write(text.getBytes()); routerOut.flush(); } @Overridepublic void sendBinary(ByteBufferdata) throwsIOException{ routerOutChannel.write(data); routerOut.flush(); } @Overridepublic void sendPing(ByteBufferdata) throwsIOException{ remoteEndpoint.sendPong(data); } @Overridepublic void sendPong(ByteBufferdata) throwsIOException{ // Did we send ping? } @Overridepublic void sendClose() throwsIOException{ routerOut.close(); } private void runInputLoop() throwsIOException{ try (InputStreamrouterIn = getRouterInputStream()) { byte[] buf = new byte[1024];ByteBufferbb =ByteBuffer.wrap(buf); int l; while ((l = routerIn.read(buf)) > 0) { bb.limit(l); remoteEndpoint.sendBinary(bb); bb.rewind(); } } finally { remoteEndpoint.sendClose(); } } }Engine.newBuilder().serverTransport( (uri, peerEndpoint) -> { if (denyHost.equals(uri.getHost())) { throw newMessageTransport.VetoException("Denied access."); } else if (routedURI.equals(uri)) { return new RoutedServer(peerEndpoint); } else { // Permit instruments to setup the servers themselves return null; } } ).build();
| Modifier and Type | Interface and Description |
|---|---|
static class |
MessageTransport.VetoException
Thrown when a transport connection is vetoed.
|
| Modifier and Type | Method and Description |
|---|---|
MessageEndpoint |
open(URI uri,
MessageEndpoint peerEndpoint)
Called when a connection to an URI is to be established.
|
MessageEndpoint open(URI uri, MessageEndpoint peerEndpoint) throws IOException, MessageTransport.VetoException
null is returned.
This method can be called concurrently from multiple threads. However, the
MessageEndpoint ought to be called on one thread at a time, unless you're sure that
the particular implementation can handle concurrent calls. The same holds true for the
returned endpoint, it's called synchronously.
uri - the connection URIpeerEndpoint - the peer endpoint representationMessageEndpoint call back, or null.MessageTransport.VetoException - to veto connection to the URL.IOException