How to get the number of user connected

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

How to get the number of user connected

Florian Minjat
Hi,
   I'd like to display on my seaside application the number of users
currently connected to a particular application. I know I have to get
some info from the sessions. But with a quick look into the code I
could'nt manage to see how I could do that.
   Any hint ?

Florian
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: How to get the number of user connected

William Harford
Florian,

(WASession allSubInstances select:[ :ea | ea isActive]) size

Will get you the total number of active sessions for all session. I  
think something like ...

(WASession allSubInstances select:
        [ :ea | ea isActive & (ea application name = "whatever" ) ]) size

Will get you what you want.

I have not tried the above but it should be close enough to get you  
started.

Will

On Dec 12, 2006, at 10:31 AM, Florian Minjat wrote:

> Hi,
>   I'd like to display on my seaside application the number of users  
> currently connected to a particular application. I know I have to  
> get some info from the sessions. But with a quick look into the  
> code I could'nt manage to see how I could do that.
>   Any hint ?
>
> Florian
> _______________________________________________
> Seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: How to get the number of user connected

Florian Minjat
Thanks again for your answer.
It works fine and answer me the number of active sessions for a given
application.
The problem is that I'd like to count the active users logged in. And
there could be several sessions by user. So I'll need to get to the
WAComponent of my application and test the name of the user.
I just manage to do that quickly with the session like this :

self state objects keysDo: [:k | (k class == MyComponent) ifTrue: [^ k
user]]

But this is ugly because I needed to define WASession>>state and
WAStateRegistry>>object to access the state. Is there any 'clean' way
to get to the application state from its session ?

Florian Minjat

William Harford wrote:

> Florian,
>
> (WASession allSubInstances select:[ :ea | ea isActive]) size
>
> Will get you the total number of active sessions for all session. I
> think something like ...
>
> (WASession allSubInstances select:
>     [ :ea | ea isActive & (ea application name = "whatever" ) ]) size
>
> Will get you what you want.
>
> I have not tried the above but it should be close enough to get you
> started.
>
> Will
>
> On Dec 12, 2006, at 10:31 AM, Florian Minjat wrote:
>
>> Hi,
>>   I'd like to display on my seaside application the number of users
>> currently connected to a particular application. I know I have to get
>> some info from the sessions. But with a quick look into the code I
>> could'nt manage to see how I could do that.
>>   Any hint ?
>>
>> Florian
>> _______________________________________________
>> Seaside mailing list
>> [hidden email]
>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
>
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

RE: How to get the number of user connected

Ramon Leon-5
> Thanks again for your answer.
> It works fine and answer me the number of active sessions for
> a given application.
> The problem is that I'd like to count the active users logged
> in. And there could be several sessions by user. So I'll need
> to get to the WAComponent of my application and test the name
> of the user.
> I just manage to do that quickly with the session like this :
>
> self state objects keysDo: [:k | (k class == MyComponent)
> ifTrue: [^ k user]]
>
> But this is ugly because I needed to define WASession>>state and
> WAStateRegistry>>object to access the state. Is there any 'clean' way
> to get to the application state from its session ?
>
> Florian Minjat

If you already know what your component is, just access it directly

MyComponent allInstances, or even, MyUser allInstances, and count them
directly, no need to go through the session.

Ramon Leon
http://onsmalltalk.com 

_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: How to get the number of user connected

Boris Popov, DeepCove Labs (SNN)
In reply to this post by Florian Minjat
Re: [Seaside] How to get the number of user connected

Or you could create your own session subclass and store your user there, which should make other things easier as well.

Cheers!

-Boris
(Sent from a BlackBerry)

----- Original Message -----
From: [hidden email] <[hidden email]>
To: William Harford <[hidden email]>
Cc: The Squeak Enterprise Aubergines Server - general discussion. <[hidden email]>
Sent: Wed Dec 13 02:36:50 2006
Subject: Re: [Seaside] How to get the number of user connected

Thanks again for your answer.
It works fine and answer me the number of active sessions for a given
application.
The problem is that I'd like to count the active users logged in. And
there could be several sessions by user. So I'll need to get to the
WAComponent of my application and test the name of the user.
I just manage to do that quickly with the session like this :

self state objects keysDo: [:k | (k class == MyComponent) ifTrue: [^ k
user]]

But this is ugly because I needed to define WASession>>state and
WAStateRegistry>>object to access the state. Is there any 'clean' way
to get to the application state from its session ?

Florian Minjat

William Harford wrote:
> Florian,
>
> (WASession allSubInstances select:[ :ea | ea isActive]) size
>
> Will get you the total number of active sessions for all session. I
> think something like ...
>
> (WASession allSubInstances select:
>     [ :ea | ea isActive & (ea application name = "whatever" ) ]) size
>
> Will get you what you want.
>
> I have not tried the above but it should be close enough to get you
> started.
>
> Will
>
> On Dec 12, 2006, at 10:31 AM, Florian Minjat wrote:
>
>> Hi,
>>   I'd like to display on my seaside application the number of users
>> currently connected to a particular application. I know I have to get
>> some info from the sessions. But with a quick look into the code I
>> could'nt manage to see how I could do that.
>>   Any hint ?
>>
>> Florian
>> _______________________________________________
>> Seaside mailing list
>> [hidden email]
>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
>
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: How to get the number of user connected

William Harford
In reply to this post by Ramon Leon-5

On Dec 13, 2006, at 11:01 AM, Ramon Leon wrote:
>
> If you already know what your component is, just access it directly
>
> MyComponent allInstances, or even, MyUser allInstances, and count them
> directly, no need to go through the session.
>

MyComponent can still be expired or part of a session that has  
expired but might still be an instance because expired sessions have  
not been cleared.



> Ramon Leon
> http://onsmalltalk.com
>
> _______________________________________________
> Seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

RE: How to get the number of user connected

Ramon Leon-5
> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf
> Of William Harford
> Sent: Wednesday, December 13, 2006 9:16 AM
> To: The Squeak Enterprise Aubergines Server - general discussion.
> Subject: Re: [Seaside] How to get the number of user connected
>
>
> On Dec 13, 2006, at 11:01 AM, Ramon Leon wrote:
> >
> > If you already know what your component is, just access it directly
> >
> > MyComponent allInstances, or even, MyUser allInstances, and
> count them
> > directly, no need to go through the session.
> >
>
> MyComponent can still be expired or part of a session that
> has expired but might still be an instance because expired
> sessions have not been cleared.

This is true... If you aren't running a session reaper to keep sessions
down, but if you want to run a production app, and not stall on session
expirations randomly, you need to run a separate service to continually
flush out expired sessions.

Anyway, you're correct, and I Boris had the answer... Custom session class,
I didn't notice he was just trying to find users on the session the hard
way.

Ramon Leon
http://onsmalltalk.com 

_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: How to get the number of user connected

Florian Minjat
Thank you all for this help. It is clear I need to do custom sessions.
I don't know why I didn't thought of it before.

Ramon Leon wrote:
> This is true... If you aren't running a session reaper to keep sessions
> down, but if you want to run a production app, and not stall on session
> expirations randomly, you need to run a separate service to continually
> flush out expired sessions.

Currently I use the default behavior for session expiration. So they
just wait to be GCed. Is there an existing 'session reaper' available
somewhere or should I make it myself? It doesn't seems to difficult,
but I dislike coding the wheel again.

Thanks again,

Florian Minjat
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: How to get the number of user connected

William Harford

On Dec 13, 2006, at 11:42 AM, Florian Minjat wrote:
> Currently I use the default behavior for session expiration. So  
> they just wait to be GCed. Is there an existing 'session reaper'  
> available somewhere or should I make it myself? It doesn't seems to  
> difficult, but I dislike coding the wheel again.

Actually the default behavior is to clear expired handlers (session,  
images, documents,  etc) every about every 10th time. See WARegistry  
#shouldCollectHandlers

Some people like to change that method to always return false. When I  
was using Squeak I added some methods to the class side of WAResigtry  
but you will most likely want to keep this code in it's own class.

Hope that gets you started.

Will
....

finalizationContinue
        ^true.


finalizationProcess
        [self finalizationContinue] whileTrue:[
                self allSubInstancesDo:[:i| i unregisterExpiredHandlers].
                Smalltalk garbageCollect.
                (Delay forSeconds: 900) wait.
        ].


initialize
        self restartFinalizationProcess.


restartFinalizationProcess
        FinalizationProcess
                ifNotNil: [FinalizationProcess terminate.
                        FinalizationProcess := nil].
        FinalizationProcess := [self finalizationProcess]
                forkAt: Processor userInterruptPriority.





>
> Thanks again,
>
> Florian Minjat
> _______________________________________________
> Seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

RE: How to get the number of user connected

Ramon Leon-5
In reply to this post by Florian Minjat
> Currently I use the default behavior for session expiration.
> So they just wait to be GCed. Is there an existing 'session
> reaper' available somewhere or should I make it myself? It
> doesn't seems to difficult, but I dislike coding the wheel again.
>
> Thanks again,
>
> Florian Minjat
> _______________________________________________
> Seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

I actually subclass ApplicationService and run a separate background process
to expire sessions.  Here's a fileOut of what I use.

'From Squeak3.8.1 of 16 July 2006 [latest update: #6744] on 13 December 2006
at 12:19:34 pm'!
ApplicationService subclass: #SSSessionExpirationService
    instanceVariableNames: ''
    classVariableNames: ''
    poolDictionaries: ''
    category: 'SentorsaSeaside-Services'!
!SSSessionExpirationService commentStamp: '<historical>' prior: 0!
SSSessionExpirationService initialize.!


!SSSessionExpirationService methodsFor: 'running' stamp: 'rjl 12/4/2006
15:58'!
runWhile: aBlock
    [aBlock value] whileTrue:
            [self informApplications.
            self sleepFor: 10000]! !


!SSSessionExpirationService methodsFor: 'private' stamp: 'rjl 12/11/2006
11:42'!
informApplications
    WADispatcher default entryPoints do:
            [:app |
            (app respondsTo: #unregisterExpiredHandlers)
                ifTrue: [app unregisterExpiredHandlers]]! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

SSSessionExpirationService class
    instanceVariableNames: ''!

!SSSessionExpirationService class methodsFor: 'as yet unclassified' stamp:
'rjl 6/17/2006 13:22'!
initialize
    (ApplicationService servicesNamed: 'seaside session manager') ifEmpty:
            [self
                addService: (self newNamed: 'seaside session manager')
start;
                yourself]! !


SSSessionExpirationService initialize!


Ramon Leon
http://onsmalltalk.com 

_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: How to get the number of user connected

Florian Minjat
Thanks again for your answers, I will try it when I find some time to
spare.
Florian

Ramon Leon wrote:

>> Currently I use the default behavior for session expiration.
>> So they just wait to be GCed. Is there an existing 'session
>> reaper' available somewhere or should I make it myself? It
>> doesn't seems to difficult, but I dislike coding the wheel again.
>>
>> Thanks again,
>>
>> Florian Minjat
>> _______________________________________________
>> Seaside mailing list
>> [hidden email]
>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
> I actually subclass ApplicationService and run a separate background process
> to expire sessions.  Here's a fileOut of what I use.
>
> 'From Squeak3.8.1 of 16 July 2006 [latest update: #6744] on 13 December 2006
> at 12:19:34 pm'!
> ApplicationService subclass: #SSSessionExpirationService
>     instanceVariableNames: ''
>     classVariableNames: ''
>     poolDictionaries: ''
>     category: 'SentorsaSeaside-Services'!
> !SSSessionExpirationService commentStamp: '<historical>' prior: 0!
> SSSessionExpirationService initialize.!
>
>
> !SSSessionExpirationService methodsFor: 'running' stamp: 'rjl 12/4/2006
> 15:58'!
> runWhile: aBlock
>     [aBlock value] whileTrue:
>             [self informApplications.
>             self sleepFor: 10000]! !
>
>
> !SSSessionExpirationService methodsFor: 'private' stamp: 'rjl 12/11/2006
> 11:42'!
> informApplications
>     WADispatcher default entryPoints do:
>             [:app |
>             (app respondsTo: #unregisterExpiredHandlers)
>                 ifTrue: [app unregisterExpiredHandlers]]! !
>
> "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
>
> SSSessionExpirationService class
>     instanceVariableNames: ''!
>
> !SSSessionExpirationService class methodsFor: 'as yet unclassified' stamp:
> 'rjl 6/17/2006 13:22'!
> initialize
>     (ApplicationService servicesNamed: 'seaside session manager') ifEmpty:
>             [self
>                 addService: (self newNamed: 'seaside session manager')
> start;
>                 yourself]! !
>
>
> SSSessionExpirationService initialize!
>
>
> Ramon Leon
> http://onsmalltalk.com 
>
>
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside