Leo Sutic wrote:
>
>>-----Original Message-----
>>From: Berin Loritsch [mailto:[EMAIL PROTECTED]]
>>Sent: den 17 december 2001 20:25
>>To: Avalon Developers List
>>Subject: Re: [Review] Event Queues
>>
>>
>>Leo Sutic wrote:
>>
>>
>>That would be the way to minimize the cost of creating a Method object,
>>
>
> But this would maybe not have to be done more than once:
>
> class MyStage extends AbstractStageWrapper {
>
> public void handleConnectionOpen (ConnectionOpenEvent event) {
> ...
> }
>
> public void handleConnectionClosed (ConnectionClosedEvent event) {
> ...
> }
>
> }
>
> class AbstractStageWrapper implements EventHandler {
>
> private final HashMap handlerMethods = new HashMap ();
>
> public void initialize () throws Exception {
> // Iterate over own handler methods, and build a
> // Class -> Method map.
> }
>
> public void handleEvent (QueueElement event) {
> Method handlerMethod = (Method) handlerMethods.get (event.getClass ());
> handlerMethod.invoke (...);
> }
> }
Go ahead and play with it. I won't mind if you add it to CVS. Right now, I am
concentrating on the queue portion, and have not addressed the Stage portion yet.
>
>
>
>>and invoking it--done several hundred times a second, and now you are
>>thrashing your Garbage Collection.
>>
>
> Like creating event methods 100 times a second?
:). It's a good thing modern JVMs are better at small final classes than
caching them would be. Otherwise this would not be a viable option.
>
>
>>In many cases, the switch/case would not only be sufficient, but
>>preferred.
>>
>
> I can only see it as preferred when the cost for invokation via
> a Method instance is comparable to the cost for running the handler,
> and I believe that to be the exception - the handler will always be
> much more expensive than the invokation.
>
> Looking above, can you fit the AbstractStageWrapper into the your Stage
> interface design? I think it gives all the flexibility needed: Use
> switch() if you want, use reflection if you want. Above all, it would
> allow me to experiment. If reflection is too expensive then the idea can
> die, and we can move on without having lost anything.
It is in CVS, nothing stopping you from doing it yourself....
I only have so much time I can squeeze to do this.
--
"They that give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety."
- Benjamin Franklin
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>