for(Tiletile:path)locked.add(tile.lock(this));// try to lock all tiles along the path
}catch(Exceptione){// if something fails: unlock all tiles locked so far
for(Tiletile:locked)try{
tile.unlock();
}catch(IOExceptionex){
LOG.warn("Problem while unlocking {}",ex);
}
throwe;
}
for(Tiletile:path)tile.lock(this);
returnthis;
CompletableFuture<Reply>promise=null;
for(Entry<Turnout,State>entry:turnouts.entrySet()){// try to switch all turnouts of this route
CompletableFuture<Reply>reply=entry.getKey().state(entry.getValue());// switching a turnout is an asynchronous process, so it returns a CompletableFuture here