Package org.jboss.netty.bootstrap

Examples of org.jboss.netty.bootstrap.ClientBootstrap


          return Channels.pipeline(
            new ObjectEncoder()
          );
        }
      };
      ClientBootstrap bootstrap = new ClientBootstrap(channelFactory);
      bootstrap.setPipelineFactory(pipelineFactory);
      // Phew. Ok. We built all that. Now what ?
      InetSocketAddress addressToConnectTo = new InetSocketAddress("localhost", 8080);
      //ChannelFuture cf = bootstrap.connect(addressToConnectTo);
      clog("Issuing Channel Connect...");
      // Waiting on a connect. (Pick one)
      ChannelFuture cf = bootstrap.connect(addressToConnectTo);
      // wait interruptibly
//      cf.await();
      // wait interruptibly with a timeout of 2000 ms.
//      cf.await(2000, TimeUnit.MILLISECONDS);
      // wait uninterruptibly
View Full Code Here


            new ObjectDecoder(ClassResolvers.cacheDisabled(getClass().getClassLoader())),
            new ClientDateHandler()           
          );
        }
      };
      ClientBootstrap bootstrap = new ClientBootstrap(channelFactory);
      bootstrap.setPipelineFactory(pipelineFactory);
      InetSocketAddress addressToConnectTo = new InetSocketAddress("localhost", 8080);
      clog("Issuing Channel Connect...");
      ChannelFuture cf = bootstrap.connect(addressToConnectTo);
      clog("Waiting for Channel Connect...");
      cf.awaitUninterruptibly();
      Date dt = new Date();
      clog("Connected. Sending Date [" + dt + "]");
      Channel channel = cf.getChannel();
View Full Code Here

    protected ChannelFuture openConnection() throws Exception {
        ChannelFuture answer;

        if (isTcp()) {
            // its okay to create a new bootstrap for each new channel
            ClientBootstrap clientBootstrap = new ClientBootstrap(channelFactory);
            clientBootstrap.setOption("keepAlive", configuration.isKeepAlive());
            clientBootstrap.setOption("tcpNoDelay", configuration.isTcpNoDelay());
            clientBootstrap.setOption("reuseAddress", configuration.isReuseAddress());
            clientBootstrap.setOption("connectTimeoutMillis", configuration.getConnectTimeout());

            // set any additional netty options
            if (configuration.getOptions() != null) {
                for (Map.Entry<String, Object> entry : configuration.getOptions().entrySet()) {
                    clientBootstrap.setOption(entry.getKey(), entry.getValue());
                }
            }

            // set the pipeline factory, which creates the pipeline for each newly created channels
            clientBootstrap.setPipelineFactory(pipelineFactory);
            answer = clientBootstrap.connect(new InetSocketAddress(configuration.getHost(), configuration.getPort()));
            if (LOG.isDebugEnabled()) {
                LOG.debug("Created new TCP client bootstrap connecting to {}:{} with options: {}",
                        new Object[]{configuration.getHost(), configuration.getPort(), clientBootstrap.getOptions()});
            }
            return answer;
        } else {
            // its okay to create a new bootstrap for each new channel
            ConnectionlessBootstrap connectionlessClientBootstrap = new ConnectionlessBootstrap(datagramChannelFactory);
View Full Code Here

        .newCachedThreadPool(), Executors.newCachedThreadPool());
    final DefenderHandler defHandler = new DefenderHandler();
    PipelineFactory defFactory = new PipelineFactory(defHandler);
    final ZombieHandler zomHandler = new ZombieHandler();
    PipelineFactory zomFactory = new PipelineFactory(zomHandler);
    ClientBootstrap bootstrap = new ClientBootstrap(factory);
    // At client side option is tcpNoDelay and at server child.tcpNoDelay
    bootstrap.setOption("tcpNoDelay", true);
    bootstrap.setOption("keepAlive", true);
    for (int i = 1; i<=50;i++){
      final InetSocketAddress udpLocalAddress;
      if(i%2==0){
        bootstrap.setPipelineFactory(defFactory);
        udpLocalAddress = defHandler.connectLocal();
      }else{
        bootstrap.setPipelineFactory(zomFactory);
        udpLocalAddress = zomHandler.connectLocal();
      }
     
      ChannelFuture future = bootstrap.connect(new InetSocketAddress(host,
          port));
     
      future.addListener(new ChannelFutureListener()
      {
        @Override
View Full Code Here

    public void init() throws AnalysisException {
      InternalLoggerFactory.setDefaultFactory(new Log4JLoggerFactory());
//        slaveEventTimeQueue = new SlaveEventTimeOutQueue();
        channelLock = new ReentrantLock();

        bootstrap = new ClientBootstrap(factory);

        bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
            public ChannelPipeline getPipeline() {
                ChannelPipeline pipe =
                        Channels.pipeline(new ObjectEncoder(8192 * 4), new ObjectDecoder(Integer.MAX_VALUE,
View Full Code Here

  producer.start();
    }
   

    public void httptest(String fileName) {
  ClientBootstrap client = new ClientBootstrap(
                 new NioClientSocketChannelFactory(
                           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

  client.releaseExternalResources();

    }

    public void initcassandradb() {
  ClientBootstrap client = new ClientBootstrap(
                 new NioClientSocketChannelFactory(
                           Executors.newCachedThreadPool(),
                           Executors.newCachedThreadPool()));

  client.setPipelineFactory(new ClientPipelineFactory());

  // Connect to server, wait till connection is established, get channel
  // to write to
  Channel channel;
  HttpRequest request;
  ChannelBuffer buffer;

  channel = client.connect(new InetSocketAddress("127.0.0.1", 8080))
      .awaitUninterruptibly().getChannel();
  request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
           "/init");

  buffer = ChannelBuffers.copiedBuffer(" ", 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();

  client.releaseExternalResources();

    }
View Full Code Here

      init();
   }

   private void init() {
      // Configure the client.
      ClientBootstrap bootstrap = new ClientBootstrap(
            new NioClientSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));

      // Set up the event pipeline factory.
      bootstrap.setPipelineFactory(new HotrodClientPipelaneFactory(decoder));

      // Start the connection attempt.
      ChannelFuture future = bootstrap.connect(serverAddress);

      // Wait until the connection attempt succeeds or fails.
      channel = future.awaitUninterruptibly().getChannel();
      if (!future.isSuccess()) {
         bootstrap.releaseExternalResources();
         throw new TransportException("Could not create netty transport", future.getCause());
      }
   }
View Full Code Here

        flushCheckInterval = Utils.getInt(storm_conf.get(Config.STORM_NETTY_FLUSH_CHECK_INTERVAL_MS), 10); // default 10 ms

        LOG.info("New Netty Client, connect to " + host + ", " + port
                + ", config: " + ", buffer_size: " + buffer_size);

        bootstrap = new ClientBootstrap(factory);
        bootstrap.setOption("tcpNoDelay", true);
        bootstrap.setOption("sendBufferSize", buffer_size);
        bootstrap.setOption("keepAlive", true);

        // Set up the pipeline factory.
View Full Code Here

        this.address = address;
        this.factory = factory;
        this.dispatcher = new Dispatcher();
        this.name = name;

        ClientBootstrap bootstrap = factory.newBootstrap();
        ProtocolOptions protocolOptions = factory.configuration.getProtocolOptions();
        ProtocolVersion protocolVersion = factory.protocolVersion == null ? ProtocolVersion.NEWEST_SUPPORTED : factory.protocolVersion;
        bootstrap.setPipelineFactory(new PipelineFactory(this, protocolVersion, protocolOptions.getCompression().compressor, protocolOptions.getSSLOptions()));

        ChannelFuture future = bootstrap.connect(address);

        writer.incrementAndGet();
        try {
            // Wait until the connection attempt succeeds or fails.
            this.channel = future.awaitUninterruptibly().getChannel();
View Full Code Here

TOP

Related Classes of org.jboss.netty.bootstrap.ClientBootstrap

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.