List of usage examples for io.netty.buffer UnpooledByteBufAllocator DEFAULT
UnpooledByteBufAllocator DEFAULT
To view the source code for io.netty.buffer UnpooledByteBufAllocator DEFAULT.
Click Source Link
From source file:com.linecorp.armeria.internal.grpc.ArmeriaMessageDeframerTest.java
License:Apache License
@Before public void setUp() { deframer = new ArmeriaMessageDeframer(listener, MAX_MESSAGE_SIZE, UnpooledByteBufAllocator.DEFAULT) .decompressor(new Gzip()); }
From source file:com.linecorp.armeria.internal.grpc.ArmeriaMessageFramerTest.java
License:Apache License
@Before public void setUp() { framer = new ArmeriaMessageFramer(UnpooledByteBufAllocator.DEFAULT, 1024); }
From source file:com.netflix.hystrix.contrib.rxnetty.metricsstream.HystrixMetricsStreamHandler.java
License:Apache License
@SuppressWarnings("unchecked") private void writeMetric(String json, HttpServerResponse<O> response) { byte[] bytes = json.getBytes(Charset.defaultCharset()); ByteBuf byteBuf = UnpooledByteBufAllocator.DEFAULT.buffer(bytes.length + EXTRA_SPACE); byteBuf.writeBytes(HEADER);/*from w ww. ja v a 2 s. c o m*/ byteBuf.writeBytes(bytes); byteBuf.writeBytes(FOOTER); response.writeAndFlush((O) byteBuf); }
From source file:com.netflix.ribbon.examples.rx.common.RecommendationServiceFallbackHandler.java
License:Apache License
@Override public Observable<ByteBuf> getFallback(HystrixExecutableInfo<?> hystrixInfo, Map<String, Object> requestProperties) { byte[] bytes = Movie.ORANGE_IS_THE_NEW_BLACK.toString().getBytes(Charset.defaultCharset()); ByteBuf byteBuf = UnpooledByteBufAllocator.DEFAULT.buffer(bytes.length); byteBuf.writeBytes(bytes);//from w w w . ja va 2s .c om return Observable.just(byteBuf); }
From source file:com.netflix.ribbon.examples.rx.RxMovieServer.java
License:Apache License
private Observable<Void> handleRecommendationsByUserId(HttpServerRequest<ByteBuf> request, HttpServerResponse<ByteBuf> response) { System.out.println("HTTP request -> recommendations by user id request: " + request.getPath()); final String userId = userIdFromPath(request.getPath()); if (userId == null) { response.setStatus(HttpResponseStatus.BAD_REQUEST); return response.close(); }/*from www .ja va2s . c o m*/ if (!userRecommendations.containsKey(userId)) { response.setStatus(HttpResponseStatus.NOT_FOUND); return response.close(); } StringBuilder builder = new StringBuilder(); for (String movieId : userRecommendations.get(userId)) { System.out.println(" returning: " + movies.get(movieId)); builder.append(movies.get(movieId)).append('\n'); } ByteBuf byteBuf = UnpooledByteBufAllocator.DEFAULT.buffer(); byteBuf.writeBytes(builder.toString().getBytes(Charset.defaultCharset())); response.write(byteBuf); return response.close(); }
From source file:com.netflix.ribbon.examples.rx.RxMovieServer.java
License:Apache License
private Observable<Void> handleRecommendationsBy(HttpServerRequest<ByteBuf> request, HttpServerResponse<ByteBuf> response) { System.out.println(format("HTTP request -> recommendations by multiple criteria: %s?%s", request.getPath(), request.getQueryString()));/*from ww w . ja va 2 s.c o m*/ List<String> category = request.getQueryParameters().get("category"); List<String> ageGroup = request.getQueryParameters().get("ageGroup"); if (category.isEmpty() || ageGroup.isEmpty()) { response.setStatus(HttpResponseStatus.BAD_REQUEST); return response.close(); } boolean any = false; StringBuilder builder = new StringBuilder(); for (Movie movie : movies.values()) { if (movie.getCategory().equals(category.get(0)) && movie.getAgeGroup().equals(ageGroup.get(0))) { System.out.println(" returning: " + movie); builder.append(movie).append('\n'); any = true; } } if (!any) { System.out.println("No movie matched the given criteria:"); for (Movie movie : movies.values()) { System.out.print(" "); System.out.println(movie); } } ByteBuf byteBuf = UnpooledByteBufAllocator.DEFAULT.buffer(); byteBuf.writeBytes(builder.toString().getBytes(Charset.defaultCharset())); response.write(byteBuf); return response.close(); }
From source file:com.schibsted.triathlon.service.RxTestServer.java
License:Apache License
private Observable<Void> handleTest(HttpServerRequest<ByteBuf> request, final HttpServerResponse<ByteBuf> response) { response.setStatus(HttpResponseStatus.OK); ByteBuf byteBuf = UnpooledByteBufAllocator.DEFAULT.buffer(); byteBuf.writeBytes("test".getBytes(Charset.defaultCharset())); response.write(byteBuf);/*from w ww . java 2s .com*/ return response.close(); }
From source file:com.spotify.folsom.client.ascii.RequestTestTemplate.java
License:Apache License
protected void assertRequest(AsciiRequest<?> request, String expectedCmd) { ByteBufAllocator bba = UnpooledByteBufAllocator.DEFAULT; ByteBuffer bb = ByteBuffer.allocate(1024); ByteBuf out = request.writeRequest(bba, bb); byte[] b = new byte[out.readableBytes()]; out.readBytes(b);/*from www. j ava 2s .c om*/ assertEquals(expectedCmd, new String(b)); }
From source file:com.tesora.dve.db.mysql.libmy.ChannelHandlerContextStub.java
License:Open Source License
@Override public ByteBufAllocator alloc() { // TODO Auto-generated method stub return UnpooledByteBufAllocator.DEFAULT; }
From source file:com.tesora.dve.db.mysql.MysqlConnection.java
License:Open Source License
@Override public void connect(String url, final String userid, final String password, final long clientCapabilities) throws PEException { PEUrl peUrl = PEUrl.fromUrlString(url); if (!"mysql".equalsIgnoreCase(peUrl.getSubProtocol())) throw new PEException(MysqlConnection.class.getSimpleName() + " does not support the sub protocol of url \"" + url + "\""); InetSocketAddress serverAddress = new InetSocketAddress(peUrl.getHost(), peUrl.getPort()); final MyBackendDecoder.CharsetDecodeHelper charsetHelper = new CharsetDecodeHelper(); mysqlBootstrap = new Bootstrap(); mysqlBootstrap // .group(inboundChannel.eventLoop()) .channel(NioSocketChannel.class).group(connectionEventGroup) .option(ChannelOption.ALLOCATOR, USE_POOLED_BUFFERS ? PooledByteBufAllocator.DEFAULT : UnpooledByteBufAllocator.DEFAULT) .handler(new ChannelInitializer<Channel>() { @Override/*from w ww .j a v a2s . c o m*/ protected void initChannel(Channel ch) throws Exception { authHandler = new MysqlClientAuthenticationHandler(new UserCredentials(userid, password), clientCapabilities, NativeCharSetCatalogImpl.getDefaultCharSetCatalog(DBType.MYSQL), targetCharset); if (PACKET_LOGGER) ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO)); ch.pipeline().addLast(authHandler) .addLast(MyBackendDecoder.class.getSimpleName(), new MyBackendDecoder(site.getName(), charsetHelper)) .addLast(StreamValve.class.getSimpleName(), new StreamValve()) .addLast(MysqlCommandSenderHandler.class.getSimpleName(), new MysqlCommandSenderHandler(site)); } }); pendingConnection = mysqlBootstrap.connect(serverAddress); // System.out.println("Create connection: Allocated " + totalConnections.incrementAndGet() + ", active " + activeConnections.incrementAndGet()); channel = pendingConnection.channel(); physicalID = UUID.randomUUID(); //TODO: this was moved from execute to connect, which avoids blocking on the execute to be netty friendly, but causes lag on checkout. Should make this event driven like everything else. -sgossard syncToServerConnect(); authHandler.assertAuthenticated(); // channel.closeFuture().addListener(new GenericFutureListener<Future<Void>>() { // @Override // public void operationComplete(Future<Void> future) throws Exception { // System.out.println(channel + " is closed"); // } // }); }