Skip to content

Commit

Permalink
Move to pure json for eventual jruby support
Browse files Browse the repository at this point in the history
  • Loading branch information
derekcollison committed Feb 8, 2011
1 parent e56c6e8 commit b2cdce2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 28 deletions.
6 changes: 1 addition & 5 deletions Gemfile
Expand Up @@ -2,11 +2,7 @@ source "http://rubygems.org"

gem 'eventmachine', '>= 0.12.10'
gem 'daemons', '>= 1.1.0'
gem 'yajl-ruby', '>= 0.8.0', :require => ['yajl', 'yajl/json_gem'], :platforms => [:mri_18, :mri_19]

platforms :jruby do
gem 'json_pure', :require => 'json'
end
gem 'json_pure', :require => 'json'

group :test do
gem 'rspec'
Expand Down
21 changes: 11 additions & 10 deletions Gemfile.lock
Expand Up @@ -4,25 +4,27 @@ PATH
nats (0.4.2)
daemons (>= 1.1.0)
eventmachine (>= 0.12.10)
yajl-ruby (>= 0.8.0)
json_pure (>= 1.5.1)

GEM
remote: http://rubygems.org/
specs:
daemons (1.1.0)
diff-lcs (1.1.2)
eventmachine (0.12.10)
rspec (2.4.0)
rspec-core (~> 2.4.0)
rspec-expectations (~> 2.4.0)
rspec-mocks (~> 2.4.0)
rspec-core (2.4.0)
rspec-expectations (2.4.0)
eventmachine (0.12.10-java)
json_pure (1.5.1)
rspec (2.5.0)
rspec-core (~> 2.5.0)
rspec-expectations (~> 2.5.0)
rspec-mocks (~> 2.5.0)
rspec-core (2.5.1)
rspec-expectations (2.5.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.4.0)
yajl-ruby (0.8.0)
rspec-mocks (2.5.0)

PLATFORMS
java
ruby

DEPENDENCIES
Expand All @@ -31,4 +33,3 @@ DEPENDENCIES
json_pure
nats!
rspec
yajl-ruby (>= 0.8.0)
25 changes: 13 additions & 12 deletions lib/nats/server.rb
Expand Up @@ -10,7 +10,6 @@
require 'fileutils'
require 'pp'


module NATSD #:nodoc: all

# Subscriber
Expand Down Expand Up @@ -89,9 +88,11 @@ def deliver_to_subscriber(subscriber, subject, reply, msg)
subscriber.conn.delete_subscriber(subscriber) if (subscriber.max_responses && subscriber.num_responses >= subscriber.max_responses)

# Check the outbound queue here and react if need be..
if subscriber.conn.get_outbound_data_size > MAX_OUTBOUND_SIZE
subscriber.conn.error_close SLOW_CONSUMER
log "Slow consumer dropped", subscriber.conn.client_info
if subscriber.conn.respond_to? :get_outbound_data_size
if subscriber.conn.get_outbound_data_size > MAX_OUTBOUND_SIZE
subscriber.conn.error_close SLOW_CONSUMER
log "Slow consumer dropped", subscriber.conn.client_info
end
end
end

Expand Down Expand Up @@ -164,7 +165,7 @@ def connect_auth_timeout
def receive_data(data)
@receive_data_calls += 1
(@buf ||= '') << data
close_connection and return if @buf =~ /(\006|\004)/ # ctrl+c or ctrl+d for telnet friendly
return close_connection if @buf =~ /(\006|\004)/ # ctrl+c or ctrl+d for telnet friendly
while (@buf && !@buf.empty? && !@closing)
# Waiting on msg payload
if @msg_size
Expand Down Expand Up @@ -198,23 +199,23 @@ def process_op(op)
ctrace 'PUB OP', op
return if @auth_pending
@pub_sub, @reply, @msg_size, = $1, $3, $4.to_i
send_data PAYLOAD_TOO_BIG and return if (@msg_size > MAX_PAYLOAD_SIZE)
send_data INVALID_SUBJECT and return if @pedantic && !(@pub_sub =~ SUB_NO_WC)
return send_data PAYLOAD_TOO_BIG if (@msg_size > MAX_PAYLOAD_SIZE)
return send_data INVALID_SUBJECT if @pedantic && !(@pub_sub =~ SUB_NO_WC)
when SUB_OP
ctrace 'SUB OP', op
return if @auth_pending
sub, qgroup, sid = $1, $3, $4
send_data INVALID_SUBJECT and return if !($1 =~ SUB)
send_data INVALID_SID_TAKEN and return if @subscriptions[sid]
return send_data INVALID_SUBJECT if !($1 =~ SUB)
return send_data INVALID_SID_TAKEN if @subscriptions[sid]
subscriber = Subscriber.new(self, sub, sid, qgroup, 0)
@subscriptions[sid] = subscriber
Server.subscribe(subscriber)
send_data OK if @verbose
when UNSUB_OP
ctrace 'UNSUB OP', op
return if @xsauth_pending
return if @auth_pending
sid, subscriber = $1, @subscriptions[$1]
send_data INVALID_SID_NOEXIST and return unless subscriber
return send_data INVALID_SID_NOEXIST unless subscriber

# If we have set max_responses, we will unsubscribe once we have received the appropriate
# amount of responses
Expand Down Expand Up @@ -258,7 +259,7 @@ def process_connect_config(config)
@verbose = config[:verbose] if config[:verbose] != nil
@pedantic = config[:pedantic] if config[:pedantic] != nil

send_data OK and return unless Server.auth_required?
return send_data OK unless Server.auth_required?

EM.cancel_timer(@auth_pending)
if Server.auth_ok?(config[:user], config[:pass])
Expand Down
2 changes: 1 addition & 1 deletion nats.gemspec
Expand Up @@ -18,7 +18,7 @@ spec = Gem::Specification.new do |s|
s.email = ["derek.collison@gmail.com"]

s.add_dependency('eventmachine', '>= 0.12.10')
s.add_dependency('yajl-ruby', '>= 0.8.0')
s.add_dependency('json_pure', '>= 1.5.1')
s.add_dependency('daemons', '>= 1.1.0')

s.require_paths = ['lib']
Expand Down

0 comments on commit b2cdce2

Please sign in to comment.