Add Persistance to Bulletin Board Posts

Add Post Persistence to the Bulletin Board Provider

The current version of Bulletin Board looses all posts when the server (or webapp) shuts down. In this section we'll add code to save the posts and restore them when the server restarts.

There are a number of ways we could do this.
The most foolproof method would probably be to use JDBC and keep posts in a database.
Less elaborate schemes would keep the posts in a disk file:
We could open a file, make the change and close the file each time a post was added or removed. That would be fairly reliable, but would involve a lot of overhead.
We're going to assume bulletin board posts aren't mission critical, and just save the posts when the server shuts down. Besides being simple, this approach allows us to demonstrate the SrvcProvFtry quiesce method.

Source Backup

The current (V0.2.0) version of BBoardProvFtry isn't very different from V0.1.0, so we won't make a permanent backup.

Add Global Fields

Define a default path for the saved posts file
Add a private constants section after the public constants:

Create a global field to hold a file object

Create methods to save and restore the bulletin board.

Create private methods in the BBoardProvFtry main class:

The methods don't need to be synchronized because they're only called at startup and shutdown.

Update the init method to load saved posts

Add local variables

Get the path to the saved posts file

Check the params list for a file parameter by iterating through it looking for a file tag.

(We usually make parameter tags case-insensitive.)

Initialize the postFile field. We use a global variable because we'll use it again at shutdown.

Restore the bulletin board from the saved posts file

First see if the file exists.
If it does we call restorePosts to restore the bulletin board.
If it doesn't we log a warning and continue:

Implement the savePosts method

We'll leverage the BBoardProvImp.getPostsMsg method to save and restore the bulletin board. The TvList class has readFrom and writeTo methods to read and write the list to disk files. For savePosts, we'll copy the bulk of the getPostsMsg method to the main class and create a method used by both getPostsMsg and savePosts.

Create a getPostList method in the main class

Fill in the savePosts method

Update the BBoardProvImp.getPostsMsg method

The new getPostsMsg method is short, so we just replace the old content.

Implement the restorePosts method

(Details omitted. It's just plain java.)

Update the quiesce method

Replace the No action needed comment with a call to savePosts:

The Bulletin Board Client

We don't have to make any changes to the client.

Deployment

For the native server version of EventWeb, we don't have to do anything.
If the BBPosts.txt file doesn't exist when the server shuts down, BBoardProvFtry will create it and save the posts in it. If it does exist, the old version will be overwritten.

For the servlet version, we want to keep configuration files in the root folder of the webapp. To do that, we use the File parameter to set the path to BBPosts.txt

Add the File parameter to the BBoardProvFtry line in RqstRouterServlet.ini:

xx/xx/16  swt