Package org.jboss.netty.channel

Examples of org.jboss.netty.channel.Channel


  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


  public static void close() {
    client.releaseExternalResources();
  }

  public static void insertData(String content) {
    Channel channel = null;
    HttpRequest request;
    ChannelBuffer buffer;
    try {
      channel = client
          .connect(new InetSocketAddress("localhost", httpPort))
          .awaitUninterruptibly().getChannel();
      request = new DefaultHttpRequest(HttpVersion.HTTP_1_1,
          HttpMethod.POST, "/insert");
      buffer = ChannelBuffers.copiedBuffer(content,
          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();
  }
View Full Code Here

        // Set up the pipeline factory.
        bootstrap.setPipelineFactory(new StormServerPipelineFactory(this));

        // Bind and start to accept incoming connections.
        Channel channel = bootstrap.bind(new InetSocketAddress(port));
        allChannels.add(channel);
    }
View Full Code Here

                if(!closing) {
                    long flushCheckTime = flushCheckTimer.get();
                    long now = System.currentTimeMillis();
                    if (now > flushCheckTime) {
                        Channel channel = channelRef.get();
                        if (null != channel && channel.isWritable()) {
                            flush(channel);
                        }
                    }
                }
               
View Full Code Here

     * We will retry connection with exponential back-off policy
     */
    private synchronized void connect() {
        try {

            Channel channel = channelRef.get();
            if (channel != null && channel.isConnected()) {
                return;
            }

            int tried = 0;
            while (tried <= max_retries) {

                LOG.info("Reconnect started for {}... [{}]", name(), tried);
                LOG.debug("connection started...");

                ChannelFuture future = bootstrap.connect(remote_addr);
                future.awaitUninterruptibly();
                Channel current = future.getChannel();
                if (!future.isSuccess()) {
                    if (null != current) {
                        current.close();
                    }
                } else {
                    channel = current;
                    break;
                }
View Full Code Here

       
        if (null == msgs || !msgs.hasNext()) {
            return;
        }

        Channel channel = channelRef.get();
        if (null == channel) {
            connect();
            channel = channelRef.get();
        }

        while (msgs.hasNext()) {
            if (!channel.isConnected()) {
                connect();
                channel = channelRef.get();
            }
            TaskMessage message = msgs.next();
            if (null == messageBatch) {
                messageBatch = new MessageBatch(messageBatchSize);
            }

            messageBatch.add(message);
            if (messageBatch.isFull()) {
                MessageBatch toBeFlushed = messageBatch;
                flushRequest(channel, toBeFlushed);
                messageBatch = null;
            }
        }

        if (null != messageBatch && !messageBatch.isEmpty()) {
            if (channel.isWritable()) {
                flushCheckTimer.set(Long.MAX_VALUE);
               
                // Flush as fast as we can to reduce the latency
                MessageBatch toBeFlushed = messageBatch;
                messageBatch = null;
View Full Code Here

            closing = true;
            LOG.info("Closing Netty Client " + name());
           
            if (null != messageBatch && !messageBatch.isEmpty()) {
                MessageBatch toBeFlushed = messageBatch;
                Channel channel = channelRef.get();
                if (channel != null) {
                    flushRequest(channel, toBeFlushed);
                }
                messageBatch = null;
            }
View Full Code Here

                pendings.decrementAndGet();
                if (!future.isSuccess()) {
                    LOG.info(
                            "failed to send requests to " + remote_addr.toString() + ": ", future.getCause());

                    Channel channel = future.getChannel();

                    if (null != channel) {
                        channel.close();
                        channelRef.compareAndSet(channel, null);
                    }
                } else {
                    LOG.debug("{} request(s) sent", requests.size());
                }
View Full Code Here

        // *** Start the Netty running ***

        // Create the monitor
        ThroughputMonitor monitor = new ThroughputMonitor(state);
        // Add the parent channel to the group
        Channel channel = bootstrap.bind(new InetSocketAddress(config.getPort()));
        channelGroup.add(channel);
       
        // Compacter handler
        ChannelFactory comFactory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),
              Executors.newCachedThreadPool(), (Runtime.getRuntime().availableProcessors() * 2 + 1) * 2);
 
View Full Code Here

                return;
            }
        }

        ReadingBuffer buffer;
        Channel channel = ctx.getChannel();
        boolean bootstrap = false;
        synchronized (messageBuffersMap) {
            buffer = messageBuffersMap.get(ctx.getChannel());
            if (buffer == null) {
                 synchronized (sharedMsgBufLock) {
                     bootstrap = true;
                     buffer = sharedState.sharedMessageBuffer.getReadingBuffer(ctx);
                     messageBuffersMap.put(channel, buffer);
                     channelGroup.add(channel);
                     LOG.warn("Channel connected: " + messageBuffersMap.size());
                 }
            }
        }
        if (bootstrap) {
           synchronized (sharedState) {
              synchronized (sharedMsgBufLock) {
                 channel.write(buffer.getZipperState());
                 buffer.initializeIndexes();
              }
           }
           for (AbortedTransaction halfAborted : sharedState.hashmap.halfAborted) {
              channel.write(new AbortedTransactionReport(halfAborted.getStartTimestamp()));
           }
        }
        ChannelBuffer cb;
        ChannelFuture future = Channels.future(channel);
        synchronized (sharedMsgBufLock) {
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.