Sha256: b7fce1b2309903aa9e6d313b3804ef33af54fc888245fbbd1055da28cf10a3b4

Contents?: true

Size: 1.53 KB

Versions: 3

Compression:

Stored size: 1.53 KB

Contents

# Attempt to provide thread-safe communication between EventMachine and AMF Socket.
# 1. Always use EM.schedule to push work to the reactor thread.
# 2. Always use @actor.enqueue to push work to the actor's thread pool.

module Tribe
  module EM
    module AmfSocket
      class ActorProxy < ::AmfSocket::AmfRpcConnection
        private

        def initialize(actor_class, options = {})
          @actor_class = actor_class || raise('You must provide an actor class.')
          @logger = Workers::LogProxy.new(options[:logger])

          @actor = @actor_class.new({ :actor_proxy => self, :logger => @logger })
        end

        #
        # EM Callbacks.  Don't call these directly.
        #

        public

        def post_init
          super

          @actor.enqueue(:post_init, nil)
        end

        def unbind
          super

          @actor.enqueue(:unbind, nil)
        end

        def receive_message(message)
          @actor.enqueue(:receive_message, message)
        end

        #
        # Public methods.  Call these from the associated actor.
        #

        public

        def close(after_writing = false)
          ::EM.schedule { close_connection(after_writing) }

          return nil
        end

        def write_message(command, params = {})
          ::EM.schedule { send_message(command, params) }

          return nil
        end

        #
        # Private methods.
        #

        private

        def write(data)
          raise 'This method can not be used with AMF Socket.'
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tribe_em_amfsocket-0.0.4 lib/tribe_em_amfsocket/actor_proxy.rb
tribe_em_amfsocket-0.0.3 lib/tribe_em_amfsocket/actor_proxy.rb
tribe_em_amfsocket-0.0.2 lib/tribe_em_amfsocket/actor_proxy.rb