/src/wrappers/zmq/library/zmq_context.e

http://github.com/tybor/Liberty · Specman e · 306 lines · 63 code · 37 blank · 206 comment · 0 complexity · 1ceef8a438120a17a2f73523f0130e55 MD5 · raw file

  1. class ZMQ_CONTEXT
  2. -- An ØMQ Context where ØMQ sockets live within.
  3. -- Each ØMQ socket lives within a specific context. Creating and
  4. -- destroying context is a counterpart of library
  5. -- initialisation/deinitialisation as used elsewhere. Ability to create
  6. -- multiple contexts saves the day when an application happens to
  7. -- link (indirectly and involuntarily) with several instances of 0MQ.
  8. -- Implementation notes: the fact that ØMQ can work in a threaded
  9. -- enviroment is currently hidden by this Liberty wrappers
  10. -- TODO: add support for pollability (ZMQ_POLL)
  11. inherit
  12. WRAPPER redefine default_create end
  13. EIFFEL_OWNED redefine default_create, dispose end
  14. insert
  15. ZMQ_EXTERNALS undefine default_create end
  16. ZMQ_SOCKET_TYPES undefine default_create end
  17. create {ANY} default_create
  18. feature {} -- Creation
  19. default_create
  20. -- Context creation; currently only non-threaded programs are handled.
  21. do
  22. from_external_pointer(zmq_init(1))
  23. end
  24. feature {} -- Disposing
  25. dispose
  26. local res: INTEGER
  27. do
  28. res := zmq_term(handle)
  29. -- TODO: handle return value
  30. end
  31. feature {ANY} -- Comparison and copying
  32. -- Since a ZMQ_CONTEXT is entirely opaque object they are not
  33. -- distinguishable so is_equal is always True. Copying just create another
  34. -- context.
  35. is_equal (another: like Current): BOOLEAN
  36. do
  37. Result:=True
  38. end
  39. copy (another: like Current)
  40. do
  41. default_create
  42. end
  43. feature {ANY} -- Request-reply pattern
  44. -- The request-reply pattern is used for sending requests from a client to
  45. -- one or more instances of a service, and receiving subsequent replies to
  46. -- each request sent.
  47. new_req_socket: ZMQ_REQ_SOCKET
  48. -- A new ZMQ_REQ_SOCKET, that sends requests to and receives replies from a service.
  49. -- This socket type allows only an alternating sequence of request -
  50. -- sending a message - and subsequent reply - receiving an answer. Each
  51. -- request sent is load-balanced among all services, and each reply
  52. -- received is matched with the last issued request.
  53. do
  54. create Result.from_external_pointer (zmq_socket(handle,zmq_req))
  55. ensure Result/=Void
  56. end
  57. new_rep_socket: ZMQ_REP_SOCKET
  58. -- A new ZMQ_REP socket to receive requests from and send replies to a client.
  59. -- It allows only an alternating sequence of request (receive) and
  60. -- subsequent reply (send) commands. Each request received
  61. -- fair-queued from among all clients, and each reply sent is routed to
  62. -- the client that issued the last request. If the original requester
  63. -- doesnt exist any more the reply is silently discarded.
  64. do
  65. create Result.from_external_pointer(zmq_socket(handle,zmq_rep))
  66. ensure Result/=Void
  67. end
  68. -- ZMQ_DEALER
  69. -- A socket of type ZMQ_DEALER is an advanced pattern used for extending request/reply
  70. -- sockets. Each message sent is load-balanced among all connected peers, and each
  71. -- message received is fair-queued from all connected peers.
  72. --
  73. -- Previously this socket was called ZMQ_XREQ and that name remains available for
  74. -- backwards compatibility.
  75. --
  76. -- When a ZMQ_DEALER socket enters an exceptional state due to having reached the high
  77. -- water mark for all peers, or if there are no peers at all, then any zmq_send(3)
  78. -- operations on the socket shall block until the exceptional state ends or at least one
  79. -- peer becomes available for sending; messages are not discarded.
  80. --
  81. -- When a ZMQ_DEALER socket is connected to a ZMQ_REP socket each message sent must
  82. -- consist of an empty message part, the delimiter, followed by one or more body parts.
  83. --
  84. -- Table 3. Summary of ZMQ_DEALER characteristics
  85. -- Compatible peer sockets ZMQ_ROUTER, ZMQ_REQ, ZMQ_REP
  86. --
  87. -- Direction Bidirectional
  88. --
  89. -- Send/receive pattern Unrestricted
  90. --
  91. -- Outgoing routing strategy Load-balanced
  92. --
  93. -- Incoming routing strategy Fair-queued
  94. --
  95. --
  96. --
  97. -- ZMQ_HWM option action Block
  98. --
  99. --
  100. -- ZMQ_ROUTER
  101. -- A socket of type ZMQ_ROUTER is an advanced pattern used for extending request/reply
  102. -- sockets. When receiving messages a ZMQ_ROUTER socket shall prepend a message part
  103. -- containing the identity of the originating peer to the message before passing it to
  104. -- the application. Messages received are fair-queued from among all connected peers.
  105. -- When sending messages a ZMQ_ROUTER socket shall remove the first part of the message
  106. -- and use it to determine the identity of the peer the message shall be routed to. If
  107. -- the peer does not exist anymore the message shall be silently discarded.
  108. --
  109. -- Previously this socket was called ZMQ_XREP and that name remains available for
  110. -- backwards compatibility.
  111. --
  112. -- When a ZMQ_ROUTER socket enters an exceptional state due to having reached the high
  113. -- water mark for all peers, or if there are no peers at all, then any messages sent to
  114. -- the socket shall be dropped until the exceptional state ends. Likewise, any messages
  115. -- routed to a non-existent peer or a peer for which the individual high water mark has
  116. -- been reached shall also be dropped.
  117. --
  118. -- When a ZMQ_REQ socket is connected to a ZMQ_ROUTER socket, in addition to the identity
  119. -- of the originating peer each message received shall contain an empty delimiter message
  120. -- part. Hence, the entire structure of each received message as seen by the application
  121. -- becomes: one or more identity parts, delimiter part, one or more body parts. When
  122. -- sending replies to a ZMQ_REQ socket the application must include the delimiter part.
  123. --
  124. -- Table 4. Summary of ZMQ_ROUTER characteristics
  125. -- Compatible peer sockets ZMQ_DEALER, ZMQ_REQ, ZMQ_REP
  126. --
  127. -- Direction Bidirectional
  128. --
  129. -- Send/receive pattern Unrestricted
  130. --
  131. -- Outgoing routing strategy See text
  132. --
  133. -- Incoming routing strategy Fair-queued
  134. --
  135. -- ZMQ_HWM option action Drop
  136. --
  137. --
  138. feature {ANY} -- Publish-subscribe pattern
  139. -- The publish-subscribe pattern is used for one-to-many distribution of
  140. -- data from a single publisher to multiple subscribers in a fan out
  141. -- fashion.
  142. new_pub_socket: ZMQ_PUB_SOCKET
  143. -- A new ZMQ_PUB_SOCKET, used by a publisher to distribute data.
  144. -- Messages sent are distributed in a fan out fashion to all connected
  145. -- peers.
  146. -- When a ZMQ_PUB_SOCKET enters an exceptional state due to having
  147. -- reached the high water mark for a subscriber, then any messages that
  148. -- would be sent to the subscriber in question shall instead be dropped
  149. -- until the exceptional state ends. The `send' command shall never
  150. -- block for this socket type.
  151. do
  152. create Result.from_external_pointer(zmq_socket(handle,zmq_pub))
  153. ensure Result/=Void
  154. end
  155. new_sub_socket: ZMQ_SUB_SOCKET
  156. -- A new ZMQ_SUB_SOCKET used by a subscriber to subscribe to data
  157. -- distributed by a publisher. Initially this socket is not subscribed
  158. -- to any messages, use `subscribe_to' or `subscribe_to_all' to specify
  159. -- which messages to subscribe to. This is a receiving only socket.
  160. do
  161. create Result.from_external_pointer(zmq_socket(handle,zmq_sub))
  162. ensure Result/=Void
  163. end
  164. feature {ANY} -- Pipeline pattern
  165. -- The pipeline pattern is used for distributing data to nodes arranged in
  166. -- a pipeline. Data always flows down the pipeline, and each stage of the
  167. -- pipeline is connected to at least one node. When a pipeline stage
  168. -- connected to multiple nodes data is load-balanced among all connected
  169. -- nodes.
  170. new_push_socket: ZMQ_PUSH_SOCKET
  171. -- A new socket used in a pipeline node to send messages to downstream
  172. -- pipeline nodes. Messages are load-balanced to all connected
  173. -- downstream nodes.
  174. -- When a ZMQ_PUSH_SOCKET enters an exceptional state due to having
  175. -- reached the high water mark for all downstream nodes, or if there
  176. -- are no downstream nodes at all, then any send operations on the
  177. -- socket shall block until the exceptional state ends or at least one
  178. -- downstream node becomes available for sending; messages are not
  179. -- discarded.
  180. -- Summary of ZMQ_PUSH characteristics
  181. -- Compatible peer sockets ZMQ_PULL
  182. --
  183. -- Direction Unidirectional
  184. --
  185. -- Send/receive pattern Send only
  186. --
  187. -- Incoming routing strategy N/A
  188. --
  189. -- Outgoing routing strategy Load-balanced
  190. --
  191. -- ZMQ_HWM option action Block
  192. do
  193. create Result.from_external_pointer(zmq_socket(handle,zmq_push))
  194. ensure Result/=Void
  195. end
  196. new_pull_socket: ZMQ_PULL_SOCKET
  197. --
  198. -- ZMQ_PULL
  199. -- A socket of type ZMQ_PULL is used by a pipeline node to receive messages from upstream
  200. -- pipeline nodes. Messages are fair-queued from among all connected upstream nodes. The
  201. -- zmq_send() function is not implemented for this socket type.
  202. --
  203. -- Deprecated alias: ZMQ_UPSTREAM.
  204. --
  205. -- Table 8. Summary of ZMQ_PULL characteristics
  206. -- Compatible peer sockets ZMQ_PUSH
  207. --
  208. -- Direction Unidirectional
  209. --
  210. -- Send/receive pattern Receive only
  211. --
  212. -- Incoming routing strategy Fair-queued
  213. --
  214. -- Outgoing routing strategy N/A
  215. --
  216. -- ZMQ_HWM option action N/A
  217. --
  218. --
  219. do
  220. create Result.from_external_pointer(zmq_socket(handle,zmq_pull))
  221. ensure Result/=Void
  222. end
  223. feature {ANY} -- Exclusive pair pattern
  224. -- The exclusive pair pattern is used to connect a peer to precisely one other peer. This
  225. -- pattern is used for inter-thread communication across the inproc transport.
  226. --
  227. -- ZMQ_PAIR
  228. -- A socket of type ZMQ_PAIR can only be connected to a single peer at any one time. No
  229. -- message routing or filtering is performed on messages sent over a ZMQ_PAIR socket.
  230. --
  231. -- When a ZMQ_PAIR socket enters an exceptional state due to having reached the high
  232. -- water mark for the connected peer, or if no peer is connected, then any zmq_send(3)
  233. -- operations on the socket shall block until the peer becomes available for sending;
  234. -- messages are not discarded.
  235. --
  236. -- Note
  237. -- ZMQ_PAIR sockets are designed for inter-thread communication across the
  238. -- zmq_inproc(7) transport and do not implement functionality such as
  239. -- auto-reconnection. ZMQ_PAIR sockets are considered experimental and may have other
  240. -- missing or broken aspects.
  241. --
  242. -- Table 9. Summary of ZMQ_PAIR characteristics
  243. -- Compatible peer sockets ZMQ_PAIR
  244. --
  245. -- Direction Bidirectional
  246. --
  247. -- Send/receive pattern Unrestricted
  248. --
  249. -- Incoming routing strategy N/A
  250. --
  251. -- Outgoing routing strategy N/A
  252. --
  253. -- ZMQ_HWM option action Block
  254. end -- class ZMQ_CONTEXT
  255. -- Zero MQ Liberty Wrappers
  256. -- Copyright (C) 2010-2017: Paolo Redaelli
  257. -- This library is free software; you can redistribute it and/or
  258. -- modify it under the terms of the GNU Lesser General Public
  259. -- License as published by the Free Software Foundation; either
  260. -- version 3 of the License, or (at your option) any later version.
  261. --
  262. -- This library is distributed in the hope that it will be useful,
  263. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  264. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  265. -- Lesser General Public License for more details.
  266. --
  267. -- You should have received a copy of the GNU Lesser General Public
  268. -- License along with this library; if not, write to the Free Software
  269. -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA