Add Change Notification to the Bulletin Board Application

Add Change Notification to the Bulletin Board Provider

We'll use EventWeb's Publish/Subscribe feature to publish notifications when the Bulletin Board changes.

We'll publish a simple BBChange message, indicating a post has been added or removed. When it gets the message, the client reloads the bulletin board.

Back up the Old BBProv Version

Copy BBoardProvFtry.java to BBoardProvFtryV010.java

Change the copy's class name to BBoardProvFtryV010

We'll only change the name in a couple of critical places. That way it'll be easier to compare the new version with the old one.

Add a Message BBoard Will Use for Change Notifications

We will add one outgoing BBChange message.

New Outgoing Message
Tag Value
BBChange (empty)

Add a tag for the BBChange message
In the // Tag-value Tags section:

(We don't need to change any of the SelfDescribing fields or methods. The tag and value stuff is for incoming messages and the other things haven't changed.)

Get a Reference to the Publish Provider

Create a global field to hold a reference to a PublishProvFtry.PublishProvImp

Update the init method to instantiate the pubProv field

We'll get a reference to the publish provider factory from the service registry. (We need to have a PublishProvFtry in the registry in order to use publish/subscribe. It's already set up in the demos.) If there's no PublishProvFtry in the registry we'll log a warning that change notifications won't be published.

Add a local variable to hold a reference to the PublishProvFtry:

Make sure we have a registry and it contains a PublishProvFtry:

Get the reference:

Get a PublishProvImp to use:

If we couldn't get a PublishProvFtry, log a warning:

Create a method to publish change notifications

Add a synchronized notifyChange method to the BBoardProvFtry main class;

This method will use pubProv to publish the BBChange message.

Add Change Notification to the BBoardProvImp Inner Class

Add a call to notifyChange to the end of the addPost method.

Add the same call to the end of the removePost method.

Add Change Notification to the Bulletin Board Client

All the client has to do is subscribe to BBChange messages and then request an update when it gets one. We add a couple lines to BBoard.js to do this.

Back up the Old BBoard.js Version

Copy BBoard.js to BBoardV010.js

Edit the New BBoard.js

Add a line to the Revision History of the new version:

Subscribe to BBChange messages

The updateStatus method is called with a status Id of TVB_STS_OPEN when the channel channel first opens. Add a line to the TVB_STS_OPEN clause in updateStatus:

Request an update when we get a BBChange messages

Add a BBChange clause to the getNewData method:

(We already have the code that handles the update.)

Deployment

We don't have to do anything new for deployment. Just replace the BBoardProvFtry and BBoard.js code.

xx/xx/16  swt