* pre-load MediaTypes, MediaDetection and Groovy classes and resources on a low-priority background thread right after startup

This commit is contained in:
Reinhard Pointner 2012-07-06 03:10:26 +00:00
parent f844b96f05
commit ae71d809ea
5 changed files with 49 additions and 18 deletions

View File

@ -22,6 +22,8 @@ import java.security.PermissionCollection;
import java.security.Permissions; import java.security.Permissions;
import java.security.Policy; import java.security.Policy;
import java.security.ProtectionDomain; import java.security.ProtectionDomain;
import java.util.Collections;
import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -45,6 +47,7 @@ import net.sourceforge.filebot.cli.ArgumentBean;
import net.sourceforge.filebot.cli.ArgumentProcessor; import net.sourceforge.filebot.cli.ArgumentProcessor;
import net.sourceforge.filebot.cli.CmdlineOperations; import net.sourceforge.filebot.cli.CmdlineOperations;
import net.sourceforge.filebot.format.ExpressionFormat; import net.sourceforge.filebot.format.ExpressionFormat;
import net.sourceforge.filebot.media.MediaDetection;
import net.sourceforge.filebot.ui.MainFrame; import net.sourceforge.filebot.ui.MainFrame;
import net.sourceforge.filebot.ui.SinglePanelFrame; import net.sourceforge.filebot.ui.SinglePanelFrame;
import net.sourceforge.filebot.ui.sfv.SfvPanelBuilder; import net.sourceforge.filebot.ui.sfv.SfvPanelBuilder;
@ -108,7 +111,7 @@ public class Main {
// GUI mode => start user interface // GUI mode => start user interface
try { try {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeAndWait(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -123,8 +126,8 @@ public class Main {
} }
}); });
// pre-load media.types (when loaded during DnD it will freeze the UI for a few hundred milliseconds) // pre-load certain classes and resources in the background
MediaTypes.getDefault(); warmupCachedResources();
// check for application updates (only when installed, i.e. not running via fatjar or webstart) // check for application updates (only when installed, i.e. not running via fatjar or webstart)
if (!"skip".equals(System.getProperty("application.update"))) { if (!"skip".equals(System.getProperty("application.update"))) {
@ -247,6 +250,36 @@ public class Main {
} }
private static void warmupCachedResources() {
Thread warmup = new Thread("warmup") {
@Override
public void run() {
try {
// pre-load media.types (when loaded during DnD it will freeze the UI for a few hundred milliseconds)
MediaTypes.getDefault();
// pre-load movie/series index
List<String> dummy = Collections.singletonList("");
MediaDetection.stripReleaseInfo(dummy, true);
MediaDetection.matchSeriesByName(dummy, 0);
MediaDetection.matchMovieName(dummy, true);
// pre-load Groovy script engine
new ExpressionFormat("").format("");
} catch (Exception e) {
Logger.getLogger(getClass().getName()).log(Level.WARNING, e.getMessage(), e);
}
}
};
// start background thread
warmup.setDaemon(true);
warmup.setPriority(Thread.MIN_PRIORITY);
warmup.start();
}
private static void restoreWindowBounds(final JFrame window, final Settings settings) { private static void restoreWindowBounds(final JFrame window, final Settings settings) {
// store bounds on close // store bounds on close
window.addWindowListener(new WindowAdapter() { window.addWindowListener(new WindowAdapter() {

View File

@ -6,6 +6,7 @@ import static java.util.Arrays.*;
import static net.sourceforge.filebot.MediaTypes.*; import static net.sourceforge.filebot.MediaTypes.*;
import static net.sourceforge.filebot.format.Define.*; import static net.sourceforge.filebot.format.Define.*;
import static net.sourceforge.filebot.hash.VerificationUtilities.*; import static net.sourceforge.filebot.hash.VerificationUtilities.*;
import static net.sourceforge.filebot.media.MediaDetection.*;
import static net.sourceforge.filebot.similarity.Normalization.*; import static net.sourceforge.filebot.similarity.Normalization.*;
import static net.sourceforge.filebot.web.EpisodeFormat.*; import static net.sourceforge.filebot.web.EpisodeFormat.*;
import static net.sourceforge.tuned.FileUtilities.*; import static net.sourceforge.tuned.FileUtilities.*;
@ -24,7 +25,6 @@ import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element; import net.sf.ehcache.Element;
import net.sourceforge.filebot.WebServices; import net.sourceforge.filebot.WebServices;
import net.sourceforge.filebot.hash.HashType; import net.sourceforge.filebot.hash.HashType;
import net.sourceforge.filebot.media.ReleaseInfo;
import net.sourceforge.filebot.mediainfo.MediaInfo; import net.sourceforge.filebot.mediainfo.MediaInfo;
import net.sourceforge.filebot.mediainfo.MediaInfo.StreamKind; import net.sourceforge.filebot.mediainfo.MediaInfo.StreamKind;
import net.sourceforge.filebot.web.Date; import net.sourceforge.filebot.web.Date;
@ -287,7 +287,6 @@ public class MediaBindingBean {
public String getVideoSource() { public String getVideoSource() {
// use inferred media file // use inferred media file
File inferredMediaFile = getInferredMediaFile(); File inferredMediaFile = getInferredMediaFile();
ReleaseInfo releaseInfo = new ReleaseInfo();
// look for video source patterns in media file and it's parent folder // look for video source patterns in media file and it's parent folder
return releaseInfo.getVideoSource(inferredMediaFile); return releaseInfo.getVideoSource(inferredMediaFile);
@ -298,7 +297,6 @@ public class MediaBindingBean {
public String getReleaseGroup() throws IOException { public String getReleaseGroup() throws IOException {
// use inferred media file // use inferred media file
File inferredMediaFile = getInferredMediaFile(); File inferredMediaFile = getInferredMediaFile();
ReleaseInfo releaseInfo = new ReleaseInfo();
// look for release group names in media file and it's parent folder // look for release group names in media file and it's parent folder
return releaseInfo.getReleaseGroup(inferredMediaFile); return releaseInfo.getReleaseGroup(inferredMediaFile);
@ -310,7 +308,7 @@ public class MediaBindingBean {
// make sure media file is defined // make sure media file is defined
checkMediaFile(); checkMediaFile();
Locale languageSuffix = new ReleaseInfo().getLanguageSuffix(FileUtilities.getName(mediaFile)); Locale languageSuffix = releaseInfo.getLanguageSuffix(FileUtilities.getName(mediaFile));
if (languageSuffix != null) if (languageSuffix != null)
return new Locale(languageSuffix.getISO3Language()); // force ISO3 letter-code return new Locale(languageSuffix.getISO3Language()); // force ISO3 letter-code

View File

@ -56,7 +56,7 @@ import net.sourceforge.filebot.web.TheTVDBClient.TheTVDBSearchResult;
public class MediaDetection { public class MediaDetection {
private static final ReleaseInfo releaseInfo = new ReleaseInfo(); public static final ReleaseInfo releaseInfo = new ReleaseInfo();
public static final FileFilter DISK_FOLDERS = releaseInfo.getDiskFolderFilter(); public static final FileFilter DISK_FOLDERS = releaseInfo.getDiskFolderFilter();
public static final FileFilter NON_CLUTTER_FILES = not(releaseInfo.getClutterFileFilter()); public static final FileFilter NON_CLUTTER_FILES = not(releaseInfo.getClutterFileFilter());
@ -319,7 +319,7 @@ public class MediaDetection {
terms.add(reduceMovieName(getName(movieFolder))); terms.add(reduceMovieName(getName(movieFolder)));
} }
List<Movie> movieNameMatches = matchMovieName(terms, locale, strict); List<Movie> movieNameMatches = matchMovieName(terms, strict);
// skip further queries if collected matches are already sufficient // skip further queries if collected matches are already sufficient
if (options.size() > 0 && movieNameMatches.size() > 0) { if (options.size() > 0 && movieNameMatches.size() > 0) {
@ -329,7 +329,7 @@ public class MediaDetection {
// if matching name+year failed, try matching only by name // if matching name+year failed, try matching only by name
if (movieNameMatches.isEmpty() && strict) { if (movieNameMatches.isEmpty() && strict) {
movieNameMatches = matchMovieName(terms, locale, false); movieNameMatches = matchMovieName(terms, false);
} }
// assume name without spacing will mess up any lookup // assume name without spacing will mess up any lookup
@ -406,7 +406,7 @@ public class MediaDetection {
} }
public static List<Movie> matchMovieName(final List<String> files, final Locale locale, final boolean strict) throws Exception { public static List<Movie> matchMovieName(final List<String> files, final boolean strict) throws Exception {
// cross-reference file / folder name with movie list // cross-reference file / folder name with movie list
final HighPerformanceMatcher nameMatcher = new HighPerformanceMatcher(3); final HighPerformanceMatcher nameMatcher = new HighPerformanceMatcher(3);
final Map<Movie, String> matchMap = new HashMap<Movie, String>(); final Map<Movie, String> matchMap = new HashMap<Movie, String>();

View File

@ -195,24 +195,24 @@ public class ReleaseInfo {
} }
public synchronized Pattern getReleaseGroupPattern(boolean strict) throws IOException { public Pattern getReleaseGroupPattern(boolean strict) throws IOException {
// pattern matching any release group name enclosed in separators // pattern matching any release group name enclosed in separators
return compile("(?<!\\p{Alnum})(" + join(releaseGroupResource.get(), "|") + ")(?!\\p{Alnum})", strict ? 0 : CASE_INSENSITIVE | UNICODE_CASE | CANON_EQ); return compile("(?<!\\p{Alnum})(" + join(releaseGroupResource.get(), "|") + ")(?!\\p{Alnum})", strict ? 0 : CASE_INSENSITIVE | UNICODE_CASE | CANON_EQ);
} }
public synchronized Pattern getBlacklistPattern() throws IOException { public Pattern getBlacklistPattern() throws IOException {
// pattern matching any release group name enclosed in separators // pattern matching any release group name enclosed in separators
return compile("(?<!\\p{Alnum})(" + join(queryBlacklistResource.get(), "|") + ")(?!\\p{Alnum})", CASE_INSENSITIVE | UNICODE_CASE | CANON_EQ); return compile("(?<!\\p{Alnum})(" + join(queryBlacklistResource.get(), "|") + ")(?!\\p{Alnum})", CASE_INSENSITIVE | UNICODE_CASE | CANON_EQ);
} }
public synchronized Movie[] getMovieList() throws IOException { public Movie[] getMovieList() throws IOException {
return movieListResource.get(); return movieListResource.get();
} }
public synchronized String[] getSeriesList() throws IOException { public String[] getSeriesList() throws IOException {
return seriesListResource.get(); return seriesListResource.get();
} }

View File

@ -21,10 +21,9 @@
^DVD ^DVD
^Film[s]? ^Film[s]?
^HVDVD_TS$ ^HVDVD_TS$
^Info
^Movie[s]? ^Movie[s]?
^New$ ^new$
^Other$ ^other$
^SAMPLE ^SAMPLE
^Season.[0-9]+ ^Season.[0-9]+
^Torrents[s]? ^Torrents[s]?
@ -62,6 +61,7 @@ Hard.Subbed
HDRip HDRip
Hindi Hindi
HQ HQ
info
iNT iNT
iNTERNAL iNTERNAL
iPod iPod