PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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