Skip to content

Instantly share code, notes, and snippets.

@CootCraig
Last active December 15, 2015 00:28
Show Gist options
  • Save CootCraig/5173030 to your computer and use it in GitHub Desktop.
Save CootCraig/5173030 to your computer and use it in GitHub Desktop.
2013-03-15 Windows, JRuby, Celluloid,ffi-rzmq problem
GEM
remote: https://rubygems.org/
specs:
actionpack (3.2.12)
activemodel (= 3.2.12)
activesupport (= 3.2.12)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.4)
rack (~> 1.4.5)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.2.1)
activemodel (3.2.12)
activesupport (= 3.2.12)
builder (~> 3.0.0)
activerecord (3.2.12)
activemodel (= 3.2.12)
activesupport (= 3.2.12)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activerecord-jdbc-adapter (1.2.7)
activerecord-jdbcmssql-adapter (1.2.7)
activerecord-jdbc-adapter (~> 1.2.7)
jdbc-jtds (>= 1.2.5, < 1.4.0)
activesupport (3.2.12)
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
builder (3.0.4)
celluloid (0.12.4)
facter (>= 1.6.12)
timers (>= 1.0.0)
erubis (2.7.0)
facter (1.6.17)
ffi (1.4.0-java)
ffi-rzmq (1.0.0)
ffi
hike (1.2.1)
i18n (0.6.4)
jdbc-jtds (1.3.0.1)
journey (1.0.4)
json (1.7.7-java)
multi_json (1.6.1)
rack (1.4.5)
rack-cache (1.2)
rack (>= 0.4)
rack-ssl (1.3.3)
rack
rack-test (0.6.2)
rack (>= 1.0)
railties (3.2.12)
actionpack (= 3.2.12)
activesupport (= 3.2.12)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
rake (10.0.3)
rdoc (3.12.2)
json (~> 1.4)
sprockets (2.2.2)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
standalone_migrations (2.0.5)
activerecord (~> 3.2.11)
railties (~> 3.2.11)
rake
thor (0.17.0)
tilt (1.3.5)
timers (1.1.0)
tzinfo (0.3.36)
PLATFORMS
java
DEPENDENCIES
activerecord-jdbcmssql-adapter
celluloid
ffi-rzmq
json
standalone_migrations (~> 2.0.5)
require "rubygems"
require "bundler/setup"
require 'java'
require '../sqljdbc4.jar'
require 'active_record'
require 'ffi-rzmq'
require 'celluloid'
require 'yaml'
require 'json'
class Cvlan_Call_Event < ActiveRecord::Base
end
class App
attr_accessor :db_config_path
attr_accessor :db_config
attr_accessor :options
attr_accessor :zmq_context
@@the_app = nil
def self.app
@@the_app = App.new unless @@the_app
@@the_app
end
def initialize
@options = {
call_event_source_address: '10.10.10.111',
zmq_publish_socket_port: 38007
}
@zmq_context = ZMQ::Context.create(1)
puts "libzmq version #{ZMQ::LibZMQ.version}"
end
def run
@db_config_path = '../db/config.yml'
@db_config = YAML.load_file(@db_config_path)
Cvlan_Call_Event.establish_connection @db_config['test']
EventLogger.supervise_as :event_logger
EventReader.supervise_as :event_reader
sleep
end
end
class EventReader
include Celluloid
attr_accessor :event_url
attr_accessor :zmq_socket
def initialize
@event_url = "tcp://#{App.app.options[:call_event_source_address]}:#{App.app.options[:zmq_publish_socket_port]}"
@zmq_socket = App.app.zmq_context.socket ZMQ::SUB
zmq_socket.setsockopt(ZMQ::SUBSCRIBE,"")
stat = zmq_socket.connect event_url
async.run
end
def run
loop do
msg = ""
stat = zmq_socket.recv_string msg
if stat == 0
Celluloid::Actor[:event_logger].async.log msg
else
puts "No recv_string"
end
end
end
end
class EventLogger
include Celluloid
def initialize
@counter = 0
@log_file = File.new 'cvlan_events.txt','a'
end
def log(msg)
file_log msg
db_log JSON.parse(msg)
end
def file_log(msg)
@log_file.write msg
@log_file.write "\n"
@log_file.fsync
@counter += 1
puts "message #{@counter}"
end
def db_log(event)
begin
save = false
rec = Cvlan_Call_Event.new do |cvlan_call_event|
begin
cvlan_call_event.call_unique_id = event['call_unique_id'].to_s if event['call_unique_id']
cvlan_call_event.vdn = event['vdn'] if event['vdn']
cvlan_call_event.call_id = event['call_id'] if event['call_id']
cvlan_call_event.event_name_s = event['event_name_s'] if event['event_name_s']
cvlan_call_event.calling_num = event['calling_num'] if event['calling_num']
cvlan_call_event.connect_num = event['connect_num'] if event['connect_num']
cvlan_call_event.read_at = event['read_at'] if event['read_at']
save = true
rescue
save = false
end
end
rec.save if save
rescue
end
end
end
App.app.run
console output from
jruby --debug -J-Djruby.jit.max=0 -J-Djruby.compile.invokedynamic=false log_test.rb
then jruby log_test.rb
=====================================
jruby --debug -J-Djruby.jit.max=0 -J-Djruby.compile.invokedynamic=false log_test.rb
Exception in thread "JRubyWorker-1" org.jruby.exceptions.RaiseException: (NoMeth
odError) undefined method `yield' for Fiber:Class
at RUBY.suspend(c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloid
-0.12.4/lib/celluloid/tasks/task_fiber.rb:37)
at RUBY.suspend(c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloid
-0.12.4/lib/celluloid/task.rb:22)
at RUBY.call(c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloid-0.
12.4/lib/celluloid/actor.rb:70)
at RUBY._send_(c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloid-
0.12.4/lib/celluloid/proxies/actor_proxy.rb:22)
at RUBY.new_link(c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloi
d-0.12.4/lib/celluloid.rb:112)
at org.jruby.RubyBasicObject.__send__(org/jruby/RubyBasicObject.java:167
7)
at org.jruby.RubyKernel.send(org/jruby/RubyKernel.java:2103)
at RUBY.start(c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloid-0
.12.4/lib/celluloid/supervision_group.rb:133)
at RUBY.initialize(c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/cellul
oid-0.12.4/lib/celluloid/supervision_group.rb:120)
at RUBY.add(c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloid-0.1
2.4/lib/celluloid/supervision_group.rb:80)
at RUBY.supervise_as(c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/cell
uloid-0.12.4/lib/celluloid/supervision_group.rb:71)
at RUBY.supervise_as(c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/cell
uloid-0.12.4/lib/celluloid/supervisor.rb:17)
at RUBY.initialize(c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/cellul
oid-0.12.4/lib/celluloid/supervision_group.rb:63)
at org.jruby.RubyBasicObject.__send__(org/jruby/RubyBasicObject.java:170
4)
at org.jruby.RubyKernel.public_send(org/jruby/RubyKernel.java:1826)
at RUBY.dispatch(c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloi
d-0.12.4/lib/celluloid/calls.rb:23)
at RUBY.handle_message(c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/ce
lluloid-0.12.4/lib/celluloid/actor.rb:327)
at RUBY.initialize(c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/cellul
oid-0.12.4/lib/celluloid/tasks/task_fiber.rb:24)
E, [2013-03-15T14:40:38.022000 #3108] ERROR -- : Celluloid::SupervisionGroup cra
shed!
Celluloid::DeadTaskError: cannot resume a dead task (dead fiber called)
c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloid-0.12.4/lib/celluloid/ta
sks/task_fiber.rb:51:in `resume'
c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloid-0.12.4/lib/celluloid/re
sponses.rb:11:in `dispatch'
c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloid-0.12.4/lib/celluloid/ac
tor.rb:329:in `handle_message'
c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloid-0.12.4/lib/celluloid/ac
tor.rb:196:in `run'
c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloid-0.12.4/lib/celluloid/ac
tor.rb:184:in `initialize'
c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloid-0.12.4/lib/celluloid/th
read_handle.rb:17:in `initialize'
org/jruby/RubyProc.java:261:in `call'
org/jruby/RubyProc.java:249:in `call'
c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloid-0.12.4/lib/celluloid/in
ternal_pool.rb:48:in `create'
org/jruby/RubyProc.java:261:in `call'
org/jruby/RubyProc.java:213:in `call'
NoMethodError: undefined method `yield' for Fiber:Class
suspend at c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloid-0.1
2.4/lib/celluloid/tasks/task_fiber.rb:37
suspend at c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloid-0.1
2.4/lib/celluloid/task.rb:22
call at c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloid-0.1
2.4/lib/celluloid/actor.rb:70
_send_ at c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloid-0.1
2.4/lib/celluloid/proxies/actor_proxy.rb:22
new_link at c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloid-0.1
2.4/lib/celluloid.rb:112
__send__ at org/jruby/RubyBasicObject.java:1677
send at org/jruby/RubyKernel.java:2103
start at c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloid-0.1
2.4/lib/celluloid/supervision_group.rb:133
initialize at c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloid-0.1
2.4/lib/celluloid/supervision_group.rb:120
add at c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloid-0.1
2.4/lib/celluloid/supervision_group.rb:80
supervise_as at c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloid-0.1
2.4/lib/celluloid/supervision_group.rb:71
supervise_as at c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloid-0.1
2.4/lib/celluloid/supervisor.rb:17
initialize at c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloid-0.1
2.4/lib/celluloid/supervision_group.rb:63
__send__ at org/jruby/RubyBasicObject.java:1704
public_send at org/jruby/RubyKernel.java:1826
dispatch at c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloid-0.1
2.4/lib/celluloid/calls.rb:23
handle_message at c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloid-0.1
2.4/lib/celluloid/actor.rb:327
initialize at c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/celluloid-0.1
2.4/lib/celluloid/tasks/task_fiber.rb:24
D, [2013-03-15T14:40:38.069000 #3108] DEBUG -- : Terminating 2 actors...
D, [2013-03-15T14:40:38.069000 #3108] DEBUG -- : Shutdown completed cleanly
=============================
jruby log_test.rb
libzmq version {:major=>2, :minor=>2, :patch=>0}
message 1
message 2
message 3
message 4
message 5
message 6
message 7
message 8
message 9
message 10
message 11
message 12
message 13
message 14
message 15
message 16
message 17
message 18
message 19
message 20
message 21
message 22
message 23
message 24
message 25
message 26
message 27
message 28
message 29
message 30
message 31
message 32
message 33
message 34
message 35
message 36
message 37
message 38
message 39
message 40
message 41
message 42
message 43
message 44
message 45
message 46
message 47
message 48
message 49
message 50
Exception in thread "JRubyWorker-2" java.lang.NullPointerException
at java.lang.invoke.MethodHandles.guardWithTest(MethodHandles.java:2111)
at org.jruby.ext.ffi.jffi.InvokeDynamic.getMethodHandle(InvokeDynamic.ja
va:44)
at org.jruby.runtime.invokedynamic.InvocationLinker.createFFIHandle(Invo
cationLinker.java:1377)
at org.jruby.runtime.invokedynamic.InvocationLinker.handleForMethod(Invo
cationLinker.java:607)
at org.jruby.runtime.invokedynamic.InvocationLinker.tryDispatchDirect(In
vocationLinker.java:561)
at org.jruby.runtime.invokedynamic.InvocationLinker.getTarget(Invocation
Linker.java:567)
at org.jruby.runtime.invokedynamic.InvocationLinker.invocationFallback(I
nvocationLinker.java:146)
at rubyjit.ZMQ::Message$$initialize_ED87C06FF9B0BAFDCE3E6EB8ED806F9DC0F1
0AF611505757.__file__(c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/ffi-rzmq-1.
0.0/lib/ffi-rzmq/message.rb:105)
at rubyjit.ZMQ::Message$$initialize_ED87C06FF9B0BAFDCE3E6EB8ED806F9DC0F1
0AF611505757.__file__(c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/gems/ffi-rzmq-1.
0.0/lib/ffi-rzmq/message.rb)
at org.jruby.ast.executable.AbstractScript.__file__(AbstractScript.java:
38)
at org.jruby.internal.runtime.methods.JittedMethod.call(JittedMethod.jav
a:161)
at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSi
te.java:316)
at org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.
java:145)
at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:
149)
at org.jruby.RubyClass.newInstance(RubyClass.java:848)
at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:5
99)
at org.jruby.runtime.invokedynamic.InvocationLinker.invocationFallback(I
nvocationLinker.java:132)
at rubyjit.ZMQ::CommonSocketBehavior$$recv_string_B1961551F9251781952487
B7A380184D1D4C41DC11505757.__file__(c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/ge
ms/ffi-rzmq-1.0.0/lib/ffi-rzmq/socket.rb:343)
at rubyjit.ZMQ::CommonSocketBehavior$$recv_string_B1961551F9251781952487
B7A380184D1D4C41DC11505757.__file__(c:/jruby/jruby-1.7.3/lib/ruby/gems/shared/ge
ms/ffi-rzmq-1.0.0/lib/ffi-rzmq/socket.rb)
at org.jruby.ast.executable.AbstractScript.__file__(AbstractScript.java:
42)
at org.jruby.internal.runtime.methods.JittedMethod.call(JittedMethod.jav
a:181)
at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:5
99)
at org.jruby.runtime.invokedynamic.InvocationLinker.invocationFallback(I
nvocationLinker.java:149)
at log_test.block_0$RUBY$run(log_test.rb:63)
at log_test$block_0$RUBY$run.call(log_test$block_0$RUBY$run)
at org.jruby.runtime.CompiledBlock19.yieldSpecificInternal(CompiledBlock
19.java:121)
at org.jruby.runtime.CompiledBlock19.yieldSpecific(CompiledBlock19.java:
96)
at org.jruby.runtime.Block.yieldSpecific(Block.java:99)
at org.jruby.RubyKernel.loop(RubyKernel.java:1409)
at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:5
99)
at org.jruby.runtime.invokedynamic.InvocationLinker.invocationFallback(I
nvocationLinker.java:224)
at log_test.method__7$RUBY$run(log_test.rb:61)
at log_test$method__7$RUBY$run.call(log_test$method__7$RUBY$run)
at log_test$method__7$RUBY$run.call(log_test$method__7$RUBY$run)
at org.jruby.RubyKernel.public_send(RubyKernel.java:1826)
at org.jruby.RubyKernel$INVOKER$s$0$0$public_send.call(RubyKernel$INVOKE
R$s$0$0$public_send.gen)
at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.j
ava:209)
at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSi
te.java:336)
at org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.
java:179)
at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:
183)
at org.jruby.ast.CallSpecialArgBlockPassNode.interpret(CallSpecialArgBlo
ckPassNode.java:64)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:105)
at org.jruby.ast.RescueNode.executeBody(RescueNode.java:224)
at org.jruby.ast.RescueNode.interpret(RescueNode.java:119)
at org.jruby.evaluator.ASTInterpreter.INTERPRET_METHOD(ASTInterpreter.ja
va:75)
at org.jruby.internal.runtime.methods.InterpretedMethod.call(Interpreted
Method.java:182)
at org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.j
ava:188)
at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSi
te.java:326)
at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:
170)
at org.jruby.ast.CallOneArgNode.interpret(CallOneArgNode.java:57)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:105)
at org.jruby.evaluator.ASTInterpreter.INTERPRET_BLOCK(ASTInterpreter.jav
a:112)
at org.jruby.runtime.Interpreted19Block.evalBlockBody(Interpreted19Block
.java:209)
at org.jruby.runtime.Interpreted19Block.yield(Interpreted19Block.java:16
0)
at org.jruby.runtime.Interpreted19Block.yieldSpecific(Interpreted19Block
.java:133)
at org.jruby.runtime.Block.yieldSpecific(Block.java:99)
at org.jruby.ast.ZYieldNode.interpret(ZYieldNode.java:25)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:105)
at org.jruby.ast.RescueNode.executeBody(RescueNode.java:224)
at org.jruby.ast.RescueNode.interpret(RescueNode.java:119)
at org.jruby.ast.EnsureNode.interpret(EnsureNode.java:96)
at org.jruby.ast.BeginNode.interpret(BeginNode.java:83)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:105)
at org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
at org.jruby.evaluator.ASTInterpreter.INTERPRET_BLOCK(ASTInterpreter.jav
a:112)
at org.jruby.runtime.Interpreted19Block.evalBlockBody(Interpreted19Block
.java:209)
at org.jruby.runtime.Interpreted19Block.yield(Interpreted19Block.java:19
7)
at org.jruby.runtime.Interpreted19Block.yield(Interpreted19Block.java:18
0)
at org.jruby.runtime.Block.yieldArray(Block.java:146)
at org.jruby.ext.fiber.ThreadFiber$1.run(ThreadFiber.java:38)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:603)
at java.lang.Thread.run(Thread.java:722)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment