Logged In Users Sample


This is a very simple modified version of the Hackers Catch Sample that comes with the IBM Connections Chat (ie Sametime) SDK. No warranty implied.
Hide details for Java Source CodeJava Source Code
/*
* Carl Tyler
* www.Epilio.com
*
* Purely provided as sample code, no warranty implied or given.
*/

import com.lotus.sametime.core.comparch.*;
import com.lotus.sametime.core.types.*;
import com.lotus.sametime.community.*;
import com.lotus.sametime.communityevents.*;
import com.lotus.sametime.core.util.connection.*;


/**
* A sample of the community events service. Shows currently Loggedin users.
*/
public class LoggedInUsers implements LoginListener,
CommunityEventsServiceListener, UserLoginListener
{
/**
* The session object.
*/
private STSession m_session;

/**
* The server application service.
*/
private ServerAppService m_saService;

/**
* The Community events component
*/
CommunityEventsService m_ceService;

private void run(String serverName)
{
// init the sametime session and load the services
// First, we create a new session, that belongs uniquely to us.
try
{
m_session = new STSession("" + this );
String [] compNames = { ServerAppService.COMP_NAME,
CommunityEventsService.COMP_NAME };

m_session.loadComponents( compNames );

m_saService = (ServerAppService)
m_session.getCompApi(ServerAppService.COMP_NAME);
m_ceService = (CommunityEventsService)
m_session.getCompApi(CommunityEventsService.COMP_NAME);
}
catch (DuplicateObjectException e)
{
System.out.println("STSession or Components created twice.");
}

// start the session
m_session.start();

// Login to sametime
m_saService.addLoginListener( this);
short loginType = STUserInstance.LT_SERVER_APP;

// The default connection is configured to connect through the Sametime
// mux. We want to connect directly to the server, so we have to set
// the port explicitly.
Connection[] connections = {new SocketConnection(1516, 17000),};
m_saService.setConnectivity(connections);
m_saService.loginAsServerApp( serverName, loginType, "LoggedInUsers", null);
}

/**
* Logged in to Sametime.
*/
public void loggedIn(LoginEvent event)
{
m_ceService.addCommunityEventsServiceListener(this);
m_ceService.addUserLoginListener(this);

}

/**
* Logged out from Sametime.
*/
public void loggedOut(LoginEvent event)
{
m_ceService.removeCommunityEventsServiceListener(this);
}

/**
* The community events service is available.
*/
public void serviceAvailable(CommunityEventsServiceEvent event)
{
System.out.println("************** Start showing logged in users *************");

//m_ceService.addUserLoginFailedListener(this);
}

/**
* The community events service is unavailable.
*/
public void serviceUnavailable(CommunityEventsServiceEvent event)
{
System.out.println("************** finish recording *************");

// m_ceService.removeLoginFailedListener(this);
}

/**
* Entry point of the application
*/
public static void main(String[] args)
{
if ( args.length != 1 )
{
System.out.println("Usage: LoggedInUsers serverName");
System.exit(0);
}

new LoggedInUsers().run(args[0]);
}

public void userLoggedIn(UserLoginEvent event) {
// TODO Auto-generated method stub

String s = "Name=" + event.getUserInstance().getName();
s += ", ip=" + event.getUserInstance().getIp();
s += ", type=" + Integer.toHexString(event.getUserInstance().getLoginType());

System.out.println(s);
}

public void userLoggedOut(UserLoginEvent arg0) {
// TODO Auto-generated method stub

}
}


You can run this from a command line on the Sametime Community server, or other trusted server in the Sametime Community.

java -jar LoggedInUsers.jar sametime.acme.com

Where sametime.acme.com is the sametime community host name.

LoggedInUsers.jarLoggedInUsers.jar