// MUST NOT return null
try {
InputStream in = cache.load(originalUrl, false, stable);
- Instance.trace("Cache " + (in != null ? "hit" : "miss") + ": "
- + url);
+ Instance.getTraceHandler().trace(
+ "Cache " + (in != null ? "hit" : "miss") + ": " + url);
if (in == null) {
try {
private static TraceHandler tracer;
static {
+ // Before we can configure it:
+ tracer = new TraceHandler(true, checkEnv("DEBUG"), false);
+
// Most of the rest is dependent upon this:
config = new ConfigBundle();
config = new ConfigBundle();
config.updateFile(configDir);
} catch (IOException e) {
- syserr(e);
+ tracer.error(e);
}
try {
uiconfig = new UiConfigBundle();
uiconfig.updateFile(configDir);
} catch (IOException e) {
- syserr(e);
+ tracer.error(e);
}
// No updateFile for this one! (we do not want the user to have custom
debug = true;
}
- tracer = new TraceHandler();
- tracer.setShowErrorDetails(debug);
- tracer.setShowTraces(trace);
+ tracer = new TraceHandler(true, debug, trace);
try {
lib = new LocalLibrary(getFile(Config.LIBRARY_DIR));
} catch (Exception e) {
- syserr(new IOException("Cannot create library for directory: "
- + getFile(Config.LIBRARY_DIR), e));
+ tracer.error(new IOException(
+ "Cannot create library for directory: "
+ + getFile(Config.LIBRARY_DIR), e));
}
// Could have used: System.getProperty("java.io.tmpdir")
//
if (coverDir != null && !coverDir.exists()) {
- syserr(new IOException(
+ tracer.error(new IOException(
"The 'default covers' directory does not exists: "
+ coverDir));
coverDir = null;
cache = new DataLoader(tmp, ua, hours, hoursLarge);
} catch (IOException e) {
- syserr(new IOException(
+ tracer.error(new IOException(
"Cannot create cache (will continue without cache)", e));
}
}
/**
* The traces handler for this {@link Cache}.
+ * <p>
+ * It is never NULL.
*
- * @return the traces handler or NULL
+ * @return the traces handler (never NULL)
*/
public static TraceHandler getTraceHandler() {
return tracer;
* the new traces handler or NULL
*/
public static void setTraceHandler(TraceHandler tracer) {
+ if (tracer == null) {
+ tracer = new TraceHandler(false, false, false);
+ }
+
Instance.tracer = tracer;
}
IOUtils.writeSmallFile(new File(configDir), "LAST_UPDATE",
Long.toString(new Date().getTime()));
} catch (IOException e) {
- syserr(e);
- }
- }
-
- /**
- * Report an error to the user
- *
- * @param e
- * the {@link Exception} to report
- */
- public static void syserr(Exception e) {
- if (tracer != null) {
tracer.error(e);
}
}
- /**
- * Notify of a debug message.
- *
- * @param message
- * the message
- */
- public static void trace(String message) {
- if (tracer != null) {
- tracer.trace(message);
- }
- }
-
/**
* Return a path, but support the special $HOME variable.
*
import be.nikiroo.fanfix.supported.BasicSupport;
import be.nikiroo.fanfix.supported.BasicSupport.SupportType;
import be.nikiroo.utils.Progress;
+import be.nikiroo.utils.TraceHandler;
import be.nikiroo.utils.Version;
-import be.nikiroo.utils.serial.ConnectActionClient;
-import be.nikiroo.utils.serial.Server;
+import be.nikiroo.utils.serial.server.ConnectActionClientObject;
+import be.nikiroo.utils.serial.server.ServerObject;
/**
* Main program entry point.
action = MainAction.valueOf(args[i].substring(2)
.toUpperCase().replace("-", "_"));
} catch (Exception e) {
- Instance.syserr(new IllegalArgumentException(
- "Unknown action: " + args[i], e));
+ Instance.getTraceHandler().error(
+ new IllegalArgumentException("Unknown action: "
+ + args[i], e));
exitCode = 255;
}
}
break;
case LIST:
if (BasicReader.getReader() == null) {
- Instance.syserr(new Exception(
- "No reader type has been configured"));
+ Instance.getTraceHandler()
+ .error(new Exception(
+ "No reader type has been configured"));
exitCode = 10;
break;
}
break;
case READ:
if (BasicReader.getReader() == null) {
- Instance.syserr(new Exception(
- "No reader type has been configured"));
+ Instance.getTraceHandler()
+ .error(new Exception(
+ "No reader type has been configured"));
exitCode = 10;
break;
}
break;
case READ_URL:
if (BasicReader.getReader() == null) {
- Instance.syserr(new Exception(
- "No reader type has been configured"));
+ Instance.getTraceHandler()
+ .error(new Exception(
+ "No reader type has been configured"));
exitCode = 10;
break;
}
break;
case START:
if (BasicReader.getReader() == null) {
- Instance.syserr(new Exception(
- "No reader type has been configured"));
+ Instance.getTraceHandler()
+ .error(new Exception(
+ "No reader type has been configured"));
exitCode = 10;
break;
}
break;
}
try {
- Server server = new RemoteLibraryServer(key, port);
+ ServerObject server = new RemoteLibraryServer(key, port);
+ server.setTraceHandler(new TraceHandler(true, true, true));
server.start();
- System.out.println("Remote server started on: " + port);
} catch (IOException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
return;
case STOP_SERVER:
try {
final String fkey = key;
- new ConnectActionClient(host, port, true) {
+ new ConnectActionClientObject(host, port, true) {
@Override
public void action(Version serverVersion)
throws Exception {
try {
send(new Object[] { fkey, "EXIT" });
} catch (Exception e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
}
}.connect();
} catch (IOException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
break;
case REMOTE:
System.out.println(story.getMeta().getLuid() + ": \""
+ story.getMeta().getTitle() + "\" imported.");
} catch (IOException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
return 1;
}
Progress pg) {
OutputType type = OutputType.valueOfNullOkUC(typeString, null);
if (type == null) {
- Instance.syserr(new Exception(trans(StringId.OUTPUT_DESC,
- typeString)));
+ Instance.getTraceHandler().error(
+ new Exception(trans(StringId.OUTPUT_DESC, typeString)));
return 1;
}
try {
Instance.getLibrary().export(luid, type, target, pg);
} catch (IOException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
return 4;
}
reader.setChapter(Integer.parseInt(chapString));
reader.read();
} catch (NumberFormatException e) {
- Instance.syserr(new IOException(
- "Chapter number cannot be parsed: " + chapString, e));
+ Instance.getTraceHandler().error(
+ new IOException("Chapter number cannot be parsed: "
+ + chapString, e));
return 2;
}
} else {
reader.read();
}
} catch (IOException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
return 1;
}
OutputType type = OutputType.valueOfAllOkUC(typeString, null);
if (type == null) {
- Instance.syserr(new IOException(trans(
- StringId.ERR_BAD_OUTPUT_TYPE, typeString)));
+ Instance.getTraceHandler().error(
+ new IOException(trans(StringId.ERR_BAD_OUTPUT_TYPE,
+ typeString)));
exitCode = 2;
} else {
BasicOutput.getOutput(type, infoCover).process(
story, target, pgOut);
} catch (IOException e) {
- Instance.syserr(new IOException(trans(
- StringId.ERR_SAVING, target), e));
+ Instance.getTraceHandler().error(
+ new IOException(trans(StringId.ERR_SAVING,
+ target), e));
exitCode = 5;
}
} else {
- Instance.syserr(new IOException(trans(
- StringId.ERR_NOT_SUPPORTED, source)));
+ Instance.getTraceHandler().error(
+ new IOException(trans(
+ StringId.ERR_NOT_SUPPORTED, source)));
exitCode = 4;
}
} catch (IOException e) {
- Instance.syserr(new IOException(trans(StringId.ERR_LOADING,
- sourceName), e));
+ Instance.getTraceHandler().error(
+ new IOException(trans(StringId.ERR_LOADING,
+ sourceName), e));
exitCode = 3;
}
}
} catch (MalformedURLException e) {
- Instance.syserr(new IOException(trans(StringId.ERR_BAD_URL,
- sourceName), e));
+ Instance.getTraceHandler()
+ .error(new IOException(trans(StringId.ERR_BAD_URL,
+ sourceName), e));
exitCode = 1;
}
BasicReader.setDefaultReaderType(readerType);
return 0;
} catch (IllegalArgumentException e) {
- Instance.syserr(new IOException("Unknown reader type: "
- + readerTypeString, e));
+ Instance.getTraceHandler().error(
+ new IOException("Unknown reader type: " + readerTypeString,
+ e));
return 1;
}
}
reader.close();
}
} catch (IOException e) {
- Instance.syserr(new IOException(
+ Instance.getTraceHandler().error(new IOException(
"Cannot download latest changelist on github.com", e));
}
}
} catch (IOException e) {
// We should not have not-supported files in the
// library
- Instance.syserr(new IOException(
+ Instance.getTraceHandler().error(new IOException(
"Cannot load file from library: " + file, e));
} finally {
pgProcess.done();
pgImport.done();
clearCache();
} catch (IOException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
pgImport.done();
meta = InfoReader.readMeta(infoFile, true);
return meta.getCover();
} catch (IOException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
}
}
InfoCover.writeInfo(newDir, name, meta);
relatedFile.delete();
} catch (IOException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
} else {
relatedFile.renameTo(new File(newDir, relatedFile.getName()));
try {
ImageIO.write(sourceCovers.get(source), "png", cover);
} catch (IOException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
sourceCovers.remove(source);
}
}
} catch (IOException e) {
// We should not have not-supported files in the
// library
- Instance.syserr(new IOException(
+ Instance.getTraceHandler().error(new IOException(
"Cannot load file from library: " + infoFile, e));
}
pgFiles.add(1);
in.close();
}
} catch (IOException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
}
try {
ImageIO.write(sourceCovers.get(source), "png", cover);
} catch (IOException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
sourceCovers.remove(source);
}
}
import be.nikiroo.fanfix.data.Story;
import be.nikiroo.utils.Progress;
import be.nikiroo.utils.Version;
-import be.nikiroo.utils.serial.ConnectActionClient;
+import be.nikiroo.utils.serial.server.ConnectActionClientObject;
/**
* This {@link BasicLibrary} will access a remote server to list the available
private <T> T getRemoteObject(final Object[] command) {
final Object[] result = new Object[1];
try {
- new ConnectActionClient(host, port, true) {
+ new ConnectActionClientObject(host, port, true) {
@Override
public void action(Version serverVersion) throws Exception {
try {
Object rep = send(command);
result[0] = rep;
} catch (Exception e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
}
}.connect();
} catch (IOException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
try {
return (T) result[0];
} catch (Exception e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
return null;
}
}
import be.nikiroo.fanfix.data.MetaData;
import be.nikiroo.fanfix.data.Story;
import be.nikiroo.utils.Version;
-import be.nikiroo.utils.serial.ConnectActionServer;
-import be.nikiroo.utils.serial.Server;
+import be.nikiroo.utils.serial.server.ConnectActionServerObject;
+import be.nikiroo.utils.serial.server.ServerObject;
/**
* Create a new remote server that will listen for order on the given port.
*
* @author niki
*/
-public class RemoteLibraryServer extends Server {
+public class RemoteLibraryServer extends ServerObject {
private final String key;
/**
}
@Override
- protected Object onRequest(ConnectActionServer action,
+ protected Object onRequest(ConnectActionServerObject action,
Version clientVersion, Object data) throws Exception {
String key = "";
String command = "";
targetName + "." + format));
} catch (IOException e) {
// Allow to continue without cover
- Instance.syserr(new IOException(
- "Failed to save the cover image", e));
+ Instance.getTraceHandler().error(
+ new IOException("Failed to save the cover image", e));
}
}
}
.getTypeName());
}
} catch (Exception e) {
- Instance.syserr(new Exception("Cannot create a reader of type: "
+ Instance.getTraceHandler().error(new Exception("Cannot create a reader of type: "
+ defaultType + " (Not compiled in?)", e));
}
try {
Desktop.getDesktop().browse(e.getURL().toURI());
} catch (IOException ee) {
- Instance.syserr(ee);
+ Instance.getTraceHandler().error(ee);
} catch (URISyntaxException ee) {
- Instance.syserr(ee);
+ Instance.getTraceHandler().error(ee);
}
}
});
try {
cacheLib.clearFromCache(luid);
} catch (IOException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
}
try {
cacheLib.delete(luid);
} catch (IOException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
}
try {
cacheLib.changeSource(luid, newSource, null);
} catch (IOException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
}
}
in.close();
in = null;
} catch (IOException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
}
in = null;
}
} catch (MalformedURLException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
} catch (IOException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
}
selectedBook.getMeta().getLuid(),
type, path, pg);
} catch (IOException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
}
});
});
} catch (IOException e) {
// TODO: error message?
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
}
});
pgOnSuccess.setProgress(0);
if (!ok) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
guessBackendType());
new Thread(app).start();
} catch (Exception e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
}
guessBackendType());
new Thread(app).start();
} catch (Exception e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
}
}
reader.setMeta(meta);
reader.read();
} catch (IOException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
}
try {
close();
} catch (IOException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
if (in != null) {
try {
close();
} catch (IOException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
if (in != null) {
File tmp = Instance.getCache().addToCache(zipIn, uuid);
images.add(tmp.toURI().toURL().toString());
} catch (Exception e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
}
}
try {
chap.getParagraphs().add(new Paragraph(new URL(uuid)));
} catch (Exception e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
}
try {
pages.add(new URL(line));
} catch (MalformedURLException e) {
- Instance.syserr(new IOException(
+ Instance.getTraceHandler().error(new IOException(
"Parsing error, a link is not correctly parsed: "
+ line, e));
}
try {
cover = ImageUtils.fromStream(zipIn);
} catch (Exception e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
}
} else if (entry.getName().equals(getDataPrefix() + "URL")) {
return sdf
.format(new Date(1000 * Long.parseLong(line)));
} catch (NumberFormatException e) {
- Instance.syserr(new IOException(
+ Instance.getTraceHandler().error(new IOException(
"Cannot convert publication date: " + line, e));
}
}
}
});
} catch (MalformedURLException e) {
- Instance.syserr(new IOException(
+ Instance.getTraceHandler().error(new IOException(
"Cannot parse chapter " + i + " url: "
+ (base + i + suffix), e));
}
}
});
} catch (MalformedURLException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
}
}
file = new File(url.toURI());
file = new File(file.getPath() + ".info");
} catch (URISyntaxException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
file = null;
}
try {
in.reset();
} catch (IOException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
line = getLine(in, "/artist/", 0, false);
}
});
} catch (MalformedURLException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
}
}
try {
in.reset();
} catch (IOException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
String linkImageLine = getLine(in, "return enlarge()", 1);
try {
in.close();
} catch (IOException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
}
setCurrentReferer(url);
pg.setProgress((i++) % pg.getMax());
} catch (IOException e) {
- Instance.syserr(new IOException(
+ Instance.getTraceHandler().error(new IOException(
"Cannot get the next manga page which is: "
+ linkNext, e));
}
try {
path = new File(source.toURI()).getPath();
} catch (URISyntaxException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
path = null;
}
file = new File(url.toURI());
file = new File(file.getPath() + ".info");
} catch (URISyntaxException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
file = null;
}