Hi,

As Hugi wrote, you can access the list via the session store.

Be careful with access to objects inside those sessions, especially EOs since 
you are outside their normal RR loop request.

I have a standard way to list active users and keep track of last access inside 
session by adding those attributes:
        private long lastSleepDate;
        private long lastUserRequestDate;
        private boolean isRequestFromUser;

and adding those overrides...

        @Override
        public void awake() {
                super.awake();
        ....
                isRequestFromUser = true;
        }

        @Override
        public void sleep() {
                lastSleepDate = System.currentTimeMillis();
                if (isRequestFromUser) {
                        lastUserRequestDate = lastSleepDate;
                }
                super.sleep();
        }

        public void setRequestIsPing() {
                isRequestFromUser = false;
        }


The setRequestIsPing is to discriminate auto refresh ping request in my page 
wrapper use to keep session alive when the app is displayed. I have this in the 
template:
<wo:AjaxPing frequency = "100000"><wo:string value = 
"$pingString"/></wo:AjaxPing>

And this in the component java class:

        public String pingString() {
                if (ERXApplication.isAjaxRequest(context().request())) {
                        session().setRequestIsPing();
                }
                return null;
        }

And this to list active sessions (SessionInfo is  POJO):

                WOServerSessionStore sessionStore = (WOServerSessionStore) 
WOApplication.application().sessionStore();
                @SuppressWarnings("unchecked")
                NSArray<Session> sessions = 
sessionStore._sessions().allValues();

                NSMutableArray<SessionInfo> sessionInfos = new 
NSMutableArray<>();
                for (Session session : sessions) {
                        SessionInfo info = new SessionInfo();
                        info.hashCode = session.hashCode();
                        info.lastSleepDatetime = session.lastSleepDatetime();
                        info.lastUserRequestDate = 
session.lastUserRequestDate();
                        info.timeOut = session.timeOutMillis();
                        info.usager = session.userAccessService().currentUser();
                        sessionInfos.add(info);
                }
                new 
ERXKey<LocalDateTime>("lastUserRequestDate").desc().sort(sessionInfos);

Regards,

Samuel


> Le 26 avr. 2024 à 08:48, Hugi Thordarson via Webobjects-dev 
> <webobjects-dev@lists.apple.com> a écrit :
> 
> Hi,
> if you're using WO's standard session store (WOServerSessionStore) you should 
> be able to access the active sessions using:
> 
> ((WOServerSessionStore)WOApplication.application().sessionStore())._sessions()
> 
> It will return a dictionary consisting of sessionID -> Session.
> 
> Not using it though, I'm achieving this myself by using the notifications 
> posted by session management (SessionDidRestoreNotification, 
> SessionDidCreateNotification and SessionDidTimeOutNotification), so I can 
> keep track of more info (like when the session was last touched).
> 
> Cheers,
> - hugi
> 
> 
>> On Apr 26, 2024, at 12:33, OCsite via Webobjects-dev 
>> <webobjects-dev@lists.apple.com> wrote:
>> 
>> Hi there,
>> 
>> is there a way to enumerate sessions which are alive inside of a 
>> WO/ERXApplication?
>> 
>> I guess I can create such a list myself, adding new ones in session.awake, 
>> keeping it weak not to prevent old sessions to be destroyed (or perhaps 
>> storing just session IDs), yadda yadda, but it would be much easier and less 
>> error-prone just to use a WO/nder service, if there's one.
>> 
>> The purpose is that we need to allow an app administrator to list all the 
>> normal users which are currently logged in, and be able to force-logout 
>> selected ones.
>> 
>> Thanks!
>> OC
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
>> Help/Unsubscribe/Update your Subscription:
>> https://lists.apple.com/mailman/options/webobjects-dev/hugi%40karlmenn.is
>> 
>> This email sent to h...@karlmenn.is
> 
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/webobjects-dev/samuel%40samkar.com
> 
> This email sent to sam...@samkar.com

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to