public interface StateRelay
Known subtypesRestStateRelay
Carries state between devices the platform will not carry it between – an iPhone and an Android tablet, two devices that are never in the same room, a phone and the web build.
Codename One ships no server for this. A relay is the application’s own endpoint, which is
also the only honest arrangement: the relay has to know which states belong to the same
person, and that is the app’s account system, not the framework’s. RestStateRelay covers
the common case over HTTPS; implement this interface directly for anything else.
Both methods are called from a background thread and may block. Neither is called on the event
dispatch thread, so ordinary blocking com.codename1.io code is correct here.
Methods
public abstract void publish(AppState state)
throws IOException | Sends a state. |
public abstract AppState fetch()
throws IOException | Asks for the newest state this user has on any device. |
Method details
publish
public abstract void publish(AppState state)
throws IOExceptionSends a state. Called after each checkpoint, so implementations that talk to a slow
endpoint should coalesce rather than send every one.
Parameters
stateAppState- the state to send
Throws
java.io.IOException- when the send failed. The framework logs it and keeps the state, which the next checkpoint’s publisher sends – unless a newer state has superseded it by then, or the user signed out in between. It is not retried on a timer: one attempt per change beats spinning against an endpoint that is down.
fetch
public abstract AppState fetch()
throws IOExceptionAsks for the newest state this user has on any device. Returning this device’s own most
recent state is fine and expected – the framework recognizes its own echo by device id and
sequence, and ignores it.
Returns
the state, or null when the endpoint has nothing
Throws
java.io.IOException- when the fetch failed