Module: Cod
- Defined in:
- lib/cod.rb,
lib/cod/pipe.rb,
lib/cod/iopair.rb,
lib/cod/select.rb,
lib/cod/channel.rb,
lib/cod/process.rb,
lib/cod/service.rb,
lib/cod/bidir_pipe.rb,
lib/cod/tcp_client.rb,
lib/cod/tcp_server.rb,
lib/cod/work_queue.rb,
lib/cod/select_group.rb,
lib/cod/simple_serializer.rb,
lib/cod/protocol_buffers_serializer.rb
Overview
The core concept of Cod are ‘channels’. (Cod::Channel::Base) You can create such channels on top of the various transport layers. Once you have such a channel, you #put messages into it and you #get messages out of it. Messages are retrieved in FIFO manner, making channels look like a communication pipe most of the time.
Cod also brings a few abstractions layered on top of channels: You can use channels to present ‘services’ (Cod::Service) to the network: A service is a simple one or two way RPC call. (one way = asynchronous)
Cod channels are serializable whereever possible. If you want to tell somebody where to write his answers and/or questions to, send him the channel! This is really powerful and used extensively in constructing the higher order primitives.
The goal of Cod is that you have to know only very few things about the network (the various transports) to be able to construct complex things. It handles reconnection and reliability for you. It also translates cryptic OS errors into plain text messages where it can’t just handle them. This should give you a clear place to look at if things go wrong. Note that this can only be ever as good as the sum of situations Cod has been tested in. Contribute your observations and we’ll come up with a way of dealing with most of the tricky stuff!
Defined Under Namespace
Modules: Beanstalk Classes: BidirPipe, Channel, ExclusiveSection, IOPair, Pipe, Process, ProtocolBuffersSerializer, ReadOnlyChannel, Select, SelectGroup, Service, SimpleSerializer, TcpClient, TcpServer, WorkQueue, WriteOnlyChannel
Class Method Summary collapse
-
.beanstalk(tube_name, server = nil) ⇒ Object
Creates a channel based on the beanstalkd messaging queue.
-
.bidir_pipe(serializer = nil, pipe_pair = nil) ⇒ Object
Creates two channels based on Cod.pipe (unidirectional IO.pipe) and links things up so that you communication is bidirectional.
-
.pipe(serializer = nil, pipe_pair = nil) ⇒ Object
Creates a pipe connection that is visible to this process and its children.
-
.process(command, serializer = nil) ⇒ Object
Runs a command via Process.spawn, then links a channel to the commands stdout and stdin.
- .select(timeout, groups) ⇒ Object
-
.stdio(serializer = nil) ⇒ Object
Links a process’ stdin and stdout up with a pipe.
-
.tcp(destination, serializer = nil) ⇒ Object
Creates a tcp connection to the destination and returns a channel for it.
-
.tcp_server(bind_to) ⇒ Object
Creates a tcp listener on bind_to and returns a channel for it.
Class Method Details
.beanstalk(tube_name, server = nil) ⇒ Object
Creates a channel based on the beanstalkd messaging queue. (see Cod::Beanstalk::Channel)
64 65 66 |
# File 'lib/cod.rb', line 64 def beanstalk(tube_name, server=nil) Cod::Beanstalk::Channel.new(tube_name, server||'localhost:11300') end |
.bidir_pipe(serializer = nil, pipe_pair = nil) ⇒ Object
Creates two channels based on Cod.pipe (unidirectional IO.pipe) and links things up so that you communication is bidirectional. Writes go to #out and reads come from #in.
38 39 40 |
# File 'lib/cod.rb', line 38 def bidir_pipe(serializer=nil, pipe_pair=nil) Cod::BidirPipe.new(serializer, pipe_pair) end |
.pipe(serializer = nil, pipe_pair = nil) ⇒ Object
Creates a pipe connection that is visible to this process and its children. (see Cod::Pipe)
29 30 31 |
# File 'lib/cod.rb', line 29 def pipe(serializer=nil, pipe_pair=nil) Cod::Pipe.new(serializer) end |
.process(command, serializer = nil) ⇒ Object
Runs a command via Process.spawn, then links a channel to the commands stdout and stdin. Returns the commands pid and the channel.
Example:
pid, channel = Cod.process('cat')
74 75 76 |
# File 'lib/cod.rb', line 74 def process(command, serializer=nil) Cod::Process.new(command, serializer) end |
.select(timeout, groups) ⇒ Object
2 3 4 |
# File 'lib/cod/select.rb', line 2 def select(timeout, groups) Select.new(timeout, groups).do end |
.stdio(serializer = nil) ⇒ Object
Links a process’ stdin and stdout up with a pipe. This means that the pipes #put method will print to stdout, and the #get method will read from stdin.
83 84 85 |
# File 'lib/cod.rb', line 83 def stdio(serializer=nil) Cod::Pipe.new(serializer, [$stdin, $stdout]) end |
.tcp(destination, serializer = nil) ⇒ Object
Creates a tcp connection to the destination and returns a channel for it. (see Cod::TcpClient)
46 47 48 49 50 |
# File 'lib/cod.rb', line 46 def tcp(destination, serializer=nil) Cod::TcpClient.new( destination, serializer || SimpleSerializer.new) end |