Headless Client Cleanup

The forum to discuss the Headless version of Servoy. Web, Java and Servlet development questions can all be posted here.

Headless Client Cleanup

Postby paulc » Tue Aug 31, 2010 5:56 pm

HI all,

I am currently working with the headless client and am unsure of how the cleanup needs to be handled. My understanding is that the application does not cleanup any headless clients on its own and I am needing a way for the user to clean up on logout(which is handled with a global variable storing the client id), onHide, when the solution is closed, and time outs?

Could someone provide me with some same code, or sample solution in which I could look at or utilize to handle the situations mentioned above?

Currently I have the client id stored into a global variable. This variable is set with a singleton type of method so that the users only have one valid client open at a time. Should I store the client IDs into an array instead of a single var? and how/when could I clean up the invalid clients.

Thanks
paulc
 
Posts: 55
Joined: Wed Feb 17, 2010 8:58 pm

Re: Headless Client Cleanup

Postby jcompagner » Tue Aug 31, 2010 7:23 pm

just store the client object itself in a global media variable
then in onsolution close you call client.shutdown()
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Headless Client Cleanup

Postby paulc » Tue Aug 31, 2010 9:27 pm

Thanks Johan,

I have added the shutdown of the client into the onSolutionClose method as you suggested.

Are there any issues regarding cleanup with timed out clients or invalid clients that we should be concerned with? or does servoy automatically do a cleanup of these items with some sort of garabge cleanup on its own?
paulc
 
Posts: 55
Joined: Wed Feb 17, 2010 8:58 pm

Re: Headless Client Cleanup

Postby jcompagner » Tue Aug 31, 2010 10:41 pm

if you have a smart client that starts a headless client
And that smart client then crashes or disconnects from the network and doesnt really come back.
Then the headless client could be hanging forever on the server..

A workaround for this could be to have a pool of Headless clients that you can use
and there id's you store in a table, with a in use flag or timestamp.
So when a client wants to use a headless client it gets one from the pool, updates the flag/timestamp
and gives it back to the pool when done for others to use.
Then you could have a batch client checking the in use id's and if a timestamp is more then X time get release it because a client really can't or shouldnt use it for that long..
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Headless Client Cleanup

Postby paulc » Tue Aug 31, 2010 11:03 pm

HI Johan,

I will try your suggestion with a pool of clients that are available for users.

I am running into an issue with the server log when I go to do a logout from within the onSolutionClose method.

When the user logs out of the application we call security.logout('iglass_main');
This will then fire the onSolutionClose method. I have included the code for that below.
Code: Select all
function onSolutionClose(force)
{
  if (globals.iglass_client_id != null || globals.iglass_client_id != '')
  {
    var client = plugins.headlessclient.getClient(globals.iglass_client_id)
   
    if (client && client.isValid())
       client.shutdown(true);
  }
 
  return true
}


The onSolutionClose method returns an exception com.servoy.extensions.plugins.headlessclient.ClientNotFoundException: Client '8EA0FD4C-03F9-47A7-936A-3B3D8DCCC3D7' not found

Is there a way to check to see if I can get the client or shutdown the client without it generating an error in the server log?

I tried the method of storing the headless client into a media variable but was unable to do so because I cannot typecast the variable to access the JSClient methods. To get around this I am storing the id into the variable instead.
paulc
 
Posts: 55
Joined: Wed Feb 17, 2010 8:58 pm

Re: Headless Client Cleanup

Postby jcompagner » Wed Sep 01, 2010 9:00 am

That client should be there right? or did you also shutdown it in another way?
But why not keep a reference to the client object itself instead of just the uuid?

then you dont have to get it but just have to do:

if (client && client.isValid())
client.shutdown(true);

But i will make that api a bit nicer, getClient() shouldnt result in a error report when there is not really an error
and you just want to get a null object if not found..
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Headless Client Cleanup

Postby paulc » Wed Sep 01, 2010 5:34 pm

Thanks Johan,

I got it working with the clieint being stored into a media variable, and the error no longer occurs.

Thanks
paulc
 
Posts: 55
Joined: Wed Feb 17, 2010 8:58 pm


Return to Servoy Headless Client

Who is online

Users browsing this forum: No registered users and 4 guests

cron