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() |
ClassFilter |
getClassFilter() |
List<CallableDecorator> |
getDecorators() |
ExecutorService |
getExecutors() |
OutputStream |
getHeaderStream() |
JarCache |
getJarCache()
Gets the JAR Cache storage.
|
Channel.Mode |
getMode() |
String |
getName() |
Map<Object,Object> |
getProperties() |
boolean |
isArbitraryCallableAllowed() |
boolean |
isRemoteClassLoadingAllowed() |
boolean |
isRestricted()
Deprecated.
Test individual features instead.
|
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 |
with(CallableDecorator decorator) |
ChannelBuilder |
withArbitraryCallableAllowed(boolean b)
If false, this channel only allows the other side to invoke methods on exported objects,
but not
Channel.call(Callable) (and its family of methods.)
The default is true . |
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 |
withClassFilter(ClassFilter filter)
Replaces the
ClassFilter used by the channel. |
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)
Sets the JAR cache storage.
|
ChannelBuilder |
withJarCacheOrDefault(JarCache jarCache)
Sets the JAR cache storage.
|
ChannelBuilder |
withMode(Channel.Mode mode)
The encoding to be used over the stream.
|
ChannelBuilder |
withoutJarCache()
Resets JAR Cache setting to the default.
|
<T> ChannelBuilder |
withProperty(ChannelProperty<T> key,
T value) |
ChannelBuilder |
withProperty(Object key,
Object value)
Sets the property.
|
ChannelBuilder |
withRemoteClassLoadingAllowed(boolean b)
Controls whether or not this channel is willing to load classes from the other side.
|
ChannelBuilder |
withRestricted(boolean restricted)
Deprecated.
Control individual features.
|
ChannelBuilder |
withRoleChecker(RoleChecker checker)
Installs another
RoleChecker . |
ChannelBuilder |
withRoles(Collection<? extends Role> actual)
Convenience method to install
RoleChecker that verifies against the fixed set of roles. |
ChannelBuilder |
withRoles(Role... roles)
Convenience method to install
RoleChecker that verifies against the fixed set of roles. |
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(@CheckForNull OutputStream header)
is
before
the data goes into the "binary mode". This is useful
when the established communication channel might include some data that might
be useful for debugging/trouble-shooting.@CheckForNull public OutputStream getHeaderStream()
@Deprecated public ChannelBuilder withRestricted(boolean restricted)
@Deprecated public boolean isRestricted()
public ChannelBuilder withArbitraryCallableAllowed(boolean b)
Channel.call(Callable)
(and its family of methods.)
The default is true
.public boolean isArbitraryCallableAllowed()
public ChannelBuilder withRemoteClassLoadingAllowed(boolean b)
true
.public boolean isRemoteClassLoadingAllowed()
public ChannelBuilder withJarCache(JarCache jarCache)
jarCache
- JAR Cache to be used. If a deprecated null
value is passed,
the behavior will be determined by the Channel
implementation.this
null
parameter value is deprecated.
withoutJarCache()
or withJarCacheOrDefault(JarCache)
should be used instead.public ChannelBuilder withJarCacheOrDefault(@CheckForNull JarCache jarCache) throws IOException
jarCache
- JAR Cache to be used.
If null
, value of JarCache.getDefault()
will be used.this
IOException
- Default JAR Cache location cannot be initializedpublic ChannelBuilder withoutJarCache()
Channel
implementation.@CheckForNull public JarCache getJarCache()
null
if it is not defined.
Channel
implementation defines the behavior in such case.public ChannelBuilder with(CallableDecorator decorator)
public List<CallableDecorator> getDecorators()
public ChannelBuilder withRoles(Role... roles)
RoleChecker
that verifies against the fixed set of roles.public ChannelBuilder withRoles(Collection<? extends Role> actual)
RoleChecker
that verifies against the fixed set of roles.public ChannelBuilder withRoleChecker(RoleChecker checker)
RoleChecker
.public ChannelBuilder withProperty(Object key, Object value)
Channel
is created, but a property set
during channel building is guaranteed to be visible to the other side as soon
as the channel is established.public <T> ChannelBuilder withProperty(ChannelProperty<T> key, T value)
public ChannelBuilder withClassFilter(ClassFilter filter)
ClassFilter
used by the channel.
By default, ClassFilter.DEFAULT
is installed.public ClassFilter getClassFilter()
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.mode
- The mode to create the transport in.cap
- Capabilities of the other side, as determined during the handshaking.IOException
Copyright © 2004–2022. All rights reserved.