Application Partitioning
A simple but dramatic example of the benefits of application partitioning is to run two identical queries on a collection. One query runs on the server and returns only the result of the query; the second query runs on the client, requiring the collection to be copied to the client.[84]
It’s pretty obvious that since the only difference between the two queries is the amount of data being copied across the network, the second query that copies much more data is slower. For the example, I use a large array of strings and create a query that returns that subset of strings that includes the query string, e.g., “el” is included in “hello” but not in “hi.”
The query method is straightforward:
public static String[] getQuery(String obj, String[] array)
{
Vector v = new Vector( );
for (int i = 0; i < array.length; i++)
if (array[i].indexOf(obj) != -1)
v.addElement(array[i]);
String[] result = new String[v.size( )];
for (int i = 0; i < result.length; i++)
result[i] = (String) v.elementAt(i);
return result;
}To run the query as a server method, I declare one server method in a
server object (i.e., in the ServerObject
interface):
public String[] getServerQuery(String obj);
This is also straightforward. The client calls
getServerQuery( ) on the server proxy object and
receives the results. To run the query on the client, I declare a
method (again in the ServerObject interface)
giving access to the String array containing the
strings to be compared:
public String[] getQueryArray( ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access