com.hazelcast.config.SerializerConfig Java Examples
The following examples show how to use
com.hazelcast.config.SerializerConfig.
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: Hazelcast.java From lannister with Apache License 2.0 | 6 votes |
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; }
Example #2
Source File: TestCustomerSerializers.java From subzero with Apache License 2.0 | 6 votes |
@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); }
Example #3
Source File: HazelcastCommandExecutorConfiguration.java From concursus with MIT License | 6 votes |
/** * 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; }
Example #4
Source File: HazelcastSerializerTest.java From bucket4j with Apache License 2.0 | 6 votes |
@Before public void setup() { SerializationConfig serializationConfig = new SerializationConfig(); for (HazelcastSerializer serializer : HazelcastSerializer.getAllSerializers(1000)) { serializationConfig.addSerializerConfig( new SerializerConfig() .setImplementation(serializer) .setTypeClass(serializer.getSerializableType()) ); serializerByClass.put(serializer.getSerializableType(), serializer); } this.serializationService = new DefaultSerializationServiceBuilder() .setConfig(serializationConfig) .build(); }
Example #5
Source File: HazelcastSerializerTest.java From bucket4j with Apache License 2.0 | 6 votes |
@Before public void setup() { SerializationConfig serializationConfig = new SerializationConfig(); for (HazelcastSerializer serializer : HazelcastSerializer.getAllSerializers(1000)) { serializationConfig.addSerializerConfig( new SerializerConfig() .setImplementation(serializer) .setTypeClass(serializer.getSerializableType()) ); serializerByClass.put(serializer.getSerializableType(), serializer); } this.serializationService = new DefaultSerializationServiceBuilder() .setConfig(serializationConfig) .build(); }
Example #6
Source File: SubZero.java From subzero with Apache License 2.0 | 5 votes |
private static <T> T useForClassesInternal(T config, Class<?>...classes) { SerializationConfig serializationConfig = extractSerializationConfig(config); for (Class<?> clazz : classes) { SerializerConfig serializerConfig = new SerializerConfig(); Serializer<?> serializer = new Serializer(clazz); serializerConfig.setImplementation(serializer); serializerConfig.setTypeClass(clazz); serializationConfig.addSerializerConfig(serializerConfig); } return config; }
Example #7
Source File: SubZeroTest.java From subzero with Apache License 2.0 | 5 votes |
@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); }
Example #8
Source File: BaseSmokeTests.java From subzero with Apache License 2.0 | 5 votes |
private void configureTypedConfig(SerializationConfig config) { SerializerConfig serializerConfig = new SerializerConfig() .setTypeClassName("info.jerrinot.subzero.it.Person") .setClassName("info.jerrinot.subzero.Serializer"); config.addSerializerConfig(serializerConfig); }
Example #9
Source File: DefaultHazelcastProvider.java From dolphin-platform with Apache License 2.0 | 5 votes |
public synchronized HazelcastInstance getHazelcastInstance(final 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; }
Example #10
Source File: ServerApp.java From java-11-examples with Apache License 2.0 | 4 votes |
public void startServer() throws Exception { LOG.info("starting hazelcast ..."); executorService = Executors.newSingleThreadExecutor(); // Register serializers in hazelcast configuration SerializerConfig sc = new SerializerConfig() .setImplementation(new InstanceInfoSerializer()) .setTypeClass(InstanceInfo.class); Config config = new Config(); config.getSerializationConfig().addSerializerConfig(sc); // Create hazelcast instance hazelcastInstance = Hazelcast.newHazelcastInstance(config); MembershipListenerImpl membershipListener = new MembershipListenerImpl(expectedClusterSize); // listen on cluster events Cluster cluster = hazelcastInstance.getCluster(); cluster.addMembershipListener(membershipListener); LOG.info("Waiting for expected cluster members to join ..."); membershipListener.awaitClusterFormation(20, TimeUnit.SECONDS); // populate clusterInfo map IAtomicLong webPortCounter = hazelcastInstance.getAtomicLong("webPortCounter"); Map<String, InstanceInfo> clusterInfo = hazelcastInstance.getMap( "clusterInfo" ); InstanceInfo instanceInfo = createInstanceInfo(cluster.getLocalMember(), clusterInfo, (int)webPortCounter.getAndAdd(1)); clusterInfo.put(instanceInfo.getId(), instanceInfo); // register leadership listener GateKeepingListener gateKeepingListener = new GateKeepingListenerImpl(); GateKeeperRunnable gateKeeperRunnable = new GateKeeperRunnable(executorService, hazelcastInstance, gateKeepingListener); executorService.submit(gateKeeperRunnable); LOG.info("initializing service layer ..."); MessageService messageService = new MessageServiceImpl(hazelcastInstance); RequestRouter requestRouter = new RequestRouter(messageService); LOG.info("starting web layer ..."); server = new Server(); ServletContextHandler context = new ServletContextHandler(server, "/data", ServletContextHandler.SESSIONS); // Register websocket handlers ServletHolder webSocketHolder = new ServletHolder(new WsServlet(requestRouter)); context.addServlet(webSocketHolder, "/websocket"); // Setup http connectors HttpConfiguration httpConfig = new HttpConfiguration(); HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory(httpConfig); ServerConnector http = new ServerConnector(server, httpConnectionFactory); http.setPort(instanceInfo.getWebServerPort()); server.addConnector(http); server.start(); LOG.info("init sequence done."); }
Example #11
Source File: CacheClient.java From code-examples with MIT License | 4 votes |
private SerializerConfig serializerConfig() { return new SerializerConfig() .setImplementation(new CarSerializer()) .setTypeClass(Car.class); }
Example #12
Source File: HazelcastSerializer.java From bucket4j with Apache License 2.0 | 3 votes |
/** * Registers custom Hazelcast serializers for all classes from Bucket4j library which can be transferred over network. * Each serializer will have different typeId, and this id will not be changed in the feature releases. * * <p> * <strong>Note:</strong> it would be better to leave an empty space in the Ids in order to handle the extension of Bucket4j library when new classes can be added to library. * For example if you called {@code getAllSerializers(10000)} then it would be reasonable to avoid registering your custom types in the interval 10000-10100. * </p> * * @param typeIdBase a starting number from for typeId sequence */ public static void addCustomSerializers(SerializationConfig serializationConfig, final int typeIdBase) { for (HazelcastSerializer serializer : HazelcastSerializer.getAllSerializers(typeIdBase)) { serializationConfig.addSerializerConfig( new SerializerConfig() .setImplementation(serializer) .setTypeClass(serializer.getSerializableType()) ); } }
Example #13
Source File: HazelcastSerializer.java From bucket4j with Apache License 2.0 | 3 votes |
/** * Registers custom Hazelcast serializers for all classes from Bucket4j library which can be transferred over network. * Each serializer will have different typeId, and this id will not be changed in the feature releases. * * <p> * <strong>Note:</strong> it would be better to leave an empty space in the Ids in order to handle the extension of Bucket4j library when new classes can be added to library. * For example if you called {@code getAllSerializers(10000)} then it would be reasonable to avoid registering your custom types in the interval 10000-10100. * </p> * * @param typeIdBase a starting number from for typeId sequence */ public static void addCustomSerializers(SerializationConfig serializationConfig, final int typeIdBase) { for (HazelcastSerializer serializer : HazelcastSerializer.getAllSerializers(typeIdBase)) { serializationConfig.addSerializerConfig( new SerializerConfig() .setImplementation(serializer) .setTypeClass(serializer.getSerializableType()) ); } }