Session Manager Statistics
| March 2006 | |
|
Software Environment
| Feature | Tested on |
| Operating System | Windows 2000 Server SP4 |
| Compiler | Sun JDK 1.4.2_08 |
| Runtime | Sun JRE 1.4.2_08 |
| DFC | 5.3 SP2 |
| Content Server | 5.3 SP1 |
Abstract
This snippet shows how to access session manager statistics such as number of identities and number of sessions
Snippet
/*
* Created on Mar 8, 2006
*
* EMC Documentum Developer Program 2006
*/
package com.documentum.devprog.snippets.session;
import com.documentum.fc.common.DfException;
import com.documentum.fc.common.IDfLoginInfo;
import com.documentum.fc.client.IDfClient;
import com.documentum.fc.client.IDfSession;
import com.documentum.fc.client.IDfSessionManager;
import com.documentum.fc.client.IDfSessionManagerStatistics;
import java.util.Iterator;
import com.documentum.com.DfClientX;
import com.documentum.com.IDfClientX;
public class SessionManagerStatistics
{
public static void main(String[] args)
{
String username = "dmadmin";
String password = "dmadmin";
String repoName = "devprog53sp1";
IDfSessionManager sessMgr = null;
IDfSession sess = null;
try
{
sessMgr = createSessionManager();
addIdentity(sessMgr, username, password, repoName);
printStatistics(sessMgr,repoName);
}
catch (Exception ex)
{
ex.printStackTrace();
}
finally
{
if ((sessMgr != null) && (sess != null))
{
sessMgr.release(sess);
}
}
}
private static void printStatistics(IDfSessionManager sm, String repoName)
throws DfException
{
IDfSession sess = null;
try
{
IDfSessionManagerStatistics stats = sm.getStatistics();
sess = sm.getSession(repoName);
System.out.println("Is Session Pooling Active: "
+ stats.isSessionPoolActive());
System.out.println("Has Active Sessions: "
+ stats.hasActiveSessions());
System.out.println("Printing Repositories and their Identities...");
Iterator iterRepo = stats.getDocbases();
while (iterRepo.hasNext())
{
String repo = (String) iterRepo.next();
System.out.println("Repository: " + repo);
System.out.println("Sessions");
Iterator iterSess = stats.getSessions(repo);
while (iterSess.hasNext())
{
IDfSession s = (IDfSession) iterSess.next();
System.out.println("Sess Id: " + s.getSessionId());
System.out.println("Ref Count: "
+ stats.getReferenceCount(sess));
}
}
}
finally
{
if (sess != null)
{
sm.release(sess);
}
}
}
/**
* Creates a new session manager instance. The session manager does not have
* any identities associated with it.
*
* @return a new session manager object.
* @throws DfException
*/
private static IDfSessionManager createSessionManager() throws DfException
{
IDfClientX clientX = new DfClientX();
IDfClient localClient = clientX.getLocalClient();
IDfSessionManager sessMgr = localClient.newSessionManager();
return sessMgr;
}
/**
* Adds a new identity to the session manager.
*/
private static void addIdentity(IDfSessionManager sm, String username,
String password, String repoName) throws DfException
{
IDfClientX clientX = new DfClientX();
IDfLoginInfo li = clientX.getLoginInfo();
li.setUser(username);
li.setPassword(password);
// check if session manager already has an identity.
// if yes, remove it.
if (sm.hasIdentity(repoName))
{
sm.clearIdentity(repoName);
}
sm.setIdentity(repoName, li);
}
}
|
 |
|