Requesting a message back from the server
Simulating server push
A client application cannot pass a PowerBuilder
object reference to EAServer. Therefore,
you cannot use a PowerBuilder object reference to push messages from
the server back to a PowerBuilder client. However, you can simulate
this behavior by using a shared object on the client to communicate
with EAServer. This technique
can be thought of as client pull, because the shared object on the client
pulls data back from the server.
How it works
To simulate server push, the client uses the SharedObjectRegister and SharedObjectGet functions
to create a shared object. Once the object has been created, the
main thread on the client makes an asynchronous call to a method on
the shared object, passing it a callback object that should be notified
when processing has finished on the server. The method on the shared
object makes a synchronous call to the EAServer component
method that performs processing. Since the shared object is running
in a separate thread on the client, the main thread on the client
can proceed with other work while the process is running on the
server.
Asynchronous processing in EAServer In this example, POST is used to make an
asynchronous call to a method on a shared object on the client.
Using POST is not supported
in the context of calls to EAServer components.
For information about asynchronous processing in EAServer, see the EAServer documentation for the ThreadManager
and MessageService modules.
For more information about the Thread Manager in EAServer
6.x, see the Automated Configuration Guide
. For information about
using the message service, see the Java Message Service User’s Guide
.
Example
This example shows how you might use a shared object to make
an asynchronous request against an EAServer component
method and return data to a client application window.
Client application window
The client application has a window called w_employee that
displays employee data in a DataWindow control. When the user clicks
the Retrieve button in the window, the client creates a shared object
that communicates with EAServer. In
addition, it creates an instance of a user object that is used to
handle callbacks from the shared object.
Instance variables
The w_employee window has these
instance variables defined:
|
1 |
uo_sharedobject iuo_sharedobject |
|
1 |
uo_callback iuo_callback |
Retrieve button
The Retrieve button creates the shared object that will communicate
with EAServer. In addition, it
creates an instance of the user object that will be used to handle
callbacks from the shared object. To allow the callback object to notify
the window of the completion of processing, the script calls a function called PassObject on
the callback object, passing it a reference to the window. Finally,
it makes an asynchronous call to the RetrieveData function
on the shared object, passing it a reference to the callback object.
The Retrieve button has the following script:
|
1 |
long ll_rv<br /> <br />SharedObjectRegister("uo_sharedobject","myshare")<br />SharedObjectGet("myshare",iuo_sharedobject)<br /> <br />iuo_callback = CREATE uo_callback<br />iuo_callback.passobject (parent)<br /> <br />iuo_sharedobject.post retrievedata(iuo_callback) |
SetDW function
The SetDW function applies the contents
of the DataWindow Blob returned from the EAServer component to a DataWindow
control in the window. The SetDW function takes
the argument ablb_data, which is of
type Blob, and returns a Long value.
The function has the following script:
|
1 |
long ll_rv<br /> <br />ll_rv = dw_employee.SetFullState(ablb_data)<br />if ll_rv = -1 then<br /> MessageBox("Error", "SetFullState call failed!")<br />end if<br /> <br />return ll_rv |
EAServer component
The EAServer component is
a PowerBuilder user object called uo_employee. The uo_employee object
has a function called RetrieveData that uses
a DataStore to retrieve employee rows from the database.
Instance variables
The uo_employee object has these
instance variables defined:
|
1 |
protected TransactionServer txnsrv<br />protected DataStore ids_datastore |
RetrieveData function
The RetrieveData function takes the argument ablb_data,
which is of type Blob, and returns a Long value.
The function has the following script:
|
1 |
long ll_rv<br />ll_rv = ids_datastore.Retrieve()<br />ll_rv = ids_datastore.GetFullState(ablb_data)<br />txnsrv.SetComplete()<br />return ll_rv |
Shared object definition
The client application uses a shared object called uo_sharedobject to communicate
with the EAServer component. The
shared object has a single function called RetrieveData.
Instance variables
The uo_sharedobject object has
these instance variables defined:
|
1 |
uo_employee iuo_employee<br />n_jagclnt_connect myconnect |
Constructor event
The Constructor event uses a custom Connection object called n_jagclnt_connect
to connect to the server. Then it creates an instance of the EAServer component:
|
1 |
long ll_rc, ll_rv<br />myconnect = create n_jagclnt_connect<br />ll_rc = myconnect.ConnectToServer()<br />ll_rv = myconnect.CreateInstance(iuo_employee, &<br /> "uo_employee") |
RetrieveData function
The RetrieveData function makes a synchronous
call to the RetrieveData function on the EAServer component. When the function
completes processing, it calls the Notify function
on the callback object, passing it the DataWindow Blob returned
from the server component.
The RetrieveData function takes an argument
called auo_callback, which is of type uo_callback:
|
1 |
blob lblb_data<br />long ll_rv<br />ll_rv = iuo_employee.retrievedata(lblb_data)<br />auo_callback.notify(lblb_data)<br />return ll_rv |
Callback object definition
When the EAServer component
has finished processing, the shared object notifies a user object
called uo_callback, which in turn
notifies the w_employee window. The uo_callback object
has two functions, Notify and PassObject.
Notify function
The Notify function calls a function called SetDW on
the w_employee window, passing it
the DataWindow Blob returned from the server
component. The Notify function takes the argument ablb_data,
which is of type Blob, and returns a Long value.
The function has the following script:
|
1 |
long ll_rv<br />ll_rv = iw_employee.setdw(ablb_data)<br />if ll_rv = -1 then<br /> MessageBox("Error", "SetDW call failed!")<br />end if<br />return ll_rv |
PassObject function
The PassObject function caches a reference
to the w_employee window in the iw_employee instance
variable. The function takes the argument aw_employee, which
is of type w_employee, and returns
a Long value:
|
1 |
iw_employee = aw_employee<br />return 1 |