PageRenderTime 27ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/ruby/binding-ruby/src/main/ruby/transport/runner.rb

#
Ruby | 71 lines | 55 code | 15 blank | 1 comment | 9 complexity | 85cb2e8730d3d2b6cb302360b8441ad8 MD5 | raw file
Possible License(s): Apache-2.0
  1. require 'socket'
  2. require 'etch/bindings/ruby/transport/runner_handler.rb'
  3. class Runner < AbstractStartable
  4. include RunnerHandler
  5. attr :handler, :thread
  6. private :handler, :thread
  7. def initialize()
  8. # do nothing
  9. end
  10. def setRunnerHandler( handler )
  11. @handler = handler
  12. end
  13. def start0()
  14. @thread = Thread.new( newThread )
  15. @thread.start()
  16. end
  17. def stop0()
  18. t = @thread
  19. if( t != nil )
  20. @thread = nil
  21. t.join()
  22. end
  23. end
  24. def run()
  25. fireStarted()
  26. first = true
  27. throw :Exception1 => e unless isStarted()
  28. while(isStarted())
  29. throw :Exception1 => e unless (!run0?( first ))
  30. if( !run0?(first))
  31. break
  32. end
  33. first = false
  34. end
  35. end
  36. catch :Exception1 => e do
  37. fireException( "run", e )
  38. end
  39. ensure fireStopped()
  40. end
  41. def fireStarted()
  42. if( @handler != nil )
  43. @handler.started( this )
  44. end
  45. def fireException( what, e )
  46. if( @handler != nil )
  47. @handler.exception( r, what, e )
  48. end
  49. def fireStopped()
  50. if( @handler != nil )
  51. @handler.stopped( this )
  52. end
  53. def run0()
  54. raise "subclasser responsibility"
  55. end
  56. end