use of org.nustaq.serialization.FSTConfiguration in project kontraktor by RuedigerMoeller.
the class HoardeTest method run.
@Test
public void run() throws InterruptedException {
FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();
ArrayList toEncode = new ArrayList();
for (int i = 0; i < 1000000; i++) {
HashMap e = new HashMap();
e.put("VALUE", new Object[] { i, 11111111, 22222222, 33333333, "pok" });
e.put("XY", new Object[] { "aposdj", "POK", 422222222, 333323333, "poasdasdk" });
e.put("XY1", new Object[] { "aposdj", "POK", 42223222, 333333, "poasdasdasdk" });
e.put("XY2", new Object[] { "aposdj", "POK", 422222222, 333323333, "poasdasdk" });
e.put("XY3", new Object[] { "aposdj", "POK", 42223222, 333333, "poasdasdasdk" });
e.put("XY4", new Object[] { "aposdj", "POK", 422222222, 333323333, "poasdasdk" });
e.put("XY5", new Object[] { "aposdj", "POK", 42223222, 333333, "poasdasdasdk" });
toEncode.add(e);
}
// warmup
testSingleThreaded(conf, toEncode, 1);
testGenericAct(toEncode, 1, 1, true);
testSingleThreaded(conf, toEncode, 6);
testGenericAct(toEncode, 8, 6, false);
System.out.println("DONE");
}
use of org.nustaq.serialization.FSTConfiguration in project kontraktor by RuedigerMoeller.
the class DataClient method export.
/**
* @param directory
*/
public IPromise export(String directory) {
Promise res = new Promise();
// use separate thread to enable slowly, blocking processing
Actors.exec.execute(() -> {
File d = new File(directory);
if (d.exists() && (!d.isDirectory() || !d.canWrite())) {
res.reject(new RuntimeException("cannot write to " + d + " or not a directory"));
return;
} else {
d.mkdirs();
}
FSTConfiguration writeConf = FSTConfiguration.createDefaultConfiguration();
Arrays.stream(config.getSchema()).forEach(desc -> {
try {
DataOutputStream fout = new DataOutputStream(new FileOutputStream(new File(d, desc.getName() + ".oos")));
CountDownLatch pl = new CountDownLatch(shards.length);
for (int i = 0; i < shards.length; i++) {
TableSpaceActor shard = shards[i];
Log.Info(this, "exporting shard " + i + " table " + desc.getName());
try {
RealLiveTable table = shard.getTableAsync(desc.getName()).await(60_000);
table.forEach(rec -> true, (rec, err) -> {
if (rec != null) {
try {
// write marker to enable recovery in case of corruption
synchronized (fout) {
fout.write(31);
fout.write(32);
fout.write(33);
fout.write(34);
byte[] b = writeConf.asByteArray(rec);
fout.writeInt(b.length);
fout.write(b);
}
} catch (IOException e) {
Log.Error(this, e);
}
} else if (err != null) {
Log.Warn(this, "error during export " + err);
pl.countDown();
} else {
// fin
pl.countDown();
}
});
} catch (Exception e) {
Log.Error(this, "export failure " + desc.getName() + " shard " + i);
}
}
try {
boolean succ = pl.await(5, TimeUnit.MINUTES);
if (!succ)
Log.Error(this, "export timed out on table " + desc.getName());
try {
fout.close();
} catch (IOException e) {
Log.Error(this, e);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
Log.Error(this, e);
}
});
res.complete();
});
return res;
}
use of org.nustaq.serialization.FSTConfiguration in project meghanada-server by mopemope.
the class Serializer method getFST.
public static FSTConfiguration getFST() {
if (fst != null) {
return fst;
}
FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();
conf.registerClass(Project.class, ProjectDependency.class, GradleProject.class, MavenProject.class, MeghanadaProject.class, ParameterName.class, MethodParameterNames.class, Scope.class, LineRange.class, Position.class, Variable.class, Range.class, Source.class, MethodParameter.class, ClassIndex.class, MemberDescriptor.class);
fst = conf;
return fst;
}
use of org.nustaq.serialization.FSTConfiguration in project redisson by redisson.
the class FstCodec method copy.
private static FSTConfiguration copy(ClassLoader classLoader, FstCodec codec) {
FSTConfiguration def = codec.config.deriveConfiguration();
def.setClassLoader(classLoader);
def.setCoderSpecific(codec.config.getCoderSpecific());
def.setCrossPlatform(codec.config.isCrossPlatform());
def.setForceClzInit(codec.config.isForceClzInit());
def.setForceSerializable(codec.config.isForceSerializable());
def.setInstantiator(codec.config.getInstantiator(null));
def.setJsonFieldNames(codec.config.getJsonFieldNames());
def.setLastResortResolver(codec.config.getLastResortResolver());
def.setName(codec.config.getName());
def.setPreferSpeed(codec.config.isPreferSpeed());
def.setStructMode(codec.config.isStructMode());
def.setShareReferences(codec.config.isShareReferences());
def.setStreamCoderFactory(codec.config.getStreamCoderFactory());
def.setVerifier(codec.config.getVerifier());
try {
Field serializationInfoRegistryField = FSTConfiguration.class.getDeclaredField("serializationInfoRegistry");
serializationInfoRegistryField.setAccessible(true);
FSTClazzInfoRegistry registry = (FSTClazzInfoRegistry) serializationInfoRegistryField.get(codec.config);
serializationInfoRegistryField.set(def, registry);
} catch (Exception e) {
throw new IllegalStateException(e);
}
return def;
}
use of org.nustaq.serialization.FSTConfiguration in project chuidiang-ejemplos by chuidiang.
the class FstExample method main.
public static void main(String[] args) throws Exception {
FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();
SomeMediumClass mediumClass = new SomeMediumClass();
byte[] barray = conf.asByteArray(mediumClass);
System.out.println(barray.length);
SomeMediumClass object = (SomeMediumClass) conf.asObject(barray);
System.out.println(object);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
FSTObjectOutput output = new FSTObjectOutput(outputStream);
output.writeObject(mediumClass);
output.close();
FSTObjectInput input = new FSTObjectInput(new ByteArrayInputStream(outputStream.toByteArray()));
object = (SomeMediumClass) input.readObject(SomeMediumClass.class);
System.out.println(object);
}
Aggregations