Polaris: use of the Active Naming and Grid API of PageBox Polaris

for
ActiveNaming Grid API Coordinator Presentation Polaris A Polaris B Download

Polaris A implementation

Overview

Polaris shows how to use the Coordinator API and the ActiveNaming Web service.

It is an example rather than a real application.

You certainly can reuse some parts of Polaris A in your applications, especially:

  • The SmartProxy that implements data-dependent and location-dependent routing and load balancing

  • The code handling transaction errors

To simplify the packaging the PolClient project includes:

  • The ShoppingBasket control that contains the core of the Polaris client

  • A minimum Login control that sets the current user in the Heap

  • A minimum Commit control

  • A page that uses the three controls above

Page including the Polaris controls

In real cases, the controls belong to different projects and can be implemented by different companies and the control assembler that uses these controls doesn’t necessarily have even access to the control sources.

Client classes

PolLogin.ascx.cs

PolLogin implements a form with a User and a Password fields. When the user clicks on the Login button the OnLogin method is called.

Parameters

Name

Function

StatusCss

CSS class of the status label

Width

Width of the PolLogin control

Css

Default CSS class of the PolLogin control

OnLogin

OnLogin stores the user name on the heap with:

PageBoxGrid.Heap.Put(ID, Session.SessionID, User.Text);

The user name is added to the Head with a Session scope and its source is the ID of the PolLogin control.

PolCommit.ascx.cs

PolCommit implements a form with a Commit button. When the user clicks on the Commit button the OnCommit method is called. When the user clicks on the Rollback button the OnRollback method is called.

Parameters

Name

Function

StatusCss

CSS class of the status label

Css

Default CSS class of the PolLogin control

OnCommit

OnCommit commits the transaction with:

PageBoxGrid.TransactionCoordinator.Commit(ID, Session.SessionID, null, ref ht);

If the Commit failed (returned false) OnCommit analyses the objects returned in ht and displays an error message.

OnRollback

OnRollback rollbacks the transaction with:

PageBoxGrid.TransactionCoordinator.Rollback(ID, Session.SessionID, null, ref ht);

If the Commit failed (returned false) OnRollback analyses the objects returned in ht and displays an error message.

ShoppingBasket.ascx.cs

ShoppingBasket.ascx allows adding and removing articles to a basket.

The user can select articles on a dropdown list and enters the number of articles.

ShoppingBasket.ascx displays the basket content on a Datagrid.

ShoppingBasket implements the Transaction interface and therefore the Prepare, Commit and Rollback methods.

Parameters

Name

Function

TitleCss

CSS class of the title ("Polaris")

StatusCss

CSS class of the status label

CopyrightCss

CSS class of the copyright label

MinWidth

Minimum width of the ShoppingBasket control (when the Datagrid contains no article)

MaxWidth

Maximum width of the ShoppingBasket control

DgHeaderCss

CSS class used to display the Datagrid header

DatagridCss

CSS class used to display the Datagrid items

DgAltCss

CSS class used to display the Datagrid alternate items

Css

Default CSS class of the ShoppingBasket control

LoginID

ID of the control that authenticates the user

SourceID

ID of the control that commits the transaction

Timeout

Time between two Prepare invocations by the TransactionCoordinator

RepositoryURL

Repository from which the Web service archive is deployed

WSArchive

Archive containing the Web service

WSName

Web service name

Location

Logical location of the client

Page_Load

Page_Load is called when the control is loaded.

Page_Load

  1. Sets the CSS class of the form according to the page setting

  2. Populates the DropDown list and the Datagrid

  3. Subscribes to transactions

OnArticleChanged

OnArticleChanged is called when the user selects another article on the DropDown list.

OnArticleChanged sets the unit price according to the selected article.

OnAdd

OnAdd is called when the user clicks on the Add button.

OnAdd

  1. Retrieve the current basket from the Heap. The basket is implemented using a Hashtable whose key is the article name and the value is a CmdRow object. The CmdRow class contains the article name, its unit price and the number of units

  2. Increases the number of units if the article was already in the basket

  3. Otherwise creates a new CmdRow

  4. Save the updated basket into the heap

  5. Binds the Datagrid to the basket

OnDelete

OnDelete is called when the user clicks on the Delete button of the Datagrid.

OnDelete

  1. Retrieves the current basket from the Heap

  2. Remove the selected CmdRow from the basket

  3. Save the updated basket into the heap

  4. Binds the Datagrid to the basket

Prepare

Prepare is called when the transaction source calls Commit.

Prepare

  1. Retrieves the current basket from the Heap

  2. Retrieves the current user from the Heap

  3. Creates a SmartProxy object and calls its GetUrl method to get the URL of an instance of the Polaris Web service

  4. Instantiate a Web service proxy and stores it in the Heap

  5. Returns false if (1) it found no suitable instance of the Polaris Web service or if (2) the Discover of the Web service instance took an exception or if (3) the CheckAccount method of the Web service instance returned false. Then it cleans up the basket.

Commit

Commit is called when the transaction source calls Commit.

Commit

  1. Retrieves the current basket from the Heap

  2. Retrieves the Web service proxy from the Heap

  3. Retrieves the current user from the Heap

  4. Calls the Order method of the Polaris Web service

  5. Returns false if the Order invocation failed

  6. Cleans up the basket

Rollback

Rollback is called when the transaction source calls Rollback.

Rollback cleans up the basket.

SmartProxy.cs

SmartProxy manages an ActiveNaming cache, wsHt.

wsHt is a Hashtable whose key is a WsKey object and value is a ArrayList.

The WsKey class manages a key that uniquely identifies a Web service and is made of:

  • A Repository URL

  • An Archive name

  • A Web service name

A wsHt entry describes the response to an ActiveNaming.GetCandidate request.

Therefore the ArrayList is a list of the Candidates found by ActiveNaming.GetCandidate.

A Candidate is represented by a PolarisKey object. The PolarisKey class allows comparing a request with a PolarisKey object using:

  • A userLow field (lowest user number managed by this instance) used for data-dependent routing

  • A userHigh field (highest user number managed by this instance) used for data-dependent routing

  • A location field (logical location of the Web service instance) used for location-dependent routing

A Web service instance manages a set of accounts. The account sets are replicated, which means that more than one Web service instance can manage an account. To choose an instance the SmartProxy

  1. Selects the Candidates at the same location as the Polaris client

  2. Selects randomly a Candidate and thus implements load balancing

Constructor

The SmartProxy constructor

  1. Checks if the WsKey(Repository URL, archive name, Web service name) is already in the wsHt cache.

  2. If it is not calls GetCandidate and adds an entry to the wsHt cache

  3. Sets the csl ArrayList with the (Repository URL, archive name, Web service name) entry in wsHt

GetUrl

GetUrl enumerates the csl ArrayList and selects entries that satisfy to two conditions

The user number falls in their range number

Their location is the same as the Polaris client

Then GetUrl uses Random to choose one of the selected entries.

GetCandidate

GetCandidate is called by the SmartProxy constructor.

GetCandidate calls the ActiveNaming.GetCandidate method of its controlling PageBox.

Server classes

RangeLoc.aspx.cs

RangeLoc.aspx is a page allowing to set the keyRange of a Web service instance.

Page allowing to set the Web service key range here made of the user lowest and highest number and of the instance location

Page_Load

Page_Load is called when RangeLoc.aspx is loaded.

Page_Load

  1. Calls GetProxy to get an ActiveNaming proxy

  2. Calls ActiveNaming.GetKeyRange to get the current key range of this server instance. The key range is represented by a string. Page_Load deserializes this key in the deserializePKR method using a SoapFormatter

  3. Sets the user lowest and highest number and the location fields on the form

OnSet

OnSet is called when the user clicks on the Set button.

OnSet

  1. Creates a PolarisKR key range using the form fields

  2. Serializes this key range in the serializePKR method using a SoapFormatter

  3. Calls ActiveNaming.SetKeyRange to set the key range of this server instance

GetProxy

GetProxy is called by Page_Load and by OnSet.

GetProxy creates and checks an ActiveNaming proxy.

ShoppingOrder.asmx.cs

ShoppingOrder.asmx simulates database updates. It implements two methods, CheckAccount and Order.

CheckAccount

CheckAccount is called by the Prepare method of the ShoppingBasket.ascx control to check if everything is ready before updating the database. Here it returns false when the account name starts with "mal" and true otherwise.

Order

Order returns true.

Contact:support@pagebox.net
2001-2004 Alexis Grandemange. Last modified .