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:org.onosproject.xmpp.core.ctl.XmppServer.java
License:Apache License
private void configureBootstrap(ServerBootstrap bootstrap) { bootstrap.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); bootstrap.option(ChannelOption.SO_RCVBUF, 2048); }
From source file:org.opendaylight.ocpjava.protocol.impl.core.TcpHandler.java
License:Open Source License
/** * Starts server on selected port./*w w w . j av a 2 s .co m*/ */ @Override public void run() { /* * We generally do not perform IO-unrelated tasks, so we want to have * all outstanding tasks completed before the executing thread goes * back into select. * * Any other setting means netty will measure the time it spent selecting * and spend roughly proportional time executing tasks. */ workerGroup.setIoRatio(100); final ChannelFuture f; try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.DEBUG)).childHandler(channelInitializer) .option(ChannelOption.SO_BACKLOG, 128).option(ChannelOption.SO_REUSEADDR, true) //modify to "false" for OCP health-check .childOption(ChannelOption.SO_KEEPALIVE, false).childOption(ChannelOption.TCP_NODELAY, true) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, DEFAULT_WRITE_HIGH_WATERMARK * 1024) .childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, DEFAULT_WRITE_LOW_WATERMARK * 1024) .childOption(ChannelOption.WRITE_SPIN_COUNT, DEFAULT_WRITE_SPIN_COUNT); if (startupAddress != null) { f = b.bind(startupAddress.getHostAddress(), port).sync(); } else { f = b.bind(port).sync(); } } catch (InterruptedException e) { LOG.error("Interrupted while binding port {}", port, e); return; } try { InetSocketAddress isa = (InetSocketAddress) f.channel().localAddress(); address = isa.getHostString(); // Update port, as it may have been specified as 0 this.port = isa.getPort(); LOG.debug("address from tcphandler: {}", address); isOnlineFuture.set(true); LOG.info("RadioHead listener started and ready to accept incoming tcp/tls connections on port: {}", port); f.channel().closeFuture().sync(); } catch (InterruptedException e) { LOG.error("Interrupted while waiting for port {} shutdown", port, e); } finally { shutdown(); } }
From source file:org.opendaylight.ocpjava.protocol.impl.serialization.SerializationFactoryTest.java
License:Open Source License
/** * Test serializer lookup & serialization *///from ww w . ja va2s .c o m @Test public void test() { SerializerRegistry registry = new SerializerRegistryImpl(); registry.init(); SerializationFactory factory = new SerializationFactory(); factory.setSerializerTable(registry); ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer(); HealthCheckInputBuilder healthcheckBuilder = new HealthCheckInputBuilder(); healthcheckBuilder.setMsgType(OcpMsgType.valueOf("HEALTHCHECKREQ")); healthcheckBuilder.setXid((long) 1234); healthcheckBuilder.setTcpLinkMonTimeout(new XsdUnsignedShort(5)); factory.messageToBuffer((short) 1, buffer, healthcheckBuilder.build()); }
From source file:org.opendaylight.ocpjava.protocol.impl.serialization.SerializationFactoryTest.java
License:Open Source License
/** * Test serializer not found scenario/*w w w.j a v a 2s. c o m*/ */ @Test(expected = IllegalStateException.class) public void testNotExistingSerializer() { SerializerRegistry registry = new SerializerRegistryImpl(); registry.init(); SerializationFactory factory = new SerializationFactory(); factory.setSerializerTable(registry); ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer(); HealthCheckInputBuilder healthcheckBuilder = new HealthCheckInputBuilder(); healthcheckBuilder.setMsgType(OcpMsgType.valueOf("HEALTHCHECKREQ")); healthcheckBuilder.setXid((long) 1234); healthcheckBuilder.setTcpLinkMonTimeout(new XsdUnsignedShort(5)); factory.messageToBuffer((short) 22, buffer, healthcheckBuilder.build()); }
From source file:org.opendaylight.openflowjava.protocol.impl.core.OFDatagramPacketEncoder.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext ctx, UdpMessageListenerWrapper wrapper, List<Object> out) throws Exception { LOG.trace("Encoding"); try {/*from w ww . j ava 2s . c o m*/ ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer(); serializationFactory.messageToBuffer(wrapper.getMsg().getVersion(), buffer, wrapper.getMsg()); out.add(new DatagramPacket(buffer, wrapper.getAddress())); } catch (Exception e) { LOG.warn("Message serialization failed: {}", e.getMessage()); Future<Void> newFailedFuture = ctx.newFailedFuture(e); wrapper.getListener().operationComplete(newFailedFuture); return; } }
From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializationFactoryTest.java
License:Open Source License
/** * Test deserializer lookup & deserialization *//*from w ww .j a v a 2 s . com*/ @Test public void test() { DeserializerRegistryImpl registry = new DeserializerRegistryImpl(); registry.init(); DeserializationFactory factory = new DeserializationFactory(); factory.setRegistry(registry); ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer(); buffer.writeByte(0); buffer.writeShort(EncodeConstants.OFHEADER_SIZE); buffer.writeInt(1234); factory.deserialize(buffer, EncodeConstants.OF13_VERSION_ID); assertEquals("Deserialization failed", 0, buffer.readableBytes()); }
From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializationFactoryTest.java
License:Open Source License
/** * Test deserializer lookup & deserialization *///from w ww.j a v a2s . c om @Test(expected = NullPointerException.class) public void testNotExistingDeserializer() { DeserializerRegistryImpl registry = new DeserializerRegistryImpl(); registry.init(); DeserializationFactory factory = new DeserializationFactory(); factory.setRegistry(registry); ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer(); buffer.writeByte(0); buffer.writeShort(EncodeConstants.OFHEADER_SIZE); buffer.writeInt(1234); factory.deserialize(buffer, (short) 0); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.VendorInputMessageFactoryTest.java
License:Open Source License
/** * Tests {@link VendorInputMessageFactory#serialize(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterOfMessage, ByteBuf)} *///from w ww. java 2 s . c o m @Test public void test() { Mockito.when(registry.getSerializer(Matchers.<MessageTypeKey<?>>any())).thenReturn(serializer); VendorInputMessageFactory factory = new VendorInputMessageFactory(); factory.injectSerializerRegistry(registry); ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer(); ExperimenterInputBuilder builder = new ExperimenterInputBuilder(); builder.setVersion((short) EncodeConstants.OF10_VERSION_ID); builder.setXid(12345L); builder.setExperimenter(new ExperimenterId(42L)); builder.setExpType(84L); builder.setExperimenterDataOfChoice(vendorData); ExperimenterInput experimenterInput = builder.build(); Mockito.when(registry.getSerializer(Matchers.<ExperimenterIdSerializerKey<ExperimenterDataOfChoice>>any())) .thenReturn(foundSerializer); factory.serialize(experimenterInput, buffer); Mockito.verify(foundSerializer, Mockito.times(1)).serialize(experimenterInput.getExperimenterDataOfChoice(), buffer); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmArpOpSerializerTest.java
License:Open Source License
/** * Test correct serialization// w w w . java 2 s. co m */ @Test public void testSerialize() { MatchEntryBuilder builder = prepareArpOpMatchEntry(1402); ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer(); serializer.serialize(builder.build(), buffer); checkHeader(buffer, false); assertEquals("Wrong value", 1402, buffer.readUnsignedShort()); assertTrue("Unexpected data", buffer.readableBytes() == 0); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmArpOpSerializerTest.java
License:Open Source License
/** * Test correct header serialization// www .ja v a2 s. co m */ @Test public void testSerializeHeader() { MatchEntryBuilder builder = prepareArpOpHeader(false); ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer(); serializer.serializeHeader(builder.build(), buffer); checkHeader(buffer, false); assertTrue("Unexpected data", buffer.readableBytes() == 0); }