boolean lockResult = false;
StandardSession stdSess = (StandardSession) sess;
//try to lock up to maxNumberOfRetries times
//poll and wait starting with 200 ms
while(keepTrying) {
lockResult = stdSess.lockForeground();
if(lockResult) {
keepTrying = false;
result = true;
break;
}