| |
"Performance Management Starts with IDL Design"
Vol. 6, Issue 1, p. 94
Listing 1: Product Catalog Proxy Implementation
public class ProductServiceProxy {
private static ProductServiceProxy instance;
private ProductServiceProxy () {}
public static ProductServiceClient getInstance() {
if(instance==null) instance= new ProductServiceProxy ();
return instance;
}
public ArrayList getProducts(String group, String category, String status)
throws SomeException{
ArrayList productList = new ArrayList ();
try {
ProductService productService = locateRemotetService();
if ( productService == null ) {
// return empty list or throw user defined exception
}
// get product list
try{
// get products using criteria
// when request returns data, prepare data and store results in collection object
} catch(SystemException se){ // handle exception}
} catch ( Exception e) { //handle exception }
return productList;
}
...
}
Listing 2: Base Iterators in IDL
#include "util/exceptions/idlexceptions.idl"
module iterator
{
interface BaseIterator {
boolean hasNext() raises (SomeRemoteException);
short count() raises (SomeRemoteException);
};
interface BaseListIterator {
boolean hasPrevious() raises (SomeRemoteException);
short previousIndex() raises (SomeRemoteException);
boolean hasNext() raises (SomeRemoteException);
short nextIndex()raises (SomeRemoteException);
short count() raises (SomeRemoteException);
};
};
Listing 3: IDL Design of Service-Specific Iterator
#include "util/iterator/iterator.idl"
module productcatalog
{
struct ProductItem{
string productName;
...
};
typedefsequence<ProductItem> ProductItemList;
interface ProductIterator : iterator::BaseListIterator {
ProductItem next() raises (SomeRemoteException);
ProductItemList nextBlock (in short size) raises (SomeRemoteException);
ProductItem previous () raises (SomeRemoteException);
ProductItemList previousBlock (in short size) raises (SomeRemoteException);
};
interface ProductCatalog {
ProductIterator getProductItems(in string group, in string category, in string status)
raises (SomeRemoteException);
};
}
Listing 4: Changes to ProductServiceProxy implementation
public class ProductServiceProxy {
private int nItems=15;
private ProductIterator remoteIterator;
private static ProductServiceProxy instance;
private ProductServiceProxy () {}
public static ProductServiceClient getInstance() {
if(instance==null) instance= new ProductServiceProxy ();
return instance;
}
public ArrayList getProducts(String group, String category, String status)
throws SomeException{
ArrayList productList = new ArrayList ();
try {
ProductService productService = locateRemoteProductService();
if ( productService == null ) {
// return empty list or throw user defined exception
}
// get product list
try{
remoteIterator=productService.getProducts(...);
} catch(SystemException se){ // handle exception}
} catch ( Exception e) { //handle exception }
return this.getMoreProducts(nItems);
}
public ArrayList getMoreProducts(int nItems) throws SomeException{
// retrieve the next 10-15 items using cache iterator
}
...
}
|
|