1 / 8

Example 2: The Publisher-Subscriber Protocol

Example 2: The Publisher-Subscriber Protocol. Have two collaborating participants. Publisher. collaboration PublisherSubscriberProtocol { participant Publisher { import void changeOp(Object[] args); protected Vector subscribers = new Vector(); export void attach(Subscriber subsc) {

gefen
Download Presentation

Example 2: The Publisher-Subscriber Protocol

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Example 2: The Publisher-Subscriber Protocol • Have two collaborating participants

  2. Publisher collaboration PublisherSubscriberProtocol { participant Publisher { import void changeOp(Object[] args); protected Vector subscribers = new Vector(); export void attach(Subscriber subsc) { subscribers.addElement(subsc);} export void detach(Subscriber subsc) { subscribers.removeElement(subsc);} import-export void changeOp() { import(); for (int i = 0; i < subscribers.size(); i++) {((Subscriber)subscribers.elementAt(i)). newUpdate(this);}}

  3. Subscriber participant Subscriber { import void subUpdate(Publisher publ); protected Publisher publ; export void newUpdate(Publisher aPubl) { publ = aPubl; subUpdate(publ);} } } }

  4. Classes for deployment Class Point { void set(…) } class InterestedInPointChange { void public notifyChange() { System.out.println("CHANGE ..."); } }

  5. Deployment 1 adapter PubSubConn1 { Publisher is played by Point { changeOp is played by set*;} Subscriber is played by InterestedInPointChange { void subUpdate(Publisher publ) { notifyChange(); System.out.println(”on Point object " + ((Point) publ).toString()); } } }

  6. Red: expected replaced Blue: from adapter Deployment 1 Point Publisher changeOp calls newUpdate attach(Subscriber) detach(Subscriber) set InterestedInPointChange Subscriber subUpdate(Publisher) newUpdate(Publisher) subUpdate(Publisher) notifyChange()

  7. Deployment 2 adapter PubSubConn2 { Publisher is played by TicTacToe { changeOp is played by {startGame, newPlayer, putMark, endGame}}; Subscriber is played by {BoardDisplay, StatusDisplay}{ void subUpdate(Publisher publ) { setGame((Game) publ); repaint(); } }; }

More Related