Smack and Fastpath

Beginner smack question here

I’m trying to connect to an Openserver 3.8.1. with Fastpath with a simple java application with Smack 3.2.2

I got to send chat messages and change the presence in the server but I could not get to join Fastpath queues.

when I get to w.joinQueue

I get this packet

is there any step I’ve not seen?

thank you in advance

Code

ConnectionConfiguration cc = new ConnectionConfiguration(“192.168.22.180”, 5222, “servername.com”);

con = new XMPPConnection(cc);

try {

con.connect();

} catch (XMPPException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

con.addPacketListener(new ChatListener(), new PacketFilter() {

@Override

public boolean accept(Packet arg0) {

// TODO Auto-generated method stub

return true;

}

});

try {

con.login(“alex”, “alex”);

} catch (XMPPException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

con.getChatManager().addChatListener(new ChatManagerListener() {

@Override

public void chatCreated(Chat chat, boolean createdLocally) {

if (!createdLocally)

chat.addMessageListener(new MessageListener() {

@Override

public void processMessage(Chat arg0, Message arg1) {

// TODO Auto-generated method stub

System.out.println(arg1.toXML());

}

});

;

}

});

    Workgroup wg = new Workgroup("demo@workgroup.servername.com", con);

Form f = new Form(Form.TYPE_RESULT);

try {

wg.joinQueue(f);

} catch (XMPPException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

From my understanding while digging in the smackx source code, as it has not much of the sample over SmackX with fastpath, each of the workgroups will have it’s own AgentSession to associated with.

Steps:

  1. Once you had loggedin to Openfire, you need to use the AgentSession object, provide it with the specific workgroup and the connection object.

  2. Then use the AgentSession object to setthe online status with AgentSession.SetOnline(true).

  3. Manage the fastpath event with it’s listener including WorkgroupInvitationListener, OfferListener, QueueUsersListener

  4. Each of the opened question from the workgroup will be notify via OfferListener, that need to be accept() or reject().

4.1 Whether accept() the offer then manage to get the muc invitation, and carrys on.

Some snippets that might be helpful:)

Login FastPath (create the AgentSession for each workgroup)

I had the FastPathAgent class which extends from the custom SmackClient class hence the login process of Openfire is managed in SmackClient.login()

public boolean loginFastPath() throws XMPPException, InterruptedException

{

super.login();

ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(super.getConnection());

DiscoverItems discoItems = discoManager.discoverItems(“workgroup.” + super.getConnection().getServiceName());

while(discoItems.getItems().hasNext())

{

Item item = discoItems.getItems().next();

getLogger().debug(String.format(“EntityID:%s, Name:%s, Node:%s”,

item.getEntityID(),

item.getName(),

item.getNode()));

}

String[] workgroups = getAssosicatedWorkgroups();

for(String workgroup : workgroups)

{

AgentSession agentSession = new AgentSession(workgroup,super.getConnection());

_agentSessionCollection.put(workgroup, agentSession);

}

FastPathStorage.addListener(this);

return true;

}

Online the agent in that workgroup

I need to manage each of the workgroup seperately hence each of the handler will be stored and manage outer.

public boolean setOnline(String workgroup) throws XMPPException

{

_agentSessionCollection.get(workgroup).setOnline(true);

FastPathInvitationHandler fpInvitationHandler = new FastPathInvitationHandler();

FastPathOfferHandler fpOfferHandler = new FastPathOfferHandler();

FastPathQueueHandler fpQHandler = new FastPathQueueHandler();

_agentHandlerCollection.put(workgroup,

new FastPathHandler(fpInvitationHandler, fpOfferHandler, fpQHandler));

_agentSessionCollection.get(workgroup).addInvitationListener(fpInvita tionHandler);

_agentSessionCollection.get(workgroup).addOfferListener(fpOfferHandle r);

_agentSessionCollection.get(workgroup).addQueueUsersListener(fpQHandl er);

return _agentSessionCollection.get(workgroup).isOnline();

}

Retrieve the workgroups

public String[] getAssosicatedWorkgroups() throws XMPPException

{

List workgroupList = new ArrayList();

for(String workGroup : Agent.getWorkgroups(“workgroup.” + super.getConnection().getServiceName(),

super.getUserBareJID(),

super.getConnection()))

{

getLogger().info("WORKGROUP : " + workGroup);

workgroupList.add(workGroup);

}

_assosicatedWorkgroups = (String[])workgroupList.toArray();

return _assosicatedWorkgroups;

}

Some of the naming may be awkard, since I am a newbie in Java

2 Likes

I’ve just discovered half of it, though I had to dig into Spark source code to find it. Then I read the mail notification from this post… Need to see my mail inbox more often…

Your answer is just perfect and very selfexplanatory. Thank you sir/lady adnarial.