本文整理了Java中com.hazelcast.config.Config.getSerializationConfig()
方法的一些代码示例,展示了Config.getSerializationConfig()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Config.getSerializationConfig()
方法的具体详情如下:
包路径:com.hazelcast.config.Config
类名称:Config
方法名:getSerializationConfig
[英]Returns the serialization configuration for this hazelcast instance. The serialization configuration defines how objects are serialized and deserialized on this instance.
[中]返回此hazelcast实例的序列化配置。序列化配置定义如何在此实例上序列化和反序列化对象。
代码示例来源:origin: com.hazelcast/hazelcast-all
@Override
public SerializationConfig getSerializationConfig() {
return staticConfig.getSerializationConfig();
}
代码示例来源:origin: hazelcast/hazelcast-jet
@Override
public SerializationConfig getSerializationConfig() {
return staticConfig.getSerializationConfig();
}
代码示例来源:origin: jerrinot/subzero
private static SerializationConfig extractSerializationConfig(Object config) {
String className = config.getClass().getName();
SerializationConfig serializationConfig;
if (className.equals("com.hazelcast.client.config.ClientConfig")) {
ClientConfig clientConfig = (ClientConfig) config;
serializationConfig = clientConfig.getSerializationConfig();
} else if (className.equals("com.hazelcast.config.Config")) {
Config memberConfig = (Config) config;
serializationConfig = memberConfig.getSerializationConfig();
} else {
throw new IllegalArgumentException("Unknown configuration object " + config);
}
return serializationConfig;
}
代码示例来源:origin: jerrinot/subzero
/**
* Use SubZero as a global serializer.
*
* This method configures Hazelcast to delegate a class serialization to SubZero when the class
* has no explicit strategy configured.
*
* @param config Hazelcast configuration to inject SubZero into
* @param serializerClazz Class of global serializer implementation to use
* @return Hazelcast configuration.
*/
public static Config useAsGlobalSerializer(Config config, Class<? extends AbstractGlobalUserSerializer> serializerClazz) {
SerializationConfig serializationConfig = config.getSerializationConfig();
injectSubZero(serializationConfig, serializerClazz);
return config;
}
代码示例来源:origin: hazelcast/hazelcast-code-samples
public static void main(String[] args) {
Config config = new Config();
config.getSerializationConfig()
.addPortableFactory(SamplePortableFactory.FACTORY_ID, new SamplePortableFactory());
// Start the Embedded Hazelcast Cluster Member.
HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
//Customer can be used here
hz.shutdown();
}
}
代码示例来源:origin: hazelcast/hazelcast-code-samples
public static void main(String[] args) {
Config config = new Config();
config.getSerializationConfig()
.addDataSerializableFactory(SampleDataSerializableFactory.FACTORY_ID,
new SampleDataSerializableFactory());
// Start the Embedded Hazelcast Cluster Member.
HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
//Employee can be used here
hz.shutdown();
}
}
代码示例来源:origin: com.sitewhere/sitewhere-core
/**
* Set up serialization configuration.
*
* @param config
*/
public static void performSerializationOverrides(Config config) {
SerializationConfig serial = config.getSerializationConfig();
if (serial == null) {
serial = new SerializationConfig();
config.setSerializationConfig(serial);
}
config.setSerializationConfig(null);
}
代码示例来源:origin: hazelcast/hazelcast-code-samples
public static void main(String[] args) {
// configure hazelcast serializers to use provided serializer for protobuf
SerializerConfig personProtoSerializerConfig = new SerializerConfig()
.setTypeClass(Person.class)
.setImplementation(new PersonProtoSerializer());
Config config = new Config();
config.getSerializationConfig().addSerializerConfig(personProtoSerializerConfig);
// uncomment the following line if you wish to use XML config instead of programmatic configuration
// config = new com.hazelcast.config.XmlConfigBuilder().build();
HazelcastInstance hazelcastInstance = newHazelcastInstance(config);
IMap<Integer, Person> personsMap = hazelcastInstance.getMap("person");
populate(personsMap);
// test member-side serialization
System.out.println("---- where email is support@hazelcast.com");
System.out.println(personsMap.values(equal("email", "support@hazelcast.com")));
System.out.println("---- where email is not support@hazelcast.com");
System.out.println(personsMap.values(new SqlPredicate("email != support@hazelcast.com")));
}
代码示例来源:origin: hazelcast/hazelcast-code-samples
public static void main(String[] args) {
Config config = new Config();
config.getSerializationConfig().setGlobalSerializerConfig(
new GlobalSerializerConfig().setImplementation(new GlobalSerializer())
);
// Start the Embedded Hazelcast Cluster Member.
HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
//GlobalSerializer will serialize/deserialize all non-builtin types
hz.shutdown();
}
}
代码示例来源:origin: hazelcast/hazelcast-code-samples
public static void main(String[] args) {
Config config = new Config();
config.getSerializationConfig().addSerializerConfig(new SerializerConfig()
.setImplementation(new CustomSerializer())
.setTypeClass(CustomSerializable.class));
// Start the Embedded Hazelcast Cluster Member.
HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
//CustomSerializer will serialize/deserialize CustomSerializable objects
hz.shutdown();
}
}
代码示例来源:origin: org.apache.marmotta/kiwi-caching-hazelcast
private void setupSerializers() {
SerializerConfig scBNode = new SerializerConfig().setImplementation(new BNodeSerializer()).setTypeClass(KiWiAnonResource.class);
hcConfiguration.getSerializationConfig().addSerializerConfig(scBNode);
SerializerConfig scBoolean = new SerializerConfig().setImplementation(new BooleanLiteralSerializer()).setTypeClass(KiWiBooleanLiteral.class);
hcConfiguration.getSerializationConfig().addSerializerConfig(scBoolean);
SerializerConfig scDate = new SerializerConfig().setImplementation(new DateLiteralSerializer()).setTypeClass(KiWiDateLiteral.class);
hcConfiguration.getSerializationConfig().addSerializerConfig(scDate);
SerializerConfig scDouble = new SerializerConfig().setImplementation(new DoubleLiteralSerializer()).setTypeClass(KiWiDoubleLiteral.class);
hcConfiguration.getSerializationConfig().addSerializerConfig(scDouble);
SerializerConfig scInt = new SerializerConfig().setImplementation(new IntLiteralSerializer()).setTypeClass(KiWiIntLiteral.class);
hcConfiguration.getSerializationConfig().addSerializerConfig(scInt);
SerializerConfig scString = new SerializerConfig().setImplementation(new StringLiteralSerializer()).setTypeClass(KiWiStringLiteral.class);
hcConfiguration.getSerializationConfig().addSerializerConfig(scString);
SerializerConfig scTriple = new SerializerConfig().setImplementation(new TripleSerializer()).setTypeClass(KiWiTriple.class);
hcConfiguration.getSerializationConfig().addSerializerConfig(scTriple);
SerializerConfig scUri = new SerializerConfig().setImplementation(new UriSerializer()).setTypeClass(KiWiUriResource.class);
hcConfiguration.getSerializationConfig().addSerializerConfig(scUri);
}
代码示例来源:origin: apache/marmotta
private void setupSerializers() {
SerializerConfig scBNode = new SerializerConfig().setImplementation(new BNodeSerializer()).setTypeClass(KiWiAnonResource.class);
hcConfiguration.getSerializationConfig().addSerializerConfig(scBNode);
SerializerConfig scBoolean = new SerializerConfig().setImplementation(new BooleanLiteralSerializer()).setTypeClass(KiWiBooleanLiteral.class);
hcConfiguration.getSerializationConfig().addSerializerConfig(scBoolean);
SerializerConfig scDate = new SerializerConfig().setImplementation(new DateLiteralSerializer()).setTypeClass(KiWiDateLiteral.class);
hcConfiguration.getSerializationConfig().addSerializerConfig(scDate);
SerializerConfig scDouble = new SerializerConfig().setImplementation(new DoubleLiteralSerializer()).setTypeClass(KiWiDoubleLiteral.class);
hcConfiguration.getSerializationConfig().addSerializerConfig(scDouble);
SerializerConfig scInt = new SerializerConfig().setImplementation(new IntLiteralSerializer()).setTypeClass(KiWiIntLiteral.class);
hcConfiguration.getSerializationConfig().addSerializerConfig(scInt);
SerializerConfig scString = new SerializerConfig().setImplementation(new StringLiteralSerializer()).setTypeClass(KiWiStringLiteral.class);
hcConfiguration.getSerializationConfig().addSerializerConfig(scString);
SerializerConfig scTriple = new SerializerConfig().setImplementation(new TripleSerializer()).setTypeClass(KiWiTriple.class);
hcConfiguration.getSerializationConfig().addSerializerConfig(scTriple);
SerializerConfig scUri = new SerializerConfig().setImplementation(new UriSerializer()).setTypeClass(KiWiUriResource.class);
hcConfiguration.getSerializationConfig().addSerializerConfig(scUri);
}
代码示例来源:origin: jerrinot/subzero
@Test
public void givenGlobalSerializerConfigDoes_whenUseAsGlobalSerializer_thenNewSubZeroIsUsedAsGlobalSerializer() {
Config config = new Config();
config.getSerializationConfig().setGlobalSerializerConfig(new GlobalSerializerConfig().setClassName("foo"));
SubZero.useAsGlobalSerializer(config);
assertEquals(Serializer.class.getName(), config.getSerializationConfig().getGlobalSerializerConfig().getClassName());
}
代码示例来源:origin: hazelcast/hazelcast-code-samples
public static void main(String[] args) {
Config config = new Config();
config.getSerializationConfig().addPortableFactory(PersonPortableFactory.FACTORY_ID, new PersonPortableFactory());
HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
IMap<Integer, PersonPortable> map = hz.getMap("map");
map.put(1, new PersonPortable("Georg", limb("left-leg"), limb("right-leg")));
map.put(2, new PersonPortable("Peter", limb("left-hand"), limb("right-hand")));
map.put(3, new PersonPortable("Hans", limb("left-leg"), limb("right-leg")));
map.put(4, new PersonPortable("Stefanie", limb("left-arm"), limb("right-arm")));
Set<PersonPortable> employees = (Set<PersonPortable>) map.values(new SqlPredicate("limbs[any].name == right-leg"));
System.out.println("People: " + employees);
Hazelcast.shutdownAll();
}
代码示例来源:origin: jerrinot/subzero
@Test
public void givenGlobalSerializerConfigDoesNotExist_whenUseAsGlobalSerializer_thenNewSubZeroIsUsedAsGlobalSerializer() {
Config config = new Config();
SubZero.useAsGlobalSerializer(config);
assertEquals(Serializer.class.getName(), config.getSerializationConfig().getGlobalSerializerConfig().getClassName());
}
代码示例来源:origin: jerrinot/subzero
@Test
public void useForClasses() {
Config config = new Config();
SubZero.useForClasses(config, String.class);
Collection<SerializerConfig> serializerConfigs = config.getSerializationConfig().getSerializerConfigs();
assertThat(serializerConfigs)
.extracting("typeClass")
.contains(String.class);
}
}
代码示例来源:origin: hazelcast/hazelcast-jet
AsyncSnapshotWriterImpl(int chunkSize, NodeEngine nodeEngine, SnapshotContext snapshotContext,
String vertexName, int memberIndex, int memberCount) {
this.nodeEngine = nodeEngine;
this.partitionService = nodeEngine.getPartitionService();
this.logger = nodeEngine.getLogger(getClass());
this.snapshotContext = snapshotContext;
this.vertexName = vertexName;
this.memberCount = memberCount;
currentSnapshotId = snapshotContext.currentSnapshotId();
useBigEndian = !nodeEngine.getHazelcastInstance().getConfig().getSerializationConfig().isUseNativeByteOrder()
|| ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN;
Bits.writeInt(serializedByteArrayHeader, Bits.INT_SIZE_IN_BYTES, SerializationConstants.CONSTANT_TYPE_BYTE_ARRAY,
useBigEndian);
buffers = new CustomByteArrayOutputStream[partitionService.getPartitionCount()];
for (int i = 0; i < buffers.length; i++) {
buffers[i] = new CustomByteArrayOutputStream(chunkSize);
buffers[i].write(serializedByteArrayHeader, 0, serializedByteArrayHeader.length);
}
JetService jetService = nodeEngine.getService(JetService.SERVICE_NAME);
this.partitionKeys = jetService.getSharedPartitionKeys();
this.partitionSequence = memberIndex;
this.numConcurrentAsyncOps = jetService.numConcurrentAsyncOps();
byte[] valueTerminatorWithHeader = nodeEngine.getSerializationService().toData(
SnapshotDataValueTerminator.INSTANCE).toByteArray();
valueTerminator = Arrays.copyOfRange(valueTerminatorWithHeader, HeapData.TYPE_OFFSET,
valueTerminatorWithHeader.length);
usableChunkSize = chunkSize - valueTerminator.length;
}
代码示例来源:origin: hazelcast/hazelcast-jet
@Override
public InternalSerializationService createSerializationService() {
InternalSerializationService ss;
try {
Config config = node.getConfig();
ClassLoader configClassLoader = node.getConfigClassLoader();
HazelcastInstanceImpl hazelcastInstance = node.hazelcastInstance;
PartitioningStrategy partitioningStrategy = getPartitioningStrategy(configClassLoader);
SerializationServiceBuilder builder = new DefaultSerializationServiceBuilder();
SerializationConfig serializationConfig = config.getSerializationConfig() != null
? config.getSerializationConfig() : new SerializationConfig();
byte version = (byte) node.getProperties().getInteger(GroupProperty.SERIALIZATION_VERSION);
ss = builder.setClassLoader(configClassLoader)
.setConfig(serializationConfig)
.setManagedContext(hazelcastInstance.managedContext)
.setPartitioningStrategy(partitioningStrategy)
.setHazelcastInstance(hazelcastInstance)
.setVersion(version)
.setNotActiveExceptionSupplier(new Supplier<RuntimeException>() {
@Override
public RuntimeException get() {
return new HazelcastInstanceNotActiveException();
}
})
.build();
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
return ss;
}
代码示例来源:origin: hazelcast/hazelcast-code-samples
public static void main(String[] args) throws ParseException {
MapAttributeConfig mapAttributeConfig = new MapAttributeConfig();
mapAttributeConfig.setName("limbName");
mapAttributeConfig.setExtractor("com.test.portable.LimbNameExtractor");
MapConfig mapConfig = new MapConfig();
mapConfig.setName("people");
mapConfig.addMapAttributeConfig(mapAttributeConfig);
Config config = new Config();
config.getSerializationConfig().addPortableFactory(PersonFactory.FACTORY_ID, new PersonFactory());
config.addMapConfig(mapConfig);
HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
IMap<Integer, Person> map = hz.getMap("people");
map.put(1, new Person("Georg", limb("left-leg"), limb("right-leg")));
map.put(2, new Person("Peter", limb("left-hand"), limb("right-hand")));
map.put(3, new Person("Hans", limb("left-finger"), limb("right-finger")));
map.put(4, new Person("Stefanie", limb("left-arm"), limb("right-arm")));
// we're using a custom attribute 'limbName' which is provided by the 'LimbNameExtractor'
Set<Person> people = (Set<Person>) map.values(Predicates.equal("limbName", "left-arm"));
System.out.println("People: " + people);
Hazelcast.shutdownAll();
}
代码示例来源:origin: jerrinot/subzero
@Test
public void testTypedCustomSerializer_configuredBySubclassing() throws Exception {
String mapName = randomMapName();
Config config = new Config();
SerializerConfig serializerConfig = new SerializerConfig();
serializerConfig.setClass(MySerializer.class);
serializerConfig.setTypeClass(AnotherNonSerializableObject.class);
config.getSerializationConfig().getSerializerConfigs().add(serializerConfig);
HazelcastInstance member = hazelcastFactory.newHazelcastInstance(config);
IMap<Integer, AnotherNonSerializableObject> myMap = member.getMap(mapName);
myMap.put(0, new AnotherNonSerializableObject());
AnotherNonSerializableObject fromCache = myMap.get(0);
assertEquals("deserialized", fromCache.name);
}
内容来源于网络,如有侵权,请联系作者删除!