Package org.jboss.netty.channel

Examples of org.jboss.netty.channel.SimpleChannelUpstreamHandler


 
  public ChannelPipeline getPipeline() throws Exception
 
    ChannelPipeline pipeline = pipeline(); // Note the static import.
    pipeline.addLast("logger",new OutLogger("1"));
    pipeline.addLast("reconnector", new SimpleChannelUpstreamHandler()
                {
           
            @Override
              public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) {
              ctx.sendUpstream(e);
View Full Code Here


  ChannelPipelineFactory factory = new ChannelPipelineFactory()
  {
    public ChannelPipeline getPipeline() throws Exception
    {
      ChannelPipeline pipeline = pipeline();
      pipeline.addLast("discoveryServer", new SimpleChannelUpstreamHandler()
      {

        @Override
        public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception
        {
View Full Code Here

    ChannelPipelineFactory factory = new ChannelPipelineFactory()
    {
      public ChannelPipeline getPipeline() throws Exception
      {
        ChannelPipeline pipeline = pipeline();
        pipeline.addLast("discoveryServer", new SimpleChannelUpstreamHandler()
        {

          @Override
          public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception
          {
View Full Code Here

        ServerBootstrap bootstrap = new ServerBootstrap(factory);
       
        bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
            public ChannelPipeline getPipeline() {
                return Channels.pipeline(new SimpleChannelUpstreamHandler()
                {
            @Override
            public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception
            {
              if (mcast != null && mcast.isInit())
                mcast.send((ChannelBuffer) e.getMessage());
            }
           
            @Override
              public void childChannelOpen(ChannelHandlerContext ctx, ChildChannelStateEvent e)
            {
              remoteChannels.add(ctx.getChannel());
              }
           
            @Override
              public void childChannelClosed(ChannelHandlerContext ctx, ChildChannelStateEvent e)
            {
              remoteChannels.add(ctx.getChannel());
              }
           
            @Override
              public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
                  Throwable cause = e.getCause();
                  System.out.println(e);           
              }
                });
            }
        });
        bootstrap.bind(new InetSocketAddress(port));
       
        try
    {
      mcast.init(new ChannelPipelineFactory() {
          public ChannelPipeline getPipeline() {
              return Channels.pipeline(new SimpleChannelUpstreamHandler()
              {
            @Override
            public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception
            {
              ChannelBuffer b = mcast.getMessage(e);
View Full Code Here

        bootstrap.setOption(
                "remoteAddress", new InetSocketAddress(host, port));

        bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
            public ChannelPipeline getPipeline() {
                return Channels.pipeline(new SimpleChannelUpstreamHandler()
                {
            @Override
            public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception
            {
              if (mcast != null && mcast.isInit())
                mcast.send((ChannelBuffer) e.getMessage());
            }
           
            @Override
              public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) {
                  timer.schedule(new TimerTask() {
                      public void run() {
                           bootstrap.connect();
                      }
                  }, RECONNECT_DELAY);
              }
           
            @Override
              public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
                  Throwable cause = e.getCause();
                  if (cause instanceof ConnectException)
                  {
                    System.out.println("conection lost: reconnecting...");
                  }
                  ctx.getChannel().close();
              }


                 
                });
            }
        });
       
        ChannelFuture f = bootstrap.connect();
        channel = f.getChannel();
       
        mcast.init(new ChannelPipelineFactory() {
            public ChannelPipeline getPipeline() {
                return Channels.pipeline(new SimpleChannelUpstreamHandler()
                {
            @Override
            public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception
            {
              ChannelBuffer b = mcast.getMessage(e);
View Full Code Here

    public void start(int port) throws IOException {
        factory = new NioDatagramChannelFactory();
        ConnectionlessBootstrap bootstrap = new ConnectionlessBootstrap(factory);
        bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
            public ChannelPipeline getPipeline() throws Exception {
                return Channels.pipeline(new SimpleChannelUpstreamHandler() {
                    @Override
                    public void childChannelOpen(ChannelHandlerContext ctx, ChildChannelStateEvent e) throws Exception {
                        System.out.println("childChannelOpen");
                        setAttribute(ctx, STATE_ATTRIBUTE, State.WAIT_FOR_FIRST_BYTE_LENGTH);
                    }
View Full Code Here

        ConnectionlessBootstrap bootstrap = new ConnectionlessBootstrap(factory);
        bootstrap.setOption("sendBufferSize", 65536);
        bootstrap.setOption("receiveBufferSizePredictorFactory", new FixedReceiveBufferSizePredictorFactory(9000));
        bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
            public ChannelPipeline getPipeline() throws Exception {
                return Channels.pipeline(new SimpleChannelUpstreamHandler() {
                    private void sendMessage(ChannelHandlerContext ctx, byte[] data) {
                        ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(data);
                        ctx.getChannel().write(buffer);
                    }
View Full Code Here

        ServerBootstrap bootstrap = new ServerBootstrap(factory);
        bootstrap.setOption("receiveBufferSize", 128 * 1024);
        bootstrap.setOption("tcpNoDelay", true);
        bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
            public ChannelPipeline getPipeline() throws Exception {
                return Channels.pipeline(new SimpleChannelUpstreamHandler() {
                    @Override
                    public void childChannelOpen(ChannelHandlerContext ctx, ChildChannelStateEvent e) throws Exception {
                        System.out.println("childChannelOpen");
                        setAttribute(ctx, STATE_ATTRIBUTE, State.WAIT_FOR_FIRST_BYTE_LENGTH);
                    }
View Full Code Here

        ClientBootstrap bootstrap = new ClientBootstrap(factory);
        bootstrap.setOption("sendBufferSize", 64 * 1024);
        bootstrap.setOption("tcpNoDelay", true);
        bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
            public ChannelPipeline getPipeline() throws Exception {
                return Channels.pipeline(new SimpleChannelUpstreamHandler() {
                    private void sendMessage(ChannelHandlerContext ctx, byte[] data) {
                        ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(data);
                        ctx.getChannel().write(buffer);
                    }

View Full Code Here

  @VisibleForTesting
  public void initServer(String fsimage) throws IOException {
    FSImageLoader loader = FSImageLoader.load(fsimage);

    ChannelPipeline pipeline = Channels.pipeline();
    pipeline.addLast("channelTracker", new SimpleChannelUpstreamHandler() {
      @Override
      public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e)
          throws Exception {
        allChannels.add(e.getChannel());
      }
View Full Code Here

TOP

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

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.