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(); } }
public static void main(String[] args) { ClientConfig clientConfig = new ClientConfig(); clientConfig.getSerializationConfig() .addPortableFactory(SamplePortableFactory.FACTORY_ID, new SamplePortableFactory()); // Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1 HazelcastInstance hz = HazelcastClient.newHazelcastClient(clientConfig); //Customer can be used here hz.shutdown(); } }
public static void main(String[] args) { ClientConfig clientConfig = new ClientConfig(); clientConfig.getSerializationConfig() .addPortableFactory(ThePortableFactory.FACTORY_ID, new ThePortableFactory()); // Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1 HazelcastInstance hz = HazelcastClient.newHazelcastClient(clientConfig); // Get a Distributed Map called "users" IMap<String, User> users = hz.getMap("users"); // Add some users to the Distributed Map generateUsers(users); // Create a Predicate from a String (a SQL like Where clause) Predicate sqlQuery = new SqlPredicate("active AND age BETWEEN 18 AND 21)"); // Creating the same Predicate as above but with a builder Predicate criteriaQuery = Predicates.and( Predicates.equal("active", true), Predicates.between("age", 18, 21) ); // Get result collections using the two different Predicates Collection<User> result1 = users.values(sqlQuery); Collection<User> result2 = users.values(criteriaQuery); // Print out the results System.out.println(result1); System.out.println(result2); // Shutdown this Hazelcast Client hz.shutdown(); } }
@Bean public HazelcastInstance hazelcast() throws Exception { ClientConfig clientConfig = new ClientConfig(); clientConfig.getGroupConfig() .setName(groupName) .setPassword(groupPassword); clientConfig.getNetworkConfig() .setAddresses(clusterMembers); clientConfig.getSerializationConfig() .addPortableFactory(1, new DevicePortableFactory()); clientConfig.setProperty("hazelcast.client.event.thread.count", eventThreadCount); return HazelcastClient.newHazelcastClient(clientConfig); } }
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(); }
public static void main(String[] args) throws Exception { System.setProperty("hazelcast.logging.type", "log4j"); JetConfig config = new JetConfig(); config.getHazelcastConfig().getSerializationConfig().addPortableFactory( TradePortableFactory.FACTORY_ID, new TradePortableFactory() );
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(); }