Class Channel<Data extends Channel.Config>
java.lang.Object
org.apidesign.jvm.channel.Channel<Data>
- Type Parameters:
Data- internal data of the channel
- All Implemented Interfaces:
AutoCloseable
Channel connects two
JVM instances. A "channel" creates two (almost)
identical instances of the Channel on both sides of the "channel" -
e.g. in each of the JVMs. The instances are initialized with the same
Channel.Config, so they both understand the same messages when communicating
with each other.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSet of methods necessary for construction of aChannel. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()static <D extends Channel.Config>
Channel<D> Factory method to initialize the Channel in the SubstrateVM.final <C, R extends C>
RExecutes a message in the other JVM.final DataGetter for data associated with the channel.booleanCheck for "real dual JVM mode".final booleanisMaster()Master channel check.toString()
-
Method Details
-
create
Factory method to initialize the Channel in the SubstrateVM.- Type Parameters:
D- type of internal data as well as provider of the pool- Parameters:
jvm- instance of HotSpot JVM to connect to (can benullto create a mock channel inside of a single JVM)configClass- the class which has public default constructor and can supply an instance of persistance pool to use for communication- Returns:
- channel for sending messages to the HotSpot JVM
-
getConfig
Getter for data associated with the channel. Each instance ofChannelon both sides of the "channel" gets different instance ofData. The data may be used in the functions that implement the logic inexecute(Class, Function)message processing.- Returns:
- data associated with this channel
- See Also:
-
isMaster
public final boolean isMaster()Master channel check. One instance of theChannelon the initializing side is marked as master. The other one is slave.- Returns:
- is master
-
isDualJvmMode
public boolean isDualJvmMode()Check for "real dual JVM mode". There is a way to create a channel in a "mock mode" viacreate(org.apidesign.ni.jvm.channel.JVM, java.lang.Class)- such emulation is running both sides of the channel in the same JVM. One can detect such a situation by checking result of this method.- Returns:
truewhen two different JVMs are on each side of the channel.falseotherwise, for example in the "mock mode".
-
execute
public final <C, R extends C> R execute(Class<C> resultType, Function<? super Channel<Data>, R> msg) Executes a message in the other JVM. The message is any subclass ofFunctionready to be serialized/deserialized via channel'sChannel.Config. The result (which is of typeR) also has to be registered for serialization/deserialization.- Type Parameters:
C- the actual type of theChannel.ConfigsubclassR- the type of result we expect the message to return- Parameters:
resultType- class with the type ofRto use for deserializationmsg- the message that gets serialized, transferred into the other JVM, deserialized on the other side andevaluatedthere- Returns:
- the value gets computed via
Function.apply(T)ofmsgin the other JVM and then it gets serialized and transferred back to us. Deserialized and the value is then returned from this method
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
toString
-