Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-1223

AS3 extension - Socket IO, asnychronous calls, callbacks

    XMLWordPrintableJSON

Details

    • Patch Available

    Description

      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.

      Attachments

        1. as3library.zip
          39 kB
          Matthias Einwag
        2. as3library.zip
          63 kB
          Matthias Einwag
        3. t_as3_generator.cc
          87 kB
          Matthias Einwag
        4. thrift.zip
          4.57 MB
          Matthias Einwag

        Activity

          People

            jensg Jens Geyer
            matthiase Matthias Einwag
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: