PageBox |
|
ActiveNaming | Grid API | Coordinator | Presentation | Polaris A | Polaris B | Download |
Polaris A implementation
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
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.
PolLogin implements a form with a User and a Password fields. When the user clicks on the Login button the OnLogin method is called.
Name | Function |
---|---|
StatusCss | CSS class of the status label |
Width | Width of the PolLogin control |
Css | Default CSS class of the PolLogin control |
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 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.
Name | Function |
---|---|
StatusCss | CSS class of the status label |
Css | Default CSS class of the PolLogin control |
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 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 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.
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 is called when the control is loaded.
Page_Load
Sets the CSS class of the form according to the page setting
Populates the DropDown list and the Datagrid
Subscribes to transactions
OnArticleChanged is called when the user selects another article on the DropDown list.
OnArticleChanged sets the unit price according to the selected article.
OnAdd is called when the user clicks on the Add button.
OnAdd
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
Increases the number of units if the article was already in the basket
Otherwise creates a new CmdRow
Save the updated basket into the heap
Binds the Datagrid to the basket
OnDelete is called when the user clicks on the Delete button of the Datagrid.
OnDelete
Retrieves the current basket from the Heap
Remove the selected CmdRow from the basket
Save the updated basket into the heap
Binds the Datagrid to the basket
Prepare is called when the transaction source calls Commit.
Prepare
Retrieves the current basket from the Heap
Retrieves the current user from the Heap
Creates a SmartProxy object and calls its GetUrl method to get the URL of an instance of the Polaris Web service
Instantiate a Web service proxy and stores it in the Heap
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 is called when the transaction source calls Commit.
Commit
Retrieves the current basket from the Heap
Retrieves the Web service proxy from the Heap
Retrieves the current user from the Heap
Calls the Order method of the Polaris Web service
Returns false if the Order invocation failed
Cleans up the basket
Rollback is called when the transaction source calls Rollback.
Rollback cleans up the basket.
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
Selects the Candidates at the same location as the Polaris client
Selects randomly a Candidate and thus implements load balancing
The SmartProxy constructor
Checks if the WsKey(Repository URL, archive name, Web service name) is already in the wsHt cache.
If it is not calls GetCandidate and adds an entry to the wsHt cache
Sets the csl ArrayList with the (Repository URL, archive name, Web service name) entry in wsHt
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 is called by the SmartProxy constructor.
GetCandidate calls the ActiveNaming.GetCandidate method of its controlling PageBox.
RangeLoc.aspx is a page allowing to set the keyRange of a Web service instance.
Page_Load is called when RangeLoc.aspx is loaded.
Page_Load
Calls GetProxy to get an ActiveNaming proxy
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
Sets the user lowest and highest number and the location fields on the form
OnSet is called when the user clicks on the Set button.
OnSet
Creates a PolarisKR key range using the form fields
Serializes this key range in the serializePKR method using a SoapFormatter
Calls ActiveNaming.SetKeyRange to set the key range of this server instance
GetProxy is called by Page_Load and by OnSet.
GetProxy creates and checks an ActiveNaming proxy.
ShoppingOrder.asmx simulates database updates. It implements two methods, CheckAccount and Order.
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 returns true.
Contact:support@pagebox.net
©2001-2004 Alexis Grandemange.
Last modified
.