Package org.jboss.netty.channel

Examples of org.jboss.netty.channel.Channel


        if (LOG.isTraceEnabled()) {
            LOG.trace("Pool[active={}, idle={}]", pool.getNumActive(), pool.getNumIdle());
        }

        // get a channel from the pool
        Channel existing;
        try {
            existing = pool.borrowObject();
            if (existing != null) {
                LOG.trace("Got channel from pool {}", existing);
            }
        } catch (Exception e) {
            exchange.setException(e);
            callback.done(true);
            return true;
        }

        // we must have a channel
        if (existing == null) {
            exchange.setException(new CamelExchangeException("Cannot get channel from pool", exchange));
            callback.done(true);
            return true;
        }

        // need to declare as final
        final Channel channel = existing;
        final AsyncCallback producerCallback = new NettyProducerCallback(channel, callback);

        // setup state as attachment on the channel, so we can access the state later when needed
        channel.setAttachment(new NettyCamelState(producerCallback, exchange));

        InetSocketAddress remoteAddress = null;
        if (!isTcp() && configuration.isUdpConnectionlessSending()) {
            // Need to specify the remoteAddress here
            remoteAddress = new InetSocketAddress(configuration.getHost(), configuration.getPort());
View Full Code Here


            }

            // set the pipeline factory, which creates the pipeline for each newly created channels
            connectionlessClientBootstrap.setPipelineFactory(pipelineFactory);
            // bind and store channel so we can close it when stopping
            Channel channel = connectionlessClientBootstrap.bind(new InetSocketAddress(0));
           
            allChannels.add(channel);
            // if udp connectionless sending is true we don't do a connect.
            // we just send on the channel created with bind which means
            // really fire and forget. You wont get an PortUnreachableException
View Full Code Here

            if (channelFuture.getCause() != null) {
                cause.initCause(channelFuture.getCause());
            }
            throw cause;
        }
        Channel answer = channelFuture.getChannel();
        // to keep track of all channels in use
        allChannels.add(answer);

        if (LOG.isDebugEnabled()) {
            LOG.debug("Creating connector to address: {}", configuration.getAddress());
View Full Code Here

    private final class NettyProducerPoolableObjectFactory implements PoolableObjectFactory<Channel> {

        @Override
        public Channel makeObject() throws Exception {
            ChannelFuture channelFuture = openConnection();
            Channel answer = openChannel(channelFuture);
            LOG.trace("Created channel: {}", answer);
            return answer;
        }
View Full Code Here

      {
        @Override
        public void operationComplete(ChannelFuture future) throws Exception
        {
          ChannelBuffer loginBuffer = getLoginBuffer("Zombie_ROOM_1_REF_KEY_1",writeSocketAddressToBuffer(udpLocalAddress));
          Channel channel = future.getChannel();
          CHANNEL_ID_ADDRESS_MAP.put(channel.getId(), udpLocalAddress);
          channel.write(loginBuffer);
        }
      });
    }
  }
View Full Code Here

          .append(":").append(config.getMasterPort()).toString();
  }
 
  public Channel getChannel(String address) throws AnalysisException
  {
    Channel channel = channels.get(address);
   
    //目前简单实现连接失败重连,后续可考虑在此处实现连接失败的策略
    if (channel != null && (channel.isConnected() || channel.isOpen())) {
      return channel;
    }
   
    String[] _addr = StringUtils.split(address,":");
    boolean isLock = false;
     
    try
    {
      isLock = channelLock.tryLock(10, TimeUnit.SECONDS);
     
      if (isLock)
      {
        //double check
        channel = channels.get(address);
       
        if (channel != null && (channel.isConnected() || channel.isOpen()))
          return channel;
       
        logger.info("trying to open new channel");
       
        future = bootstrap.connect(new InetSocketAddress(_addr[0],Integer.valueOf(_addr[1])));
View Full Code Here

      if(logger.isInfoEnabled())
          logger.info("trying to get tasks from master " + requestEvent.getRequestJobCount());
      responseQueue.put(requestEvent.getSequence(), requestEvent);
//      slaveEventTimeQueue.add(requestEvent);
     
      Channel channel = getChannel(leaderChannel);
     
      requestEvent.setChannel(channel);
     
      ChannelFuture channelFuture = channel.write(requestEvent);

      // why ??, 这里不必等待
      //channelFuture.await(10, TimeUnit.SECONDS);

      channelFuture.addListener(new ChannelFutureListener() {
View Full Code Here

           
            // 简单的用这种模式模拟阻塞请求
            responseQueue.put(jobResponseEvent.getSequence(), jobResponseEvent);
//            slaveEventTimeQueue.add(jobResponseEvent);
           
            Channel channel = getChannel(master);
            jobResponseEvent.setChannel(channel);
            final long start = System.currentTimeMillis();
            ChannelFuture channelFuture = channel.write(jobResponseEvent);
//            channelFuture.await(10, TimeUnit.SECONDS);

            channelFuture.addListener(new ChannelFutureListener() {
                public void operationComplete(ChannelFuture future) {
                    if (!future.isSuccess()) {
View Full Code Here

        logger.info("Trying to send monitor info to master");
      }
     
      responseQueue.put(sendSlaveMonitorInfoEvent.getSequence(), sendSlaveMonitorInfoEvent);
     
      Channel channel = getChannel(leaderChannel);
      sendSlaveMonitorInfoEvent.setChannel(channel);
      ChannelFuture channelFuture = channel.write(sendSlaveMonitorInfoEvent);

      channelFuture.addListener(new ChannelFutureListener() {
        public void operationComplete(ChannelFuture future) {
          if (!future.isSuccess()) {
            responseQueue.remove(event.getSequence());
View Full Code Here

                           Executors.newCachedThreadPool(),
                           Executors.newCachedThreadPool()));

  client.setPipelineFactory(new ClientPipelineFactory());

  Channel channel = null;
  HttpRequest request;
  ChannelBuffer buffer;

  try {
      FileInputStream fstream = new FileInputStream(fileName);

      DataInputStream in = new DataInputStream(fstream);
      BufferedReader br = new BufferedReader(new InputStreamReader(in));
      String strLine;

      long starttimestamp = System.currentTimeMillis();
      long endtimestamp = System.currentTimeMillis();
     
      int recCount = 0;

      while ((strLine = br.readLine()) != null) {
    channel = client
        .connect(new InetSocketAddress("127.0.0.1", 8080))
        .awaitUninterruptibly().getChannel();
    request = new DefaultHttpRequest(HttpVersion.HTTP_1_1,
             HttpMethod.POST, "/insert");
    recCount++;
    if ((recCount % 1000) == 1) {
        endtimestamp = System.currentTimeMillis();
        System.out.print("It took " );
        System.out.print( endtimestamp - starttimestamp );
        System.out.println(" ms to load 1000 records through http");
        starttimestamp = endtimestamp;
    }
   
    buffer = ChannelBuffers.copiedBuffer(strLine,
                 Charset.defaultCharset());
    request.addHeader(
          org.jboss.netty.handler.codec.http.HttpHeaders.Names.CONTENT_LENGTH,
          buffer.readableBytes());
    request.setContent(buffer);
    channel.write(request).awaitUninterruptibly().getChannel()
        .getCloseFuture().awaitUninterruptibly();
    ;
      }

  } catch (Exception e) {// Catch exception if any
      System.err.println("Error: " + e.getMessage());
  }
  channel.getCloseFuture().awaitUninterruptibly();

  client.releaseExternalResources();

    }
View Full Code Here

TOP

Related Classes of org.jboss.netty.channel.Channel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.