lib/foxbat/pipeline.rb in foxbat-0.2.4 vs lib/foxbat/pipeline.rb in foxbat-0.2.5
- old
+ new
@@ -8,32 +8,43 @@
module Foxbat
class Pipeline
include ChannelPipelineFactory
- def initialize(handler, group, options={}, ssl_context=nil, &block)
+ HANDLER = "handler"
+ SSL_HANDLER = "ssl"
+
+ def initialize(handler, group, client, options={}, ssl_context=nil, &block)
@options = options
@handler = handler
+ @client_mode = client
+
+ if handler.class == Module
+ @handler = Class.new(EM::Connection)
+ @handler.send(:include, handler)
+ end
+
@group = group
@block = block
@context = ssl_context
end
def getPipeline
pipeline = Channels.pipeline
if @context
- engine = Security.create_ssl_engine(@context)
- pipeline.addLast("ssl", SslHandler.new(engine))
+ engine = Security.create_ssl_engine(@context, @client_mode)
+ pipeline.addLast(SSL_HANDLER, SslHandler.new(engine))
end
+
h = @handler.new(@options)
@block.call(h) if @block
connection = NettyConnection.new(h, @group)
- pipeline.addLast("handler", connection)
+ pipeline.addLast(HANDLER, connection)
pipeline
end
def releaseExternalResources
- p 'cleaning up factory...'
+ # todo
end
end
end