Class: Foxbat::NettyConnection
- Inherits:
-
SimpleChannelUpstreamHandler
- Object
- SimpleChannelUpstreamHandler
- Foxbat::NettyConnection
- Defined in:
- lib/foxbat/netty_connection.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(connection, group) ⇒ NettyConnection
constructor
A new instance of NettyConnection.
- #send_file(path) ⇒ Object
- #set_read_timeout(seconds) ⇒ Object
- #write(data, broadcast = false) ⇒ Object
Constructor Details
#initialize(connection, group) ⇒ NettyConnection
Returns a new instance of NettyConnection.
11 12 13 14 15 16 |
# File 'lib/foxbat/netty_connection.rb', line 11 def initialize(connection, group) @connection = connection @group = group connection.netty_handler = self super() end |
Instance Method Details
#close ⇒ Object
32 33 34 |
# File 'lib/foxbat/netty_connection.rb', line 32 def close @channel.close end |
#send_file(path) ⇒ Object
26 27 28 29 30 |
# File 'lib/foxbat/netty_connection.rb', line 26 def send_file(path) file_channel = RandomAccessFile.new(path, 'r').getChannel region = DefaultFileRegion.new(file_channel, 0, file_channel.size, true) @channel.write(region) end |
#set_read_timeout(seconds) ⇒ Object
36 37 38 |
# File 'lib/foxbat/netty_connection.rb', line 36 def set_read_timeout(seconds) end |
#write(data, broadcast = false) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/foxbat/netty_connection.rb', line 18 def write(data, broadcast=false) data = data.to_java_bytes if data.is_a?(String) buf = ChannelBuffers.copiedBuffer(data) recipient = broadcast ? @group : @channel recipient.write(buf) end |