简体   繁体   中英

Remotely get notifications in order to update a progress monitor

I have a complex application containing a server and a frontend part.

I am trying in the frontend part to update a progress monitor according to an action that takes place in the server part. The action from the server part is called remotely from the frontend. But I am having trouble getting the notifications real time to update the monitor.

My code structure looks somewhat like this:

class frontend_class1{
       public void method {
          List<String> strings = initializeStrings();
          progressMonitor.begingTask("", noOfSteps);
          reponse = frontend_class2.method2(strings);
          progressMonitor.worked(1);
       }

class frontend_class2{
       public responseType method2(List<String> strings){
          ServerClassRemote remote = new ServerClassRemote();
          response = remote.serverMethod(strings);
          return response;
       }

class server_class{
       public serverMethod(List<String> strings){
          otherMethod(strings);
       }
       public otherMethod(List<String> strings){
          someOtherMethod(strings);
       }
       public someOtherMethod(List<String> strings){
          for (String s:Strings){
              doSomethingWithString(s);
              setStatus(true);
          }
       }
       public setStatus(boolean status){
          myVar = status;
       }
       public boolean getStatus(){
          return status;
       }

My intention is to send a notification to the frontend from the server side, so that the progress monitor is updated with one each time a string is done with.

That is why I included the status methods: to ask from the frontend what the status is, in a separate thread running, theoretically, simultaneously with the other method (serverMethod) and then resetting the status. Something like this:

new Thread(new Runnable() {
            public void run() {
                if (remote.getChanged()) {
                    remote.setChanged(false);
                }
            }
        }).start();

But they don't run concurrently. How could I get the status each time a string from the list is finished so that I can update my progress monitor?

Instead of just setting the status is someOtherMethod you could send the update report with a new thread to the front end. If you do not have a way of sending this update yet you will probably need to have the fornt_end run some kind of server to receive at least these messages. Maybe some RMI, should be easy enough to implement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM