List of usage examples for io.netty.buffer PooledByteBufAllocator DEFAULT
PooledByteBufAllocator DEFAULT
To view the source code for io.netty.buffer PooledByteBufAllocator DEFAULT.
Click Source Link
From source file:io.reactivex.netty.protocol.http.client.HttpClientRequest.java
License:Apache License
public <S> HttpClientRequest<T> withRawContentSource(final Observable<S> rawContentSource, final ContentTransformer<S> transformer) { this.rawContentSource = rawContentSource.map(new Func1<S, ByteBuf>() { @Override//from w ww. j a va 2 s .c o m public ByteBuf call(S rawContent) { return transformer.call(rawContent, PooledByteBufAllocator.DEFAULT); } }); return this; }
From source file:io.reactivex.netty.server.AbstractServerBuilder.java
License:Apache License
public B defaultChannelOptions() { channelOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); return returnBuilder(); }
From source file:io.reactivex.netty.server.ConnectionBasedServerBuilder.java
License:Apache License
@Override public B defaultChannelOptions() { channelOption(ChannelOption.SO_KEEPALIVE, true); childChannelOption(ChannelOption.SO_KEEPALIVE, true); childChannelOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); return super.defaultChannelOptions(); }
From source file:io.scalecube.socketio.serialization.PacketEncoder.java
License:Apache License
public static ByteBuf encodePacket(final Packet packet) throws IOException { ByteBuf dataBytes = packet.getData(); boolean hasData = dataBytes != null; CompositeByteBuf compositeByteBuf = PooledByteBufAllocator.DEFAULT.compositeBuffer(hasData ? 1 : 2); byte[] typeBytes = packet.getType().getValueAsBytes(); int headerCapacity = typeBytes.length + DELIMITER_LENGTH + DELIMITER_LENGTH + (hasData ? DELIMITER_LENGTH : 0); ByteBuf headerByteBuf = PooledByteBufAllocator.DEFAULT.buffer(headerCapacity, headerCapacity); headerByteBuf.writeBytes(typeBytes); headerByteBuf.writeBytes(DELIMITER_BYTES); headerByteBuf.writeBytes(DELIMITER_BYTES); if (hasData) { headerByteBuf.writeBytes(DELIMITER_BYTES); }//from w w w . j a v a 2s . c om compositeByteBuf.addComponent(headerByteBuf); int compositeReadableBytes = headerByteBuf.readableBytes(); if (hasData) { compositeByteBuf.addComponent(dataBytes); compositeReadableBytes += dataBytes.readableBytes(); } compositeByteBuf.writerIndex(compositeReadableBytes); return compositeByteBuf; }
From source file:io.scalecube.socketio.serialization.PacketFramer.java
License:Apache License
public static ByteBuf encodePacketsFrame(final PacketsFrame packetsFrame) throws IOException { List<Packet> packets = packetsFrame.getPackets(); if (packets.size() == 1) { Packet packet = packets.get(0);//from ww w.j a v a 2s .co m return PacketEncoder.encodePacket(packet); } else { CompositeByteBuf compositeByteBuf = PooledByteBufAllocator.DEFAULT.compositeBuffer(packets.size() * 2); int compositeReadableBytes = 0; for (Packet packet : packets) { // Decode packet ByteBuf packetByteBuf = PacketEncoder.encodePacket(packet); // Prepare length prepender int packetLength = getUtf8CharCountByByteCount(packetByteBuf, 0, packetByteBuf.readableBytes()); byte[] packetLengthBytes = String.valueOf(packetLength).getBytes(CharsetUtil.UTF_8); int packetLengthPrependerCapacity = packetLengthBytes.length + DELIMITER_BYTES_SIZE + DELIMITER_BYTES_SIZE; ByteBuf packetLengthPrependerByteBuf = PooledByteBufAllocator.DEFAULT .buffer(packetLengthPrependerCapacity, packetLengthPrependerCapacity); packetLengthPrependerByteBuf.writeBytes(DELIMITER_BYTES); packetLengthPrependerByteBuf.writeBytes(packetLengthBytes); packetLengthPrependerByteBuf.writeBytes(DELIMITER_BYTES); // Update composite byte buffer compositeByteBuf.addComponent(packetLengthPrependerByteBuf); compositeByteBuf.addComponent(packetByteBuf); compositeReadableBytes += packetLengthPrependerByteBuf.readableBytes() + packetByteBuf.readableBytes(); } compositeByteBuf.writerIndex(compositeReadableBytes); return compositeByteBuf; } }
From source file:io.scalecube.socketio.SocketIOServer.java
License:Apache License
private ServerBootstrap createDefaultServerBootstrap() { return new ServerBootstrap().group(new NioEventLoopGroup(), new NioEventLoopGroup()) .channel(NioServerSocketChannel.class).childOption(ChannelOption.TCP_NODELAY, true) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); }//w ww .j a v a 2 s .co m
From source file:io.vertx.ext.asyncsql.impl.BaseSQLClient.java
License:Open Source License
protected Configuration getConfiguration(String defaultHost, int defaultPort, String defaultDatabase, String defaultUser, String defaultPassword, String defaultCharset, long defaultConnectTimeout, long defaultTestTimeout, JsonObject config) { String host = config.getString("host", defaultHost); int port = config.getInteger("port", defaultPort); String username = config.getString("username", defaultUser); String password = config.getString("password", defaultPassword); String database = config.getString("database", defaultDatabase); Charset charset = Charset.forName(config.getString("charset", defaultCharset)); long connectTimeout = config.getLong("connectTimeout", defaultConnectTimeout); long testTimeout = config.getLong("testTimeout", defaultTestTimeout); Long queryTimeout = config.getLong("queryTimeout"); Option<Duration> queryTimeoutOption = (queryTimeout == null) ? Option.empty() : Option.apply(Duration.apply(queryTimeout, TimeUnit.MILLISECONDS)); log.info("Creating configuration for " + host + ":" + port); return new Configuration(username, host, port, Option.apply(password), Option.apply(database), charset, 16777216, PooledByteBufAllocator.DEFAULT, Duration.apply(connectTimeout, TimeUnit.MILLISECONDS), Duration.apply(testTimeout, TimeUnit.MILLISECONDS), queryTimeoutOption); }
From source file:jlibs.wamp4j.netty.NettyClientEndpoint.java
License:Apache License
@Override public void connect(final URI uri, final ConnectListener listener, final String... subProtocols) { final SslContext sslContext; if ("wss".equals(uri.getScheme())) { try {/* w w w . j a v a 2 s . c om*/ if (sslSettings == null) { sslContext = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE) .build(); } else { sslContext = SslContextBuilder.forClient().trustManager(sslSettings.trustCertChainFile) .keyManager(sslSettings.certificateFile, sslSettings.keyFile, sslSettings.keyPassword) .build(); } } catch (Throwable thr) { listener.onError(thr); return; } } else if ("ws".equals(uri.getScheme())) sslContext = null; else throw new IllegalArgumentException("invalid protocol: " + uri.getScheme()); final int port = uri.getPort() == -1 ? (sslContext == null ? 80 : 443) : uri.getPort(); Bootstrap bootstrap = new Bootstrap().group(eventLoopGroup).channel(NioSocketChannel.class) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .option(ChannelOption.MAX_MESSAGES_PER_READ, 50000).option(ChannelOption.WRITE_SPIN_COUNT, 50000) .handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { if (sslContext != null) ch.pipeline().addLast(sslContext.newHandler(ch.alloc(), uri.getHost(), port)); WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, Util.toString(subProtocols), false, new DefaultHttpHeaders()); ch.pipeline().addLast(new HttpClientCodec(), new HttpObjectAggregator(8192), new WebSocketClientProtocolHandler(handshaker) { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { super.exceptionCaught(ctx, cause); listener.onError(cause); } }, new HandshakeListener(handshaker, listener)); } }); bootstrap.connect(uri.getHost(), port).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { assert !future.channel().isOpen(); listener.onError(future.cause()); } } }); }
From source file:jlibs.wamp4j.netty.NettyEndpoint.java
License:Apache License
@Override public WAMPOutputStream createOutputStream() { return new NettyOutputStream(PooledByteBufAllocator.DEFAULT.buffer()); }
From source file:jlibs.wamp4j.netty.NettyServerEndpoint.java
License:Apache License
@Override public void bind(final URI uri, final String subProtocols[], final AcceptListener listener) { final SslContext sslContext; if ("wss".equals(uri.getScheme())) { try {//from w ww . j a v a 2 s . c om if (sslSettings == null) { SelfSignedCertificate ssc = new SelfSignedCertificate(); sslSettings = new SSLSettings().keyFile(ssc.privateKey()).certificateFile(ssc.certificate()); } ClientAuth clientAuth = ClientAuth.values()[sslSettings.clientAuthentication.ordinal()]; sslContext = SslContextBuilder .forServer(sslSettings.certificateFile, sslSettings.keyFile, sslSettings.keyPassword) .clientAuth(clientAuth).trustManager(sslSettings.trustCertChainFile).build(); } catch (Throwable thr) { listener.onError(thr); return; } } else if ("ws".equals(uri.getScheme())) sslContext = null; else throw new IllegalArgumentException("invalid protocol: " + uri.getScheme()); int port = uri.getPort(); if (port == -1) port = sslContext == null ? 80 : 443; ServerBootstrap bootstrap = new ServerBootstrap().group(eventLoopGroup) .channel(NioServerSocketChannel.class) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childOption(ChannelOption.MAX_MESSAGES_PER_READ, 50000) .childOption(ChannelOption.WRITE_SPIN_COUNT, 50000) .childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { if (sslContext != null) ch.pipeline().addLast(sslContext.newHandler(ch.alloc())); ch.pipeline().addLast(new HttpServerCodec(), new HttpObjectAggregator(65536), new Handshaker(uri, listener, subProtocols)); } }); bootstrap.bind(uri.getHost(), port).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { channel = future.channel(); channel.attr(ACCEPT_LISTENER).set(listener); listener.onBind(NettyServerEndpoint.this); } else listener.onError(future.cause()); } }); }