Interface ClajProvider
public interface ClajProvider
Interface to provide client implementation dependent things.
Everything must be thread-safe, as they will be run on proxy, pinger or calling thread.
With exception of proxy/pinger callbacks, including show* and connectClient(String, int, Runnable, ByteBuffer) methods,
as they will be posted to the main thread via postTask(Runnable).
-
Method Summary
Modifier and TypeMethodDescriptionvoidconnectClient(String host, int port, Runnable success, ByteBuffer joinPacket) Connect the client to the specified server.default arc.net.NetListenergetConnectionListener(ClajProxy proxy) Listener where events are runs, added to all virtual connections.default ExecutorServiceExecutor used to post blocking connection tasks.com.xpdustry.claj.common.packets.ConnectionPayloadPacket.SerializerEssential for the protocol to work!com.xpdustry.claj.common.status.ClajTypegetType()The implementation type, used to validate compatibility between room host and clients.com.xpdustry.claj.common.status.ClajVersionThe CLaJ version, used to request a room creation.default voidhandlePingerError(ClajPinger pinger, Throwable error) default voidhandleProxyError(ClajProxy proxy, Throwable error) default ClajPingerUsed to create new pinger clients.default ClajProxynewProxy()Used to create new proxy clients.voidUsed to post tasks to the main thread, when receiving a packet or running callbacks.default <T> TreadRoomState(long roomId, com.xpdustry.claj.common.status.ClajType type, ByteBuffer buff) Decode the room state received by the server.default voidshowMessage(ClajProxy proxy, com.xpdustry.claj.common.status.MessageType message) default voiddefault voidshowTextMessage(ClajProxy proxy, String text) default ByteBufferwriteRoomState(ClajProxy proxy) The actual room state, in an encoded form.
-
Method Details
-
postTask
Used to post tasks to the main thread, when receiving a packet or running callbacks. -
getExecutor
Executor used to post blocking connection tasks. Ifnull, they will run and block the current thread. -
newProxy
Used to create new proxy clients. Cannot benull. -
newPinger
Used to create new pinger clients. Cannot benull. -
handleProxyError
-
handlePingerError
-
getType
com.xpdustry.claj.common.status.ClajType getType()The implementation type, used to validate compatibility between room host and clients.
Can benullto not make any validation (not recommended).
This means that if the room host doesn't specify it, any CLaJ implementation can join the room at the cost of possible deserialization errors.
And if a client doesn't specify it, the CLaJ server is free to reject it or not.Note that a room without a type will never be displayed in the room browser, even if it is public.
-
getVersion
com.xpdustry.claj.common.status.ClajVersion getVersion()The CLaJ version, used to request a room creation.
Must be equals to the server. -
getConnectionListener
Listener where events are runs, added to all virtual connections. Can benull.
Be aware that the events will be called from the proxy thread. So you likely want to post them to another thread or whatever you want, to avoid slowing the proxy. -
writeRoomState
The actual room state, in an encoded form. (must be flipped for send)
Will be requested by the server if needed.nullcan be returned to not provide state.Max buffer size is
8128, as defined inRoomStatePacket.MAX_BUFF_SIZE. -
readRoomState
default <T> T readRoomState(long roomId, com.xpdustry.claj.common.status.ClajType type, ByteBuffer buff) Decode the room state received by the server. -
connectClient
Connect the client to the specified server.- Parameters:
success- can benulland must be called when connected successfully.joinPacket- must be send in the client connection after connected successfully. The server has little a queue in case this condition is not fully met.
-
getPacketWrapperSerializer
com.xpdustry.claj.common.packets.ConnectionPayloadPacket.Serializer getPacketWrapperSerializer()Essential for the protocol to work!This defines how encapsulated packets are serialized and deserialized.
This method is called once by the global manager (Claj). -
showTextMessage
-
showMessage
-
showPopup
-