Header containing initialization data like activation.
Get state.
Get current state of connection state with the worker server.
List of values are such like below:
NONE
: This instance is newly created, but did nothing yet.CONNECTING
: The connect
method is on running.OPEN
: The connection is online.CLOSING
: The close
method is on running.CLOSED
: The connection is offline.Connect to remote server.
The connect() method tries to connect an SharedWorker
instance. If the
SharedWorker
instance is not created yet, the SharedWorker
instance would be newly
created. After the creation, the SharedWorker
program must open that server using
the SharedWorkerServer.open() method.
After you business has been completed, you've to close the SharedWorker
using one of
them below. If you don't close that, vulnerable memory usage and communication channel
would not be destroyed and it may cause the memory leak:
JS File to be SharedWorkerServer.
Detailed options like timeout.
Protected
destructorDestroy the communicator.
A destroy function must be called when the network communication has been closed.
It would destroy all function calls in the remote system (by Driver<Controller>
),
which are not returned yet.
The error instance would be thrown to those function calls. If the disconnection is abnormal, then write the detailed reason why into the error instance.
Optional
error: ErrorAn error instance to be thrown to the unreturned functions.
Get Driver for RFC (Remote Function Call).
The Controller
is an interface who defines provided functions from the remote
system. The Driver
is an object who makes to call remote functions, defined in
the Controller
and provided by Provider
in the remote system, possible.
In other words, calling a functions in the Driver<Controller>
, it means to call
a matched function in the remote system's Provider
object.
Controller
: Definition onlyDriver
: Remote Function CallAn interface for provided features (functions & objects) from the remote system (Provider
).
Whether to convert type of function parameters to be compatible with their primitive.
A Driver for the RFC.
Join connection.
Wait until the connection to be closed.
Join connection or timeout.
Wait until the connection to be closed until timeout.
The maximum milliseconds for joining.
Whether awaken by disconnection or timeout.
Join connection or time expiration.
Wait until the connection to be closed until time expiration.
The maximum time point to join.
Whether awaken by disconnection or time expiration.
Protected
replyData Reply Function.
A function should be called when data has come from the remote system.
When you receive a message from the remote system, then parse the message with your special protocol and covert it to be an Invoke object. After the conversion, call this method.
Structured data converted by your special protocol.
Set Provider
An object would be provided for remote system.
SharedWorker Connector
The
SharedWorkerConnector
is a communicator class which connects to anSharedWorker
instance, and interacts with it through RFC (Remote Function Call) concept.You can connect to the SharedWorkerServer using connect method. The interaction would be started if the server accepts your connection by calling the SharedWorkerAcceptor.accept method. If the remote server rejects your connection through SharedWorkerAcceptor.reject method, the exception would be thrown.
After the connection, don't forget to closing the connection, if your business logics have been completed, to clean up the resources. Otherwise, the closing must be performed by the remote shared worker server, you can wait the remote server's closing signal through the join method.
Also, when declaring this
SharedWorkerConnector
type, you've to define three generic arguments;Header
,Provider
andRemote
. Those generic arguments must be same with the ones defined in the target WebSocketServer and SharedWorkerAcceptor classes (Provider
andRemote
must be reversed).For reference, the first
Header
type represents an initial data from the remote client after the connection. I recommend utilize it as an activation tool for security enhancement. The second generic argumentProvider
represents a provider from client to server, and the otherRemote
means a provider from the remote server to client.