public class ChannelBuilder extends Object
Channel
, including hand-shaking between two sides
and various configuration switches to change the behaviour of Channel
.Constructor and Description |
---|
ChannelBuilder(String name,
ExecutorService executors)
Specify the minimum mandatory parameters.
|
Modifier and Type | Method and Description |
---|---|
Channel |
build(CommandTransport transport) |
Channel |
build(InputStream is,
OutputStream os)
Performs a handshake over the communication channel and builds a
Channel . |
Channel |
build(Socket s) |
Channel |
build(SocketChannel s) |
ClassLoader |
getBaseLoader() |
Capability |
getCapability() |
ExecutorService |
getExecutors() |
OutputStream |
getHeaderStream() |
JarCache |
getJarCache() |
Channel.Mode |
getMode() |
String |
getName() |
boolean |
isRestricted() |
protected CommandTransport |
makeTransport(InputStream is,
OutputStream os,
Channel.Mode mode,
Capability cap)
Instantiate a transport.
|
protected CommandTransport |
negotiate(InputStream is,
OutputStream os)
Performs hand-shaking and creates a
CommandTransport . |
ChannelBuilder |
withBaseLoader(ClassLoader base)
Specify the classloader used for deserializing remote commands.
|
ChannelBuilder |
withCapability(Capability capability)
Controls the capabilities that we'll advertise to the other side.
|
ChannelBuilder |
withHeaderStream(OutputStream header)
If non-null, receive the portion of data in is before
the data goes into the "binary mode".
|
ChannelBuilder |
withJarCache(JarCache jarCache) |
ChannelBuilder |
withMode(Channel.Mode mode)
The encoding to be used over the stream.
|
ChannelBuilder |
withRestricted(boolean restricted)
If true, this channel won't accept
Command s that allow the remote end to execute arbitrary closures
--- instead they can only call methods on objects that are exported by this channel. |
public ChannelBuilder(String name, ExecutorService executors)
name
- Human readable name of this channel. Used for debug/logging. Can be anything.executors
- Commands sent from the remote peer will be executed by using this Executor
.public String getName()
public ExecutorService getExecutors()
public ChannelBuilder withBaseLoader(ClassLoader base)
Channel.getRemoteProperty(Object)
. Sometimes two parties
communicate over a channel and pass objects around as properties, but those types might not be
visible from the classloader loading the Channel
class. In such a case, specify a classloader
so that those classes resolve. If null, Channel.class.getClassLoader()
is used.public ClassLoader getBaseLoader()
public ChannelBuilder withMode(Channel.Mode mode)
public Channel.Mode getMode()
public ChannelBuilder withCapability(Capability capability)
public Capability getCapability()
public ChannelBuilder withHeaderStream(OutputStream header)
public OutputStream getHeaderStream()
public ChannelBuilder withRestricted(boolean restricted)
Command
s that allow the remote end to execute arbitrary closures
--- instead they can only call methods on objects that are exported by this channel.
This also prevents the remote end from loading classes into JVM.
Note that it still allows the remote end to deserialize arbitrary object graph
(provided that all the classes are already available in this JVM), so exactly how
safe the resulting behavior is is up to discussion.public boolean isRestricted()
public ChannelBuilder withJarCache(JarCache jarCache)
public JarCache getJarCache()
public Channel build(InputStream is, OutputStream os) throws IOException
Channel
.is
- Stream connected to the remote peer. It's the caller's responsibility to do
buffering on this stream, if that's necessary.os
- Stream connected to the remote peer. It's the caller's responsibility to do
buffering on this stream, if that's necessary.IOException
public Channel build(Socket s) throws IOException
IOException
public Channel build(SocketChannel s) throws IOException
IOException
public Channel build(CommandTransport transport) throws IOException
IOException
protected CommandTransport negotiate(InputStream is, OutputStream os) throws IOException
CommandTransport
.
This is an implementation detail of ChannelBuilder and it's protected
just so thatIOException
protected CommandTransport makeTransport(InputStream is, OutputStream os, Channel.Mode mode, Capability cap) throws IOException
is
- The negotiated input stream that hidesos
- the underlying stream.cap
- Capabilities of the other side, as determined during the handshaking.IOException
Copyright © 2014. All rights reserved.