Class: Cod::Channel

Inherits:
Object
  • Object
show all
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 (Cod::Channel) 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

Beanstalk::Channel, BidirPipe, Pipe, TcpClient

Instance Method Summary collapse

Instance Method Details

#client(answers_to) ⇒ Object

Produces a service client that connects to this channel and receives service answers to the channel indicated by answers_to.



52
53
54
# File 'lib/cod/channel.rb', line 52

def client(answers_to)
  abstract_method_error
end

#getObject

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.



25
26
27
# File 'lib/cod/channel.rb', line 25

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.



38
39
40
41
# File 'lib/cod/channel.rb', line 38

def interact(msg)
  put msg
  get
end

#put(msg) ⇒ Object

Puts one message into a channel.



31
32
33
# File 'lib/cod/channel.rb', line 31

def put(msg)
  abstract_method_error
end

#serviceObject

Produces a service that has this channel as communication point.



45
46
47
# File 'lib/cod/channel.rb', line 45

def service
  abstract_method_error
end