FabricJavaPool

   日期:2020-05-06     浏览:85    评论:0    
核心提示:文章目录FabricJavaPoolWhyHowFabricJavaPoolhttps://githjava

文章目录

  • FabricJavaPool
  • Why
  • How

FabricJavaPool

https://github.com/SamYuan1990/FabricJavaPool

Why

我们来看一下下边两个图,如果我们用web,java,fabric network的结构做一个可交互的页面来展示区块链的数据。(实际上本人更倾向于用java+spring做rest服务器)
理论上讲,我们不希望每次页面请求数据都做一次IO,相对的,我们希望有个链接池,在池子处理好IO。当然逻辑上我们可以把这个pool和用户的session或者cookie绑定(另外的故事了)

Person webUI Java Server Blockchain Network click give me some data 1 It takes some time for IO as network/msp etc.. give me some data 1 give me some data 2 It takes some time for IO as network/msp etc.. give me some data 2 give me some data n give me some data n click another give me some Data 2 It takes some time for IO as network/msp etc.. give me some Data 2 Person webUI Java Server Blockchain Network Person webUI Java Server Blockchain Network click give me some data 1 It takes some time for IO as network/msp etc as a pool? give me some data 2 give me some data 2 give me some datan give me some data n click another give me some Data 2 give me some Data 2 Person webUI Java Server Blockchain Network

How

介于fabric-java-sdk本身不提供这个功能,我就自己造了个轮子。
用了common-pool和fabric-java-sdk,详情见test代码。

        ObjectPool<Channel>  myChannelPool= new FabricJavaPool("./src/test/resources/Networkconfig.json",getUser(),"mychannel");
        try {
            Channel myChannel = myChannelPool.borrowObject();
            assertNotEquals("Test borrow item channel not null",myChannel,null);
            assertEquals("Test borrow item channel",myChannel.isInitialized(),true);
            Channel myChannel2 = myChannelPool.borrowObject();
            assertNotEquals("Test borrow item channel2 not null",myChannel2,null);
            assertEquals("Test borrow item channel2",myChannel2.isInitialized(),true);
            assertEquals("Test item should diff",myChannel2.equals(myChannel),false);
            myChannelPool.returnObject(myChannel);
            myChannelPool.returnObject(myChannel2);
            String rs=Query(myChannel,"mycc","query","a");
            assertEquals("90",rs);
            String rs2=Query(myChannel2,"mycc","query","a");
            assertNotEquals("91",rs2);
        } catch (Exception e) {
            e.printStackTrace();
        }
 
打赏
 本文转载自:网络 
所有权利归属于原作者,如文章来源标示错误或侵犯了您的权利请联系微信13520258486
更多>最近资讯中心
更多>最新资讯中心
更多>相关资讯中心
0相关评论

推荐图文
推荐资讯中心
点击排行
最新信息
新手指南
采购商服务
供应商服务
交易安全
关注我们
手机网站:
新浪微博:
微信关注:

13520258486

周一至周五 9:00-18:00
(其他时间联系在线客服)

24小时在线客服