Package aQute.lib.link
Class Link<L,R>
java.lang.Object
java.lang.Thread
aQute.lib.link.Link<L,R>
- Type Parameters:
L
- The type of the local serverR
- The type of the remote server
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Runnable
This is a simple RPC module that has a R(remote) and L(ocal) interface. The R
interface is implemented on the remote side. The methods on this subclass are
then available remotely. I.e. this is a two way street. Void messages are
asynchronous, other messages block to a reply.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final JSONCodec
(package private) static final String[]
(package private) final Executor
(package private) final AtomicInteger
(package private) final DataInputStream
(package private) L
(package private) static final org.slf4j.Logger
private ThreadLocal<Integer>
(package private) final DataOutputStream
(package private) final ConcurrentMap<Integer,
Link.Result> (package private) final AtomicBoolean
(package private) R
(package private) final AtomicBoolean
(package private) boolean
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
ConstructorsConstructorDescriptionLink
(Class<R> remoteType, DataInputStream in, DataOutputStream out, Executor es) Create a new link based on an Data in/output stream.Link
(Class<R> remoteType, InputStream in, OutputStream out, Executor es) Create a new link based on an in/output stream.Create a new link based on a socket. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close this link.(package private) void
executeCommand
(String cmd, int id, List<byte[]> args) getInput()
Get the input stream(package private) Method
Get the output streamGet the proxy to the remote peer.boolean
isOpen()
Answer if this link is openvoid
Open the stream by providing the local interface to use(package private) void
response
(int msgId, byte[] data) void
run()
The thread method that receives the messages from the input stream(package private) int
static <L,
R> Closeable server
(String name, Class<R> type, int port, String host, Function<Link<L, R>, L> local, boolean localOnly, ExecutorService es) Create a server.static <L,
R> Closeable server
(String name, Class<R> type, ServerSocket server, Function<Link<L, R>, L> local, boolean localOnly, Executor es) Create a server.void
Change the object used for the remote.protected void
private void
void
Transfer the link to another and close this link object(package private) <T> T
waitForResult
(int id, Type type) Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
Field Details
-
Constructor Details
-
Link
Create a new link based on an in/output stream. This link is still closed. Call open to activate the link.- Parameters:
remoteType
- the remote typein
- the incoming messages streamout
- where messages are send to
-
Link
Create a new link based on an Data in/output stream. This link is still closed. Call open to activate the link.- Parameters:
remoteType
- the remote typein
- the incoming messages streamout
- where messages are send to
-
Link
Create a new link based on a socket. This link is still closed. Call open to activate the link.- Parameters:
type
- the type of the remotesocket
- the socket- Throws:
IOException
-
-
Method Details
-
open
Open the stream by providing the local interface to use- Parameters:
local
- the local server
-
close
Close this link. This will also close the peer link. If local implements Closeable then the local server will also be notified by calling close. Since we also close the remote peer link we also try to call close on the remote peer.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
getRemote
Get the proxy to the remote peer.- Returns:
- the remote peer
-
run
public void run()The thread method that receives the messages from the input stream -
server
public static <L,R> Closeable server(String name, Class<R> type, int port, String host, Function<Link<L, R>, throws IOExceptionL> local, boolean localOnly, ExecutorService es) Create a server. This server will create instances when it is contacted.- Parameters:
name
- the name of the servertype
- the remote typeport
- the local porthost
- on which host to registerlocal
- the local's peer interfacelocalOnly
- only accept calls from the local host- Returns:
- a closeable to close the link
- Throws:
IOException
-
server
public static <L,R> Closeable server(String name, Class<R> type, ServerSocket server, Function<Link<L, R>, L> local, boolean localOnly, Executor es) Create a server. This server will create instances when it is contacted.- Parameters:
name
- the name of the servertype
- the remote typeserver
- the Socket Serverlocal
- the local's peer interfacelocalOnly
- only accept calls from the local host- Returns:
- a closeable to close the link
-
isOpen
public boolean isOpen()Answer if this link is open- Returns:
- true if this link is open
-
getOutput
Get the output stream- Returns:
- the output stream
-
getInput
Get the input stream- Returns:
- the input stream
-
setRemote
Change the object used for the remote.- Parameters:
remote
- peer
-
transfer
Transfer the link to another and close this link object- Parameters:
result
- the result of the call that caused the transfer- Throws:
Exception
-
terminate
-
getMethod
-
send
- Throws:
Exception
-
response
void response(int msgId, byte[] data) -
waitForResult
- Throws:
Exception
-
trace
-
executeCommand
- Throws:
Exception
-