def start
    @em_lock.synchronize{
      # TODO on event of the process ending this thread will be
      # shutdown before a local finalizer can be run,
      # would be good to gracefully shut this down / wait for completion
      @reactor_thread  = Thread.new {
        begin
          EventMachine.run
        rescue Exception => e
          # TODO option to autorestart the reactor on errors ?
          puts "Critical exception #{e}\n#{e.backtrace.join("\n")}"
        ensure
          @em_lock.synchronize { @reactor_thread = nil }
        end
      } unless @reactor_thread
    }
    sleep 0.01 until EventMachine.reactor_running? # XXX hack but needed
    self
  end
def start
    @em_lock.synchronize{
      # TODO on event of the process ending this thread will be
      # shutdown before a local finalizer can be run,
      # would be good to gracefully shut this down / wait for completion
      @reactor_thread  = Thread.new {
        begin
          EventMachine.run
        rescue Exception => e
          # TODO option to autorestart the reactor on errors ?
          puts "Critical exception #{e}\n#{e.backtrace.join("\n")}"
        ensure
          @em_lock.synchronize { @reactor_thread = nil }
        end
      } unless @reactor_thread
    }
    sleep 0.01 until EventMachine.reactor_running? # XXX hack but needed
    self
  end
EMAdapter initializer
 Start the eventmachine reactor thread if not running