Package org.jboss.netty.channel

Examples of org.jboss.netty.channel.Channel


                e.getCause());
        e.getChannel().close();
    }

    private void sendNumbers(ChannelStateEvent e) {
        Channel channel = e.getChannel();
        while (channel.isWritable()) {
            if (i <= count) {
                channel.write(Integer.valueOf(i));
                i ++;
            } else {
                break;
            }
        }
View Full Code Here


        // Make a new connection.
        ChannelFuture connectFuture =
            bootstrap.connect(new InetSocketAddress(host, port));

        // Wait until the connection is made successfully.
        Channel channel = connectFuture.awaitUninterruptibly().getChannel();

        // Get the handler instance to retrieve the answer.
        FactorialClientHandler handler =
            (FactorialClientHandler) channel.getPipeline().getLast();

        // Print out the answer.
        System.err.format(
                "Factorial of %,d is: %,d", count, handler.getFactorial());
View Full Code Here

        // Start the connection attempt.
        ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port));

        // Wait until the connection attempt succeeds or fails.
        Channel channel = future.awaitUninterruptibly().getChannel();
        if (!future.isSuccess()) {
            future.getCause().printStackTrace();
            bootstrap.releaseExternalResources();
            return;
        }

        // Prepare the HTTP request.
        HttpRequest request = new DefaultHttpRequest(
                HttpVersion.HTTP_1_1, HttpMethod.GET, uri.toASCIIString());
        request.setHeader(HttpHeaders.Names.HOST, host);
        request.setHeader(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
        request.setHeader(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP);

        // Set some example cookies.
        CookieEncoder httpCookieEncoder = new CookieEncoder(false);
        httpCookieEncoder.addCookie("my-cookie", "foo");
        httpCookieEncoder.addCookie("another-cookie", "bar");
        request.setHeader(HttpHeaders.Names.COOKIE, httpCookieEncoder.encode());

        // Send the HTTP request.
        channel.write(request);

        // Wait for the server to close the connection.
        channel.getCloseFuture().awaitUninterruptibly();

        // Shut down executor threads to exit.
        bootstrap.releaseExternalResources();
    }
View Full Code Here

    @Override
    public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e)
            throws Exception {
        // Suspend incoming traffic until connected to the remote host.
        final Channel inboundChannel = e.getChannel();
        inboundChannel.setReadable(false);

        // Start the connection attempt.
        ClientBootstrap cb = new ClientBootstrap(cf);
        cb.getPipeline().addLast("handler", new OutboundHandler(e.getChannel()));
        ChannelFuture f = cb.connect(new InetSocketAddress(remoteHost, remotePort));

        outboundChannel = f.getChannel();
        f.addListener(new ChannelFutureListener() {
            public void operationComplete(ChannelFuture future) throws Exception {
                if (future.isSuccess()) {
                    // Connection attempt succeeded:
                    // Begin to accept incoming traffic.
                    inboundChannel.setReadable(true);
                } else {
                    // Close the connection if the connection attempt has failed.
                    inboundChannel.close();
                }
            }
        });
    }
View Full Code Here

});
   
     // Start the connection attempt.
    ChannelFuture future = bootstrap.connect(new InetSocketAddress("localhost", 8080));
    // Wait until the connection attempt succeeds or fails.
    Channel channel = future.awaitUninterruptibly().getChannel();
    if (future.isSuccess())
      System.out.println("connected");
   
    // get a proxy
View Full Code Here

   */
      public Object invoke(Object proxy, Method method, Object []args)
        throws Throwable
      {
        String mangleName;
        Channel channel = getChannel();

        synchronized (_mangleMap) {
          mangleName = _mangleMap.get(method);
        }

        if (mangleName == null) {
          String methodName = method.getName();
          Class []params = method.getParameterTypes();

          // equals and hashCode are special cased
          if (methodName.equals("equals")
        && params.length == 1 && params[0].equals(Object.class)) {
      Object value = args[0];
      if (value == null || ! Proxy.isProxyClass(value.getClass()))
        return Boolean.FALSE;

      Object proxyHandler = Proxy.getInvocationHandler(value);

      if (! (proxyHandler instanceof AsyncHessianProxy))
        return Boolean.FALSE;
     
      AsyncHessianProxy handler = (AsyncHessianProxy) proxyHandler;

      return new Boolean(this.equals(handler));
          }
          else if (methodName.equals("hashCode") && params.length == 0)
      return new Integer(System.identityHashCode(this));
          else if (methodName.equals("getHessianType"))
      return proxy.getClass().getInterfaces()[0].getName();
          else if (methodName.equals("getHessianURL"))
      return channel == null ? "?" : channel.toString();
          else if (methodName.equals("toString") && params.length == 0)
      return "HessianProxy[" + _api + "]";
         
          if (! _factory.isOverloadEnabled())
      mangleName = method.getName();
View Full Code Here

        _valid = false;
      }
     
      public String getHost()
      {
        Channel c = getChannel();
        if (c == null)
          return null;
        InetSocketAddress addr =  (InetSocketAddress) c.getRemoteAddress();
        return addr.getHostName();
      }
View Full Code Here

       
        bootstrap.setPipelineFactory(
               new RPCServerPipelineFactory(executor, factory, acl));

        // Bind and start to accept incoming connections.
        Channel channel =  bootstrap.bind(new InetSocketAddress(serverPort));
        if (serverPort == 0)
          serverPort = ((InetSocketAddress)channel.getLocalAddress()).getPort();
       
        System.out.println("bound to port "+serverPort);
       
        DiscoveryServer discovery = new DiscoveryServer();
        discovery.setName("serviceManagerServer");
View Full Code Here

 
 

  protected void sendMessage(HessianRPCReplyMessage message)
  {
    Channel ch = message.getChannel();
    if (ch != null)
      ch.write(message);
    else
      ahessianLogger.warn("message channel null -> ignored: #"+message.getCallId());
    /*
    //ahessianLogger.warn("send reply for #"+message.getHeaders().get(CALL_ID_STRING));
    if (message.isValid())
View Full Code Here

    @Override
    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception
    {
      if (_stopping)
        return;
      Channel session = ctx.getChannel();
      Message msg = (Message) e.getMessage();
      if (msg.getCode() == Constants.WRAPPER_MSG_STOP)
        try
        {
          System.out.println("wrapper manager received stop command");
          _stopping = true;
          if (session != null)
            session.close();
          // Thread.sleep(100);
          if (msg.getMessage() != null && msg.getMessage().length() > 0)
            try
            {
              _exitCode = Integer.parseInt(msg.getMessage());
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.