activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Li Li <fancye...@gmail.com>
Subject how to wrapper a high level request-response thread-safe library
Date Fri, 07 Mar 2014 02:40:44 GMT
hi all,
     I want to wrapper a high level library using activemq to
implement a request-reply service. the user of this library have 2
kind of api --synchronized blocking and asynchronized callback.
     usage1:
          MainThread:
               RequestResponseWrapper wrapper=new RequestResponseWrapper();
               wrapper.setMaxConcurrentThrad(10);
               wrapper.setTimeout(10000);
               Thread[] workers=new Thread[N];
               for(int i=0;i<N;i++){
                       workers[i]=new WorkerThread(wrapper);
                       workers[i].start();
                }
                for(int i=0;i<N;i++){
                       workers[i].join();
                }
            WorkerThread:
               while(true){
                     String req=...;
                     String response=wrapper.request(req);
                     System.out.println(response);
                }
       usage2:
          MainThread:
               RequestResponseWrapper wrapper=new RequestResponseWrapper();
               wrapper.setMaxConcurrentThrad(10);
               wrapper.setTimeout(10000);
               CallBack callBack=new CallBack();
               wrapper.setCallBack(callBack);
               while(true){
                     String req=...;
                     wrapper.asyncRequest(req);
               }
          CallBack:
               onSuccess(String request,String response){

               }
               onFail(String request, int failReason){

               }


Any suggestion for me? I need implement both the java and c++ library.

Mime
View raw message