Skip to content

Commit

Permalink
renamed Reactor to Context
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Ammous committed Feb 20, 2011
1 parent 8d11928 commit 188bc2e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 35 deletions.
10 changes: 5 additions & 5 deletions example/simple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ def on_readable(socket, messages)
end

EM.run do
reactor = EM::ZeroMQ::Reactor.new(1)
ctx = EM::ZeroMQ::Context.new(1)

# setup two push sockets
push_socket1 = reactor.bind( ZMQ::PUSH, 'tcp://127.0.0.1:2091')
push_socket2 = reactor.bind( ZMQ::PUSH, 'ipc:///tmp/a')
push_socket3 = reactor.bind( ZMQ::PUSH, 'inproc://simple_test')
push_socket1 = ctx.bind( ZMQ::PUSH, 'tcp://127.0.0.1:2091')
push_socket2 = ctx.bind( ZMQ::PUSH, 'ipc:///tmp/a')
push_socket3 = ctx.bind( ZMQ::PUSH, 'inproc://simple_test')

# setup one pull sockets listening to both push sockets
pull_socket = reactor.connect( ZMQ::PULL, 'tcp://127.0.0.1:2091', EMTestPullHandler.new)
pull_socket = ctx.connect( ZMQ::PULL, 'tcp://127.0.0.1:2091', EMTestPullHandler.new)
pull_socket.connect('ipc:///tmp/a')
pull_socket.connect('inproc://simple_test')

Expand Down
8 changes: 4 additions & 4 deletions lib/em-zeromq/reactor.rb → lib/em-zeromq/context.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#
# different ways to create a socket:
# reactor.bind(:xreq, 'tcp://127.0.0.1:6666')
# reactor.bind('xreq', 'tcp://127.0.0.1:6666')
# reactor.bind(ZMQ::XREQ, 'tcp://127.0.0.1:6666')
# ctx.bind(:xreq, 'tcp://127.0.0.1:6666')
# ctx.bind('xreq', 'tcp://127.0.0.1:6666')
# ctx.bind(ZMQ::XREQ, 'tcp://127.0.0.1:6666')
#
module EventMachine
module ZeroMQ
class Reactor
class Context
READABLES = [ ZMQ::SUB, ZMQ::PULL, ZMQ::XREQ, ZMQ::XREP, ZMQ::REP, ZMQ::REQ ]
WRITABLES = [ ZMQ::PUB, ZMQ::PUSH, ZMQ::XREQ, ZMQ::XREP, ZMQ::REP, ZMQ::REQ ]

Expand Down
25 changes: 25 additions & 0 deletions spec/context_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require File.join(File.dirname(__FILE__), %w[spec_helper])

describe 'Context' do
before do
@ctx = EM::ZeroMQ::Context.new(1)
end

it 'can be created with a context' do
zmq_ctx = ZMQ::Context.new(1)
ctx = EM::ZeroMQ::Context.new( zmq_ctx )
ctx.instance_variable_get('@context').should == zmq_ctx
end

it 'can create socket' do
EM::run do
s1 = @ctx.bind(:xreq, 'tcp://127.0.0.1:5555')
s2 = @ctx.bind('xreq', 'tcp://127.0.0.1:5556')
s3 = @ctx.bind(ZMQ::XREQ, 'tcp://127.0.0.1:5557')

s1.instance_variable_get('@socket').name.should == 'XREQ'
EM::stop_event_loop
end
end
end

25 changes: 0 additions & 25 deletions spec/reactor_spec.rb

This file was deleted.

2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def rand_addr(scheme='tcp')
addr
end

SPEC_CTX = EM::ZeroMQ::Reactor.new(1)
SPEC_CTX = EM::ZeroMQ::Context.new(1)
def spec_ctx
SPEC_CTX
end

0 comments on commit 188bc2e

Please sign in to comment.