powered by Jive Software

Using SMACK for creating a large number of client connections

I am using the SMACK xmpp library to test the performance of an XMPP server.

But while using the SMACK library to create like 300 clients and then repeatedly pumping packets like roster add, Vcard Get, Roster remove and stuff , the library throws an excepion sometimes during the run.

For instance , it sometimes shows this exception:

Exception in thread “main” java.lang.NullPointerException

at org.jivesoftware.smackx.packet.VCard.doLoad(VCard.java:481)

at org.jivesoftware.smackx.packet.VCard.load(VCard.java:464)

at Load.SimpleClient.sendVcrdGet(SimpleClient.java:326)

at Load.SimpleClient.do_actions(SimpleClient.java:114)

at Load.SwingUser.main(SwingUser.java:71)

Is it because i am creating so many instances of the library?

Thanking You,

Rahul.

Hey Rahul,

It may be helpful to post some of your code if that is possible.

Alex

I am publishing a part of the code for the SimpleClient class . There is another class which creates several instances of this SimpleClient class and then invokes the do_actions method on those instances with the paramters.

public class SimpleClient[/b] implements ConnectionEstablishedListener , PacketListener ,RosterListener{

private Statistics stats = Statistics.getInstance();

private int state = 0;

private XMPPConnection xc = null;

private int upper = 0;

private Roster my_roster = null;

private String username = null;

private int number = 0 ;

private String password = “welcome1”;

private String hostname = null;

private int port = 5222;

private String basename = null;

public SimpleClient(String basename,int number,int upper,String hostname,int port) {

this.basename = basename ;

this.username = basename + number;

this.upper = upper;

this.hostname = hostname ;

this.port = port ;

System.out.println("Creating client " + username);

}

public void login()[/b] {

XMPPConnection.addConnectionListener(this);

try{

this.xc = new XMPPConnection(this.hostname,this.port,“xyz.com”);

xc.addPacketListener(this,new myPackFil());

// Most servers require you to login before performing other tasks.

xc.login(this.username, “welcome1”);

this.my_roster = xc.getRoster();

this.my_roster.addRosterListener(this);

state = 1;

this.stats.setNumLogin();

}

catch(XMPPException e){

e.printStackTrace();

}

}

/*this function sends in the specified number of packets as given by

*the arguments

**/

public void do_actions[/b](int mesg, int pres , int ros_add ,int ros_rem , int ros_ren , int vcrd_get ,int vcrd_set,int mod_ver) {

System.out.println(“MESG:”+mesg+" PRES:"+pres+" ROS ADD:"+ros_add+" ROS REM:"+ ros_rem + " ROS REN:"+ ros_ren+" VCRD GET:"+vcrd_get+" VCRD SET:"+vcrd_set + " VER:"+mod_ver);

for(int i=0;i<mesg;i++) {

this.sendChat();

}

for(int i=0;i<pres;i++){

this.sendPresence();

}

System.out.println("roster add is " + ros_add);

for(int i=0;i<ros_add;i++){

this.addRoster();

}

System.out.println("roster rem is " + ros_rem);

for(int i=0;i<ros_rem;i++){

this.remRoster();

}

System.out.println("roster ren is " + ros_ren);

for(int i=0;i<ros_ren;i++){

this.renRoster();

}

System.out.println("vcard get is " + vcrd_get);

for(int i=0;i<vcrd_get;i++){

this.sendVcrdGet();

}

for(int i=0;i<vcrd_set;i++){

this.sendVcrdSet();

}

for(int i=0;i<mod_ver;i++){

this.sendVersion();

}

}

public void logout(){

this.xc.close();

this.stats.subNumConnd();

}

public void sendPresence() {

Random rtd = new Random();

String status = “Away”;

switch(rtd.nextInt(4)) {

case 0: {

status = “Away”;

break;

}

case 1: {

status = “Be Right Back”;

break;

}

case 2: {

status = “Gone For Lunch”;

break;

}

case 3:{

status = “Not At My Desk”;

break;

}

}

Presence prs = new Presence(Presence.Type.AVAILABLE );

prs.setStatus(status);

this.xc.sendPacket(prs);

this.stats.setNumPrscSent();;

}

public void addRoster() {

//System.out.println(“COMING IN”);

Roster.setDefaultSubscriptionMode(Roster.SUBSCRIPTION_ACCEPT_ALL);

if( this.my_roster == null) {

this.my_roster = this.xc.getRoster();

this.my_roster.addRosterListener(this);

}

this.my_roster.reload();

Random rtd = new Random();

String user_selected = “testnew” + rtd.nextInt(this.upper+1) + "@xyz.com";

try{

this.my_roster.createEntry(user_selected,user_selected,null);

}

catch(Exception e) {

this.stats.setNumErrors();

e.printStackTrace();

}

this.stats.setNumRostAdd();

}

public void remRoster(){

Roster.setDefaultSubscriptionMode(Roster.SUBSCRIPTION_ACCEPT_ALL);

if( this.my_roster == null) {

this.my_roster = this.xc.getRoster();

this.my_roster.addRosterListener(this);

}

this.my_roster.reload();

Random rtd = new Random();

int selected = rtd.nextInt(this.my_roster.getEntryCount());

RosterEntry chosen = null;

Iterator all = this.my_roster.getEntries();

for(int count =0; all.hasNext();count++ ) {

RosterEntry temp = (RosterEntry)all.next();

if(count == selected) {

chosen = temp;

}

}

try{

this.my_roster.removeEntry(chosen);

}

catch( Exception e) {

this.stats.setNumErrors();

e.printStackTrace();

}

this.stats.setNumRostRem();

}

public void renRoster() {

Roster.setDefaultSubscriptionMode(Roster.SUBSCRIPTION_ACCEPT_ALL);

if( this.my_roster == null) {

this.my_roster = this.xc.getRoster();

this.my_roster.addRosterListener(this);

}

this.my_roster.reload();

Random rtd = new Random();

if(this.my_roster.getGroupCount() != 0)

{

int selected = rtd.nextInt(this.my_roster.getGroupCount());

RosterGroup chosen = null;

Iterator all = this.my_roster.getGroups();

for(int count =0; all.hasNext();count++ ) {

RosterGroup temp = (RosterGroup)all.next();

if(count == selected) {

chosen = temp;

}

}

chosen.setName(“NEW NAME” + rtd.nextInt(100));

this.stats.setNumRostRenGrp();

}

}

public void sendChat() {

Random rtd = new Random();

int selected = rtd.nextInt(this.upper+1);

Message my_msg = new Message(“testnew”+selected + "@xyz.com");

my_msg.setBody(“HELLO WORLD”);

this.xc.sendPacket(my_msg);

this.stats.setNumChtSent();

}

public void sendVcrdGet() {

Random rtd = new Random();

int selected ;

do {

selected = rtd.nextInt(this.upper+1);

}while(selected == 0);

System.out.println(“getting vcard for :” + this.basename + selected);

ProviderManager.addIQProvider(“VCARD”,“vcard-temp”,new VCardProvider());

VCard vcrd = new VCard();

try{

vcrd.load(this.xc, this.basename + selected + "@xyz.com");

}

catch(XMPPException e) {

this.stats.setNumErrors();

e.printStackTrace();

}/*

catch(NullPointerException e) {

System.out.println(“the username : " + this.basename + selected + " gave null”);

}*/

this.stats.setNumVcrdGet();

}

Hey Rahul,

The stack trace that you posted is not the one that corresponds with the latest code in SVN. Could you try using the latest code of SVN or the nightly build version and let us know if the problem still persists? If you are still getting the exception please post the new stack trace that contains the updated line numbers.

Thanks,

– Gato