@Nonnull public PhotonSessionStatePerApp stateLastAppID () { return state (getLastApplicationID ()); }
/** * @return The one and only instance for the current session. Never * <code>null</code>. * @see #getInstanceIfInstantiated() */ @Nonnull public static PhotonSessionState getInstance () { return getSessionSingleton (PhotonSessionState.class); }
/** * @return The one and only instance for the current session. It may be * <code>null</code> if this singleton was not yet instantiated. * @see #getInstance() */ @Nullable public static PhotonSessionState getInstanceIfInstantiated () { return getSessionSingletonIfInstantiated (PhotonSessionState.class); }
public static void setStatePerApp (@Nonnull final IRequestWebScopeWithoutResponse aRequestScope) final PhotonSessionState aSessionState = PhotonSessionState.getInstanceIfInstantiated (); sAppID = aSessionState.getLastApplicationID (); if (StringHelper.hasNoText (sAppID)) sAppID = PhotonGlobalState.getInstance ().getDefaultApplicationID (); if (aSessionState != null) final PhotonSessionStatePerApp aSessionStatePerApp = aSessionState.state (sAppID);
final PhotonSessionState aSessionState = PhotonSessionState.getInstance (); aSessionState.setLastApplicationID (sAppID); final PhotonSessionStatePerApp aAppSessionState = aSessionState.state (sAppID); final PhotonGlobalStatePerApp aAppGlobalState = PhotonGlobalState.state (sAppID);
@Nullable private static String _getApplicationIDOrNull (@Nonnull final IRequestWebScopeWithoutResponse aRequestScope) { String sAppID = aRequestScope.attrs ().getCastedValue (REQUEST_ATTR_APP_ID); if (StringHelper.hasNoText (sAppID)) { // Fallback to last saved state from session final PhotonSessionState aPSS = PhotonSessionState.getInstanceIfInstantiated (); if (aPSS != null) sAppID = aPSS.getLastApplicationID (); // None in request nor session -> fall back to default if (StringHelper.hasNoText (sAppID)) sAppID = PhotonGlobalState.getInstance ().getDefaultApplicationID (); } return sAppID; }
@Nullable private static PhotonRequestState _getRequestStateOrNull (@Nonnull final IRequestWebScopeWithoutResponse aRequestScope) { PhotonRequestState ret = aRequestScope.attrs ().getCastedValue (REQUEST_ATTR_STATE); if (ret == null) { // Fallback to last saved state from session final String sAppID = _getApplicationIDOrNull (aRequestScope); if (StringHelper.hasText (sAppID)) { final PhotonSessionState aSessionState = PhotonSessionState.getInstanceIfInstantiated (); if (aSessionState != null) { final PhotonSessionStatePerApp aSessionStatePerApp = aSessionState.state (sAppID); // Is e.g. empty if a new session state was created! if (aSessionStatePerApp.isNotEmpty ()) ret = new PhotonRequestState (aSessionStatePerApp); } // Global state as last resort if (ret == null) ret = new PhotonRequestState (PhotonGlobalState.state (sAppID)); } // else - no app ID - we're lost } return ret; }