CRecordSessionExpired

In nyssr.net, when a session token expires or the session is closed, a broadcast is sent to all nodes.
You can register an observer for this message to receive it directly.

This message belongs to the session manager API.
It is part of the kernel.

{
  "id": "274f6cd9-f1fe-4973-9f0e-fd26db19d276",
  "name": "SESSION_EXPIRED",
  "description": "A session has been expired due to inactivity.",
  "isService": "true",
  "namespaces": "SYSTEM",
  "slots": [
  ]
}

Usage

Install the observer

The observer for receiving the message is easiest to set up by handling the CRecordStartTarget message. This is the message that every target receives first after registration. Here, we use the RecordHelper. Alternatively, you can retrieve the SYSTEM namespace, then the nanoservice registry, and finally call the addObserver() method.

private boolean asyncStartTarget(@NotNull final CEnvelope aEnvelope,
                                 @NotNull final CRecord aRecord) throws CException
{
    if (aEnvelope.isAnswer())
    {
        return false;
    }
    else
    {
        // either use the RecordHelper
        mDependencies.getRecordHelper()
                     .addObserver(CRecordSessionExpired.class,
                                  this,
                                  false);
        // or use the Nanoservice registry
        mDependencies.getSystemNanoserviceRegistry()
                     .addObserver(CRecordSessionExpired.class,
                                  this,
                                  false);

        // ...
        aEnvelope.setResultSuccess();
        return true;
    }
}

Catch the message

To catch the message, we need a message handler. We add it in the constructor.

// constructor:
addMessageHandler(CRecordSessionExpired.ID,
                  this::asyncSessionExpired);
private boolean asyncSessionExpired(@NotNull final CEnvelope aEnvelope,
                                    @NotNull final CRecord aRecord)
{
    if (aEnvelope.isAnswer())
    {
        return false;
    }
    else
    {
        final byte[] sessionToken = aEnvelope.getSessionToken();
        // ...
        return true;
    }
}