protected static Transceiver initializeTransceiver(int serverPort) throws IOException { return new NettyTransceiver(new InetSocketAddress( serverPort), CONNECT_TIMEOUT_MILLIS); }
/** * Closes this transceiver and disconnects from the remote peer. * Cancels all pending RPCs, sends an IOException to all pending callbacks, * and blocks until the close has completed. */ @Override public void close() { close(true); }
/** * Creates a NettyTransceiver, and attempts to connect to the given address. * {@link #DEFAULT_CONNECTION_TIMEOUT_MILLIS} is used for the connection * timeout. * @param addr the address to connect to. * @param channelFactory the factory to use to create a new Netty Channel. * @throws IOException if an error occurs connecting to the given address. */ public NettyTransceiver(InetSocketAddress addr, ChannelFactory channelFactory) throws IOException { this(addr, channelFactory, buildDefaultBootstrapOptions(null)); }
final NettyTransceiver transceiver = new NettyTransceiver(new InetSocketAddress(serverPort), 60000L); final Mail mail = SpecificRequestor.getClient(Mail.class, transceiver); quitOnFailure.set(true); now = System.currentTimeMillis(); transceiver.close(); // Without the patch, this close seems to hang forever
@Override public ChannelPipeline getPipeline() throws Exception { ChannelPipeline p = Channels.pipeline(); p.addLast("frameDecoder", new NettyFrameDecoder()); p.addLast("frameEncoder", new NettyFrameEncoder()); p.addLast("handler", createNettyClientAvroHandler()); return p; } });
public static void main(String[] args) throws IOException { if (args.length != 3) { System.out.println("Usage: <to> <from> <body>"); System.exit(1); } logger.info("Starting Server"); // usually this would be another app, but for simplicity startServer(); logger.info("Server started"); NettyTransceiver client = new NettyTransceiver(new InetSocketAddress(65333)); // client code - attach to the server and send a message EmailSender proxy = SpecificRequestor.getClient(EmailSender.class, client); logger.info("Client built, got proxy"); // fill in the Message record and send it EmailMessage message = new EmailMessage(); message.setTo(new Utf8(args[0])); message.setFrom(new Utf8(args[1])); message.setBody(new Utf8(args[2])); logger.info("Calling proxy.send with message: {} ", message.toString()); logger.info("Result: {}", proxy.send(message)); // cleanup client.close(); server.close(); } }
@Override public ChannelPipeline getPipeline() throws Exception { ChannelPipeline p = Channels.pipeline(); p.addLast("frameDecoder", new NettyFrameDecoder()); p.addLast("frameEncoder", new NettyFrameEncoder()); p.addLast("handler", createNettyClientAvroHandler()); return p; } });
@Override public Transceiver createTransceiver() throws Exception{ return new NettyTransceiver(new InetSocketAddress(server.getPort()), 2000L); }
/** * Closes this transceiver and disconnects from the remote peer. * Cancels all pending RPCs, sends an IOException to all pending callbacks, * and blocks until the close has completed. */ @Override public void close() { close(true); }
/** * Creates a NettyTransceiver, and attempts to connect to the given address. * @param addr the address to connect to. * @param channelFactory the factory to use to create a new Netty Channel. * @param connectTimeoutMillis maximum amount of time to wait for connection * establishment in milliseconds, or null to use * {@link #DEFAULT_CONNECTION_TIMEOUT_MILLIS}. * @throws IOException if an error occurs connecting to the given address. */ public NettyTransceiver(InetSocketAddress addr, ChannelFactory channelFactory, Long connectTimeoutMillis) throws IOException { this(addr, channelFactory, buildDefaultBootstrapOptions(connectTimeoutMillis)); }
protected static Transceiver initializeTransceiver(int serverPort) throws IOException { return new NettyTransceiver(new InetSocketAddress(serverPort), new SSLChannelFactory(), CONNECT_TIMEOUT_MILLIS); }
nettyTransceiver.close(); updateExecutor.shutdownNow();
/** * Creates a NettyTransceiver, and attempts to connect to the given address. * {@link #DEFAULT_CONNECTION_TIMEOUT_MILLIS} is used for the connection * timeout. * @param addr the address to connect to. * @param channelFactory the factory to use to create a new Netty Channel. * @throws IOException if an error occurs connecting to the given address. */ public NettyTransceiver(InetSocketAddress addr, ChannelFactory channelFactory) throws IOException { this(addr, channelFactory, buildDefaultBootstrapOptions(null)); }
protected static Transceiver initializeTransceiver(int serverPort) throws IOException { return new NettyTransceiver(new InetSocketAddress(serverPort), new CompressionChannelFactory(), CONNECT_TIMEOUT_MILLIS); }
/** * Creates a NettyTransceiver, and attempts to connect to the given address. * @param addr the address to connect to. * @param channelFactory the factory to use to create a new Netty Channel. * @param connectTimeoutMillis maximum amount of time to wait for connection * establishment in milliseconds, or null to use * {@link #DEFAULT_CONNECTION_TIMEOUT_MILLIS}. * @throws IOException if an error occurs connecting to the given address. */ public NettyTransceiver(InetSocketAddress addr, ChannelFactory channelFactory, Long connectTimeoutMillis) throws IOException { this(addr, channelFactory, buildDefaultBootstrapOptions(connectTimeoutMillis)); }
@BeforeClass public static void initializeConnections() throws Exception { // start server Responder responder = new SpecificResponder(Simple.class, simpleService); server = new NettyServer(responder, new InetSocketAddress(0)); server.start(); int serverPort = server.getPort(); System.out.println("server port : " + serverPort); transceiver = new NettyTransceiver(new InetSocketAddress( serverPort), TestNettyServer.CONNECT_TIMEOUT_MILLIS); simpleClient = SpecificRequestor.getClient(Simple.Callback.class, transceiver); }
transceiver = new NettyTransceiver(this.address, socketChannelFactory, tu.toMillis(timeout));
@Test(expected = IOException.class) public void testNettyTransceiverReleasesNettyChannelOnFailingToConnect() throws Exception { ServerSocket serverSocket = null; LastChannelRememberingChannelFactory socketChannelFactory = null; try { serverSocket = new ServerSocket(0); socketChannelFactory = new LastChannelRememberingChannelFactory(); try { new NettyTransceiver( new InetSocketAddress(serverSocket.getLocalPort()), socketChannelFactory, 1L ); } finally { assertEquals("expected that the channel opened by the transceiver is closed", false, socketChannelFactory.lastChannel.isOpen()); } } finally { if (serverSocket != null) { // closing the server socket will actually free up the open channel in the // transceiver, which would have hung otherwise (pre AVRO-1407) serverSocket.close(); } if (socketChannelFactory != null) { socketChannelFactory.releaseExternalResources(); } } }
System.out.println("server2 port : " + serverPort); transceiver2 = new NettyTransceiver(new InetSocketAddress( serverPort), TestNettyServer.CONNECT_TIMEOUT_MILLIS);
@Test public void testConnectionsCount() throws Exception { Transceiver transceiver2 = new NettyTransceiver(new InetSocketAddress( server.getPort()), CONNECT_TIMEOUT_MILLIS); Mail proxy2 = SpecificRequestor.getClient(Mail.class, transceiver2); proxy.fireandforget(createMessage()); proxy2.fireandforget(createMessage()); Assert.assertEquals(2, ((NettyServer) server).getNumActiveConnections()); transceiver2.close(); // Check the active connections with some retries as closing at the client // side might not take effect on the server side immediately int numActiveConnections = ((NettyServer) server).getNumActiveConnections(); for (int i = 0; i < 50 && numActiveConnections == 2; ++i) { System.out.println("Server still has 2 active connections; retrying..."); Thread.sleep(100); numActiveConnections = ((NettyServer) server).getNumActiveConnections(); } Assert.assertEquals(1, numActiveConnections); }