-
-
Save BanzaiMan/4221249 to your computer and use it in GitHub Desktop.
jruby integer unboxing / type selection issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/Users/fsg/projects/jruby-1.7.1/bin/jruby | |
require 'java' | |
require 'pry' | |
# $CLASSPATH << "jars/netty-4.0.0.Alpha7/jar/all-in-one/" | |
require 'jars/netty-4.0.0.Alpha7/jar/all-in-one/netty-4.0.0.Alpha7.jar' | |
java_import 'java.net.InetSocketAddress' | |
java_import 'java.util.concurrent.Executors' | |
java_import 'io.netty.buffer.Unpooled' | |
java_import 'io.netty.buffer.DefaultMessageBuf' | |
java_import 'io.netty.bootstrap.ServerBootstrap' | |
java_import 'io.netty.bootstrap.Bootstrap' | |
java_import 'io.netty.channel.ChannelPipeline' | |
java_import 'io.netty.channel.Channel' | |
java_import 'io.netty.channel.socket.nio.NioDatagramChannel' | |
java_import 'io.netty.channel.ChannelInboundHandlerAdapter' | |
java_import 'io.netty.channel.ChannelInboundMessageHandlerAdapter' | |
java_import 'io.netty.channel.ChannelInboundMessageHandler' | |
java_import 'io.netty.channel.ChannelInitializer' | |
java_import 'io.netty.channel.socket.nio.NioEventLoopGroup' | |
java_import 'io.netty.channel.socket.nio.NioServerSocketChannel' | |
java_import 'io.netty.channel.ChannelOption' | |
java_import 'io.netty.channel.socket.DatagramPacket' | |
class Incoming < ChannelInboundHandlerAdapter | |
def newInboundBuffer(ctx) | |
puts "got into incoming.newinboundbuffer\n" | |
return Unpooled.buffer(512) | |
end | |
def exceptionCaught(ctx,cause) | |
puts "exception caught: #{cause.inspect}\n" | |
end | |
def inboundBufferUpdated(ctx) | |
puts "got something\n" | |
ctx.flush() | |
end | |
end | |
class MyInitializer < ChannelInitializer | |
def initChannel(sch) | |
sch.pipeline().addLast(Incoming.new()) | |
end | |
def self.exceptionCaught(ctx,throwable) | |
puts "exception caught\n" | |
end | |
end | |
x = ServerBootstrap.new() | |
.group(NioEventLoopGroup.new(), NioEventLoopGroup.new()) | |
.channel(NioServerSocketChannel.new().java_class) | |
.localAddress(8080) | |
.option(ChannelOption::SO_BACKLOG, 100.to_java(:int)) | |
.childOption(ChannelOption::TCP_NODELAY, true) | |
.childHandler(MyInitializer.new()) | |
f = x.bind().sync() | |
# NOTE: crashes because it tries to convert the '100' into a Long on the 'option' line, but option | |
# expects a java plain integer. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment