当前位置: 首页>>代码示例>>Java>>正文


Java ChannelException类代码示例

本文整理汇总了Java中org.jboss.netty.channel.ChannelException的典型用法代码示例。如果您正苦于以下问题:Java ChannelException类的具体用法?Java ChannelException怎么用?Java ChannelException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ChannelException类属于org.jboss.netty.channel包,在下文中一共展示了ChannelException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: startRpcServer

import org.jboss.netty.channel.ChannelException; //导入依赖的package包/类
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;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:23,代码来源:TestFrameDecoder.java

示例2: start

import org.jboss.netty.channel.ChannelException; //导入依赖的package包/类
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;
}
 
开发者ID:iVCE,项目名称:RDFS,代码行数:27,代码来源:NettyMapOutputHttpServer.java

示例3: testNewChannel_forwardsWrappedFactoryFailure

import org.jboss.netty.channel.ChannelException; //导入依赖的package包/类
@Test
public void testNewChannel_forwardsWrappedFactoryFailure() {
	final ChannelException innerException = new ChannelException();
	mockContext.checking(new Expectations() {
		{
			one(realChannelFactory).newChannel(
					with(any(ChannelPipeline.class)));
			will(throwException(innerException));
		}
	});

	try {
		factory.newChannel(Channels.pipeline(new SimpleChannelHandler()));
		fail("Expected ChannelException");
	} catch (ChannelException e) {
		assertSame(innerException, e);
	}
}
 
开发者ID:reines,项目名称:httptunnel,代码行数:19,代码来源:HttpTunnelServerChannelFactoryTest.java

示例4: testLifecycle

import org.jboss.netty.channel.ChannelException; //导入依赖的package包/类
@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());
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:36,代码来源:TestAvroSource.java

示例5: startSource

import org.jboss.netty.channel.ChannelException; //导入依赖的package包/类
private void startSource(String encoding, String ack, String batchSize, String maxLineLength)
    throws InterruptedException {
  boolean bound = false;

  for (int i = 0; i < 100 && !bound; i++) {
    try {
      Context context = new Context();
      context.put("port", String.valueOf(selectedPort = 10500 + i));
      context.put("bind", "0.0.0.0");
      context.put("ack-every-event", ack);
      context.put("encoding", encoding);
      context.put("batch-size", batchSize);
      context.put("max-line-length", maxLineLength);

      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());
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:32,代码来源:TestNetcatSource.java

示例6: testLifecycle

import org.jboss.netty.channel.ChannelException; //导入依赖的package包/类
@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());
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:33,代码来源:TestLegacyAvroSource.java

示例7: startServer

import org.jboss.netty.channel.ChannelException; //导入依赖的package包/类
private void startServer() {
    ChannelFactory channelFactory = new NioServerSocketChannelFactory(
            newCachedThreadPool(groupedThreads("onos/fpm", "sm-boss-%d")),
            newCachedThreadPool(groupedThreads("onos/fpm", "sm-worker-%d")));
    ChannelPipelineFactory pipelineFactory = () -> {
        // Allocate a new session per connection
        FpmSessionHandler fpmSessionHandler =
                new FpmSessionHandler(new InternalFpmListener());
        FpmFrameDecoder fpmFrameDecoder =
                new FpmFrameDecoder();

        // Setup the processing pipeline
        ChannelPipeline pipeline = Channels.pipeline();
        pipeline.addLast("FpmFrameDecoder", fpmFrameDecoder);
        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();
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:35,代码来源:FpmManager.java

示例8: start

import org.jboss.netty.channel.ChannelException; //导入依赖的package包/类
public void start() {
    log.debug("BGP Session Manager start.");
    isShutdown = false;

    ChannelFactory channelFactory = new NioServerSocketChannelFactory(
            newCachedThreadPool(groupedThreads("onos/bgp", "sm-boss-%d")),
            newCachedThreadPool(groupedThreads("onos/bgp", "sm-worker-%d")));
    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);
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:37,代码来源:BgpSessionManager.java

示例9: start_failsWhenCantBindPort

import org.jboss.netty.channel.ChannelException; //导入依赖的package包/类
@Test
public void start_failsWhenCantBindPort() {
  thrown.expect(ChannelException.class);
  thrown.expectMessage("Failed to bind to: 0.0.0.0/0.0.0.0:12345");

  ScribeCollector.Builder builder =
      ScribeCollector.builder().storage(new InMemoryStorage()).port(12345);

  try (ScribeCollector first = builder.build().start()) {
    try (ScribeCollector samePort = builder.build().start()) {
    }
  }
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:14,代码来源:ScribeCollectorTest.java

示例10: createRpcService

import org.jboss.netty.channel.ChannelException; //导入依赖的package包/类
/**
 * Utility method to create RPC service from configuration and hostname, port.
 *
 * @param hostname   The hostname/address that describes the TaskManager's data location.
 * @param port           If true, the TaskManager will not initiate the TCP network stack.
 * @param configuration                 The configuration for the TaskManager.
 * @return   The rpc service which is used to start and connect to the TaskManager RpcEndpoint .
 * @throws IOException      Thrown, if the actor system can not bind to the address
 * @throws Exception      Thrown is some other error occurs while creating akka actor system
 */
public static RpcService createRpcService(String hostname, int port, Configuration configuration) throws Exception {
	LOG.info("Starting AkkaRpcService at {}.", NetUtils.unresolvedHostAndPortToNormalizedString(hostname, port));

	final ActorSystem actorSystem;

	try {
		Config akkaConfig;

		if (hostname != null && !hostname.isEmpty()) {
			// remote akka config
			akkaConfig = AkkaUtils.getAkkaConfig(configuration, hostname, port);
		} else {
			// local akka config
			akkaConfig = AkkaUtils.getAkkaConfig(configuration);
		}

		LOG.debug("Using akka configuration \n {}.", akkaConfig);

		actorSystem = AkkaUtils.createActorSystem(akkaConfig);
	} catch (Throwable t) {
		if (t instanceof ChannelException) {
			Throwable cause = t.getCause();
			if (cause != null && t.getCause() instanceof java.net.BindException) {
				String address = NetUtils.hostAndPortToUrlString(hostname, port);
				throw new IOException("Unable to bind AkkaRpcService actor system to address " +
					address + " - " + cause.getMessage(), t);
			}
		}
		throw new Exception("Could not create TaskManager actor system", t);
	}

	final Time timeout = Time.milliseconds(AkkaUtils.getTimeout(configuration).toMillis());
	return new AkkaRpcService(actorSystem, timeout);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:45,代码来源:AkkaRpcServiceUtils.java

示例11: createRpcService

import org.jboss.netty.channel.ChannelException; //导入依赖的package包/类
/**
 * Utility method to create RPC service from configuration and hostname, port.
 *
 * @param hostname   The hostname/address that describes the TaskManager's data location.
 * @param port           If true, the TaskManager will not initiate the TCP network stack.
 * @param configuration                 The configuration for the TaskManager.
 * @return   The rpc service which is used to start and connect to the TaskManager RpcEndpoint .
 * @throws IOException      Thrown, if the actor system can not bind to the address
 * @throws Exception      Thrown is some other error occurs while creating akka actor system
 */
public static RpcService createRpcService(String hostname, int port, Configuration configuration) throws Exception {
	LOG.info("Starting AkkaRpcService at {}.", NetUtils.hostAndPortToUrlString(hostname, port));

	final ActorSystem actorSystem;

	try {
		Config akkaConfig;

		if (hostname != null && !hostname.isEmpty()) {
			// remote akka config
			akkaConfig = AkkaUtils.getAkkaConfig(configuration, hostname, port);
		} else {
			// local akka config
			akkaConfig = AkkaUtils.getAkkaConfig(configuration);
		}

		LOG.debug("Using akka configuration \n {}.", akkaConfig);

		actorSystem = AkkaUtils.createActorSystem(akkaConfig);
	} catch (Throwable t) {
		if (t instanceof ChannelException) {
			Throwable cause = t.getCause();
			if (cause != null && t.getCause() instanceof java.net.BindException) {
				String address = NetUtils.hostAndPortToUrlString(hostname, port);
				throw new IOException("Unable to bind AkkaRpcService actor system to address " +
					address + " - " + cause.getMessage(), t);
			}
		}
		throw new Exception("Could not create TaskManager actor system", t);
	}

	final Time timeout = Time.milliseconds(AkkaUtils.getTimeout(configuration).toMillis());
	return new AkkaRpcService(actorSystem, timeout);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:45,代码来源:RpcServiceUtils.java

示例12: start

import org.jboss.netty.channel.ChannelException; //导入依赖的package包/类
public synchronized int start(
  Configuration conf, ChannelPipelineFactory pipelineFactory) {
  ServerBootstrap bootstrap = new ServerBootstrap(channelFactory);
  bootstrap.setPipelineFactory(pipelineFactory);
  bootstrap.setOption(
    BOOTSTRAP_BACKLOG_PARAM,
    conf.getInt(BACKLOG_CONF, DEFAULT_BACKLOG));
  // 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;
}
 
开发者ID:rhli,项目名称:hadoop-EAR,代码行数:31,代码来源:NettyMapOutputHttpServer.java

示例13: run

import org.jboss.netty.channel.ChannelException; //导入依赖的package包/类
public void run(GameManager gameManager) throws Exception {
    ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
    CreeperAuthenticationHandler handler = new CreeperAuthenticationHandler(gameManager);
    bootstrap.setPipelineFactory(new CreeperServerPipelineFactory(handler));
    try {
        bootstrap.bind(new InetSocketAddress(port));
    } catch (ChannelException e) {
        exitServer(e.getMessage(), 127);
    }
}
 
开发者ID:chriskearney,项目名称:creeper,代码行数:11,代码来源:CreeperServer.java

示例14: testFrames

import org.jboss.netty.channel.ChannelException; //导入依赖的package包/类
@Test
public void testFrames() {

  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);
      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.
      }
    }
  }

  XDR xdrOut = createGetportMount();
  int headerSize = xdrOut.size();
  int bufsize = 2 * 1024 * 1024;
  byte[] buffer = new byte[bufsize];
  xdrOut.writeFixedOpaque(buffer);
  int requestSize = xdrOut.size() - headerSize;

  // Send the request to the server
  testRequest(xdrOut, serverPort);

  // Verify the server got the request with right size
  assertEquals(requestSize, resultSize);
}
 
开发者ID:Seagate,项目名称:hadoop-on-lustre2,代码行数:37,代码来源:TestFrameDecoder.java

示例15: tryListen

import org.jboss.netty.channel.ChannelException; //导入依赖的package包/类
public boolean tryListen() {
    try {
        this.bootstrap.getPipeline().addLast("encoder", new NetworkEncoder());
        this.bootstrap.getPipeline().addLast("decoder", new NetworkDecoder());
        this.bootstrap.getPipeline().addLast("handler", new ConnectionHandler());
        this.bootstrap.bind(new InetSocketAddress(this.ip, this.port));
    } catch (final ChannelException ex) {
        logger.error("Couldn't open connection to " + this.ip + ":" + this.port + ".", ex);
        return false;
    }
    logger.info("Connection to " + this.ip + ":" + this.port + " created.");
    return true;
}
 
开发者ID:SteveWinfield,项目名称:IDK-Server-Java,代码行数:14,代码来源:ConnectionListener.java


注:本文中的org.jboss.netty.channel.ChannelException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。