How to install and run SwapBox

  • For Windows users, download SwapBox , unzip it. A directory named sbox is created.
  • Run the batch file named swaprun.bat at sbox\swapbox\

Introduction to SwapBox

SwapBox is an extension to Sun’s BeanBox , which is a test container for JavaBeans. SwapBox follows the event communication mechanism used in the BeanBox. Therefore, applications created within SwapBox are event-driven. No direct method invocation among beans is allowed. Event adapters are the only mechanism to interact among beans. The swappable JavaBeans must firstly be wired up in the SwapBox such that they could be swapped out at runtime. The approach to wire up two beans in the SwapBox is the same to that in the BeanBox. More details on this could be found at Sun’s website.

Configure Hot Swapping Policy

Before swapping out a running bean, a swap administrator has to first come up with a swapping policy file. The file is in XML format, and is constructed visually. The swapping policy includes how to handle interactions in case of partner-aware and partner-unaware swapping, how to map states from the old bean to the new bean, the time constraint for the swapping, and so on. An example hot swapping policy is listed as follows.

sbox codes

From the example, we can see there are five states in the old bean mapped to the new bean. In this example, the old state names are identical to the new state names. However, they are not necessarily identical. One method named start at the old bean is no longer existed at the new bean. Its role is replaced by a new method named newStart. This demonstrate SwapBox is able to handle interface change between different versions.

A swap administrator configure a hot swapping policy by selecting the old bean, then push the submenu named config swap at swap menu. A red bubber hand is then showing up to lead to the target bean. Figure 1 shows this process. There are four panels showing up one by one. The panels provide options to configure the hot swapping policy. What the swap administrator does is to select from these options and save it as an XML file. The XML format file is needed to hot swap an old bean.

Configure Hot Swapping Policy 2.2 Hot Swap a Bean

Configure Hot Swapping Policy 2.2 Hot Swap a Bean

In order to hot swap a bean, the swap administrator has to select the old bean, click the swap submenu at the swap menu. A red bubber hand similiar to configuring hot swapping policy is then showing up to lead to the target bean. After selecting the target bean, the swap administrator selects the hot swapping policy file. Then hot swapping begins. The swap administrator can not interfere the swapping when it is in progress. If the swapping suceeds, the old bean is deleted from SwaBox, and the new bean gets running. If the swapping fails, the old bean keeps running. Figrue 2 shows the red bubber hand to select the target bean. Figure 3 gives what it looks like after a successful hot swapping.

Select the New Bean (The bean with the colourful bars)

Select the New Bean (The bean with the colourful bars)

The Appearence after a Successful Hot Swapping

The Appearence after a Successful Hot Swapping

Applications

Currently we have two applications, one is a  GameBaordBean , the other is  SortingBean . A GameBoardBean application consists of a visual frame bean named GameBoardBean and two button beans, one labeled “Start”, the other “Stop”. The GameBoardBean is able to display serials of changing graphics. Two event interactions are established among the three beans. The start button fires out an ActionEvent to a start method at the GameBoardBean. The stop button fires out another ActionEvent to a stop method at the GameBoardBean. Pressing the start button, the graphic starts changing routinely. Pressing the stop button, changing stops. The NewGameBoardBean has slight difference with the GameBoardBean with respect to dispalying the colorful bars and some interface change. The basic steps to swap out GameBoardBean with NewGameBoardBean are shown in Figure 1 to 3. With the hot swapping policy listed above, the GameBoardBean could be swapped out with the NewGameBoardBean.

SortingBean is another application. It consists of a sorting bean and a GUI bean. The GUI bean generates random data set for sorting, and sends request event to the sorting bean. The sorting bean sends back a SortingDone event to the GUI bean, where the sorted and how much time is used for the sorting are displayed. The old sorting bean implements bubble sort algorithm, whilst the new one implements quick sort algorithm. We could swap out the bubble sorting bean (when it is busy at sorting ) with quick sorting bean. The sorting job is then finished at the quick sorting bean.

Publication

A position paper, The SwapBox: A Test Container and a Framework for Hot Swappable JavaBeans, resulted from SwapBox work is accepted at the 6th International Workshop on Component-based Software