Examples of ClientBootstrap


Examples of org.jboss.netty.bootstrap.ClientBootstrap

  private ClientBootstrap _clientBootstrap;
  private final TimeoutPolicy _timeoutPolicy;

  public SimpleTestHttpClient(ChannelFactory channelFactory, TimeoutPolicy timeoutPolicy) throws Exception
  {
    _clientBootstrap = new ClientBootstrap(channelFactory);
    ChannelPipeline pipeline = createPipeline();
    _clientBootstrap.setPipeline(pipeline);
    _timeoutPolicy = timeoutPolicy;
  }
View Full Code Here

Examples of org.jboss.netty.bootstrap.ClientBootstrap

    workerThreadFactory = new ExecutorThreadFactory("ClientWorkerPool", true);
    bossPool = Executors.newCachedThreadPool(bossThreadFactory);
    workerPool = Executors.newCachedThreadPool(workerThreadFactory);
    channelFactory = new NioClientSocketChannelFactory(bossPool, workerPool);
    pipelineFactory = new ChannelPipelineFactoryImpl(providers);
    bootstrap = new ClientBootstrap(channelFactory);
    bootstrap.setOptions(channelOptions);
    bootstrap.setPipelineFactory(pipelineFactory);
 
View Full Code Here

Examples of org.jboss.netty.bootstrap.ClientBootstrap

     * @param url URL to connect to.
     * @param callback Callback interface to receive events
     * @return A WebSocket client. Call {@link WebSocketClient#connect()} to connect.
     */
    public WebSocketClient newClient(final URI url, final WebSocketCallback callback) {
        ClientBootstrap bootstrap = new ClientBootstrap(socketChannelFactory);

        String protocol = url.getScheme();
        if (!protocol.equals("ws") && !protocol.equals("wss")) {
            throw new IllegalArgumentException("Unsupported protocol: " + protocol);
        }

        final WebSocketClientHandler clientHandler = new WebSocketClientHandler(bootstrap, url, callback);

        bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
            public ChannelPipeline getPipeline() throws Exception {
                ChannelPipeline pipeline = Channels.pipeline();
                pipeline.addLast("decoder", new HttpResponseDecoder());
                pipeline.addLast("encoder", new HttpRequestEncoder());
                pipeline.addLast("ws-handler", clientHandler);
View Full Code Here

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

Examples of org.jboss.netty.bootstrap.ClientBootstrap

            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

Examples of org.jboss.netty.bootstrap.ClientBootstrap

    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

Examples of org.jboss.netty.bootstrap.ClientBootstrap

        .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

Examples of org.jboss.netty.bootstrap.ClientBootstrap

    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

Examples of org.jboss.netty.bootstrap.ClientBootstrap

  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

Examples of org.jboss.netty.bootstrap.ClientBootstrap

  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
TOP
Copyright © 2018 www.massapi.com. 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.