Skip to content

Commit 6bc5e74

Browse files
author
Open Lowcode SAS
committed
Close #170 Close #167
1 parent aea20ab commit 6bc5e74

File tree

3 files changed

+171
-74
lines changed

3 files changed

+171
-74
lines changed

src/org/openlowcode/client/runtime/ClientDisplay.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ public void changed(
446446
updateStatusBar("displayed page succesfully");
447447

448448
}
449-
parent.setBusinessScreenFrozen(false);
449+
450450

451451
} catch (Exception e) {
452452
logger.warning("Error in displaying page " + e.getMessage());
@@ -457,7 +457,7 @@ public void changed(
457457
}
458458

459459
updateStatusBar("Error in displaying page :" + e.getMessage(), true);
460-
parent.setBusinessScreenFrozen(false);
460+
461461

462462
}
463463
}

src/org/openlowcode/client/runtime/ClientSession.java

Lines changed: 127 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ public class ClientSession {
7979

8080
private String questionmarkicon;
8181

82+
private boolean busy;
83+
8284
/**
8385
* @return gets the locale on the machine
8486
*/
@@ -131,7 +133,10 @@ public void setShowTechDetails(boolean techdetails) {
131133
* @param urltoconnecto first URL to connect to, null if not used
132134
* @param questionmarkicon question mark icon URL
133135
*/
134-
public ClientSession(ClientMainFrame mainframe, ActionSourceTransformer transformer, String urltoconnecto,
136+
public ClientSession(
137+
ClientMainFrame mainframe,
138+
ActionSourceTransformer transformer,
139+
String urltoconnecto,
135140
String questionmarkicon) {
136141
this.mainframe = mainframe;
137142
this.displaysforconnection = new ArrayList<ClientDisplay>();
@@ -278,20 +283,21 @@ public ClientData getClientData() {
278283
* @param page page to show the data coming back from the inline
279284
* action
280285
*/
281-
public void sendInlineAction(String actionname, String modulename, CActionData actionattributes,
282-
CPage page) {
286+
public void sendInlineAction(String actionname, String modulename, CActionData actionattributes, CPage page) {
283287
ClientDisplay activedisplay = displaysforconnection.get(activedisplayindex);
284288

285289
long startaction = System.currentTimeMillis();
286-
this.setBusinessScreenFrozen(true);
290+
this.setBusinessScreenFrozen(true, connectiontoserver);
291+
ConnectionToServer localconnectiontoserver = connectiontoserver;
287292
activedisplay.updateStatusBar("Send action to the server " + modulename + "." + actionname);
288293
Thread thread = new Thread() {
289294
@Override
290295
public void run() {
291296
try {
292-
activedisplay.updateStatusBar("Connection Established with " + connectiontoserver.getServer() + " "
293-
+ connectiontoserver.getPort());
294-
connectiontoserver.sendMessage((writer) -> {
297+
298+
activedisplay.updateStatusBar("Connection Established with " + localconnectiontoserver.getServer()
299+
+ " " + connectiontoserver.getPort());
300+
MessageElement firstelement = localconnectiontoserver.sendMessage((writer) -> {
295301
writer.startNewMessage();
296302
writer.startStructure("REQUEST");
297303
writer.addStringField("CID", cid);
@@ -305,21 +311,23 @@ public void run() {
305311
writer.endMessage();
306312
writer.flushMessage();
307313
});
314+
if (localconnectiontoserver.isRelevant()) {
315+
DisplayPageFeedback exceptionmessage = enrichPageWithInlineData(firstelement,localconnectiontoserver, page,
316+
activedisplay, startaction, techdetails, modulename, actionname);
308317

309-
DisplayPageFeedback exceptionmessage = enrichPageWithInlineData(page, activedisplay, startaction,
310-
techdetails, modulename, actionname);
311-
long endaction = System.currentTimeMillis();
312-
if (exceptionmessage.getErrormessage() != null) {
318+
long endaction = System.currentTimeMillis();
319+
if (exceptionmessage.getErrormessage() != null) {
313320

314-
activedisplay
315-
.updateStatusBar("Error message from server : " + exceptionmessage.getErrormessage()
316-
+ " - execution time (ms) : " + (endaction - startaction), true);
321+
activedisplay
322+
.updateStatusBar("Error message from server : " + exceptionmessage.getErrormessage()
323+
+ " - execution time (ms) : " + (endaction - startaction), true);
317324

325+
}
318326
}
319-
setBusinessScreenFrozen(false);
327+
setBusinessScreenFrozen(false, localconnectiontoserver);
320328
} catch (Exception e) {
321329
treatException(e);
322-
setBusinessScreenFrozen(false);
330+
setBusinessScreenFrozen(false, localconnectiontoserver);
323331

324332
}
325333
}
@@ -342,15 +350,17 @@ public void sendaction(String actionname, String modulename, CActionData actiona
342350
ClientDisplay activedisplay = displaysforconnection.get(activedisplayindex);
343351

344352
long startaction = System.currentTimeMillis();
345-
this.setBusinessScreenFrozen(true);
353+
this.setBusinessScreenFrozen(true, connectiontoserver);
354+
ConnectionToServer localconnectiontoserver = connectiontoserver;
346355
activedisplay.updateStatusBar("Send action to the server " + modulename + "." + actionname);
347356
Thread thread = new Thread() {
348357
@Override
349358
public void run() {
350359
try {
351-
activedisplay.updateStatusBar("Connection Established with " + connectiontoserver.getServer() + " "
352-
+ connectiontoserver.getPort());
353-
connectiontoserver.sendMessage((writer) -> {
360+
361+
activedisplay.updateStatusBar("Connection Established with " + localconnectiontoserver.getServer()
362+
+ " " + localconnectiontoserver.getPort());
363+
MessageElement firstelement = localconnectiontoserver.sendMessage((writer) -> {
354364
writer.startNewMessage();
355365
writer.startStructure("REQUEST");
356366
writer.addStringField("CID", cid);
@@ -366,8 +376,9 @@ public void run() {
366376
writer.flushMessage();
367377
});
368378

369-
DisplayPageFeedback exceptionmessage = displayPage(activedisplay, startaction, techdetails, modulename,
370-
actionname, openinnewtab);
379+
DisplayPageFeedback exceptionmessage = displayPage(firstelement, localconnectiontoserver,
380+
activedisplay, startaction, techdetails, modulename, actionname, openinnewtab);
381+
setBusinessScreenFrozen(false, localconnectiontoserver);
371382
long endaction = System.currentTimeMillis();
372383
if (exceptionmessage.getErrormessage() != null) {
373384

@@ -379,7 +390,7 @@ public void run() {
379390

380391
} catch (Exception e) {
381392
treatException(e);
382-
setBusinessScreenFrozen(false);
393+
setBusinessScreenFrozen(false, localconnectiontoserver);
383394

384395
}
385396
}
@@ -395,21 +406,26 @@ public void run() {
395406
* @param back true if back is possible
396407
*/
397408
public void sendLink(String address, boolean back) {
409+
ConnectionToServer localconnectiontoserver = connectiontoserver;
398410
try {
399411
ClientDisplay activedisplay = displaysforconnection.get(activedisplayindex);
412+
400413
boolean confirmcontinue = activedisplay.checkContinueWarning();
401414
if (confirmcontinue) {
402415
long startaction = System.currentTimeMillis();
403-
setBusinessScreenFrozen(true);
416+
setBusinessScreenFrozen(true, localconnectiontoserver);
417+
localconnectiontoserver = connectiontoserver;
418+
final ConnectionToServer localconnectionfinal = localconnectiontoserver;
404419
activedisplay.updateStatusBar("requested connection to the address " + address);
405420
Thread thread = new Thread() {
406421
@Override
407422
public void run() {
408423
try {
409-
String application = connectiontoserver.connectToAddressAndGetApplication(address);
424+
425+
String application = localconnectionfinal.connectToAddressAndGetApplication(address);
410426
activedisplay.updateStatusBar("Connection Established with "
411-
+ connectiontoserver.getServer() + " " + connectiontoserver.getPort());
412-
connectiontoserver.sendMessage((writer) -> {
427+
+ localconnectionfinal.getServer() + " " + localconnectionfinal.getPort());
428+
MessageElement startelement = localconnectionfinal.sendMessage((writer) -> {
413429
writer.startNewMessage();
414430
writer.startStructure("REQUEST");
415431
if (cid != null)
@@ -424,8 +440,8 @@ public void run() {
424440
writer.flushMessage();
425441
});
426442

427-
DisplayPageFeedback exceptionmessage = displayPage(activedisplay, startaction, techdetails,
428-
null, null, false);
443+
DisplayPageFeedback exceptionmessage = displayPage(startelement,localconnectionfinal, activedisplay,
444+
startaction, techdetails, null, null, false);
429445
long endaction = System.currentTimeMillis();
430446
if (exceptionmessage.getErrormessage() != null) {
431447

@@ -436,10 +452,10 @@ public void run() {
436452
true);
437453

438454
}
439-
455+
setBusinessScreenFrozen(false, localconnectionfinal);
440456
} catch (Exception e) {
441457
treatException(e);
442-
setBusinessScreenFrozen(false);
458+
setBusinessScreenFrozen(false, localconnectionfinal);
443459

444460
}
445461
}
@@ -448,29 +464,36 @@ public void run() {
448464
}
449465
} catch (Exception e) {
450466
treatException(e);
451-
setBusinessScreenFrozen(false);
467+
setBusinessScreenFrozen(false, localconnectiontoserver);
452468

453469
}
454470
}
455471

456472
/**
457-
* @param page current page
458-
* @param activedisplay client display for the action
459-
* @param starttime start time of the interaction with the server (for
460-
* performance audit purposes)
461-
* @param showtechdetails true if all technical details (memory, speed of
462-
* request, network bandwidth used)
463-
* @param module name of the module
464-
* @param action name of the line action
473+
* @param localconnectiontoserver local connection to server
474+
* @param page current page
475+
* @param activedisplay client display for the action
476+
* @param starttime start time of the interaction with the server
477+
* (for performance audit purposes)
478+
* @param showtechdetails true if all technical details (memory, speed
479+
* of request, network bandwidth used)
480+
* @param module name of the module
481+
* @param action name of the line action
465482
* @return a feedback if processing happened well or not
466483
* @throws IOException if any network breadkown
467484
* @throws OLcRemoteException if anythink bad happened on the server during the
468485
* request
469486
*/
470-
public DisplayPageFeedback enrichPageWithInlineData(CPage page, ClientDisplay activedisplay, long starttime,
471-
boolean showtechdetails, String module, String action) throws IOException, OLcRemoteException {
472-
MessageReader reader = connectiontoserver.getReader();
473-
MessageElement startelement = reader.getNextElement();
487+
public DisplayPageFeedback enrichPageWithInlineData(
488+
MessageElement startelement,
489+
ConnectionToServer localconnectiontoserver,
490+
CPage page,
491+
ClientDisplay activedisplay,
492+
long starttime,
493+
boolean showtechdetails,
494+
String module,
495+
String action) throws IOException, OLcRemoteException {
496+
MessageReader reader = localconnectiontoserver.getReader();
474497
if (startelement instanceof MessageError) {
475498
MessageError messageerror = (MessageError) startelement;
476499
DisplayPageFeedback feedback = new DisplayPageFeedback(
@@ -507,23 +530,33 @@ public DisplayPageFeedback enrichPageWithInlineData(CPage page, ClientDisplay ac
507530
}
508531

509532
/**
510-
* @param activedisplay current display
511-
* @param starttime start time of the exchange with the server
512-
* @param showtechdetails true to show tech details
513-
* @param module name of the module
514-
* @param action name of the action
515-
* @param openinnewtab true to open in new tabs
533+
* @param startelement first element read from the server (error or
534+
* message start)
535+
* @param localconnectiontoserver a copy of the server connection valid at time
536+
* of start of request
537+
* @param activedisplay current display
538+
* @param starttime start time of the exchange with the server
539+
* @param showtechdetails true to show tech details
540+
* @param module name of the module
541+
* @param action name of the action
542+
* @param openinnewtab true to open in new tabs
516543
* @return a feedback
517544
* @throws IOException if any network breadkown
518545
* @throws OLcRemoteException if anythink bad happened on the server during the
519546
* request
520547
*/
521-
public DisplayPageFeedback displayPage(ClientDisplay activedisplay, long starttime, boolean showtechdetails,
522-
String module, String action, boolean openinnewtab) throws IOException, OLcRemoteException {
523-
MessageReader reader = connectiontoserver.getReader();
548+
public DisplayPageFeedback displayPage(
549+
MessageElement startelement,
550+
ConnectionToServer localconnectiontoserver,
551+
ClientDisplay activedisplay,
552+
long starttime,
553+
boolean showtechdetails,
554+
String module,
555+
String action,
556+
boolean openinnewtab) throws IOException, OLcRemoteException {
557+
MessageReader reader = localconnectiontoserver.getReader();
524558
logger.info("starts displaying page in thread " + Thread.currentThread().getId() + " for " + module + "."
525559
+ action + " with openinnewtab=" + openinnewtab);
526-
MessageElement startelement = reader.getNextElement();
527560
if (startelement instanceof MessageError) {
528561
MessageError messageerror = (MessageError) startelement;
529562
DisplayPageFeedback feedback = new DisplayPageFeedback(
@@ -585,16 +618,14 @@ public DisplayPageFeedback displayPage(ClientDisplay activedisplay, long startti
585618
reader.returnNextEndStructure("DISPLAYPAGE");
586619
reader.returnNextEndMessage();
587620
logger.finer("finishes parsing");
588-
589-
590-
591-
592-
593-
594-
activedisplay.setandDisplayPage(title, fulladdress, page, address, starttime,
595-
reader.charcountsinceStartMessage(), page.getBufferedDataUsed() / 1024,
596-
this.pagebuffer.getTotalBufferSize() / 1024, showtechdetails, openinnewtab);
597-
621+
if (localconnectiontoserver.isRelevant()) {
622+
activedisplay.setandDisplayPage(title, fulladdress, page, address, starttime,
623+
reader.charcountsinceStartMessage(), page.getBufferedDataUsed() / 1024,
624+
this.pagebuffer.getTotalBufferSize() / 1024, showtechdetails, openinnewtab);
625+
} else {
626+
logger.severe("Connection " + localconnectiontoserver.hashCode()
627+
+ " is not relevant anymore, page is not shown");
628+
}
598629
return new DisplayPageFeedback(null, reader.charcountsinceStartMessage(), pagestring);
599630
}
600631
// ---------------------------- EXCEPTION CASE 1 - DISPLAY SERVER ERROR
@@ -687,16 +718,43 @@ public static void printException(Exception e) {
687718
}
688719

689720
/**
690-
* @param frozen true if widgets should be frozen as one communication is
691-
* already happening in the server
721+
* @param frozen true if widgets should be frozen as one communication
722+
* is already happening in the server
723+
* @param localconnection the currentconnection
692724
*/
693-
public void setBusinessScreenFrozen(boolean frozen) {
725+
public void setBusinessScreenFrozen(boolean frozen, ConnectionToServer localconnection) {
694726
// closing message if required (if error while sending the message)
727+
if (frozen)
728+
if (busy) {
729+
logger.warning("** Client session connection management - Opening second connection");
730+
connectiontoserver.markAsIrrelevant();
731+
logger.warning(" ---> Connection " + connectiontoserver.hashCode() + " marked as irrelevant");
732+
connectiontoserver = new ConnectionToServer(connectiontoserver);
733+
logger.warning(" ---> Opening new connection " + connectiontoserver.hashCode());
734+
} else {
735+
logger.warning("** Client session connection management - Busy on first connection");
736+
this.busy = true;
737+
}
738+
739+
if (!frozen) {
740+
if (localconnection == connectiontoserver) {
741+
logger.warning("** Client session connection management - close current connection");
742+
this.busy = false;
743+
} else {
744+
logger.warning("** Client session connection management - closing obsolete connection");
745+
try {
746+
localconnection.stopConnection();
747+
} catch (IOException exception) {
748+
logger.warning("Error in closing obsolete connection " + exception.getMessage());
749+
750+
}
751+
}
752+
753+
}
695754
connectiontoserver.resetSendingMessage();
696755
// making connection bar active again
697756
for (int i = 0; i < this.displaysforconnection.size(); i++)
698757
displaysforconnection.get(i).setBusinessScreenFrozen(frozen);
699-
;
700758

701759
}
702760

@@ -724,7 +782,7 @@ public void stopconnection() {
724782
}
725783
this.getActiveClientDisplay().updateStatusBar("Connectionerror " + e.getMessage());
726784

727-
setBusinessScreenFrozen(false);
785+
setBusinessScreenFrozen(false, connectiontoserver);
728786
}
729787

730788
}

0 commit comments

Comments
 (0)