Thursday, October 13, 2011

Using the Java API to Logout Users From a Server

There was a question on the Network54 board today regarding the Java API and logging off all users from a given application.   I quickly wrote up a quick (but untested) bit of Java API code as an example, but decided to post it here as Network54 mangles the formatting of code examples.   Without further ado, here is the code in a more readable format:

void disconnectUsersOfApplication(IEssOlapServer server, String applicationName) throws EssException {
    // get the connections to the server
    IEssIterator connections = server.getConnections();

    // loop the connections
    for (int i = 0; i < connections.getCount(); i++) {
        // cast to a connection info object
        IEssOlapServer.IEssOlapConnectionInfo connection = 
         (IEssOlapServer.IEssOlapConnectionInfo)connections
         .getAt(i);

        // if the connection is to the target app
        if (connection.getConnectedApplicationName()
         .equalsIgnoreCase(applicationName)) {
            // log them off
            connection.logoffUser();
        }
    }
}

No comments: