AS3 extension - Socket IO, asnychronous calls, callbacks
--------------------------------------------------------
Key: THRIFT-1223
URL: https://issues.apache.org/jira/browse/THRIFT-1223
Project: Thrift
Issue Type: New Feature
Components: AS3 - Compiler, AS3 - Library
Reporter: Matthias Einwag
Hi everyone,
first of all I'm new to Thrift and JIRA, so I hope I can get this right.
I will try to attach my modified version of the AS3 generator and the AS3 libs.
I did some work on the AS3 implementation of thrift to get TCP/IP socket
support. This includes a new transport TSocket.
Because actionscript supports only non-blocking IO you must use
TFramedTransport, which is also added and wraps around TSocket.
Some example code to create a framed transport:
private var socket:Socket;
private var transport:TIOStreamTransport;
private var framedTransport:TFramedTransport;
socket = new Socket("127.0.0.1",9090);
transport = new TSocket(socket);
transport.open();
framedTransport = new TFramedTransport(transport);
As I did not like the current asynchronous implementation of Thrift/AS3, I did
some further changes:
- For each service function a send function and a receive function is generated
- The send function sends the data over the transport and creates an
AsyncResult object (similar to the Deferred in the Py-Twisted implementation),
which stores error and success callback functions as well as the corresponding
receive function. I would also like to add a timeout timer later to this.
- I now use a processor object for clients and servers. The processor registers
at the transport and is notified when a new Frame was received. Then process()
is called which decodes one message. The processor has a dictionary that
contains the sent requests (TAsyncResult objects). If a response message is
requested the processor calls the recveive function for the request, which will
then lead to a success or error call. This is not similar to the Java and
Py-Twisted implementation where the sequence id and dictionary is stored in the
client. But I find it more useful because I can support callbacks (see later).
- The generic implementation TProcessor can be used to support client only
functionality.
Example:
protocol = new TBinaryProtocol(framedTransport);
processor = new TProcessor(protocol);
client = new ServiceClient(processor);
TAsyncResult ar = client.send_doSomething(successHandler,errorHandler);
- Derived processors are used for server side functionality and callbacks
Example:
service = new
ServiceProcessor(theComponentThatImplementsTheServiceInterface,protocol);
Now this type of processor can be used to send requests (creating a client as
seen above) and meanwhile will also process incoming requests for the specified
service.
I need to use this for callbacks (events that are sent spontaneously from the
server to the actionscript client)
Missing:
- Improved error handling. At the moment the as3 client does not detect if the
server disconnect, only if it sends a request.
- "Real" server side functionality. Would need a serversocket that creates a
new serviceProcessor for each client that connects.
- The older HTTP transports are currently not compatible. They have to be
changed to the new processor usage and must send a TMessageReceivedEvent to the
processor. Maybe some minor changes I could add, but I have no time to test
HTTP.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira