com.esotericsoftware.kryo.Kryo.DefaultInstantiatorStrategy Java Examples

The following examples show how to use com.esotericsoftware.kryo.Kryo.DefaultInstantiatorStrategy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KryoSerialization.java    From JPPF with Apache License 2.0 6 votes vote down vote up
/**
 * Create a Kryo instance, with its instantiator strategy and a set of
 * common serializers (from kryo-serializers project) initialized.
 * @return an instance of {@link Kryo}.
 */
private static Kryo createKryo() {
  final Kryo kryo = new Kryo(new CustomClassResolver(), new MapReferenceResolver());
  kryo.setAutoReset(true);
  kryo.setInstantiatorStrategy(new DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));

  kryo.register(ObjectName.class, new ObjectNameSerializer());
  kryo.register(OffloadableNotification.class, new GenericObjectSerializer());
  kryo.register(TaskExecutionNotification.class, new GenericObjectSerializer());
  kryo.register(TaskGraph.class, new JobTaskGraphSerializer());
  kryo.register(Collection.class, new CollectionSerializer());
  kryo.register(Arrays.asList( "" ).getClass(), new ArraysAsListSerializer() );
  kryo.register(Collections.EMPTY_LIST.getClass(), new CollectionsEmptyListSerializer() );
  kryo.register(Collections.EMPTY_MAP.getClass(), new CollectionsEmptyMapSerializer() );
  kryo.register(Collections.EMPTY_SET.getClass(), new CollectionsEmptySetSerializer() );
  kryo.register(Collections.singletonList( "" ).getClass(), new CollectionsSingletonListSerializer() );
  kryo.register(Collections.singleton( "" ).getClass(), new CollectionsSingletonSetSerializer() );
  kryo.register(Collections.singletonMap( "", "" ).getClass(), new CollectionsSingletonMapSerializer() );
  kryo.register(GregorianCalendar.class, new GregorianCalendarSerializer());
  kryo.register(InvocationHandler.class, new JdkProxySerializer());
  UnmodifiableCollectionsSerializer.registerSerializers(kryo);
  SynchronizedCollectionsSerializer.registerSerializers(kryo);
  kryo.register(EnumMap.class, new EnumMapSerializer());
  kryo.register(EnumSet.class, new EnumSetSerializer());
  return kryo;
}
 
Example #2
Source File: SerializationUtil.java    From dubbox with Apache License 2.0 5 votes vote down vote up
protected Kryo initialValue() {
	Kryo kryo = new Kryo();
	kryo.setReferences(false);
	kryo.setRegistrationRequired(false);
	kryo.setInstantiatorStrategy(new DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
	return kryo;
}
 
Example #3
Source File: AbstractConfig.java    From trainbenchmark with Eclipse Public License 1.0 5 votes vote down vote up
public static <T extends AbstractConfig<?>> T fromFile(final String path, final Class<T> clazz) throws FileNotFoundException {
	final Kryo kryo = new Kryo();
	kryo.setInstantiatorStrategy(new DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
    try (final Input input = new Input(new FileInputStream(path))) {
		final T bc = kryo.readObject(input, clazz);
		return bc;
	}
}
 
Example #4
Source File: LevelDbStore.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
		Kryo kryo = new Kryo();
		kryo.setReferences(false);
		kryo.setRegistrationRequired(false);
		kryo.setInstantiatorStrategy(new DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
//		kryo.register(Transaction.class);
//		kryo.register(Xid.class);
//		kryo.register(TransactionType.class);
//		kryo.register(TransactionStatus.class);
//		kryo.register(Participant.class);
		
//		Output output = new Output(new ByteArrayOutputStream());//new Output(new FileOutputStream("file.bin"));
//		
//		DefaultTransaction defaultTransaction = new DefaultTransaction();
//		defaultTransaction.setXid(new DefaultXid("1", "2", "3"));
//		
//		kryo.writeObject(output, defaultTransaction);
//		output.flush();
//		output.close();
		
		Options options = new Options();
		options.createIfMissing(true);
		options.cacheSize(100 * 1048576); // 100MB cache
		options.logger(new org.iq80.leveldb.Logger() {
			public void log(String message) {
				TransactionLog.REPOSITORY.info(message);
			}
		});
		DB db = Iq80DBFactory.factory.open(new File("txtreedb"), options);
		
//		String stats = db.getProperty("leveldb.stats");
//		System.out.println(stats);
		
		DBIterator iterator = null;
		try {
			iterator = db.iterator();
			for(iterator.seekToFirst(); iterator.hasNext(); iterator.next()) {
				String key = Iq80DBFactory.asString(iterator.peekNext().getKey());
				Transaction value = (Transaction) SerializationUtil.deserialize(iterator.peekNext().getValue());
				
				System.out.println(key+" = "+value);
			}
		} finally {
			if (iterator != null) {
				iterator.close();
			}
		}

//		String transactionId = "f282205a-e794-4bda-83a2-bb28b8839cad";
//		Input input = new Input(db.get(Iq80DBFactory.bytes(transactionId)));
//		Transaction transaction = (Transaction) kryo.readClassAndObject(input);
//		System.out.println(transaction);
	}
 
Example #5
Source File: SerializeUtils.java    From ByteJTA with GNU Lesser General Public License v3.0 4 votes vote down vote up
public Kryo create() {
	Kryo kryo = new Kryo();
	kryo.setInstantiatorStrategy(new DefaultInstantiatorStrategy(new SerializingInstantiatorStrategy()));
	return kryo;
}