[libbluray-devel] [Git][videolan/libbluray][master] 2 commits: BDJ: split cleanup from shutdown
Petri Hintukainen (@hpi)
gitlab at videolan.org
Sun Oct 2 16:13:35 UTC 2022
Petri Hintukainen pushed to branch master at VideoLAN / libbluray
Commits:
619c2004 by Petri Hintukainen at 2022-10-02T19:11:18+03:00
BDJ: split cleanup from shutdown
So that cleanup is not bypassed if shutdown fails.
- - - - -
36b925bc by Petri Hintukainen at 2022-10-02T19:11:47+03:00
BDJ: delay storage cleanup to shutdown
Avoid removing directories until all Xlets have been stopped.
- - - - -
2 changed files:
- src/libbluray/bdj/java/org/videolan/BDJAppProxy.java
- src/libbluray/bdj/java/org/videolan/Libbluray.java
Changes:
=====================================
src/libbluray/bdj/java/org/videolan/BDJAppProxy.java
=====================================
@@ -26,7 +26,9 @@ import org.dvb.application.DVBJProxy;
import java.awt.EventQueue;
import java.io.File;
+import java.util.HashMap;
import java.util.LinkedList;
+import java.util.Map;
import javax.tv.xlet.Xlet;
class BDJAppProxy implements DVBJProxy, Runnable {
@@ -150,16 +152,7 @@ class BDJAppProxy implements DVBJProxy, Runnable {
logger.error("release(): STOP timeout, killing Xlet " + context.getThreadGroup().getName());
}
- final String persistentOrg = System.getProperty("dvb.persistent.root") + File.separator +
- (String)context.getXletProperty("dvb.org.id") + File.separator;
- final String persistentApp = persistentOrg + (String)context.getXletProperty("dvb.app.id");
-
context.release();
-
- if (new File(persistentApp).delete()) {
- if (!(new File(persistentOrg).delete()))
- logger.info("Error removing " + persistentOrg);
- }
}
public void addAppStateChangeEventListener(AppStateChangeEventListener listener) {
@@ -191,6 +184,50 @@ class BDJAppProxy implements DVBJProxy, Runnable {
return context;
}
+ private void createStorage()
+ {
+ final String persistentOrg = System.getProperty("dvb.persistent.root") + File.separator +
+ (String)context.getXletProperty("dvb.org.id") + File.separator;
+ final String persistentApp = persistentOrg + (String)context.getXletProperty("dvb.app.id");
+ File f = new File(persistentApp);
+ if (!f.isDirectory() && !f.mkdirs()) {
+ logger.error("Error creating persistent storage " + persistentApp);
+ }
+
+ final String budaOrg = System.getProperty("bluray.bindingunit.root") + File.separator +
+ (String)context.getXletProperty("dvb.org.id") + File.separator;
+ final String budaDisc = budaOrg + org.bluray.ti.DiscManager.getDiscManager().getCurrentDisc().getId();
+ File fb = new File(budaDisc);
+ if (!fb.isDirectory() && !fb.mkdirs()) {
+ logger.error("Error creating BUDA storage " + budaDisc);
+ }
+
+ synchronized (cleanupMapLock) {
+ cleanupMap.put(persistentApp,
+ new Runnable() {
+ public void run() {
+ if (new File(persistentApp).delete()) {
+ logger.info("Removed empty " + persistentApp);
+ if (new File(persistentOrg).delete()) {
+ logger.info("Removed empty " + persistentOrg);
+ }
+ }
+ }
+ });
+ cleanupMap.put(budaDisc,
+ new Runnable() {
+ public void run() {
+ if (new File(budaDisc).delete()) {
+ logger.info("Removed empty " + budaDisc);
+ if (new File(budaOrg).delete()) {
+ logger.info("Removed empty " + budaOrg);
+ }
+ }
+ }
+ });
+ }
+ }
+
private boolean doLoad() {
if (state == NOT_LOADED) {
try {
@@ -210,21 +247,7 @@ class BDJAppProxy implements DVBJProxy, Runnable {
return false;
if (state == LOADED) {
try {
- String persistent = System.getProperty("dvb.persistent.root") + File.separator +
- (String)context.getXletProperty("dvb.org.id") + File.separator +
- (String)context.getXletProperty("dvb.app.id");
- File f = new File(persistent);
- if (!f.isDirectory() && !f.mkdirs()) {
- logger.error("Error creating persistent storage " + persistent);
- }
-
- String buda = System.getProperty("bluray.bindingunit.root") + File.separator +
- (String)context.getXletProperty("dvb.org.id") + File.separator +
- org.bluray.ti.DiscManager.getDiscManager().getCurrentDisc().getId();
- File fb = new File(buda);
- if (!fb.isDirectory() && !fb.mkdirs()) {
- logger.error("Error creating BUDA storage " + buda);
- }
+ createStorage();
xlet.initXlet(context);
state = PAUSED;
@@ -381,6 +404,19 @@ class BDJAppProxy implements DVBJProxy, Runnable {
private Thread thread;
private static final Logger logger = Logger.getLogger(BDJAppProxy.class.getName());
+ private static Map cleanupMap = new HashMap();
+ private static Object cleanupMapLock = new Object();
+
+ protected static void cleanup() {
+ Object[] arr;
+ synchronized (cleanupMapLock) {
+ arr = cleanupMap.values().toArray();
+ cleanupMap = new HashMap();
+ }
+ for (int i = 0; i < arr.length; i++)
+ ((Runnable)arr[i]).run();
+ }
+
private static class AppCommand {
public AppCommand(int cmd, Object arg) {
this.cmd = cmd;
=====================================
src/libbluray/bdj/java/org/videolan/Libbluray.java
=====================================
@@ -434,10 +434,15 @@ public class Libbluray {
Status.shutdown();
ServiceContextFactoryImpl.shutdown();
FontFactory.unloadDiscFonts();
- CacheDir.remove();
} catch (Throwable e) {
System.err.println("shutdown() failed: " + e + "\n" + Logger.dumpStack(e));
}
+ try {
+ BDJAppProxy.cleanup();
+ CacheDir.remove();
+ } catch (Throwable e) {
+ System.err.println("cleanup failed: " + e + "\n" + Logger.dumpStack(e));
+ }
nativePointer = 0;
titleInfos = null;
synchronized (bdjoFilesLock) {
View it on GitLab: https://code.videolan.org/videolan/libbluray/-/compare/eb16e097b69402b9cda3ebbe5773e55a38c1fcd9...36b925bca0ab6648c2fbf688fcb28e85efcb4dc3
--
View it on GitLab: https://code.videolan.org/videolan/libbluray/-/compare/eb16e097b69402b9cda3ebbe5773e55a38c1fcd9...36b925bca0ab6648c2fbf688fcb28e85efcb4dc3
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the libbluray-devel
mailing list