Whilst evaluating Lightstreamer I have created a little "echo" facility using a metadata adapter and a data adapter. It basically works, so I feel I have the fundamentals within my grasp. My problem is that when I have multiple clients use the echo facility, the message sent by one client is echoed back to all the connected clients rather than only the one that sent it. A rather novel facility should I want to use instant messaging - but in this case I do not. I just want the message sent back to the client that sent it - and that is all.
Clearly I something fundamentally wrong here - probably to do with my "subscribe" and "sendMessage" methods. Can somebody give me a pointer as to what I should be doing below:
public void subscribe(String itemName, Object itemHandle, boolean needsIterator) throws SubscriptionException, FailureException {
// We must be ready to accept subscription requests. If we receive an "echo" item we will start a thread to
// handle the data.
// If more users subscribe to the “echo” item, the subscribe method is not called anymore.
// When the last user unsubscribes from this item, our Adapter is notified through the unsubscribe call
logDebug("EchoDataAdapter subscribed: "+itemHandle.toString());
if (!itemName.equals("echo")) {
// only one item for a unique echo is managed
throw new SubscriptionException("No such item");
}
assert(subscribed == null);
subscribed = itemHandle;
}
public void sendMessage(String message) {
// Receives a message from the metadata adapter, which we will simply echo back
//logDebug("EchoDataAdapter received sendMessage: "+message);
this.echoMessage(message);
}
private void echoMessage(String message) {
final Object currHandle = subscribed;
final HashMap<String, String> echo = new HashMap<String, String>();
echo.put("message", message);
//If we have a listener create a new Runnable to be used as a task to pass the
//new update to the listener
Runnable echoMessage = new Runnable() {
public void run() {
// call the update on the listener;
// in case the listener has just been detached,
// the listener should detect the case
logDebug("Echoing "+echo.get("message"));
listener.smartUpdate(currHandle, echo, false);
}
};
//We add the task on the executor to pass to the listener the actual status
executor.execute(echoMessage);
}
Also, when a connection is made a session gets created. How do I get that session identifier on the client?
Thanks