本文整理汇总了Java中com.hazelcast.config.SerializerConfig类的典型用法代码示例。如果您正苦于以下问题:Java SerializerConfig类的具体用法?Java SerializerConfig怎么用?Java SerializerConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SerializerConfig类属于com.hazelcast.config包,在下文中一共展示了SerializerConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createConfig
import com.hazelcast.config.SerializerConfig; //导入依赖的package包/类
private Config createConfig() {
Config config;
try {
config = new XmlConfigBuilder(Application.class.getClassLoader().getResource(CONFIG_NAME)).build();
}
catch (IOException e) {
logger.error(e.getMessage(), e);
throw new Error(e);
}
config.getSerializationConfig().addDataSerializableFactory(SerializableFactory.ID, new SerializableFactory());
config.getSerializationConfig().getSerializerConfigs().add(new SerializerConfig().setTypeClass(JsonNode.class)
.setImplementation(JsonSerializer.makePlain(JsonNode.class)));
return config;
}
示例2: testTypedCustomSerializer_configuredBySubclassing
import com.hazelcast.config.SerializerConfig; //导入依赖的package包/类
@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);
}
示例3: addCommandExecutorConfiguration
import com.hazelcast.config.SerializerConfig; //导入依赖的package包/类
/**
* Add configuration to the supplied {@link Config} to support the use of a {@link HazelcastCommandExecutor}.
* @param config The {@link Config} to configure.
* @return The updated {@link Config}.
*/
public Config addCommandExecutorConfiguration(Config config) {
SerializerConfig serializerConfig = new SerializerConfig()
.setImplementation(RemoteCommandSerialiser.using(
objectMapper,
CommandTypeMatcher.matchingAgainst(typeInfoMap)))
.setTypeClass(RemoteCommand.class);
ManagedContext managedContext = CommandProcessingManagedContext
.processingCommandsWith(dispatchingCommandProcessor);
config.getSerializationConfig().addSerializerConfig(serializerConfig);
config.setManagedContext(config.getManagedContext() == null
? managedContext
: CompositeManagedContext.of(managedContext, config.getManagedContext()));
config.addExecutorConfig(new ExecutorConfig(executorName, threadsPerNode));
return config;
}
示例4: setupSerializers
import com.hazelcast.config.SerializerConfig; //导入依赖的package包/类
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);
}
示例5: Transport
import com.hazelcast.config.SerializerConfig; //导入依赖的package包/类
/**
* Initializes the {@link HazelcastInstance} for this global runtime instance.
*
* @param runtime
* the global runtime instance
* @param master
* member to connect to or null
* @param localhost
* the preferred ip address of this host or null
* @param compact
* reduce thread creation if set
* @param kryo
* use kryo serialization if set
*/
protected Transport(GlobalRuntimeImpl runtime, String master,
String localhost, boolean compact, boolean kryo) {
this.runtime = runtime;
// config
final Config config = new Config();
config.setProperty("hazelcast.logging.type", "none");
config.setProperty("hazelcast.wait.seconds.before.join", "0");
config.setProperty("hazelcast.socket.connect.timeout.seconds", "1");
config.setProperty("hazelcast.connection.monitor.max.faults", "0");
if (compact) {
config.setProperty("hazelcast.operation.thread.count", "2");
config.setProperty("hazelcast.operation.generic.thread.count", "2");
config.setProperty("hazelcast.io.thread.count", "2");
config.setProperty("hazelcast.event.thread.count", "2");
config.addExecutorConfig(
new ExecutorConfig(ExecutionService.ASYNC_EXECUTOR, 2));
config.addExecutorConfig(
new ExecutorConfig(ExecutionService.SYSTEM_EXECUTOR, 2));
config.addExecutorConfig(
new ExecutorConfig(ExecutionService.SCHEDULED_EXECUTOR, 2));
}
// kryo
if (kryo) {
config.getSerializationConfig().addSerializerConfig(
new SerializerConfig().setTypeClass(SerializableRunnable.class)
.setImplementation(new KryoSerializer()));
}
config.addMapConfig(
new MapConfig(APGAS_FINISH).setInMemoryFormat(InMemoryFormat.OBJECT));
// join config
final JoinConfig join = config.getNetworkConfig().getJoin();
join.getMulticastConfig().setEnabled(false);
join.getTcpIpConfig().setEnabled(true);
if (localhost != null) {
System.setProperty("hazelcast.local.localAddress", localhost);
}
if (master != null) {
join.getTcpIpConfig().addMember(master);
}
config.setInstanceName(APGAS);
hazelcast = Hazelcast.newHazelcastInstance(config);
me = hazelcast.getCluster().getLocalMember();
allMembers = hazelcast.getList(APGAS_PLACES);
allMembers.add(me);
int id = 0;
for (final Member member : allMembers) {
if (member.getUuid().equals(me.getUuid())) {
break;
}
++id;
}
here = id;
executor = hazelcast.getExecutorService(APGAS_EXECUTOR);
}
示例6: init
import com.hazelcast.config.SerializerConfig; //导入依赖的package包/类
private void init() {
checkConfig();
if (usingHazelcast) {
ClientConfig clientConfig = new ClientConfig();
clientConfig.getGroupConfig().setName(hazelcastUser).setPassword(hazelcastPassword);
for (int i = 0; i < hazelcastServers.length; i++) {
clientConfig.getNetworkConfig().addAddress(hazelcastServers[i]);
}
clientConfig.getSerializationConfig().getSerializerConfigs().add(new SerializerConfig().setTypeClass(MutableRepositoryItemExt.class).setImplementation(new MutableRepositoryItemExtHazelcastSerializer()));
HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
itemCache = client.getMap("itemCacheMap");
//itemCache = new HashMap<String, MutableRepositoryItemExt>();
} else if (usingMapDB) {
MutableRepositoryItemExtMapDBSerializer MutableRepositoryItemExtMapDBSerializer = new MutableRepositoryItemExtMapDBSerializer();
MutableRepositoryItemExtArrayMapDBSerializer MutableRepositoryItemExtArrayMapDBSerializer = new MutableRepositoryItemExtArrayMapDBSerializer();
mapDB = DBMaker.newTempFileDB().transactionDisable().asyncWriteEnable().make();
itemCache = mapDB.createHashMap("itemCacheMap").keySerializer(org.mapdb.Serializer.STRING).valueSerializer(MutableRepositoryItemExtMapDBSerializer).make();
MutableRepositoryItemExtArrayMapDBSerializer.setItemCache(itemCache);
queryCache = mapDB.createHashMap("queryCacheMap").keySerializer(org.mapdb.Serializer.STRING).valueSerializer(MutableRepositoryItemExtArrayMapDBSerializer).make();
} else {
itemCache = new ConcurrentHashMap<String, MutableRepositoryItemExt>();
queryCache = new ConcurrentHashMap<String, MutableRepositoryItemExt>();
}
}
示例7: useForClasses
import com.hazelcast.config.SerializerConfig; //导入依赖的package包/类
/**
* Use SubZero as a serializer for selected classes only.
*
* @param config Hazelcast configuration to inject SubZero into
* @param classes classes Hazelcast should serialize via SubZero
* @return Hazelcast configuration
*/
public static Config useForClasses(Config config, Class<?>...classes) {
SerializationConfig serializationConfig = config.getSerializationConfig();
for (Class<?> clazz : classes) {
SerializerConfig serializerConfig = new SerializerConfig();
Serializer<?> serializer = new Serializer(clazz);
serializerConfig.setImplementation(serializer);
serializerConfig.setTypeClass(clazz);
serializationConfig.addSerializerConfig(serializerConfig);
}
return config;
}
示例8: useForClasses
import com.hazelcast.config.SerializerConfig; //导入依赖的package包/类
@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);
}
示例9: createTypedConfig
import com.hazelcast.config.SerializerConfig; //导入依赖的package包/类
private Config createTypedConfig() {
Config config = new Config();
SerializerConfig serializerConfig = new SerializerConfig()
.setTypeClassName("info.jerrinot.subzero.it.Person")
.setClassName("info.jerrinot.subzero.Serializer");
SerializationConfig serializationConfig = config.getSerializationConfig();
serializationConfig.addSerializerConfig(serializerConfig);
return config;
}
示例10: TypesafeHazelcastConfig
import com.hazelcast.config.SerializerConfig; //导入依赖的package包/类
/**
* @param name Hazelcast instance name
* @param config TypeSafe typeSafeConfig
* @param serializerConfigs can be empty
*/
public TypesafeHazelcastConfig(@NonNull final String name, @NonNull final com.typesafe.config.Config config, @NonNull final Set<SerializerConfig> serializerConfigs) {
this.hazelcastConfig = createHazelcastConfig(
name,
config,
serializerConfigs.isEmpty() ? Optional.empty() : Optional.of(ImmutableSet.copyOf(serializerConfigs))
);
}
示例11: testHazelcastConfigFactory_withSerializers
import com.hazelcast.config.SerializerConfig; //导入依赖的package包/类
/**
* Test of hazelcastConfigFactory method, of class HazelcastConfigFactory.
*/
@Test
public void testHazelcastConfigFactory_withSerializers() {
LOG.info("hazelcastConfigFactory");
String hazelcastInstanceName = "testHazelcastConfigFactory_withSerializers";
final Set<SerializerConfig> serializerConfigs = ImmutableSet.of(
new SerializerConfig().setImplementation(new JsonObjectSerializer()).setTypeClass(JsonObject.class)
);
final HazelcastConfigFactory factory1 = HazelcastConfigFactory.hazelcastConfigFactory(hazelcastInstanceName + 1, serializerConfigs);
final com.hazelcast.config.Config hazelcastConfig1 = factory1.apply(config.getConfig(ConfigUtil.joinPath("Hazelcast", "application-1")));
final HazelcastInstance hazelcast1 = Hazelcast.newHazelcastInstance(hazelcastConfig1);
final HazelcastConfigFactory factory2 = HazelcastConfigFactory.hazelcastConfigFactory(hazelcastInstanceName + 2, serializerConfigs);
final com.hazelcast.config.Config hazelcastConfig2 = factory2.apply(config.getConfig(ConfigUtil.joinPath("Hazelcast", "application-2")));
final HazelcastInstance hazelcast2 = Hazelcast.newHazelcastInstance(hazelcastConfig2);
test(hazelcast1, hazelcast2);
final JsonObject json = Json.createObjectBuilder().add("a", 1).build();
final String mapName = "testHazelcastConfigFactory_withSerializers_map";
final Map<String, Object> map1 = hazelcast1.getMap(mapName);
map1.put("json", json);
final Map<String, Object> map2 = hazelcast2.getMap(mapName);
final JsonObject json2 = (JsonObject) map2.get("json");
assertThat(json2.getInt("a"), is(1));
}
示例12: createHazelcastInstance
import com.hazelcast.config.SerializerConfig; //导入依赖的package包/类
private HazelcastInstance createHazelcastInstance() {
ClientConfig config = new ClientConfig();
config.getNetworkConfig().addAddress("localhost" + ":" + 5701);
config.getGroupConfig().setName("distribution-app");
final SerializerConfig dolphinEventSerializerConfig = new SerializerConfig().
setImplementation(new CustomStreamSerializer()).setTypeClass(CustomEventFormat.class);
config.getSerializationConfig().getSerializerConfigs().add(dolphinEventSerializerConfig);
return HazelcastClient.newHazelcastClient(config);
}
示例13: getHazelcastInstance
import com.hazelcast.config.SerializerConfig; //导入依赖的package包/类
public synchronized HazelcastInstance getHazelcastInstance(HazelcastConfig configuration) {
if (hazelcastInstance == null) {
final String serverName = configuration.getServerName();
final String serverPort = configuration.getServerPort();
final String groupName = configuration.getGroupName();
LOG.debug("Hazelcast server name: {}", serverName);
LOG.debug("Hazelcast server port: {}", serverPort);
LOG.debug("Hazelcast group name: {}", groupName);
final ClientConfig clientConfig = new ClientConfig();
clientConfig.getNetworkConfig().setConnectionAttemptLimit(configuration.getConnectionAttemptLimit());
clientConfig.getNetworkConfig().setConnectionAttemptPeriod(configuration.getConnectionAttemptPeriod());
clientConfig.getNetworkConfig().setConnectionTimeout(configuration.getConnectionTimeout());
clientConfig.getNetworkConfig().addAddress(serverName + ":" + serverPort);
clientConfig.getGroupConfig().setName(groupName);
clientConfig.setProperty(LOGGER_PROPERTY_NAME, LOGGER_PROPERTY_SLF4J_TYPE);
final SerializerConfig dolphinEventSerializerConfig = new SerializerConfig().
setImplementation(new EventStreamSerializer()).setTypeClass(DolphinEvent.class);
clientConfig.getSerializationConfig().getSerializerConfigs().add(dolphinEventSerializerConfig);
hazelcastInstance = HazelcastClient.newHazelcastClient(clientConfig);
}
return hazelcastInstance;
}
示例14: hazelcastInstance
import com.hazelcast.config.SerializerConfig; //导入依赖的package包/类
@Bean(destroyMethod = "shutdown")
public HazelcastInstance hazelcastInstance() {
Config config = new Config();
int port = SocketUtils.findAvailableTcpPort();
config.getNetworkConfig()
.setPort(port);
System.out.println("Hazelcast port #: " + port);
SerializerConfig serializer = new SerializerConfig()
.setImplementation(new ObjectStreamSerializer())
.setTypeClass(Object.class);
config.getSerializationConfig()
.addSerializerConfig(serializer);
MapAttributeConfig attributeConfig = new MapAttributeConfig()
.setName(HazelcastSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)
.setExtractor(PrincipalNameExtractor.class.getName());
config.getMapConfig(HazelcastSessionRepository.DEFAULT_SESSION_MAP_NAME)
.addMapAttributeConfig(attributeConfig)
.addMapIndexConfig(new MapIndexConfig(
HazelcastSessionRepository.PRINCIPAL_NAME_ATTRIBUTE, false));
return Hazelcast.newHazelcastInstance(config);
}
示例15: create
import com.hazelcast.config.SerializerConfig; //导入依赖的package包/类
public Set<SerializerConfig> create() {
Set<SerializerConfig> set = new HashSet<>();
int id = 0;
for (Class<?> c : classes) {
id = id + 1;
set.add(new SerializerConfig().setImplementation(new HzGsonSerializer(gson, id, c)).setTypeClass(c));
}
setupCustom(set, id);
return set;
}