词条 | Whiteboard Pattern |
释义 |
OSGi service model is a collaboration model which supports service registry. The service registry allows applications or bundles to register services, which are simple Java interfaces to implement different functionalities. The dynamic nature of the service registry is useful to track the services that can show up or leave at any time. Whiteboard Pattern is created to support such OSGi service model, which was not supported by Listener Pattern.[1][2] IntroductionThe Listener Pattern[1]The Listener Pattern is typically known as Observer Pattern. It is a Behavioral Pattern (aka Publish-Subscribe), which deals with dynamic changes in the state of different objects. Listener Pattern follows a structure where an event listener is registered to event source. Now whenever an event source changes its state, all its event listeners get notified about the change through event object. In this pattern, everything is controlled by event source. Implementation of Listener pattern is very complicated. Listener pattern supports many event listeners, so all listeners are registered to an event source. No event listener has access control over an event source, so for every service a new file is to be created. This creates an overhead of class file and, affects the program running time and memory usage. Also, when an event listener is exiting, its registration is to be cancelled from the event source. Vice versa, when an event source is exiting, it makes sure that all its event listeners Whiteboard PatternWhiteboard Pattern can be suggested by a role, where an event listener is looking for a special service. Another role could be when an event listener is looking for a looked service. Whiteboard Pattern follows a structure where an event listener is registered to event source. This [https://osgi.org/javadoc/r4v41/org/osgi/framework/ServiceRegistration.html service registration] is maintained by service registry, which is application programming interface for managing services. Bundle implements this interface and registers the service in service registry. Bundles are typically a group of Java classes, furnished with well-written manifest file, which help to bind with many other services. Now, an event listener can find the service in the service registry, or react to it when the service is executed. In this pattern, control is given to an event listener. Implementation of Whiteboard Pattern is complex, because it has to handle all the services dynamically. To handle this dynamic nature Whiteboard Pattern is implemented using application bundles and server bundles. As the framework registry can be reused dynamically, the implementation becomes easier. Both application bundles and server bundles are responsible for managing the services and their inter-dependencies to the framework.[1][3] Advantages and Disadvantages: Over Listener PatternAdvantages[1][4]
Disadvantages[1][4]
Usage and ExampleTypically OSGi model for Whiteboard Pattern handles inter-dependencies with many bundles.[5] Some usages are stated using following examples: I) A TV Show is to be projected on LCD. Suppose a service named ‘Display’ service will project the contents that cycles over many bundles, which contains different contents. Suppose this content is provided by some ‘Providers’. An interface can be implemented by any bundles whose contents want to be displayed, where ‘Providers’ are catechized for getting the content. A ‘DisplayInstructor’ is responsible to cycle through all the screens in the service registry and display the final content at that particular point of time, which is managed by ‘TimeManager’ which implements ‘Providers’.[1] This shows that the dependency between ‘DisplayInstructor’ and ‘TimeManager’ is handled. And both of them can work simultaneously or in any order at any time. II) A group of friends uses a web based UI portal to store an article. Friends are working on article's sections. A section contains the contents which is added by some members of the group. Using whiteboard pattern, the dependencies for adding the content and displaying it on the web portal is handled. And both of these tasks can be done simultaneously or in any order at any moment. An Example for Whiteboard Pattern HandlerConclusion[1]The Whiteboard pattern implementation is smaller and simpler, and thus less prone to programming errors. As per the code size, it is significant that listener pattern can have more deadlock possibilities than the whiteboard pattern. The OSGi environment doesn’t entirely follow basic programming rules with Java, rather it shows some features of its own over Java. The Listener Pattern puts such programming rules over OSGi environment, which can be considered first drawback. Apart from that, Listener Pattern doesn’t suit for dynamic changes, which are expected in the OSGi environment. The Listener pattern, a programmer of the event listener is full in-charge of the program. He decides event sources that are registered to the listener, and all the dependencies between them. A Bundle is not an application running autonomously from other applications. It is a component running to bind with the other bundles in the environment. Bundles have to be configured and managed properly. Bundles should be written in such format that they do not show direct control, rather provide a service that can be connected and configured with other bundles. The Whiteboard pattern supports such functionality of bundles and show significant improvement over listener pattern. These reasons are intimidating factors to apply whiteboard pattern, where managing the inter-bundle dependencies is required. References1. ^1 2 3 4 5 6 7 {{Cite web|url=https://www.osgi.org/wp-content/uploads/whiteboard1.pdf|title=Listeners Considered Harmful: The "Whiteboard" Pattern (Technical Whitepaper)|last=|first=|date=|website=|publisher=|access-date=}} 2. ^{{Cite web|url=https://www.osgi.org/developer/architecture/|title=OSGi Architecture|last=|first=|date=|website=|publisher=|access-date=}} 3. ^{{Cite web|url=http://spring.io/blog/2008/02/18/creating-osgi-bundles/|title=Certified Bundles|last=|first=|date=|website=|publisher=|access-date=}} 4. ^1 {{Cite web|url=http://mitk.org/images/b/b1/BugSquashingSeminars$Design_Pattern_Observer_Whiteboard.pdf|title=Observer & Whiteboard Pattern|last=|first=|date=|website=|publisher=|access-date=}} 5. ^{{Cite web|url=https://www.osgi.org/developer/specifications/|title=OSGi Specifications|last=|first=|date=|website=|publisher=|access-date=}} External links
1 : Software design patterns |
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。