Giter VIP home page Giter VIP logo

snake-rpc's Introduction

snake-rpc

An RPC framework based on Hessian(http://hessian.caucho.com)

the name 'snake' comes from the Animal Year of snake in Chinese(the year 2013).

compared with hessian, snake-rpc has several new features:

  • ablity to serialize InputStream/OutputStream;
  • unlimited InputStream/OutputStream parameters;
  • ablity to reuse remote objects returned by a method call;

for example:

Connection con = client.getConnection();
ResultSet rs = con.queryForResultSet("select * from users");

this feature is very useful for those objects which are valid only on the server-side, e.g, the Connection or ResultSet objects;

see https://github.com/bluejoe2008/snake-rpc/blob/master/test/cn/bluejoe/snake/client/SnakeClientTest.java for example usage.

###server side codes

  • Step 1: since a SnakeServlet class is provided by snake-rpc, users can create a derived classes and register accessible service objects within init() methods:

      public class MySnakeServlet extends SnakeServlet
      {
      
      	@Override
      	public void init(ServletConfig config) throws ServletException
      	{
      		super.init(config);
      		//declares that FileObjects are only avaliable on server side
      		_skeleton.declareServerSideObjectClass(FileObject.class);
      		//register an object named file
      		_skeleton.registerServiceObject("file", new FileObjectImpl(new File("./testdir")));
      	}
      
      }
    
  • Step 2: configures the Servet in web.xml as normal.

  • Step 3: start up web server.

###client side codes

  • Step 1: creates a SnakeClient first:

      HttpHost hc = new HttpHost("http://localhost:8080");
      _client = new SnakeClient(hc, "http://localhost:8080/rpc", "", "");
    
  • Step 2: uses createServiceObjectProxy() to retrieve remote object:

      FileObject fo = (FileObject) _client.createServiceObjectProxy("file", FileObject.class);
    
  • Step 3: now you got the FileObject object, just call methods on it:

      FileObject[] cfs = fo.listFiles();
      Assert.assertEquals(1, cfs.length);
      FileObject cfs0 = cfs[0];
      Assert.assertEquals(false, cfs0.isDirectory());
      Assert.assertEquals(f1.length(), cfs0.length());
    

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.