/tutorial/storable/example3/repository_server.e

http://github.com/tybor/Liberty · Specman e · 88 lines · 66 code · 12 blank · 10 comment · 2 complexity · 7ef8ecc7599381c1f863afd836cccc6d MD5 · raw file

  1. class REPOSITORY_SERVER
  2. --
  3. -- This class is quite similar to MULTIPLEX_SERVER in the tutorial/net tutorial. It is used here as a central
  4. -- repository.
  5. --
  6. inherit
  7. REPOSITORY[STRING]
  8. -- The server itself is a repository in regard to its connections.
  9. XML_STREAM_REPOSITORY[STRING]
  10. redefine make
  11. end
  12. insert
  13. SERVER[REPOSITORY_CONNECTION]
  14. export {} all
  15. end
  16. create {ANY}
  17. make
  18. feature {REPOSITORY_CONNECTION}
  19. update_from_io_stream (io_stream: INPUT_STREAM)
  20. require
  21. io_stream.is_connected
  22. do
  23. update_from_stream(io_stream)
  24. end
  25. write_to_io_stream (io_stream: OUTPUT_STREAM)
  26. require
  27. io_stream.is_connected
  28. do
  29. write_to_stream(create {XML_REPOSITORY_OUTPUT}.make(io_stream, "1"))
  30. end
  31. feature {}
  32. make
  33. local
  34. host: HOST; tcp: TCP_ACCESS
  35. do
  36. Precursor
  37. -- Start a server on the local machine, listening on port 2001
  38. create host.make("localhost")
  39. create tcp.make(host, 2001, True)
  40. start(tcp)
  41. end
  42. handle_error (error_message: STRING)
  43. do
  44. if error_message /= Void then
  45. std_error.put_string(error_message)
  46. std_error.put_new_line
  47. else
  48. std_error.put_string(once "Could not start the server%N")
  49. end
  50. die_with_code(1)
  51. end
  52. new_connection: REPOSITORY_CONNECTION
  53. do
  54. create Result.make(Current)
  55. end
  56. feature {REPOSITORY_CONNECTION}
  57. shutdown
  58. -- A connection asked the server to shut down
  59. do
  60. server.shutdown
  61. end
  62. halt
  63. -- A connection asked the server to halt
  64. do
  65. server.halt
  66. end
  67. connection_done (a_connection: REPOSITORY_CONNECTION)
  68. -- A connection is just finished.
  69. do
  70. connections := connections - 1
  71. if connections = 0 and then server.done and then stack.current_loop /= Void then
  72. -- If all the connections are closed and the server is shut down, then we exit the loop.
  73. stack.break
  74. end
  75. end
  76. end -- class REPOSITORY_SERVER