[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[dash-dev] easy listening


Bjorn and I have shown that we can write listeners in Monkey Script. Our approach has been to write a series of scripts that share state through common global scope, identified with the Scope metadata tag. Although this demonstrates the generality of the current implementation, it does not serve the need of casual scripting well.


I would like to write a single script and use additional metadata to trigger the subscribe/unsubscribe logic expected of listeners. We are considering adding a tag something like:

	Listen: objectAccessor().addListener(this)

We solicit advice on this or other schemes to achieve the same effect. Below are some thoughts that come to mind.

Purpose
-------

Allow casually written scripts to avail themselves to information transmitted within Eclipse through listener protocols. Avoid accidental dangling listeners by capturing as much of the listener idiom in the metadata handlers as possible.

Likely Implementation
---------------------

Metadata tag processing would parse the tag value using regular expressions to find the object accessor function and an add listener method. These would be evaluated as follows:

* The object accessor function would be evaluated by the script engine to produce a wrapped java object. It would be an error for the script to not implement the function or for the function to return a non-java object other than null.

* The add listener method will be invoked through java reflection. A corresponding remove message will be inferred and invoked too.

* The type of the addListener argument (this, above) will be retrieved as part of the java reflection and a dynamic proxy created. The proxy will necessarily invoke additional functions within the script engine, wrapping and passing java arguments as indicated by the particular method signature. A script need not implement all handler methods.

Use Cases
---------

* A user saves a script with the Listen: tag. The objectAccessor is immediately invoked and if not null, the subscription is made and listening begins.

If the script had a previously subscribed listener, it will be unsubscribed before the new subscription happens.

* A user invokes a script's main through the monkey menu. Whether or not the main is present, the listen unsubscription/resubscription proceeds so that the object accessor has the opportunity to deliver a different subject.

* A user saves a script with an error or that otherwise foils the unsubscribe/resubscribe mechanism. The user receives notification and any dangling subscription is discarded.

* A user creates a stop-listening menu. It works by causing the object accessor to return null. The listening stops with no error message.

Concerns
--------

Can we predict the pattern of addListener/removeListener methods. Are there other pairs we should recognize?

Are there threading issues?

Can we parse the metadata with regular expressions? Are there variations that people would expect to work that can't be parsed without a context-free grammar.



Thanks and best regards. -- Ward