Managing Clients from Servoy Solution

Have you ever wanted to get the number of Clients connected a specific Servoy Application Server?

Have you ever wanted to alert a specific client from your Servoy Solution itself?

Have you ever wanted to check whether a Client is alive or not or want to forcefully terminate the Client session?

Further Details

Previous Situation

Alerting or shutdown a client from another Client is not doable in Servoy.

We also can not terminate a Rich Client session, as because the Rich Client Session does not have expired Mechanism, only Web Client has due to the fact that it has a low level HTTP server Web Session.

Current Situation

Hurrah! Now, you can do all those stuffs, alerting or shutting down a client (Rich Client/ Web Client), straight from your Servoy Solution, by the help of a Plug-in. The Plug-in uses Java RMI to talk with the Servoy Application Server Instance.

Introducing Server Utility Plug-in for Servoy – “mfServerUtils 1.0”

“mfServerUtils”, is a FREE Servoy Plug-in(Developed by me :)) that gives the power to developer to control the Application Server and any connected Clients, running on the server. The Plug-in is smart enough to give you the capability to control the client’s (Rich Client & Web Client) behavior such as alerting Client, shutting down Client etc. Not only about the Clients can you also control your Servoy Application Server such as alerting all Clients, shutting down the server, restarting the server etc. And all these powerful things right from your Servoy Solution it self. For the security reason, I have added one property called “com.mindfire.plugins.mfserverutils.accesscode” to the Servoy Properties. I recommend, this property should be set and checked while calling any methods of the Plug-in. For more information, click here.

Installation

Installation of mfServerUtils is very easy. Please, follow the below steps to install the Plug-in.

Steps:

Download the Plug-in from here and unzip the file. Copy all the files (mfServerUtils.jar & mfServerUtils.jar.jnlp) to the \application_server\plugins folder & Restart Servoy. Go to the Servoy Admin Page by navigating to http://serverIPAddress:port/servoy-admin. Move on to the Server Plug-ins page, by clicking on the link “Server Plug-ins” at left menu. Now, you can able to see the “com.mindfire.plugins.mfserverutils.accesscode” property listed under the Header, “Mindfire Solutions: Server Utility Plug-in”. Set a value for the access-code for the Plug-in. FOR SECURITY REASON, ACCESS-CODE MUST BE SET UP FROM THE SERVOY ADMIN PAGE & CALLED PRIOR TO EVERY CALL TO THE PLUG-IN. Restart Servoy Server.

Now, you are ready with the Plug-in and its powerful features.

How to USE the Plug-in

Accessing Application Server Instance

You can get Instance of the Application Server by calling to the getApplicationServer() method of the Plug-in. Any calls to the plug-in must followed by checking the access-code. This will return you an object of class JSApplicationServer. Now, you can call any of the methods under the JSApplicationServer Node.

//Check for access-code

var appServer = null;

var access = plugins.mfServerUtils.checkAccessCode(”);

if(access) {

//Get Application Server Instance

appServer = plugins.mfServerUtils.getApplicationServer();

}else {

application.output(‘Oops!! access-code does not match.’)}

}

You can get an instance of the Application Server running remotely by passing server address & the port number as arguments to the getApplicationServer () method.

//Get Instance of an Application Server running remotely.

appServer = plugins.mfServerUtils.getApplicationServer(“remote_ip”,“remote_port_number”);

With the instance of the Application Server, you can shutdown the Application Server, alert all clients connected to the Application Server or restart Server.

//Alert all clients connected to the Application Server

appServer.alertAllClients(‘Hey, this message is from the server.’);

//Shutting down the Application Server

appServer.shutdownServer();

//Restarting the Application Server

appServer.restartServer();

Accessing Client Instance

You can get the instance of a specific Client or instances of list of all connected Clients by calling to the getClient() or getClients() method respectively. Any calls to the plug-in must followed by checking the access-code.This will return you an object of class JSClient. Now, you can call any of the methods under the JSClient Node.

//Check for access-code

var access = plugins.mfServerUtils.checkAccessCode(”);

if(access){

//Getting a specific Client Instance

var client = plugins.mfServerUtils.getClient(security.getClientID().toString());

//Getting instance of All Clients connected to the Application Server.

var clientList = plugins.mfServerUtils.getAllClients();

for(var count=0; count

var curClient = clientList[count];

//Now, the curClient is single Client instance. Call any methods.

}

}

else {

application.output(‘Oops!! access-code doesn’t match.’)}

}

You can get an instance of the Clients running in the remote Application Server by passing server address & the port number as arguments to the getClient() or getClients() method.

//Getting a specific Client Instance of the Application Server running remotely

var client = plugins.mfServerUtils.getClient(security.getClientID().toString(),

“remote_ip”,“remote_port_number”);

//Getting instance of All Clients connected to the Application Server running remotely

var clientList = plugins.mfServerUtils.getAllClients(“remote_ip”,“remote_port_number”);

With the instance of Client, you can alert client, check the Client is alive or not or can able to shutdown client.

//Alerting the Client

client.alertClient(‘Hey, you are alerted!!’);

//Checking the Client is alive or not

if(client.isClientAlive()){

application.output(‘Client is Alive’);

}else{

application.output(‘Client is not Alive’);

}

//Shutting down Client

client.shutdownClient();

150 150 Burnignorance | Where Minds Meet And Sparks Fly!