JeeWiz Home

 
  
 
Contents  >   3.  Tutorial
 


3.3 Modelling a System

 3.3.1  Modelling Properties
 3.3.2  Amending The Application
 3.3.3  Adding A Processing Unit
 3.3.4  Adding the Vehicle Bean to the CongestionZoneProcessor
 3.3.5  Adding the Payment Bean to the CongestionZoneProcessor
 3.3.6  Adding the Congestion Charge Bean to the CongestionZoneProcessor
 3.3.7  Adding the Fine Bean to the CongestionZoneProcessor
 3.3.8  Siblings or Children
 3.3.9  Adding a Space to the Processing Unit
 3.3.10  Adding a Subscriber
 3.3.11  Adding a Action
 3.3.12  Adding a Receiver
 3.3.13  Adding the Lifecycle-Events
 3.3.14  Another Processing Unit
 3.3.15  Adding a Service

3.3.1  Modelling Properties
In this section, we model the system by fleshing out the .osm file.

To start adding to the model, double-click on the .osm file in the Package Explorer window. This will open the file and show this:

Note that the CongestionChargeModel.osm window is selected.

To ensure the Properties View is visible, right-click on and select 'Show Properties View'

The properties view is context sensitive and allows you to set the values of appropriate properties.


3.3.2  Amending The Application
Expand the model and you will see

Select the Application row. In the properties view you will see

In the properties view, amend the name of the application to 'CongestionChargeApp'. On pressing 'Enter' the model will change to

By the way, if you prefer to navigate by typing rather than using the mouse, once you have selected an element on the model, you can navigate up/down and open/close up the model using the up/down/left/right keys.
You can also use the Delete key to delete objects, and use Ctrl-Z and Ctrl-Y for Edit-Undo and Edit-Redo.

3.3.3  Adding A Processing Unit
Now we are going to add some sub-elements to the Application. The sub-elements of Application are

  • Deployment Option
  • Jar
  • Processing Unit (PU)

Let's add a ProcessingUnit which will hold some Java beans. A PU can declare Java beans, but any beans will be added into a common jar called by default CongestionChargeApp_GSBFramework and will be available for use by all processing units.

Right click on the Application row and select

New Child -> Processing Unit

A new ProcessingUnit 'jar1' is added to the model

In the properties view change the name of the Jar to 'CongestionZoneProcessor' and set the package to 'com.cc.zone'.

Did you notice in the list of properties the property 'Can Be Partitioned'. In GigaSystemBuilder this property is set 'false' by default. To make a Processing Unit capable of being partitioned this must be set to 'true'. The idea is that by manually switching the value to 'true' the modeller or developer will have spent at least a few moments thinking about the implications of the Processing Unit being partitioned. In this example we definitely want the 'CongestionZoneProcessor' to be partitioned, so alter the value to 'true'.


3.3.4  Adding the Vehicle Bean to the CongestionZoneProcessor
Now for the Vehicle bean.

To add a Java Bean, right click on the ProcesssingUnit row and select

New Child -> Java Bean

A Java Bean is added to the model

In the properties view change the name of the Java Bean to a 'Vehicle'.

Now we'll add 4 fields to the bean - they are 'children' of the bean. To do this, right-click on the Bean row and select

New Child -> Field

In the properties view set the names and types of the fields as follows

Field Type
make String.  ('String' is the default so you don't have to enter it.)
model String
licencePlate String. Also set the Routing property to true.
yearBuilt int

You can duplicate an item by holding down the control, selecting it with the mouse and moving and dropping it (while the '+' sign is showing) to another valid point in the diagram.

The model should now be:


3.3.5  Adding the Payment Bean to the CongestionZoneProcessor
Now add another bean to the Processing Unit and name it 'Payment'. Add three fields

Field Type
recNo String
carRecord String
price int


3.3.6  Adding the Congestion Charge Bean to the CongestionZoneProcessor
Now add a third bean to the Processing Unit and name it 'CongestionCharge'. Make it extend the Payment bean. This is done by using the dropdown on the 'Extends Object' property:

Add one field

Field Type
dateValid Date


3.3.7  Adding the Fine Bean to the CongestionZoneProcessor
Now add a fourth bean to the Processing Unit and name it 'Fine'. Make it also extend the Payment bean.

Add one field:

Field Type
paid boolean


3.3.8  Siblings or Children
Note: Notice that as well as the option to add a 'New Child' you could also add a 'New Sibling'.


3.3.9  Adding a Space to the Processing Unit
The Processing Unit 'CongestionZoneProcessor' is going to contain a space into which the CongestionCharge and Vehicles are fed. So, create a space below the Processing Unit and call it 'CongestionZone'


3.3.10  Adding a Subscriber
We want to capture the fact that a Vehicle enters the CongestionZone. To do that we require an event handler. There are three we can choose from - Browser, Receiver, and Subscriber. The most suitable for our example is Subscriber. An event handler requires three pieces of information the name of the event (Name) the space on which the event should listen (Space) and the object they are listening for (Template Bean).

In the generated code the event will become a method which is called when the event is triggered. The developer needs to add business logic into this method. This will be explained further on in the tutorial.

Create an Receiver under the CongestionZoneProcessor and call it 'vehicleDrivesIntoZone'. Set the 'Space' to be CongestionZone Space (the only one available) and set the Template Bean to be the Java Bean Vehicle. It is important to note by setting the Template Bean you are merely telling the listener what type of object to listen for. The particular instance of the Template Bean can be set after the application has been built. The default instance used is the wildcard instance - i.e any default values are set to null.


3.3.11  Adding a Action
The receiver modelled in the previous section will generate a method into which the developer could add the business logic to process a vehicle driven into the Congestion Zone. However in order to include an 'Action' in the tutorial what we will do is create an action to process the vehicle. The business logic of the receiver will simply call the method generated from this action. Create an Action under the CongestionZoneProcessor and call it 'processVehicle'. It should have an Input Object of Vehicle and a Result Object of Fine.


3.3.12  Adding a Receiver
We need to add another event handler to handle the payment of the CongestionCharge. In this case however the Receiver is most suitable event handler (this is because it performs a 'take' rather than a 'read'). Create a Receiver setting the name as 'handleChargePayment', the Template Bean as 'CongestionCharge' and the Space as 'CongestionZone'. As we can use the 'handleChargePayment' to process the payments we won't add another action here.


3.3.13  Adding the Lifecycle-Events
Lifecycle events are used to adjust the objects . We need two lifecycle-events. The first will be used to filter out any vehicles made before the year 1972 before it enters the space. The second will be used to log the vehicles that once they enter the space. To do this select the 'CongestionZone' space and add a lifecycle-event sub-element. Name it 'removeOldCars'. Set the JavaBean to be 'Vehicle' and the operations to be 'before-write'

In a similar way create the second lifecycle-event. Set its name to be 'logVehicle'. Again set the JavaBean to be 'Vehicle' but this time set the operation to be 'after-write':


3.3.14  Another Processing Unit
Add another Processing Unit and call it 'RoadUsers'. Give it a package of 'com.cc.road'. This is going to simply feed the CongestionCharge and Vehicles in to the CongestionZone.

The next couple of steps will result in a helper class with a couple of methods on it which will make the implementation easier. Add an action to 'RoadUsers' and call it 'payCongestionCharge'. Make its inputObject be 'CongestionCharge'. Leave the resultObject blank.

Add a second action and call it 'driveVehicleIntoZone'. Make its inputObject be Vehicle. Again leave the resultObject blank.

Now we need to create some vehicles and drive them into the congestion zone. To do this we will use a pulse, which will allow us to create vehicles (at a frequency of our choice). A pulse is a child of a processing unit. Create a 'Pulse' on the RoadUsers Processing Unit. Call it 'createVehicle' and set the period '1000'.


3.3.15  Adding a Service
Add another Processing Unit and call it 'DVLA'. Give it a package of 'com.cc.dvla'. Create a space called 'dvlaSpace'.

In Britain the DVLA is the Driving and Vehicle Licensing Authority. This Processing Unit is going to contain a service which will check the licencePlate on a vechicle. The service will be passed a String and will return either true or false depending on whether the licencePlate is valid. Create a service called 'LicenceService' and a BusinessMethod on the service called 'isLicenceValid'. Create a 'Business Method Parameter' on the isLicenceValid. Call it 'licence' and leave its type as the default of 'string'. On 'isLicenceValid' set the 'Return Type' to be 'Boolean'.

All that is left now is to build it - this will be covered in the next section.


Copyright (c) 2001-2009 New Technology/enterprise Ltd.