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 Details

    • postTask

      void postTask(Runnable task)
      Used to post tasks to the main thread, when receiving a packet or running callbacks.
    • getExecutor

      default ExecutorService getExecutor()
      Executor used to post blocking connection tasks. If null, they will run and block the current thread.
    • newProxy

      default ClajProxy newProxy()
      Used to create new proxy clients. Cannot be null.
    • newPinger

      default ClajPinger newPinger()
      Used to create new pinger clients. Cannot be null.
    • handleProxyError

      default void handleProxyError(ClajProxy proxy, Throwable error)
    • handlePingerError

      default void handlePingerError(ClajPinger pinger, Throwable error)
    • getType

      com.xpdustry.claj.common.status.ClajType getType()
      The implementation type, used to validate compatibility between room host and clients.
      Can be null to 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

      default arc.net.NetListener getConnectionListener(ClajProxy proxy)
      Listener where events are runs, added to all virtual connections. Can be null.
      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

      default ByteBuffer writeRoomState(ClajProxy proxy)
      The actual room state, in an encoded form. (must be flipped for send)
      Will be requested by the server if needed. null can be returned to not provide state.

      Max buffer size is 8128, as defined in RoomStatePacket.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

      void connectClient(String host, int port, Runnable success, ByteBuffer joinPacket)
      Connect the client to the specified server.
      Parameters:
      success - can be null and 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

      default void showTextMessage(ClajProxy proxy, String text)
    • showMessage

      default void showMessage(ClajProxy proxy, com.xpdustry.claj.common.status.MessageType message)
    • showPopup

      default void showPopup(ClajProxy proxy, String text)