Methods Summary |
---|
public synchronized void | addListener(MessageListener listener)Registers the given listener for the given ID.
String id = listener.getId();
MessageListener registered = (MessageListener) listeners.get(id);
if ( registered != null ) {
if ( registered != listener ) {
throw new IllegalStateException("Listener " + registered.getClass().getName()
+ " already registered for ID " + id);
}
}
else {
listener.setContext(context);
listeners.put(id, listener);
}
|
public void | changed(StatusTextEvent event)Parses the event to see if it's a valid message and dispatches it.
processIncomingMessage(event.text, ((Browser)event.widget).getUrl());
|
public void | changed(TitleEvent event)
processIncomingMessage(event.title, ((Browser)event.widget).getUrl());
|
public void | deregisterBrowser(Browser browser)Detaches this dispatcher from the given {@link Browser}.
This dispatcher listens for dispose events from the browser
and calls this method in response.
browser.removeStatusTextListener(this);
browser.removeTitleListener(this);
|
public void | dispatch(BrowserMessage message)Dispatches the given message to the appropriate listener.
if ( message == null ) {
return;
}
context.debug("Received " + message);
// handle messages for dispatcher and context regardless of sequence number
String listenerId = message.getListenerId();
if ( LISTENER_ID.equals(listenerId) ) {
handleMessage(message);
}
else if ( BrowserContext.LISTENER_ID.equals(listenerId) ) {
context.handleMessage(message);
}
else {
if ( ! isValidSequence(message) ) {
context.debug("Ignoring duplicate: " + message);
}
else {
MessageListener listener = getListener(listenerId);
if ( listener == null ) {
context.debug("No listener registered with ID " + listenerId);
}
else {
listener.handleMessage(message);
message.complete(true, true, null);
}
}
}
|
public MessageListener | getListener(java.lang.String id)Returns the listener with the given ID.
return (MessageListener) listeners.get(id);
|
public void | handleMessage(BrowserMessage message)Handles operations intended for the dispatcher.
String operationId = message.getOperationId();
if ( OP_RESET_SEQUENCE.equals(operationId) ) {
resetSequence();
}
else {
throw new IllegalArgumentException("Unknown operation: " + operationId);
}
|
public boolean | isValidSequence(BrowserMessage message)Determines whether or not the given sequence number is still valid
for the given {@link Browser}. If the number is valid, it is stored
as the last seen sequence number.
int sequence = message.getSequence();
if ( sequence < 0 ) {
Debug.outNoStack("Invalid sequence number: " + sequence);
return false;
}
if ( sequence <= lastSequence ) {
context.debug("Duplicate sequence number: " + sequence
+ ", last: " + lastSequence);
return false;
}
lastSequence = sequence;
return true;
|
private void | processIncomingMessage(java.lang.String msg, java.lang.String referer)
if (msg == null) {
return;
}
try {
class_mon.enter();
if (sLastEventText != null && msg.equals(sLastEventText)) {
return;
}
sLastEventText = msg;
} finally {
class_mon.exit();
}
if (msg.startsWith(BrowserMessage.MESSAGE_PREFIX)) {
try {
BrowserMessage browserMessage = new BrowserMessage(msg);
browserMessage.setReferer(referer);
dispatch(browserMessage);
} catch (Exception e) {
Debug.out(e);
}
}
|
public void | registerBrowser(Browser browser)Attaches this dispatcher to the given {@link Browser} to receive
status text change and dispose events.
browser.addStatusTextListener(this);
browser.addTitleListener(this);
|
public synchronized void | removeListener(MessageListener listener)Deregisters the listener with the given ID.
removeListener(listener.getId());
|
public synchronized void | removeListener(java.lang.String id)Deregisters the listener with the given ID.
MessageListener removed = (MessageListener) listeners.remove(id);
if ( removed == null ) {
// throw new IllegalStateException("No listener is registered for ID " + id);
}
else {
removed.setContext(null);
}
|
public void | resetSequence()Resets the sequence number for the given {@link Browser} to 0.
context.debug("Reseting sequence number");
lastSequence = INITIAL_LAST_SEQUENCE;
|