Skip to content

Commit

Permalink
removed save-on-shutdown, using save-on-change pragma now for data st…
Browse files Browse the repository at this point in the history
…orage
  • Loading branch information
s1mpl3x committed Sep 27, 2014
1 parent b5d043c commit 0130d7b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/main/java/eu/over9000/skadi/SkadiMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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..");
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/eu/over9000/skadi/channel/ChannelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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());
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/eu/over9000/skadi/gui/SettingsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ public void actionPerformed(final ActionEvent e) {
.isSelected();

SkadiLogging.log("settings updated");

PersistenceManager.getInstance().saveData();

SettingsDialog.this.setVisible(false);
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/eu/over9000/skadi/io/PersistenceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private PersistenceManager() {
}
}

public void saveData() {
public synchronized void saveData() {
try {
final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
final DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/eu/over9000/skadi/util/ImportFollowedUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -132,6 +133,9 @@ public static String importFollowedChannelsFromTwitch(final String username, fin
count++;
}
}

PersistenceManager.getInstance().saveData();

return "Imported " + count + " of " + newChannels.size() + " followed channels.";
}
}

0 comments on commit 0130d7b

Please sign in to comment.