Intro to the open source edition of Hazelcast











![Server public static void main(String[] args){ Hazelcast. Instance instance = Hazelcast. new. Hazelcast. Instance(); Server public static void main(String[] args){ Hazelcast. Instance instance = Hazelcast. new. Hazelcast. Instance();](https://slidetodoc.com/presentation_image_h/77e7489125da287a6b24f3c94a42968c/image-12.jpg)
![Client public static void main(String[] args) throws …… { Hazelcast. Instance instance = Hazelcast. Client public static void main(String[] args) throws …… { Hazelcast. Instance instance = Hazelcast.](https://slidetodoc.com/presentation_image_h/77e7489125da287a6b24f3c94a42968c/image-13.jpg)











- Slides: 24
Intro to the open source edition of Hazelcast by Peter Schmeltzer hazelcast. com / hazelcast. org
Some Use Cases • • Caching No. SQL Data Store Database cache/proxy Application Scaling In-Memory Computing Messaging Web Session Replication
Hazelcast 3. 5 Architecture
Basic Architecture (Embedded Server) JVM Hazelcast. Instance (Hazelcast Server)
Basic Architecture (Embedded Server) Business Logic Other…. JVM Hazelcast. Instance (Hazelcast Server) Data Access Objects
Basic Architecture (Client/Server) Hazelcast. Instance (Hazelcast Server) JVM Hazelcast Client (Still Hazelcast. Instance) JVM
Basic Architecture (Client/Server) Cluster Hazelcast. Instance (Hazelcast Server) JVM Hazelcast Client (Still Hazelcast. Instance) Hazelcast. Instance (Hazelcast Server) JVM
Initialization • Hazelcast. xml • Spring • Programmatic
Programmatic Server: Hazelcast. Instance instance = Hazelcast. new. Hazelcast. Instance(); Client: Hazelcast. Instance instance = Hazelcast. Client. new. Hazelcast. Client(); Same interface for both server and client
Spring <bean id="cluster. Service. Bean" class="com. pschmeltzer. cluster. Cluster. Service"> <constructor-arg ref="global. Executor"/> </bean> <bean id="migration. Listener" factory-bean="cluster. Service. Bean" factory-method="get. Migration. Listener"/> <bean id="membership. Listener" factory-bean="cluster. Service. Bean" factorymethod="get. Membership. Listener"/> <hz: hazelcast id="instance"> <hz: config> <hz: group name="dev" password="test"/> <hz: properties> <hz: property name="hazelcast. logging. type">log 4 j</hz: property> </hz: properties> <hz: network port="12345" port-auto-increment="true"> <hz: join> <hz: multicast enabled="true"/> </hz: join> </hz: network> <hz: listeners> <hz: listener implementation="cluster. Service. Bean"/> <hz: listener implementation="migration. Listener"/> <hz: listener implementation="membership. Listener"/> </hz: listeners> </hz: config> </hz: hazelcast>
Short Demo (Client/Server Mode) • • • Start server Get map and store some entries Start second server Start client Get entries and discover their location Hazelcast Map Reduce – Map, Combine, Reduce, Collate
Server public static void main(String[] args){ Hazelcast. Instance instance = Hazelcast. new. Hazelcast. Instance(); Map<String, Person> person. Map = instance. get. Map("person-map"); if(person. Map. is. Empty()) { person. Map. put("peter", new Person("peter", 25, "Kentwood")); person. Map. put("jacob", new Person("jacob", 21, "Greenville")); person. Map. put("dan", new Person("dan", 19, "Greenville")); } }
Client public static void main(String[] args) throws …… { Hazelcast. Instance instance = Hazelcast. Client. new. Hazelcast. Client(); IMap<String, Person> person. Map = instance. get. Map("person-map"); Basic. Util. log("Partition Location: "); for(Map. Entry<String, Person> entry : person. Map. entry. Set()){ log(entry + " partition " + instance. get. Partition. Service(). get. Partition(entry. get. Key()). get. Owner()); } …
Client … Basic. Util. log("Predicate Filtering"); person. Map. key. Set( new Predicate<String, Person>() { @Override public boolean apply(Map. Entry<String, Person> entry) { return entry. get. Value(). get. Age() > 20; } } ). for. Each(Basic. Util: : log); …
Client Job. Tracker job. Tracker = instance. get. Job. Tracker("default"); Key. Value. Source<String, Person> source = Key. Value. Source. from. Map(person. Map); Job<String, Person> job = job. Tracker. new. Job(source); ICompletable. Future<Map<String, Double>> future = job. mapper(new Person. By. Hometown. To. Age. Mapper()). combiner(new Age. Combiner. Factory()). reducer(new Avg. Age. Reducer. Factory()). submit(); Map<String, Double> results = future. get(); for(Map. Entry<String, Double> entry : results. entry. Set()){ Basic. Util. log(entry); }
Demo. . …
Short Demo • Populate product listing • Subscribe to products local to my jvm • Store products local to my jvm
Price Server / Embedded instance. get. Partition. Service(). add. Migration. Listener(new Migration. Listener() { @Override public void migration. Started(Migration. Event migration. Event) { } @Override public void migration. Completed(Migration. Event migration. Event) { perform. Diff(); } @Override public void migration. Failed(Migration. Event migration. Event) { perform. Diff(); } });
Demo. . …
Use Case • Real time display of aggregated trade data • Multiple sources aggregate to single view • Location aware data processing
Database Cache <bean id="hz. User. Map. Store" class="com. tl. core. cache. map. stores. Bog. User. Loader"> <constructor-arg ref="bog. Proxy. Map"/> </bean> <hz: map name="USERS" eviction-policy="LRU" max-idle-seconds="3600" time-to-live-seconds="21600"> <hz: map-store enabled="true" write-delay-seconds="0" implementation="hz. User. Map. Store"/> </hz: map>
Database Cache public interface Map. Store<K, V> extends Map. Loader<K, V> { void store(K var 1, V var 2); void store. All(Map<K, V> var 1); void delete(K var 1); void delete. All(Collection<K> var 1); }
Database Cache @Override public User load(User. Key user. Key) { Backoffice. Proxy proxy = map. get. For. Broker. Key(user. Key. get. Broker. Key()); if(proxy != null){ try { return proxy. get. User(user. Key. get. Login()); } catch (Business. Exception e) { log. error("Map Store could not load user: " + user. Key, e); } } return null; }
Intro to the open source edition of Hazelcast by Peter Schmeltzer hazelcast. com / hazelcast. org