Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public interface SessionStore

Where HttpSessions are kept between requests.

Two are provided, chosen by cn1.session.store: memory (the default) and db, which keeps them in the server’s database so any instance behind a load balancer can serve any client. Implement this for another – a cache server – and pass it to Backend.Builder.sessionStore.

Methods

public abstract HttpSession load(String id) throws IOExceptionThe session with this id, or null when there is none or it expired.
public abstract void save(HttpSession session, String previousId) throws IOExceptionRecords a session after a request that created or changed it.
public abstract void delete(String id) throws IOExceptionForgets a session.
public default Object consumeAttribute(String id, String name) throws IOExceptionAtomically removes and returns an attribute from the stored session.
public abstract int purgeExpired(long now) throws IOExceptionDrops every session that has expired by now; answers how many.
public abstract int size()How many sessions are kept, or -1 when that is expensive to know.

Method details

load

public abstract HttpSession load(String id) throws IOException
The session with this id, or null when there is none or it expired.

save

public abstract void save(HttpSession session, String previousId) throws IOException
Records a session after a request that created or changed it. When its id changed, previousId names the entry to drop; otherwise it is null.

delete

public abstract void delete(String id) throws IOException
Forgets a session.

consumeAttribute

public default Object consumeAttribute(String id, String name) throws IOException
Atomically removes and returns an attribute from the stored session. Concurrent callers, including callers in other server instances, must receive a given value at most once. Used for single-use security challenges. Custom stores must implement this before serving passkey ceremonies; the default fails closed instead of emulating an unsafe load/save sequence.

purgeExpired

public abstract int purgeExpired(long now) throws IOException
Drops every session that has expired by now; answers how many.

size

public abstract int size()
How many sessions are kept, or -1 when that is expensive to know.