L
- The type of the local serverR
- The type of the remote serverpublic class Link<L,R>
extends java.lang.Thread
implements java.io.Closeable
Modifier and Type | Class and Description |
---|---|
(package private) static class |
Link.Result |
Modifier and Type | Field and Description |
---|---|
(package private) static JSONCodec |
codec |
(package private) static java.lang.String[] |
EMPTY |
(package private) java.util.concurrent.Executor |
executor |
(package private) java.util.concurrent.atomic.AtomicInteger |
id |
(package private) java.io.DataInputStream |
in |
(package private) L |
local |
(package private) static org.slf4j.Logger |
logger |
private java.lang.ThreadLocal<java.lang.Integer> |
msgid |
(package private) java.io.DataOutputStream |
out |
(package private) java.util.concurrent.ConcurrentMap<java.lang.Integer,Link.Result> |
promises |
(package private) java.util.concurrent.atomic.AtomicBoolean |
quit |
(package private) R |
remote |
(package private) java.lang.Class<R> |
remoteClass |
(package private) java.util.concurrent.atomic.AtomicBoolean |
started |
(package private) boolean |
transfer |
Constructor and Description |
---|
Link(java.lang.Class<R> remoteType,
java.io.DataInputStream in,
java.io.DataOutputStream out,
java.util.concurrent.Executor es)
Create a new link based on an Data in/output stream.
|
Link(java.lang.Class<R> remoteType,
java.io.InputStream in,
java.io.OutputStream out,
java.util.concurrent.Executor es)
Create a new link based on an in/output stream.
|
Link(java.lang.Class<R> type,
java.net.Socket socket,
java.util.concurrent.Executor es)
Create a new link based on a socket.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close this link.
|
(package private) void |
executeCommand(java.lang.String cmd,
int id,
java.util.List<byte[]> args) |
java.io.DataInputStream |
getInput()
Get the input stream
|
(package private) java.lang.reflect.Method |
getMethod(java.lang.String cmd,
int count) |
java.io.DataOutputStream |
getOutput()
Get the output stream
|
R |
getRemote()
Get the proxy to the remote peer.
|
boolean |
isOpen()
Answer if this link is open
|
void |
open(L local)
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 |
send(int msgId,
java.lang.reflect.Method m,
java.lang.Object[] args) |
static <L,R> java.io.Closeable |
server(java.lang.String name,
java.lang.Class<R> type,
int port,
java.lang.String host,
java.util.function.Function<Link<L,R>,L> local,
boolean localOnly,
java.util.concurrent.ExecutorService es)
Create a server.
|
static <L,R> java.io.Closeable |
server(java.lang.String name,
java.lang.Class<R> type,
java.net.ServerSocket server,
java.util.function.Function<Link<L,R>,L> local,
boolean localOnly,
java.util.concurrent.Executor es)
Create a server.
|
void |
setRemote(java.lang.Object remote)
Change the object used for the remote.
|
protected void |
terminate(java.lang.Exception t) |
private void |
trace(java.lang.String string) |
void |
transfer(java.lang.Object result)
Transfer the link to another and close this link object
|
(package private) <T> T |
waitForResult(int id,
java.lang.reflect.Type type) |
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
static final org.slf4j.Logger logger
static final java.lang.String[] EMPTY
static final JSONCodec codec
final java.io.DataInputStream in
final java.io.DataOutputStream out
final java.lang.Class<R> remoteClass
final java.util.concurrent.atomic.AtomicInteger id
final java.util.concurrent.ConcurrentMap<java.lang.Integer,Link.Result> promises
final java.util.concurrent.atomic.AtomicBoolean quit
final java.util.concurrent.atomic.AtomicBoolean started
final java.util.concurrent.Executor executor
volatile boolean transfer
private java.lang.ThreadLocal<java.lang.Integer> msgid
R remote
L local
public Link(java.lang.Class<R> remoteType, java.io.InputStream in, java.io.OutputStream out, java.util.concurrent.Executor es)
remoteType
- the remote typein
- the incoming messages streamout
- where messages are send topublic Link(java.lang.Class<R> remoteType, java.io.DataInputStream in, java.io.DataOutputStream out, java.util.concurrent.Executor es)
remoteType
- the remote typein
- the incoming messages streamout
- where messages are send topublic Link(java.lang.Class<R> type, java.net.Socket socket, java.util.concurrent.Executor es) throws java.io.IOException
type
- the type of the remotesocket
- the socketjava.io.IOException
public void open(L local)
local
- the local serverpublic void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
public R getRemote()
public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public static <L,R> java.io.Closeable server(java.lang.String name, java.lang.Class<R> type, int port, java.lang.String host, java.util.function.Function<Link<L,R>,L> local, boolean localOnly, java.util.concurrent.ExecutorService es) throws java.io.IOException
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 hostjava.io.IOException
public static <L,R> java.io.Closeable server(java.lang.String name, java.lang.Class<R> type, java.net.ServerSocket server, java.util.function.Function<Link<L,R>,L> local, boolean localOnly, java.util.concurrent.Executor es)
name
- the name of the servertype
- the remote typeserver
- the Socket Serverlocal
- the local's peer interfacelocalOnly
- only accept calls from the local hostpublic boolean isOpen()
public java.io.DataOutputStream getOutput()
public java.io.DataInputStream getInput()
public void setRemote(java.lang.Object remote)
remote
- peerpublic void transfer(java.lang.Object result) throws java.lang.Exception
result
- the result of the call that caused the transferjava.lang.Exception
protected void terminate(java.lang.Exception t)
java.lang.reflect.Method getMethod(java.lang.String cmd, int count)
int send(int msgId, java.lang.reflect.Method m, java.lang.Object[] args) throws java.lang.Exception
java.lang.Exception
void response(int msgId, byte[] data)
<T> T waitForResult(int id, java.lang.reflect.Type type) throws java.lang.Exception
java.lang.Exception
private void trace(java.lang.String string)
void executeCommand(java.lang.String cmd, int id, java.util.List<byte[]> args) throws java.lang.Exception
java.lang.Exception