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 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) ⇒ Cod::Service::Client

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

Parameters:

Returns:



66
67
68
# File 'lib/cod/channel.rb', line 66

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.

Returns:

  • (Object)

    the next message waiting in the channel



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.

Parameters:

  • msg (Object)

    any Ruby object that should be sent as message

Returns:

  • (Object)

    the answer from the other end.



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.

Parameters:

  • msg (Object)

    any Ruby object that should be sent as message



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

def put(msg)
  abstract_method_error
end

#serviceCod::Service

Produces a service that has this channel as communication point.

Returns:



56
57
58
# File 'lib/cod/channel.rb', line 56

def service
  abstract_method_error
end