Class: Cod::Channel
- Inherits:
-
Object
- Object
- Cod::Channel
- Defined in:
- lib/cod/channel.rb
Overview
Channels transport Ruby objects from one end to the other. The communication setup varies a bit depending on the transport used for the channel, but the interface you interact with doesn’t vary. You can #put messages into a channel and you then #get them out of it.
Synopsis
channel.put [:a, :ruby, :object]
channel.get # => [:a, :ruby, :object]
By default, channels will serialize the messages you give them using Marshal.dump and Marshal.load. You can change this by passing your own serializer to the channel upon construction; see SimpleSerializer for a description of the interface such a serializer needs to implement.
This class is the abstract superclass of all Cod channels. It doesn’t have a transport by its own, but implements the whole interface for documentation purposes.
Direct Known Subclasses
Instance Method Summary collapse
-
#client(answers_to) ⇒ Cod::Service::Client
Produces a service client that connects to this channel and receives service answers to the channel indicated by answers_to.
-
#get ⇒ Object
Obtains one message from the channel.
-
#interact(msg) ⇒ Object
Interact with a channel by first writing msg to it, then reading back the other ends answer.
-
#put(msg) ⇒ void
Puts one message into a channel.
-
#service ⇒ Cod::Service
Produces a service that has this channel as communication point.
Instance Method Details
#client(answers_to) ⇒ Cod::Service::Client
Produces a service client that connects to this channel and receives service answers to the channel indicated by answers_to.
66 67 68 |
# File 'lib/cod/channel.rb', line 66 def client(answers_to) abstract_method_error end |
#get ⇒ Object
Obtains one message from the channel. If the channel is empty, but theoretically able to receive more messages, blocks forever. But if the channel is somehow broken, an exception is raised.
28 29 30 |
# File 'lib/cod/channel.rb', line 28 def get abstract_method_error end |
#interact(msg) ⇒ Object
Interact with a channel by first writing msg to it, then reading back the other ends answer.
47 48 49 50 |
# File 'lib/cod/channel.rb', line 47 def interact(msg) put msg get end |
#put(msg) ⇒ void
This method returns an undefined value.
Puts one message into a channel.
37 38 39 |
# File 'lib/cod/channel.rb', line 37 def put(msg) abstract_method_error end |
#service ⇒ Cod::Service
Produces a service that has this channel as communication point.
56 57 58 |
# File 'lib/cod/channel.rb', line 56 def service abstract_method_error end |