String message = null;
if (originalArgs.length > 3)
message = originalArgs[3];
// Create client
XMPPChatClient client = new XMPPChatClient(this, this);
// connect
client.connect(originalArgs[0], originalArgs[1]);
// Wait for 5s for the roster/presence information to be received
final Object lock = new Object();
synchronized (lock) {
lock.wait(5000);
}
// Get desired user ID from rosterUsers map. This is just looking for a
// user that's active and on our contacts list
ID targetID = (ID) rosterUsers.get(originalArgs[2]);
if (targetID == null) {
System.out
.println("target user="
+ originalArgs[2]
+ " is not on active on your contacts list. Cannot send message to this user");
return new Integer(0);
}
// Construct message
String msgToSend = (message == null) ? "Hi, I'm an ECF chat robot."
: message;
System.out.println("ECF chat robot example sending to targetAccount="
+ originalArgs[2] + " message=" + msgToSend);
// Send chat message to targetID
client.sendChat(targetID, msgToSend);
// Get shared object container adapter
ISharedObjectContainer socontainer = (ISharedObjectContainer) client
.getContainer().getAdapter(ISharedObjectContainer.class);
// Create and add shared object to container
TrivialSharedObject sharedObject = new TrivialSharedObject();
socontainer.getSharedObjectManager().addSharedObject(
IDFactory.getDefault().createStringID(
TrivialSharedObject.class.getName()), sharedObject,
null);
// Send messages via shared object...and wait a short while before sending the next one
int count = 0;
synchronized (lock) {
while (count++ < 5) {
// Send shared object message
sharedObject.sendMessageTo(targetID, "hello from "
+ originalArgs[0]+" via shared object");
lock.wait(5000);
}
}
// Close up nicely
client.close();
return IApplication.EXIT_OK;
}