1

I have a client server program where the client is requesting a (jasper)report from server and displays it on screen. The report-fetching part is handled by Swingworker on client side as the report might take a while to arrive (server running query against a DB etc.).

Below is my SwingWorker code:

class ReportFetcher extends SwingWorker<JasperPrint, Void> {        
    private String reportName;        
    public ReportFetcher (String reportName) {
        this.reportName = reportName;
    }

    @Override
    protected JasperPrint doInBackground() {
        SocketClient client = new SocketClient(serverAddress, 9999);
        client.sendSignal("Report-" + reportName);
        JasperPrint print = null;
        try {
           print = client.getReport();
           System.out.println("Report fetched : " + reportName);
        } catch (Exception ex) {
           ...            
        }
        client.close();
        return print;       
    }

    @Override
    protected void done()  {
        JasperViewer jv = null;
        try {
             jv = new JasperViewer(get(), false);
        } catch (Exception e) {
            ...
        }
        if (jv != null) {
            jv.setTitle(reportName);
            ...
            jv.setVisible(true);
        }                     
    }      
}

In the code above the whole time-consuming code on client side is just a single method call : print = client.getReport(); So would it possible at all to use a progress bar in this case ? (ie since there are no intermediate signs of progress) ? Any suggestions ?

nullPointer
  • 4,419
  • 1
  • 15
  • 27
  • You could listen to the client progress. If stronger coupling is not an issue you could also get a progress bar from client. – c0der Jul 29 '19 at 10:08
  • When you have some time-consuming steps server-side (for example you run more than one DB query), you can start thread (server side of course) and poll its state from client. – Sergiy Medvynskyy Jul 29 '19 at 10:38
  • @Sergiy wouldn't it be the same issue on server side too? I mean how could you get progress for a running DB query from java? – nullPointer Jul 29 '19 at 10:57
  • 1
    @funkyjelly You are right, for a single query it's not possible. But some reports require more than one query, and, in some cases, time for report generation. In this case you can display a progress bar, that really displays progress. When you have only one time consuming operation (the DB query) it's not possible. – Sergiy Medvynskyy Jul 30 '19 at 06:13
  • 1
    @funkyjelly 1. I would consider loading all reports before starting client app. Also you could create kind of demon\service which permanently checks if client report templates are up to date. 2. If p1. is not the option you can collect some metrics and store it on client side. For example you could measure the method getReport() avg. running time, store/update the value locally and use it to show progress bar. – Oleks Aug 03 '19 at 21:55
  • @Oleksandr point 1 is not an option. Point 2 makes sense indeed but I think it would add unnecessary complexity for a very simple feature such as a progress bar. In the end I decided to simply show some "processing" animation message during the report generation. – nullPointer Aug 05 '19 at 06:27

0 Answers0