4040import org .phoebus .applications .saveandrestore .ui .VNoData ;
4141import org .phoebus .applications .saveandrestore .ui .VTypePair ;
4242import org .phoebus .core .vtypes .VDisconnectedData ;
43- import org .phoebus .core .vtypes .VTypeHelper ;
4443import org .phoebus .framework .jobs .JobManager ;
44+ import org .phoebus .saveandrestore .util .SnapshotUtil ;
4545import org .phoebus .ui .dialog .DialogHelper ;
4646import org .phoebus .ui .dialog .ExceptionDetailsErrorDialog ;
4747import org .phoebus .ui .time .DateTimePane ;
5050import java .text .SimpleDateFormat ;
5151import java .time .Instant ;
5252import java .util .ArrayList ;
53- import java .util .Collections ;
5453import java .util .Comparator ;
5554import java .util .Date ;
5655import java .util .List ;
5756import java .util .Optional ;
58- import java .util .concurrent .CountDownLatch ;
59- import java .util .concurrent .TimeUnit ;
6057import java .util .function .Consumer ;
6158import java .util .logging .Level ;
6259import java .util .regex .Pattern ;
@@ -83,6 +80,7 @@ public class SnapshotTableViewController extends BaseSnapshotTableViewController
8380
8481 private final SimpleBooleanProperty compareViewEnabled = new SimpleBooleanProperty (false );
8582
83+ private SnapshotUtil snapshotUtil ;
8684
8785 @ FXML
8886 public void initialize () {
@@ -147,6 +145,8 @@ public void initialize() {
147145 valueColumn .visibleProperty ().bind (compareViewEnabled .not ());
148146
149147 compareViewEnabled .addListener ((ob , o , n ) -> snapshotTableView .layout ());
148+
149+ snapshotUtil = new SnapshotUtil ();
150150 }
151151
152152 public void setSnapshotController (SnapshotController snapshotController ) {
@@ -429,48 +429,36 @@ public void restoreFromService(Snapshot snapshot, Consumer<List<RestoreResult>>
429429 @ SuppressWarnings ("unused" )
430430 public void restoreFromClient (Snapshot snapshot , Consumer <List <RestoreResult >> completion ) {
431431 new Thread (() -> {
432- CountDownLatch countDownLatch = new CountDownLatch (snapshot .getSnapshotData ().getSnapshotItems ().size ());
433432
433+ List <SnapshotItem > itemsToRestore = new ArrayList <>();
434434 List <RestoreResult > restoreResultList = new ArrayList <>();
435435
436- snapshot .getSnapshotData ().getSnapshotItems ()
437- .forEach (e -> pvs .get (getPVKey (e .getConfigPv ().getPvName (), e .getConfigPv ().isReadOnly ())).setCountDownLatch (countDownLatch ));
438-
439436 for (SnapshotItem entry : snapshot .getSnapshotData ().getSnapshotItems ()) {
440437 TableEntry e = tableEntryItems .get (getPVKey (entry .getConfigPv ().getPvName (), entry .getConfigPv ().isReadOnly ()));
441438
442- RestoreResult restoreResult = new RestoreResult ();
443- restoreResult .setSnapshotItem (entry );
444-
445439 boolean restorable = e .selectedProperty ().get () &&
446440 !e .readOnlyProperty ().get () &&
447441 entry .getValue () != null &&
448442 !entry .getValue ().equals (VNoData .INSTANCE );
449443
450444 if (restorable ) {
451- final SaveAndRestorePV pv = pvs .get (getPVKey (e .pvNameProperty ().get (), e .readOnlyProperty ().get ()));
452- if (entry .getValue () != null ) {
453- try {
454- pv .getPv ().write (VTypeHelper .toObject (entry .getValue ()));
455- } catch (Exception writeException ) {
456- restoreResult .setErrorMsg (writeException .getMessage ());
457- restoreResultList .add (restoreResult );
458- } finally {
459- pv .countDown ();
460- }
461- }
462- } else {
463- restoreResult .setErrorMsg (entry .getConfigPv ().getPvName () + " is not restoreable" );
464- countDownLatch .countDown ();
445+ itemsToRestore .add (entry );
465446 }
466447 }
467448
468449 try {
469- countDownLatch .await (10 , TimeUnit .MINUTES );
470- } catch (InterruptedException e ) {
471- LOGGER .log (Level .INFO , "Encountered InterruptedException" , e );
450+ restoreResultList = snapshotUtil .restore (itemsToRestore );
451+ } catch (Exception e ) {
452+ Platform .runLater (() -> {
453+ Alert alert = new Alert (Alert .AlertType .ERROR );
454+ alert .setTitle (Messages .errorActionFailed );
455+ alert .setContentText (e .getMessage ());
456+ alert .setHeaderText (Messages .restoreFailed );
457+ DialogHelper .positionDialog (alert , snapshotTableView , -150 , -150 );
458+ alert .showAndWait ();
459+ });
472460 }
473-
461+ // Legacy
474462 if (restoreResultList .isEmpty ()) {
475463 LOGGER .log (Level .FINE , "Restored snapshot {0}" , snapshot .getSnapshotNode ().getName ());
476464 } else {
0 commit comments