org.jboss.netty.channel.ChannelException Java Examples
The following examples show how to use
org.jboss.netty.channel.ChannelException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestFrameDecoder.java From big-c with Apache License 2.0 | 6 votes |
private static int startRpcServer(boolean allowInsecurePorts) { Random rand = new Random(); int serverPort = 30000 + rand.nextInt(10000); int retries = 10; // A few retries in case initial choice is in use. while (true) { try { RpcProgram program = new TestFrameDecoder.TestRpcProgram("TestRpcProgram", "localhost", serverPort, 100000, 1, 2, allowInsecurePorts); SimpleTcpServer tcpServer = new SimpleTcpServer(serverPort, program, 1); tcpServer.run(); break; // Successfully bound a port, break out. } catch (ChannelException ce) { if (retries-- > 0) { serverPort += rand.nextInt(20); // Port in use? Try another. } else { throw ce; // Out of retries. } } } return serverPort; }
Example #2
Source File: TestFrameDecoder.java From hadoop with Apache License 2.0 | 6 votes |
private static int startRpcServer(boolean allowInsecurePorts) { Random rand = new Random(); int serverPort = 30000 + rand.nextInt(10000); int retries = 10; // A few retries in case initial choice is in use. while (true) { try { RpcProgram program = new TestFrameDecoder.TestRpcProgram("TestRpcProgram", "localhost", serverPort, 100000, 1, 2, allowInsecurePorts); SimpleTcpServer tcpServer = new SimpleTcpServer(serverPort, program, 1); tcpServer.run(); break; // Successfully bound a port, break out. } catch (ChannelException ce) { if (retries-- > 0) { serverPort += rand.nextInt(20); // Port in use? Try another. } else { throw ce; // Out of retries. } } } return serverPort; }
Example #3
Source File: NettyMapOutputHttpServer.java From RDFS with Apache License 2.0 | 6 votes |
public synchronized int start(ChannelPipelineFactory pipelineFactory) { ServerBootstrap bootstrap = new ServerBootstrap(channelFactory); bootstrap.setPipelineFactory(pipelineFactory); // Try to bind to a port. If the port is 0, netty will select a port. int bindAttempt = 0; while (bindAttempt < DEFAULT_BIND_ATTEMPT_MAX) { try { InetSocketAddress address = new InetSocketAddress(port); Channel ch = bootstrap.bind(address); accepted.add(ch); port = ((InetSocketAddress) ch.getLocalAddress()).getPort(); break; } catch (ChannelException e) { LOG.warn("start: Likely failed to bind on attempt " + bindAttempt + " to port " + port, e); // Only increment the port number when set by the user if (port != 0) { ++port; } ++bindAttempt; } } LOG.info(this.getClass() + " is listening on port " + port); return port; }
Example #4
Source File: DefaultSocketChannelConfig.java From android-netty with Apache License 2.0 | 5 votes |
public void setReuseAddress(boolean reuseAddress) { try { socket.setReuseAddress(reuseAddress); } catch (SocketException e) { throw new ChannelException(e); } }
Example #5
Source File: DefaultSocketChannelConfig.java From android-netty with Apache License 2.0 | 5 votes |
public int getTrafficClass() { try { return socket.getTrafficClass(); } catch (SocketException e) { throw new ChannelException(e); } }
Example #6
Source File: DefaultSocketChannelConfig.java From android-netty with Apache License 2.0 | 5 votes |
public boolean isKeepAlive() { try { return socket.getKeepAlive(); } catch (SocketException e) { throw new ChannelException(e); } }
Example #7
Source File: DefaultSocketChannelConfig.java From android-netty with Apache License 2.0 | 5 votes |
public boolean isReuseAddress() { try { return socket.getReuseAddress(); } catch (SocketException e) { throw new ChannelException(e); } }
Example #8
Source File: DefaultSocketChannelConfig.java From android-netty with Apache License 2.0 | 5 votes |
public boolean isTcpNoDelay() { try { return socket.getTcpNoDelay(); } catch (SocketException e) { throw new ChannelException(e); } }
Example #9
Source File: DefaultSocketChannelConfig.java From android-netty with Apache License 2.0 | 5 votes |
public void setKeepAlive(boolean keepAlive) { try { socket.setKeepAlive(keepAlive); } catch (SocketException e) { throw new ChannelException(e); } }
Example #10
Source File: DefaultSocketChannelConfig.java From android-netty with Apache License 2.0 | 5 votes |
public void setReceiveBufferSize(int receiveBufferSize) { try { socket.setReceiveBufferSize(receiveBufferSize); } catch (SocketException e) { throw new ChannelException(e); } }
Example #11
Source File: DefaultSocketChannelConfig.java From android-netty with Apache License 2.0 | 5 votes |
public int getSendBufferSize() { try { return socket.getSendBufferSize(); } catch (SocketException e) { throw new ChannelException(e); } }
Example #12
Source File: DefaultSocketChannelConfig.java From android-netty with Apache License 2.0 | 5 votes |
public void setSendBufferSize(int sendBufferSize) { try { socket.setSendBufferSize(sendBufferSize); } catch (SocketException e) { throw new ChannelException(e); } }
Example #13
Source File: DefaultSocketChannelConfig.java From android-netty with Apache License 2.0 | 5 votes |
public void setSoLinger(int soLinger) { try { if (soLinger < 0) { socket.setSoLinger(false, 0); } else { socket.setSoLinger(true, soLinger); } } catch (SocketException e) { throw new ChannelException(e); } }
Example #14
Source File: DefaultSocketChannelConfig.java From android-netty with Apache License 2.0 | 5 votes |
public void setTcpNoDelay(boolean tcpNoDelay) { try { socket.setTcpNoDelay(tcpNoDelay); } catch (SocketException e) { throw new ChannelException(e); } }
Example #15
Source File: DefaultSocketChannelConfig.java From android-netty with Apache License 2.0 | 5 votes |
public void setTrafficClass(int trafficClass) { try { socket.setTrafficClass(trafficClass); } catch (SocketException e) { throw new ChannelException(e); } }
Example #16
Source File: NioWorker.java From android-netty with Apache License 2.0 | 5 votes |
public void run() { SocketAddress localAddress = channel.getLocalAddress(); SocketAddress remoteAddress = channel.getRemoteAddress(); if (localAddress == null || remoteAddress == null) { if (future != null) { future.setFailure(new ClosedChannelException()); } close(channel, succeededFuture(channel)); return; } try { if (server) { channel.channel.configureBlocking(false); } channel.channel.register(selector, channel.getRawInterestOps(), channel); if (future != null) { channel.setConnected(); future.setSuccess(); } if (server || !((NioClientSocketChannel) channel).boundManually) { fireChannelBound(channel, localAddress); } fireChannelConnected(channel, remoteAddress); } catch (IOException e) { if (future != null) { future.setFailure(e); } close(channel, succeededFuture(channel)); if (!(e instanceof ClosedChannelException)) { throw new ChannelException("Failed to register a socket to the selector.", e); } } }
Example #17
Source File: DefaultNioSocketChannelConfig.java From android-netty with Apache License 2.0 | 5 votes |
public ReceiveBufferSizePredictor getReceiveBufferSizePredictor() { ReceiveBufferSizePredictor predictor = this.predictor; if (predictor == null) { try { this.predictor = predictor = getReceiveBufferSizePredictorFactory().getPredictor(); } catch (Exception e) { throw new ChannelException("Failed to create a new " + ReceiveBufferSizePredictor.class.getSimpleName() + '.', e); } } return predictor; }
Example #18
Source File: DefaultSocketChannelConfig.java From android-netty with Apache License 2.0 | 5 votes |
public int getSoLinger() { try { return socket.getSoLinger(); } catch (SocketException e) { throw new ChannelException(e); } }
Example #19
Source File: DefaultSocketChannelConfig.java From android-netty with Apache License 2.0 | 5 votes |
public int getReceiveBufferSize() { try { return socket.getReceiveBufferSize(); } catch (SocketException e) { throw new ChannelException(e); } }
Example #20
Source File: BgpSessionManager.java From onos with Apache License 2.0 | 5 votes |
public void start() { log.debug("BGP Session Manager start."); isShutdown = false; ChannelFactory channelFactory = new NioServerSocketChannelFactory( newCachedThreadPool(groupedThreads("onos/bgp", "sm-boss-%d", log)), newCachedThreadPool(groupedThreads("onos/bgp", "sm-worker-%d", log))); ChannelPipelineFactory pipelineFactory = () -> { // Allocate a new session per connection BgpSession bgpSessionHandler = new BgpSession(BgpSessionManager.this); BgpFrameDecoder bgpFrameDecoder = new BgpFrameDecoder(bgpSessionHandler); // Setup the processing pipeline ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("BgpFrameDecoder", bgpFrameDecoder); pipeline.addLast("BgpSession", bgpSessionHandler); return pipeline; }; InetSocketAddress listenAddress = new InetSocketAddress(bgpPort); serverBootstrap = new ServerBootstrap(channelFactory); // serverBootstrap.setOptions("reuseAddr", true); serverBootstrap.setOption("child.keepAlive", true); serverBootstrap.setOption("child.tcpNoDelay", true); serverBootstrap.setPipelineFactory(pipelineFactory); try { serverChannel = serverBootstrap.bind(listenAddress); allChannels.add(serverChannel); } catch (ChannelException e) { log.debug("Exception binding to BGP port {}: ", listenAddress.getPort(), e); } }
Example #21
Source File: FpmManager.java From onos with Apache License 2.0 | 5 votes |
private void startServer() { HashedWheelTimer timer = new HashedWheelTimer( groupedThreads("onos/fpm", "fpm-timer-%d", log)); ChannelFactory channelFactory = new NioServerSocketChannelFactory( newCachedThreadPool(groupedThreads("onos/fpm", "sm-boss-%d", log)), newCachedThreadPool(groupedThreads("onos/fpm", "sm-worker-%d", log))); ChannelPipelineFactory pipelineFactory = () -> { // Allocate a new session per connection IdleStateHandler idleHandler = new IdleStateHandler(timer, IDLE_TIMEOUT_SECS, 0, 0); FpmSessionHandler fpmSessionHandler = new FpmSessionHandler(this, new InternalFpmListener()); FpmFrameDecoder fpmFrameDecoder = new FpmFrameDecoder(); // Setup the processing pipeline ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("FpmFrameDecoder", fpmFrameDecoder); pipeline.addLast("idle", idleHandler); pipeline.addLast("FpmSession", fpmSessionHandler); return pipeline; }; InetSocketAddress listenAddress = new InetSocketAddress(FPM_PORT); serverBootstrap = new ServerBootstrap(channelFactory); serverBootstrap.setOption("child.reuseAddr", true); serverBootstrap.setOption("child.keepAlive", true); serverBootstrap.setOption("child.tcpNoDelay", true); serverBootstrap.setPipelineFactory(pipelineFactory); try { serverChannel = serverBootstrap.bind(listenAddress); allChannels.add(serverChannel); } catch (ChannelException e) { log.debug("Exception binding to FPM port {}: ", listenAddress.getPort(), e); stopServer(); } }
Example #22
Source File: TestLegacyAvroSource.java From mt-flume with Apache License 2.0 | 5 votes |
@Test public void testLifecycle() throws InterruptedException { boolean bound = false; for (int i = 0; i < 100 && !bound; i++) { try { Context context = new Context(); context.put("port", String.valueOf(selectedPort = 41414 + i)); context.put("host", "0.0.0.0"); Configurables.configure(source, context); source.start(); bound = true; } catch (ChannelException e) { // Assume port in use, try another one } } Assert .assertTrue("Reached start or error", LifecycleController.waitForOneOf( source, LifecycleState.START_OR_ERROR)); Assert.assertEquals("Server is started", LifecycleState.START, source.getLifecycleState()); source.stop(); Assert.assertTrue("Reached stop or error", LifecycleController.waitForOneOf(source, LifecycleState.STOP_OR_ERROR)); Assert.assertEquals("Server is stopped", LifecycleState.STOP, source.getLifecycleState()); }
Example #23
Source File: TestAvroSource.java From mt-flume with Apache License 2.0 | 5 votes |
@Test public void testLifecycle() throws InterruptedException { boolean bound = false; for (int i = 0; i < 100 && !bound; i++) { try { Context context = new Context(); context.put("port", String.valueOf(selectedPort = 41414 + i)); context.put("bind", "0.0.0.0"); Configurables.configure(source, context); source.start(); bound = true; } catch (ChannelException e) { /* * NB: This assume we're using the Netty server under the hood and the * failure is to bind. Yucky. */ } } Assert .assertTrue("Reached start or error", LifecycleController.waitForOneOf( source, LifecycleState.START_OR_ERROR)); Assert.assertEquals("Server is started", LifecycleState.START, source.getLifecycleState()); source.stop(); Assert.assertTrue("Reached stop or error", LifecycleController.waitForOneOf(source, LifecycleState.STOP_OR_ERROR)); Assert.assertEquals("Server is stopped", LifecycleState.STOP, source.getLifecycleState()); }
Example #24
Source File: DefaultPinpointClientHandler.java From pinpoint with Apache License 2.0 | 5 votes |
private ChannelFuture write0(Object message) { if (channel.isWritable()) { return channel.write(message); } else { return Channels.failedFuture(channel, new ChannelException(WRITE_BUFFER_FULL_MESSAGE)); } }
Example #25
Source File: TestLegacyAvroSource.java From mt-flume with Apache License 2.0 | 4 votes |
@Test public void testRequest() throws InterruptedException, IOException { boolean bound = false; int i; for (i = 0; i < 100 && !bound; i++) { try { Context context = new Context(); context.put("port", String.valueOf(selectedPort = 41414 + i)); context.put("host", "0.0.0.0"); Configurables.configure(source, context); source.start(); bound = true; } catch (ChannelException e) { // Assume port in use, try another one } } Assert .assertTrue("Reached start or error", LifecycleController.waitForOneOf( source, LifecycleState.START_OR_ERROR)); Assert.assertEquals("Server is started", LifecycleState.START, source.getLifecycleState()); // setup a requester, to send a flume OG event URL url = new URL("http", "0.0.0.0", selectedPort, "/"); Transceiver http = new HttpTransceiver(url); FlumeOGEventAvroServer client = SpecificRequestor.getClient( FlumeOGEventAvroServer.class, http); AvroFlumeOGEvent avroEvent = AvroFlumeOGEvent.newBuilder().setHost("foo"). setPriority(Priority.INFO).setNanos(0).setTimestamp(1). setFields(new HashMap<CharSequence, ByteBuffer> ()). setBody(ByteBuffer.wrap("foo".getBytes())).build(); client.append(avroEvent); // check if the even has arrived in the channel through OG avro source Transaction transaction = channel.getTransaction(); transaction.begin(); Event event = channel.take(); Assert.assertNotNull(event); Assert.assertEquals("Channel contained our event", "foo", new String(event.getBody())); transaction.commit(); transaction.close(); source.stop(); Assert.assertTrue("Reached stop or error", LifecycleController.waitForOneOf(source, LifecycleState.STOP_OR_ERROR)); Assert.assertEquals("Server is stopped", LifecycleState.STOP, source.getLifecycleState()); }
Example #26
Source File: TestAvroSource.java From mt-flume with Apache License 2.0 | 4 votes |
@Test public void testSslRequest() throws InterruptedException, IOException { boolean bound = false; for (int i = 0; i < 10 && !bound; i++) { try { Context context = new Context(); context.put("port", String.valueOf(selectedPort = 41414 + i)); context.put("bind", "0.0.0.0"); context.put("ssl", "true"); context.put("keystore", "src/test/resources/server.p12"); context.put("keystore-password", "password"); context.put("keystore-type", "PKCS12"); Configurables.configure(source, context); source.start(); bound = true; } catch (ChannelException e) { /* * NB: This assume we're using the Netty server under the hood and the * failure is to bind. Yucky. */ Thread.sleep(100); } } Assert .assertTrue("Reached start or error", LifecycleController.waitForOneOf( source, LifecycleState.START_OR_ERROR)); Assert.assertEquals("Server is started", LifecycleState.START, source.getLifecycleState()); AvroSourceProtocol client = SpecificRequestor.getClient( AvroSourceProtocol.class, new NettyTransceiver(new InetSocketAddress( selectedPort), new SSLChannelFactory())); AvroFlumeEvent avroEvent = new AvroFlumeEvent(); avroEvent.setHeaders(new HashMap<CharSequence, CharSequence>()); avroEvent.setBody(ByteBuffer.wrap("Hello avro ssl".getBytes())); Status status = client.append(avroEvent); Assert.assertEquals(Status.OK, status); Transaction transaction = channel.getTransaction(); transaction.begin(); Event event = channel.take(); Assert.assertNotNull(event); Assert.assertEquals("Channel contained our event", "Hello avro ssl", new String(event.getBody())); transaction.commit(); transaction.close(); logger.debug("Round trip event:{}", event); source.stop(); Assert.assertTrue("Reached stop or error", LifecycleController.waitForOneOf(source, LifecycleState.STOP_OR_ERROR)); Assert.assertEquals("Server is stopped", LifecycleState.STOP, source.getLifecycleState()); }
Example #27
Source File: TestAvroSource.java From mt-flume with Apache License 2.0 | 4 votes |
private void doRequest(boolean serverEnableCompression, boolean clientEnableCompression, int compressionLevel) throws InterruptedException, IOException { boolean bound = false; for (int i = 0; i < 100 && !bound; i++) { try { Context context = new Context(); context.put("port", String.valueOf(selectedPort = 41414 + i)); context.put("bind", "0.0.0.0"); context.put("threads", "50"); if (serverEnableCompression) { context.put("compression-type", "deflate"); } else { context.put("compression-type", "none"); } Configurables.configure(source, context); source.start(); bound = true; } catch (ChannelException e) { /* * NB: This assume we're using the Netty server under the hood and the * failure is to bind. Yucky. */ } } Assert .assertTrue("Reached start or error", LifecycleController.waitForOneOf( source, LifecycleState.START_OR_ERROR)); Assert.assertEquals("Server is started", LifecycleState.START, source.getLifecycleState()); AvroSourceProtocol client; if (clientEnableCompression) { client = SpecificRequestor.getClient( AvroSourceProtocol.class, new NettyTransceiver(new InetSocketAddress( selectedPort), new CompressionChannelFactory(6))); } else { client = SpecificRequestor.getClient( AvroSourceProtocol.class, new NettyTransceiver(new InetSocketAddress( selectedPort))); } AvroFlumeEvent avroEvent = new AvroFlumeEvent(); avroEvent.setHeaders(new HashMap<CharSequence, CharSequence>()); avroEvent.setBody(ByteBuffer.wrap("Hello avro".getBytes())); Status status = client.append(avroEvent); Assert.assertEquals(Status.OK, status); Transaction transaction = channel.getTransaction(); transaction.begin(); Event event = channel.take(); Assert.assertNotNull(event); Assert.assertEquals("Channel contained our event", "Hello avro", new String(event.getBody())); transaction.commit(); transaction.close(); logger.debug("Round trip event:{}", event); source.stop(); Assert.assertTrue("Reached stop or error", LifecycleController.waitForOneOf(source, LifecycleState.STOP_OR_ERROR)); Assert.assertEquals("Server is stopped", LifecycleState.STOP, source.getLifecycleState()); }
Example #28
Source File: DistributedLogClientImpl.java From distributedlog with Apache License 2.0 | 4 votes |
void handleRequestException(SocketAddress addr, ProxyClient sc, Optional<StreamOp> op, Throwable cause) { boolean resendOp = false; boolean removeOwnerFromStream = false; SocketAddress previousAddr = addr; String reason = cause.getMessage(); if (cause instanceof ConnectionFailedException || cause instanceof java.net.ConnectException) { routingService.removeHost(addr, cause); onServerLeft(addr, sc); removeOwnerFromStream = true; // redirect the request to other host. resendOp = true; } else if (cause instanceof ChannelException) { // java.net.ConnectException typically means connection is refused remotely // no process listening on remote address/port. if (cause.getCause() instanceof java.net.ConnectException) { routingService.removeHost(addr, cause.getCause()); onServerLeft(addr); reason = cause.getCause().getMessage(); } else { routingService.removeHost(addr, cause); reason = cause.getMessage(); } removeOwnerFromStream = true; // redirect the request to other host. resendOp = true; } else if (cause instanceof ServiceTimeoutException) { // redirect the request to itself again, which will backoff for a while resendOp = true; previousAddr = null; } else if (cause instanceof WriteException) { // redirect the request to other host. resendOp = true; } else if (cause instanceof ServiceException) { // redirect the request to other host. clientManager.removeClient(addr, sc); resendOp = true; } else if (cause instanceof TApplicationException) { handleTApplicationException(cause, op, addr, sc); } else if (cause instanceof Failure) { handleFinagleFailure((Failure) cause, op, addr); } else { // Default handler handleException(cause, op, addr); } if (op.isPresent()) { if (removeOwnerFromStream) { ownershipCache.removeOwnerFromStream(op.get().stream, addr, reason); } if (resendOp) { doSend(op.get(), previousAddr); } } }
Example #29
Source File: DistributedLogClientImpl.java From distributedlog with Apache License 2.0 | 4 votes |
void handleRequestException(SocketAddress addr, ProxyClient sc, Optional<StreamOp> op, Throwable cause) { boolean resendOp = false; boolean removeOwnerFromStream = false; SocketAddress previousAddr = addr; String reason = cause.getMessage(); if (cause instanceof ConnectionFailedException || cause instanceof java.net.ConnectException) { routingService.removeHost(addr, cause); onServerLeft(addr, sc); removeOwnerFromStream = true; // redirect the request to other host. resendOp = true; } else if (cause instanceof ChannelException) { // java.net.ConnectException typically means connection is refused remotely // no process listening on remote address/port. if (cause.getCause() instanceof java.net.ConnectException) { routingService.removeHost(addr, cause.getCause()); onServerLeft(addr); reason = cause.getCause().getMessage(); } else { routingService.removeHost(addr, cause); reason = cause.getMessage(); } removeOwnerFromStream = true; // redirect the request to other host. resendOp = true; } else if (cause instanceof ServiceTimeoutException) { // redirect the request to itself again, which will backoff for a while resendOp = true; previousAddr = null; } else if (cause instanceof WriteException) { // redirect the request to other host. resendOp = true; } else if (cause instanceof ServiceException) { // redirect the request to other host. clientManager.removeClient(addr, sc); resendOp = true; } else if (cause instanceof TApplicationException) { handleTApplicationException(cause, op, addr, sc); } else if (cause instanceof Failure) { handleFinagleFailure((Failure) cause, op, addr); } else { // Default handler handleException(cause, op, addr); } if (op.isPresent()) { if (removeOwnerFromStream) { ownershipCache.removeOwnerFromStream(op.get().stream, addr, reason); } if (resendOp) { doSend(op.get(), previousAddr); } } }
Example #30
Source File: TestTSOChannelHandlerNetty.java From phoenix-omid with Apache License 2.0 | 4 votes |
@Test(timeOut = 10_000) public void testMainAPI() throws Exception { // Check initial state assertNull(channelHandler.listeningChannel); assertNull(channelHandler.channelGroup); // Check initial connection channelHandler.reconnect(); assertTrue(channelHandler.listeningChannel.isOpen()); assertEquals(channelHandler.channelGroup.size(), 1); assertEquals(((InetSocketAddress) channelHandler.listeningChannel.getLocalAddress()).getPort(), 1434); // Check connection close channelHandler.closeConnection(); assertFalse(channelHandler.listeningChannel.isOpen()); assertEquals(channelHandler.channelGroup.size(), 0); // Check re-closing connection channelHandler.closeConnection(); assertFalse(channelHandler.listeningChannel.isOpen()); assertEquals(channelHandler.channelGroup.size(), 0); // Check connection after closing channelHandler.reconnect(); assertTrue(channelHandler.listeningChannel.isOpen()); assertEquals(channelHandler.channelGroup.size(), 1); // Check re-connection channelHandler.reconnect(); assertTrue(channelHandler.listeningChannel.isOpen()); assertEquals(channelHandler.channelGroup.size(), 1); // Exercise closeable with re-connection trial channelHandler.close(); assertFalse(channelHandler.listeningChannel.isOpen()); assertEquals(channelHandler.channelGroup.size(), 0); try { channelHandler.reconnect(); } catch (ChannelException e) { // Expected: Can't reconnect after closing assertFalse(channelHandler.listeningChannel.isOpen()); assertEquals(channelHandler.channelGroup.size(), 0); } }