From 0130d7b93c43622222f795fea14dd99f2613ce73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Strau=C3=9F?= Date: Sat, 27 Sep 2014 22:54:48 +0200 Subject: [PATCH] removed save-on-shutdown, using save-on-change pragma now for data storage --- src/main/java/eu/over9000/skadi/SkadiMain.java | 2 -- src/main/java/eu/over9000/skadi/channel/ChannelManager.java | 5 +++++ src/main/java/eu/over9000/skadi/gui/SettingsDialog.java | 3 +++ src/main/java/eu/over9000/skadi/io/PersistenceManager.java | 4 ++-- src/main/java/eu/over9000/skadi/util/ImportFollowedUtil.java | 4 ++++ 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/eu/over9000/skadi/SkadiMain.java b/src/main/java/eu/over9000/skadi/SkadiMain.java index bfaaa9e..228ef7c 100644 --- a/src/main/java/eu/over9000/skadi/SkadiMain.java +++ b/src/main/java/eu/over9000/skadi/SkadiMain.java @@ -163,8 +163,6 @@ public void run() { for (final Channel channel : ChannelManager.getInstance().getChannels()) { channel.closeStreamAndChat(); } - SkadiLogging.log("SAVING DATA.."); - PersistenceManager.getInstance().saveData(); if (SkadiMain.this.lockingSocket != null) { SkadiLogging.log("RELEASING LOCK.."); diff --git a/src/main/java/eu/over9000/skadi/channel/ChannelManager.java b/src/main/java/eu/over9000/skadi/channel/ChannelManager.java index d443f7e..e502cb6 100644 --- a/src/main/java/eu/over9000/skadi/channel/ChannelManager.java +++ b/src/main/java/eu/over9000/skadi/channel/ChannelManager.java @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.List; +import eu.over9000.skadi.io.PersistenceManager; import eu.over9000.skadi.logging.SkadiLogging; import eu.over9000.skadi.util.ChannelDataRetriever; import eu.over9000.skadi.util.ChannelURLUtil; @@ -87,6 +88,7 @@ public boolean addChannel(final String url, final boolean userAdd) { if (userAdd) { SkadiLogging.log("added new channel " + fixedUrl); + PersistenceManager.getInstance().saveData(); } return true; @@ -99,6 +101,9 @@ public void removeChannel(final Channel channel) { listener.removed(channel, this.channels.size()); } } + + PersistenceManager.getInstance().saveData(); + SkadiLogging.log("removed channel " + channel.getURL()); } diff --git a/src/main/java/eu/over9000/skadi/gui/SettingsDialog.java b/src/main/java/eu/over9000/skadi/gui/SettingsDialog.java index f9e02f8..6fcfc3c 100644 --- a/src/main/java/eu/over9000/skadi/gui/SettingsDialog.java +++ b/src/main/java/eu/over9000/skadi/gui/SettingsDialog.java @@ -142,6 +142,9 @@ public void actionPerformed(final ActionEvent e) { .isSelected(); SkadiLogging.log("settings updated"); + + PersistenceManager.getInstance().saveData(); + SettingsDialog.this.setVisible(false); } }); diff --git a/src/main/java/eu/over9000/skadi/io/PersistenceManager.java b/src/main/java/eu/over9000/skadi/io/PersistenceManager.java index 78c23f4..afbc7b8 100644 --- a/src/main/java/eu/over9000/skadi/io/PersistenceManager.java +++ b/src/main/java/eu/over9000/skadi/io/PersistenceManager.java @@ -88,7 +88,7 @@ private PersistenceManager() { } } - public void saveData() { + public synchronized void saveData() { try { final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); final DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); @@ -170,7 +170,7 @@ private void loadChannels(final Element channelsRootElement) { } - public void loadData() { + public synchronized void loadData() { try { final FileInputStream stream = new FileInputStream(this.dataFile); diff --git a/src/main/java/eu/over9000/skadi/util/ImportFollowedUtil.java b/src/main/java/eu/over9000/skadi/util/ImportFollowedUtil.java index 3d8b75f..f955e67 100644 --- a/src/main/java/eu/over9000/skadi/util/ImportFollowedUtil.java +++ b/src/main/java/eu/over9000/skadi/util/ImportFollowedUtil.java @@ -32,6 +32,7 @@ import eu.over9000.skadi.channel.ChannelManager; import eu.over9000.skadi.gui.ImportDialog; +import eu.over9000.skadi.io.PersistenceManager; import eu.over9000.skadi.logging.SkadiLogging; /** @@ -132,6 +133,9 @@ public static String importFollowedChannelsFromTwitch(final String username, fin count++; } } + + PersistenceManager.getInstance().saveData(); + return "Imported " + count + " of " + newChannels.size() + " followed channels."; } }