| // |
| // Licensed to the Apache Software Foundation (ASF) under one |
| // or more contributor license agreements. See the NOTICE file |
| // distributed with this work for additional information |
| // regarding copyright ownership. The ASF licenses this file |
| // to you under the Apache License, Version 2.0 (the |
| // "License"); you may not use this file except in compliance |
| // with the License. You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, |
| // software distributed under the License is distributed on an |
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| // KIND, either express or implied. See the License for the |
| // specific language governing permissions and limitations |
| // under the License. |
| // |
| |
| = DevFaqLookupEventBus |
| :jbake-type: wiki |
| :jbake-tags: wiki, devfaq, needsreview |
| :jbake-status: published |
| |
| == Using Event Bus in NetBeans |
| |
| [source,java] |
| ---- |
| |
| Dne Monday 26 November 2007 17:37:48 Rob Ratcliff napsal(a): |
| > For the bus we developed, we could subscribe by a specific type, for all |
| > subclasses of a type or for certain message header attributes of an |
| > event. We also had a bus per "session" (the GUI could display multiple |
| > sessions/workspaces using tabs -- equivalent to a JMS topic) so that |
| > only events related to that session would be delivered. And, like I |
| > mentioned earlier, there was support to register as a "GUI" listener or |
| > a "business" listener so that events would automatically be delivered in |
| > the correct thread to avoid EDT lockup and rendering issues. |
| > |
| > I'd be interested in hearing what you and others think about these types |
| > of capabilities and how they compare to the NetBeans paradigms. |
| ---- |
| |
| I've been thinking about this for a while and I believe that there is event |
| bus like system in NetBeans. It is link:http://bits.netbeans.org/dev/javadoc/org-openide-util/org/openide/util/Utilities.html#actionsGlobalContext()[Utilities.actionsGlobalContext()] |
| |
| We have our event bus and it is accessible via |
| link:http://bits.netbeans.org/dev/javadoc/org-openide-util/org/openide/util/Utilities.html#actionsGlobalContext()[Utilities.actionsGlobalContext()]. Indeed it may not be perfect, but it plays |
| exactly the role described in the presentation. Menu, Toolbar, etc. listen on |
| it, while somebody else updates it. |
| |
| Indeed, there could be some improvements. We do not support merging of events |
| or network access, but if one really cares, there is a way to plug into the |
| system. All one needs to do is to implement |
| link:http://bits.netbeans.org/dev/javadoc/org-openide-util/org/openide/util/ContextGlobalProvider.html[ContextGlobalProvider] |
| One sample implelemention is in openide/windows and second in |
| imagine.dev.java.net. |
| |
| I've heard a complain that... |
| |
| *> This is a central listener, not an event bus* |
| |
| ... however this boils down to a question: How do you envision an event bus? |
| It is a place to contain events or objects that somehow appear in the system. |
| It allows anyone to selectively listen on what is happening in link:https://spar.dev.java.net/source/browse/spar/trunk/code/plugins/spar/src/com/jasperpotts/spar/event/application/[the bus] |
| |
| So in fact event bus is a central listener. Just like |
| link:http://bits.netbeans.org/dev/javadoc/org-openide-util/org/openide/util/Utilities.html#actionsGlobalContext()[Utilities.actionsGlobalContext()]. |
| |
| Indeed it could be improved. Is there anyone who would like to contribute in |
| improving our actionsGlobalContext? If so, what should be done? |
| |
| [source,java] |
| ---- |
| |
| Hi Jaroslav, |
| |
| I think it'd be useful to define exactly what an event bus is (like you |
| mentioned), what use cases it supports and how NetBeans supports these |
| use cases currently and how it might support these in the future. |
| |
| I used an EventBus approach in my last project for receiving |
| asynchronous data events from the Network (such as position updates, |
| network status events) and internal events such as service status |
| (network disconnected) and other state change events such as "sensor |
| network reconfigured"...essentially when it made more sense to use a hub |
| and spoke communication model rather than a point-to-point. There could |
| be multiple instances of the EventBus, which used a EDT type of model |
| (dispatcher thread/queue) and supported subscriptions by type (any event |
| derived from a base class) or property of the header. |
| ---- |
| |
| Since the "Lookup Library" allows you to uncouple senders from |
| receivers, and allows receivers to be notified of changes, I consider it |
| as a small event bus. |
| |
| I consider "local lookups" as a small event bus, where you can listen to |
| different "event topics". In the previous case, it would probably be enough to dedicate on Lookup for the network events and create various types holding enough information about the events. The you could add/remove/change the content of the lookup and deliver events about such changes. |
| |
| [source,java] |
| ---- |
| |
| The instances |
| could be looked up globally or injected into a given component. It |
| supported "business" and "GUI" subscriptions to automatically deliver |
| the event in the correct thread. If I did it again, I'm thinking I'd |
| use a JMS style API that supported a Hibernate style OQL subscription. |
| (I have some more details here: |
| http://developers.sun.com/learning/javaoneonline/j1sessn.jsp?sessn=TS-3723&yr=2007&track=2) |
| |
| The EventBus talk given at JavaOne 2006 had some great use case examples: |
| EventBus |
| https://eventbus.dev.java.net/HopOnTheEventBus-Web.ppt |
| |
| These frameworks provide some other use cases and API examples: |
| |
| D-Bus |
| http://www.freedesktop.org/wiki/Software/dbus |
| http://www.freedesktop.org/wiki/IntroductionToDBus |
| |
| JUIPiter |
| http://juipiter.sourceforge.net |
| |
| Bradlee Johnson's ReflectionBus |
| http://sourceforge.net/projects/werx/ |
| |
| Jasper-Potts - Why Spaghetti Is Not Tasty: Architecting Full-Scale |
| Swing Apps, 2007 JavaOne Conference, TS-3316 |
| http://developers.sun.com/learning/javaoneonline/j1sessn.jsp?sessn=TS-3316&yr=2007&track=2 |
| |
| (Also see the JMS API and the OMG COS Notification Service API.) |
| |
| I don't have much time to spend a lot of time coding on the side right |
| now, but I'd be happy to help define requirements and use cases if that |
| would be useful to you. |
| |
| Thanks! |
| Rob |
| ---- |
| |
| === Apache Migration Information |
| |
| The content in this page was kindly donated by Oracle Corp. to the |
| Apache Software Foundation. |
| |
| This page was exported from link:http://wiki.netbeans.org/DevFaqLookupEventBus[http://wiki.netbeans.org/DevFaqLookupEventBus] , |
| that was last modified by NetBeans user Admin |
| on 2009-11-06T15:51:59Z. |
| |
| |
| *NOTE:* This document was automatically converted to the AsciiDoc format on 2018-01-10, and needs to be reviewed. |