org.nustaq.serialization.FSTConfiguration Java Examples
The following examples show how to use
org.nustaq.serialization.FSTConfiguration.
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: JetLinksRedisConfiguration.java From jetlinks-community with Apache License 2.0 | 6 votes |
@Bean public ReactiveRedisTemplate<Object, Object> reactiveRedisTemplate( ReactiveRedisConnectionFactory reactiveRedisConnectionFactory, ResourceLoader resourceLoader) { FstSerializationRedisSerializer serializer = new FstSerializationRedisSerializer(() -> { FSTConfiguration configuration = FSTConfiguration.createDefaultConfiguration() .setForceSerializable(true); configuration.setClassLoader(resourceLoader.getClassLoader()); return configuration; }); @SuppressWarnings("all") RedisSerializationContext<Object, Object> serializationContext = RedisSerializationContext .newSerializationContext() .key((RedisSerializer)new StringRedisSerializer()) .value(serializer) .hashKey(StringRedisSerializer.UTF_8) .hashValue(serializer) .build(); return new ReactiveRedisTemplate<>(reactiveRedisConnectionFactory, serializationContext); }
Example #2
Source File: FstExample.java From chuidiang-ejemplos with GNU Lesser General Public License v3.0 | 6 votes |
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); }
Example #3
Source File: Serializer.java From meghanada-server with GNU General Public License v3.0 | 6 votes |
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; }
Example #4
Source File: BinarySerializerTest.java From Thunder with Apache License 2.0 | 6 votes |
@Test public void testFSTFunction2() throws Exception { Map<String, String> m1 = new HashMap<String, String>(); m1.put("a", "1"); m1.put("b", "2"); Map<String, String> m2 = Collections.unmodifiableMap(m1); FSTConfiguration fst = FSTSerializerFactory.createFST(); byte[] bytes = FSTSerializer.serialize(fst, (Serializable) m2); LOG.info(bytes.toString()); Map<String, String> m3 = FSTSerializer.deserialize(fst, bytes); LOG.info(m3.toString()); }
Example #5
Source File: FstSerializer.java From netty-learning with Apache License 2.0 | 5 votes |
private static FSTConfiguration getFSTConfiguration(Class<?> clz) throws IOException { try { return configurationLoadingCache.get(clz); } catch (ExecutionException e) { throw new IOException("create FSTConfiguration error, class:"+clz); } }
Example #6
Source File: FSTSerializer.java From Hive2Hive with MIT License | 5 votes |
/** * Create a FST serializer (faster and more efficient than Java default serialization). * * @param useUnsafe <code>true</code> to use <code>sun.misc.Unsafe</code> class, otherwise, a fallback is * used. * @param securityProvider the security provider, needed to decode key pairs correctly */ public FSTSerializer(boolean useUnsafe, ISecurityClassProvider securityProvider) { if (!useUnsafe) { // don't use sun.misc.Unsafe class FSTUtil.unFlaggedUnsafe = null; logger.debug("Disabled the use of 'sun.misc.Unsafe' for the serialization"); } fst = FSTConfiguration.createDefaultConfiguration(); // register all often serialized classes for speedup. Note that every peer should have the same // configuration, which also depends on the order! Changing these registrations might break backward // compatibility! fst.registerClass(UserProfile.class, FolderIndex.class, FileIndex.class, UserPermission.class, Locations.class, UserPublicKey.class, MetaFileSmall.class, MetaFileLarge.class, FileVersion.class, MetaChunk.class, Chunk.class, EncryptedNetworkContent.class, ContactPeerMessage.class, ResponseMessage.class); // for all public / private keys for full compatibility among multiple security providers fst.registerClass(securityProvider.getRSAPublicKeyClass(), securityProvider.getRSAPrivateKeyClass(), securityProvider.getRSAPrivateCrtKeyClass()); // for performance improvements, native TomP2P classes which are serialized quite often fst.registerClass(PeerAddress.class, PeerSocketAddress.class, Number160.class); // Since PeerAddresses are serialized very often, this is just an efficiency improvement fst.registerSerializer(PeerAddress.class, new FSTPeerAddressSerializer(), false); // register the acceptance reply enum fst.registerClass(AcceptanceReply.class); }
Example #7
Source File: FSTJsonSerializer.java From Thunder with Apache License 2.0 | 5 votes |
public static <T> String toJson(FSTConfiguration fst, T object) { if (object == null) { throw new SerializerException("Object is null"); } return fst.asJsonString(object); }
Example #8
Source File: FSTJsonSerializer.java From Thunder with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public static <T> T fromJson(FSTConfiguration fst, String json, Class<T> clazz) { if (StringUtils.isEmpty(json)) { throw new SerializerException("Json is null or empty"); } return (T) fst.asObject(json.getBytes()); }
Example #9
Source File: FSTJsonSerializerFactory.java From Thunder with Apache License 2.0 | 5 votes |
public static FSTConfiguration getDefaultFST() { if (usePool) { return getFST(pool); } else { return fst; } }
Example #10
Source File: FSTSerializer.java From Thunder with Apache License 2.0 | 5 votes |
public static <T> byte[] serialize(FSTConfiguration fst, T object) { if (object == null) { throw new SerializerException("Object is null"); } return fst.asByteArray(object); }
Example #11
Source File: FSTSerializer.java From Thunder with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public static <T> T deserialize(FSTConfiguration fst, byte[] bytes) { if (ArrayUtils.isEmpty(bytes)) { throw new SerializerException("Bytes is null or empty"); } return (T) fst.asObject(bytes); }
Example #12
Source File: FSTSerializerFactory.java From Thunder with Apache License 2.0 | 5 votes |
public static FSTConfiguration getDefaultFST() { if (usePool) { return getFST(pool); } else { return fst; } }
Example #13
Source File: BinarySerializerTest.java From Thunder with Apache License 2.0 | 5 votes |
@Test public void testFSTFunction1() throws Exception { User user1 = CoreFactory.createUser1(); FSTConfiguration fst = FSTSerializerFactory.createFST(); byte[] bytes = FSTSerializer.serialize(fst, user1); LOG.info(bytes.toString()); User user2 = FSTSerializer.deserialize(fst, bytes); LOG.info(user2.toString()); }
Example #14
Source File: JsonSerializerTest.java From Thunder with Apache License 2.0 | 5 votes |
@Test public void testFSTFunction() throws Exception { User user1 = CoreFactory.createUser1(); FSTConfiguration fst = FSTJsonSerializerFactory.createFST(); String json = FSTJsonSerializer.toJson(fst, user1); LOG.info(json); User user2 = FSTJsonSerializer.fromJson(fst, json, User.class); LOG.info(user2.toString()); }
Example #15
Source File: SerializerCore.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
/** * Initializes the delegate serializer */ private void initFST() { fastSerialConfig = FSTConfiguration.createDefaultConfiguration(); if(classes != null) { fastSerialConfig.registerClass(classes); } }
Example #16
Source File: FstCodec.java From redisson with Apache License 2.0 | 5 votes |
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; }
Example #17
Source File: FstCodec.java From redisson with Apache License 2.0 | 5 votes |
public FstCodec(FSTConfiguration fstConfiguration, boolean useCache) { config = fstConfiguration; FSTSerializerRegistry reg = config.getCLInfoRegistry().getSerializerRegistry(); reg.putSerializer(Hashtable.class, new FSTMapSerializerV2(), true); reg.putSerializer(ConcurrentHashMap.class, new FSTMapSerializerV2(), true); config.setStreamCoderFactory(new FSTDefaultStreamCoderFactory(config)); this.useCache = useCache; }
Example #18
Source File: FstSerializationRedisSerializer.java From jetlinks-community with Apache License 2.0 | 5 votes |
public FstSerializationRedisSerializer(Supplier<FSTConfiguration> supplier) { this(new FastThreadLocal<FSTConfiguration>() { @Override protected FSTConfiguration initialValue() { return supplier.get(); } }); }
Example #19
Source File: Serializer.java From meghanada-server with GNU General Public License v3.0 | 5 votes |
@Nullable public static <T> T asObject(byte[] b, Class<T> clazz) { FSTConfiguration fst = getFST(); Object obj = fst.asObject(b); if (isNull(obj)) { return null; } return clazz.cast(obj); }
Example #20
Source File: FstSerializer.java From mango with Apache License 2.0 | 5 votes |
private static FSTConfiguration getFSTConfiguration(Class<?> clz) throws IOException { try { return configurationLoadingCache.get(clz); } catch (ExecutionException e) { throw new IOException("create FSTConfiguration error, class:"+clz); } }
Example #21
Source File: FstCodec.java From redisson with Apache License 2.0 | 4 votes |
public FstCodec() { this(FSTConfiguration.createDefaultConfiguration()); }
Example #22
Source File: GridNode.java From vlingo-lattice with Mozilla Public License 2.0 | 4 votes |
public GridNode(final GridRuntime gridRuntime, final Node localNode) { this.gridRuntime = gridRuntime; this.localNode = localNode; final FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration(); // set classloader with available proxy classes conf.setClassLoader(gridRuntime.worldClassLoader()); final HardRefHolder holder = gridRuntime.world().actorFor(HardRefHolder.class, Definition.has(ExpiringHardRefHolder.class, ExpiringHardRefHolder::new)); this.outbound = stage().actorFor( GridActorControl.Outbound.class, OutboundGridActorControl.class, new OutboundGridActorControlInstantiator( localNode.id(), new FSTEncoder(conf), correlation::put, new OutBuffers(holder))); this.gridRuntime.setOutbound(outbound); final GridActorControl.Inbound inbound = stage().actorFor( GridActorControl.Inbound.class, InboundGridActorControl.class, new InboundGridActorControlInstantiator( gridRuntime, correlation::remove)); this.applicationMessageHandler = new GridApplicationMessageHandler( localNode.id(), gridRuntime.hashRing(), inbound, outbound, new FSTDecoder(conf), holder, scheduler()); this.quorumObservers = new ArrayList<>(3); registerQuorumObserver(gridRuntime); }
Example #23
Source File: FSTDecoder.java From vlingo-lattice with Mozilla Public License 2.0 | 4 votes |
public FSTDecoder(FSTConfiguration conf) { this.conf = conf; }
Example #24
Source File: HTMObjectOutput.java From htm.java with GNU Affero General Public License v3.0 | 4 votes |
public HTMObjectOutput(OutputStream out, FSTConfiguration config) { super(out, config); }
Example #25
Source File: HTMObjectInput.java From htm.java with GNU Affero General Public License v3.0 | 4 votes |
public HTMObjectInput(InputStream in, FSTConfiguration config) throws IOException { super(in, config); }
Example #26
Source File: FSTEncoder.java From vlingo-lattice with Mozilla Public License 2.0 | 4 votes |
public FSTEncoder(FSTConfiguration conf) { this.conf = conf; }
Example #27
Source File: TemporalMemoryTest.java From htm.java with GNU Affero General Public License v3.0 | 4 votes |
@SuppressWarnings("unchecked") private <T> T deepCopyPlain(T t) { FSTConfiguration fastSerialConfig = FSTConfiguration.createDefaultConfiguration(); byte[] bytes = fastSerialConfig.asByteArray(t); return (T)fastSerialConfig.asObject(bytes); }
Example #28
Source File: FstCodec.java From redisson with Apache License 2.0 | 4 votes |
FSTDefaultStreamCoderFactory(FSTConfiguration fstConfiguration) { this.fstConfiguration = fstConfiguration; }
Example #29
Source File: ToolSerialize.java From protools with Apache License 2.0 | 4 votes |
public static synchronized FSTConfiguration getCONFIGURATION() { return CONFIGURATION; }
Example #30
Source File: FSTSerializer.java From J2Cache with Apache License 2.0 | 4 votes |
public FSTSerializer() { fstConfiguration = FSTConfiguration.getDefaultConfiguration(); fstConfiguration.setClassLoader(Thread.currentThread().getContextClassLoader()); }