use of org.commonjava.propulsor.boot.BootException in project indy by Commonjava.
the class JaxRsBooter method main.
public static void main(final String[] args) {
setDefaultUncaughtExceptionHandler();
BootOptions boot;
try {
boot = loadFromSysProps("indy", BOOT_DEFAULTS_PROP, HOME_PROP);
} catch (final BootException e) {
e.printStackTrace();
System.err.printf("ERROR: %s", e.getMessage());
System.exit(ERR_LOAD_BOOT_OPTIONS);
return;
}
try {
if (boot.parseArgs(args)) {
Booter booter = new JaxRsBooter();
booter.runAndWait(boot);
}
} catch (final BootException e) {
e.printStackTrace();
System.err.printf("ERROR: %s", e.getMessage());
System.exit(ERR_START);
}
}
use of org.commonjava.propulsor.boot.BootException in project indy by Commonjava.
the class Main method loadFromJsonFile.
private void loadFromJsonFile(CacheHandle<Object, Object> cache, MigrationOptions options) throws BootException {
AtomicReference<Throwable> error = new AtomicReference<>();
try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(options.getDataFile())))) {
cache.executeCache((c) -> {
try {
String key;
int count = 0;
while ((key = in.readLine()) != null) {
try {
Object k = objectMapper.readValue(key, TrackingKey.class);
Object v = objectMapper.readValue(in.readLine(), TrackedContent.class);
c.putAsync(k, v);
count++;
} catch (Exception e) {
logger.error("Failed to read entry key: {}", key, e);
error.set(e);
}
}
logger.info("Load entries: {}", count);
} catch (Exception e) {
logger.error("Failed to read data file header.", e);
error.set(e);
}
return true;
});
} catch (IOException e) {
error.set(e);
}
if (error.get() != null) {
throw new BootException("Failed to read data from file: " + options.getDataFile(), error.get());
}
}
use of org.commonjava.propulsor.boot.BootException in project indy by Commonjava.
the class Main method dumpJsonFile.
private void dumpJsonFile(CacheHandle<Object, Object> cache, MigrationOptions options) throws BootException {
AtomicReference<Throwable> error = new AtomicReference<>();
try (BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(options.getDataFile()))) {
String lineSeparator = System.getProperty("line.separator");
cache.executeCache((c) -> {
if (error.get() == null) {
c.forEach((k, v) -> {
if (error.get() == null) {
try {
out.write(objectMapper.writeValueAsBytes(k));
out.write(lineSeparator.getBytes());
out.write(objectMapper.writeValueAsBytes(v));
out.write(lineSeparator.getBytes());
out.flush();
} catch (IOException e) {
logger.error("Failed to write entry with key: " + k, e);
error.set(e);
}
}
});
}
return true;
});
} catch (IOException e) {
error.set(e);
}
if (error.get() != null) {
throw new BootException("Failed to write data to file: " + options.getDataFile(), error.get());
}
}
use of org.commonjava.propulsor.boot.BootException in project indy by Commonjava.
the class Main method main.
public static void main(String[] args) {
Thread.currentThread().setUncaughtExceptionHandler((thread, error) -> {
if (error instanceof InvocationTargetException) {
final InvocationTargetException ite = (InvocationTargetException) error;
System.err.println("In: " + thread.getName() + "(" + thread.getId() + "), caught InvocationTargetException:");
ite.getTargetException().printStackTrace();
System.err.println("...via:");
error.printStackTrace();
} else {
System.err.println("In: " + thread.getName() + "(" + thread.getId() + ") Uncaught error:");
error.printStackTrace();
}
});
MigrationOptions options = new MigrationOptions();
try {
if (options.parseArgs(args)) {
try {
int result = new Main().run(options);
if (result != 0) {
System.exit(result);
}
} catch (final BootException e) {
System.err.printf("ERROR INITIALIZING BOOTER: %s", e.getMessage());
System.exit(ERR_INIT);
}
}
} catch (final BootException e) {
System.err.printf("ERROR: %s", e.getMessage());
System.exit(ERR_PARSE_ARGS);
}
}
Aggregations