Hi, anybody knows how to get the number of concurrent users in Servoy? Do I need a plug-in for this?
erikd:
Hi, anybody knows how to get the number of concurrent users in Servoy? Do I need a plug-in for this?
Here is a function I’ve been playing with a short time ago but I’m not sure its working currently as I need to get it up to the server with multiple clients.
For sure it gets the Client count in developer (1 obviously) but does not return any other info so far such as HostID etc. HTH
function whosLoggedIn()
{
//Returns an array of JSClientInformation elements describing the clients connected to the server.
//plugins.maintenance.setMaintenanceMode(true)
var clients = plugins.maintenance.getConnectedClients();
//plugins.maintenance.setMaintenanceMode(false)
//var clients = application.getActiveClientCount(true);
numberOfClients = clients.length
////application.output("There are " + clients.length + " connected clients.");
for (var i = 0; i < clients.length; i++)
{
forms.security_frm_whos_logged_in.vClientID = clients[i].getClientID();
application.output(' Client ID ' +clients[i].getClientID())
forms.security_frm_whos_logged_in.vClientUserName = clients[i].getUserName();
application.output(' User Name ' +clients[i].getUserName())
forms.security_frm_whos_logged_in.vNumberOfClients = clients.length;
application.output(' No Client ' +clients.length)
forms.security_frm_whos_logged_in.vHostConnect = clients[i].getHostIdentifier();
application.output(' Host ID ' +clients[i].getHostIdentifier())
}
}
Thanks, Kahuna for sharing this.
you basically need only 2 functions to do this:
application.addClientInfo() to set an identifier for each user you want. (we use this to set the tennant_id)
application getClientCountForInfo() to get a count of clients with specific info (in our case the tennant_id).
mboegem:
you basically need only 2 functions to do this:application.addClientInfo() to set an identifier for each user you want. (we use this to set the tennant_id)
application getClientCountForInfo() to get a count of clients with specific info (in our case the tennant_id).
Thanks for that Mark - when do you run addClientInfo() ?
Kahuna:
when do you run addClientInfo() ?
It depends on what your goal is, but we need to keep out users when the number of tenant users exceeds the number of users we keep in the tenant record.
So directly at startup we add the clientinfo (=tenant UUID), then do a count directly after that (this order is needed because a relogin won’t unregister the user from the server)
The number of users we keep in the tenant record are the number of concurrent users the tenant has subscribed to.
Hi Kahuna, I tried your code in the application server above but there was an error in plugins.maintenance.getConnectedClients() syntax. Method returns blank and throws org.mozilla.javascript.EcmaError due to Cannot read property “length” on the variable.
But when I test it in my Servoy Developer it works fine. Do I need to configure application server other than the maintenance.jar file plug-in?
you can’t use the maintance plugin in a real smart client!
You can only use it in a pre or post import solution hook…
Harjo:
you can’t use the maintance plugin in a real smart client!
You can only use it in a pre or post import solution hook…
Thanks Harjo
erikd - Use Marks code - it works fine and allows some other neat features too.
Thanks Mark.
I already moved to the codes application.getClientCountForInfo() and application.addClientInfo(). I just noticed that when I call application.getClientCountForInfo() it only decreases its value by 1 if I close a client application. How do I do this at runtime where I can force application.getClientCountForInfo() to decrease by 1? There is no application.removeClientCountForInfo().
erikd:
I already moved to the codes application.getClientCountForInfo() and application.addClientInfo(). I just noticed that when I call application.getClientCountForInfo() it only decreases its value by 1 if I close a client application. How do I do this at runtime where I can force application.getClientCountForInfo() to decrease by 1? There is no application.removeClientCountForInfo().
Another question is, how do I get details/information from the logged users through these functions?