I am currently looking into using Yielder to implement a simple micro-
process framework (http://kamaelia.sourceforge.net/MiniAxon/). One of
the problems I am having at the moment is that any class that I want
to have a yield method in must be a direct sub-class of Yielder. This
is proving awkward as I would like to have a deeper hierarchy (Yielder-
>Microprocess->Component->CustomComponent) and require that the yield
method be implemented by the CustomComponent.
One possibility is to add support for annotating a yield method and
creating a static yieldReturn Method. I.e. the code would then look
like:
public class Foo {
@Yeildable
public int next() {
int i = 0;
while (true) {
Yielder.yieldReturn(i++);
}
}
}
I am going to have a go at implementing this.
Mike.
And a different approach, maybe: The restriction for the direct sub-
classing only comes from YieldChecker class. A more thorough check
could be made there to find out if the class is a sub-class of Yield
at any level, and if so manipulate it. That might make it easier, and
more intuitive too (in my opinion, annotations are going to make it
less intuitive together with annonymous classes).
What do you think?
And then, YielderChecker calls this utility method (located in the
Util class) with the superName parameter.
I have implemented a quick solution which just puts an @Yieldable
annotation on the subclass and the agent checks for both the
superclass and the annotation. Not elegant but works for the moment.
Mike.
It should work though! The class wasn't classloaded but maybe it needs
some fine-tuning, such as making sure the Yielder class is always not
manipulated (easy to do, just check the className parameter), the
direct sub-class of Yielder will be manipulated (easy to check,
compare superName to Yielder.class.getName()) and any other sub-class
could go up the hierarchy - the Yielder and direct sub-classes should
load properly.
This is theoretical, but from my understanding of class loading it
should work this way... Shouldn't it?
Mike.
public static boolean isYielderInHierarchy(String className) {
String name = className.replace('/', '.');
try {
return Yielder.class.isAssignableFrom(Class.forName(name));
} catch (ClassNotFoundException e) {
e.printStackTrace();
return false;
}
}
Mike.
Okay, I'll check in the changes with some JUnits to test it.