Skip to content
Browse files

- Add EM::open_datagram_socket stub

- Add EventMachine::Connection#post_init support
- Pass args and block to EM::Connection initializer
  • Loading branch information...
1 parent 4a53a69 commit 993c3a995c2e83674a784ae8e3b499fe03b96228 @jordansissel jordansissel committed May 26, 2011
View
25 lib/netty-eventmachine/connection.rb
@@ -4,6 +4,7 @@
class EventMachine::Connection < org.jboss.netty.channel.SimpleChannelUpstreamHandler
# add this interface
include org.jboss.netty.channel.Channel
+ #include org.jboss.netty.channel.ChannelHandler
USASCII = java.nio.charset.Charset.defaultCharset
@@ -13,11 +14,33 @@ def initialize(*args)
super()
end
+ # EventMachine API,
+ public
+ def self.connect(bind_addr, bind_port, host, port)
+ # TODO(sissel):
+ end # def EventMachine::Connection.connect
+
+ private
+ def post_init_setup(context)
+ @peeraddr = context.getChannel.getRemoteAddress
+ p :port => @peeraddr.getPort
+ p :address => @peeraddr.getAddress
+ end # def post_init_setup
+
+ # org.jboss.netty.channel.Channel#channelConnected
+ public
+ def channelConnected(context, event)
+ if respond_to?(:post_init)
+ post_init_setup(context)
+ post_init
+ end
+ end # def channelConnected
+
# org.jboss.netty.channel.Channel#messageReceived
public
def messageReceived(context, event)
- puts event.getMessage
if respond_to?(:receive_data)
+ #p event.getMessage.toString(USASCII)
receive_data(event.getMessage.toString(USASCII))
end
end # def messageReceived
View
12 lib/netty-eventmachine/em_api.rb
@@ -20,7 +20,7 @@ def self.start_server(address, port=nil, handlerclass=nil, *args, &block)
)
bootstrap = org.jboss.netty.bootstrap.ServerBootstrap.new(channelfactory)
- bootstrap.setPipelineFactory(EventMachine::Netty::Pipeline.new(handlerclass, *args))
+ bootstrap.setPipelineFactory(EventMachine::Netty::Pipeline.new(handlerclass, *args, &block))
# TODO(sissel): Make this tunable, maybe a 'class'-wide setting on
# handlerclass?
bootstrap.setOption("child.tcpNoDelay", true)
@@ -33,6 +33,11 @@ def self.start_server(address, port=nil, handlerclass=nil, *args, &block)
end
end # def start_server
+ public
+ def self.open_datagram_socket(address, port, handlerclass=nil, *args, &block)
+ # TODO(sissel): Implement
+ end # def open_datagram_socket
+
public # EventMachine API, run
def self.run(&block)
block.call
@@ -58,4 +63,9 @@ def self.next_tick(&block)
def self.fork_reactor(&block)
raise NotImplemented.new
end # def fork_reactor
+
+ public
+ def self.reactor_running?
+ return true
+ end
end
View
7 lib/netty-eventmachine/netty/pipeline.rb
@@ -4,15 +4,16 @@
class EventMachine::Netty::Pipeline
include org.jboss.netty.channel.ChannelPipelineFactory
- def initialize(handlerclass, *args)
+ def initialize(handlerclass, *args, &block)
@handlerclass = handlerclass
@args = args
+ @block = block
end # def initialize
public # org.jboss.netty.channel.ChannelPipelineFactory#getPipeline
def getPipeline
- p "getPipeline" => [ @handlerclass ]
- handler = @handlerclass.new(*@args)
+ #p "getPipeline" => [ @handlerclass ]
+ handler = @handlerclass.new(*@args, &@block)
return org.jboss.netty.channel.Channels.pipeline(handler)
end # def getPipeline
end # class EventMachine::Netty::Pipeline

0 comments on commit 993c3a9

Please sign in to comment.
Something went wrong with that request. Please try again.