Strategy ONE

Obtaining a List of the Top 50 User Connections

The sample code below illustrates how to obtain a list of the top fifty user connections, sorted by the number of open jobs. If there are more than fifty user connections, only the first fifty are returned, with the order of the connections determined by the sort criteria.

 // create a WebObjectsFactory instance

 WebObjectsFactory factory = WebObjectsFactory.getInstance();

 

 // Get the user connection source object

 UserConnectionSource source = (UserConnectionSource) factory.getMonitorSource(EnumWebMonitorType.WebMonitorTypeUserConnection);

 

 // Set up the sort condition to sort on the open jobs field in descending order

 MonitorSort msort = source.getSortCriteria();

 msort.add(EnumDSSXMLUserConnectionInfo.DssXmlUserConnOpenJobs, EnumDSSXMLOrder.DssXmlDescending);

 

 // Set up the flag to obtain browsing information

 source.setLevel(EnumDSSXMLLevelFlags.DssXmlBrowsingLevel);

 

 // Set up the maximum number of user connections we want to browse

 source.setMaxCount(50);

 

 try {

      // Sends the request to Intelligence Server to retrieve user connection information

      UserConnectionResults results = source.getUserConnections();

 

      // Loop through the results to print out user connection information, such as

      // the user name, project name, session ID, and open jobs

      for (int i=0; i < results.getCount(); i++) {

           UserConnection singleConn = results.get(i);

           System.out.print("User: " + singleConn.getUserName());

           System.out.print(", project: " + singleConn.getProjectName());

           System.out.print(", sessionID: " + singleConn.getSessionID());

           System.out.print(", open jobs: " + singleConn.getOpenJobs());

           System.out.println();

      }

 } catch (WebObjectsAdminException woae) {

          woae.printStackTrace();

 }

This list is pre-sorted in descending order by open jobs and contains a maximum of fifty connections (set in the code). If there are more than fifty connections on the server, the additional connections are not returned in the results.

Sample output

The output would look something like the following:

User: John Doe, project: MicroStrategy Tutorial, sessionID: <sessionID>, open jobs: 15

User: Jane Doe, project: Testing project, sessionID: <sessionID>, open jobs: 7

User: Administrator, project: Testing project, sessionID: <sessionID>, open jobs: 3

In this sample, if there are more than fifty user connections, only the top fifty are shown.