use of org.nustaq.kson.Kson in project kontraktor by RuedigerMoeller.
the class BasicWebAppConfig method read.
public static BasicWebAppConfig read(String pathname, Class[] mappedClasses, Class<? extends BasicWebAppConfig> target) {
Kson kson = new Kson().map(target);
if (mappedClasses != null) {
kson.map(mappedClasses);
}
try {
Object raw = kson.readObject(new File(pathname));
BasicWebAppConfig cfg = (BasicWebAppConfig) raw;
String confString = kson.writeObject(cfg);
System.out.println("run with config from " + new File(pathname).getCanonicalPath());
System.out.println(confString);
return cfg;
} catch (Exception e) {
Log.Warn(null, pathname + " not found or parse error. " + e.getClass().getSimpleName() + ":" + e.getMessage());
try {
String sampleconf = kson.writeObject(target.newInstance());
System.out.println("Defaulting to:\n" + sampleconf);
} catch (Exception e1) {
e1.printStackTrace();
}
}
try {
return target.newInstance();
} catch (Exception e) {
FSTUtil.rethrow(e);
}
return null;
}
use of org.nustaq.kson.Kson in project kontraktor by RuedigerMoeller.
the class ClusterCfg method read.
public static ClusterCfg read(String pathname) {
Kson kson = new Kson().map(ClusterCfg.class, DataCfg.class, TableDescription.class);
try {
ClusterCfg clCfg = (ClusterCfg) kson.readObject(new File(pathname));
String confString = kson.writeObject(clCfg);
System.out.println("run with config from " + new File(pathname).getCanonicalPath());
System.out.println(confString);
return clCfg;
} catch (Exception e) {
Log.Warn(null, pathname + " not found or parse error. " + e.getClass().getSimpleName() + ":" + e.getMessage());
try {
String sampleconf = kson.writeObject(new ClusterCfg());
System.out.println("Defaulting to:\n" + sampleconf);
} catch (Exception e1) {
e1.printStackTrace();
}
}
return new ClusterCfg();
}
use of org.nustaq.kson.Kson in project kontraktor by RuedigerMoeller.
the class WSKrouterStarterConfig method read.
public static WSKrouterStarterConfig read() {
File lookup = new FileLookup("wskrouter.kson").lookup();
Kson kson = new Kson().map(RoutedServiceEntry.class).map(WSKrouterStarterConfig.class);
try {
WSKrouterStarterConfig res = (WSKrouterStarterConfig) kson.readObject(lookup);
return res;
} catch (Exception e) {
WSKrouterStarterConfig cfg = new WSKrouterStarterConfig();
cfg.services = new RoutedServiceEntry[] { new RoutedServiceEntry("sample/v1/json", SerializerType.JsonNoRef) };
try {
String s = kson.writeObject(cfg);
System.out.println("wskrouter.kson not found, defaulting to ");
System.out.println(s);
return cfg;
} catch (Exception e1) {
e1.printStackTrace();
}
}
return null;
}
Aggregations