Deprecation

This document is DEPRECATED.

Please consider any information here as out of date. DO NOT use this document.

Instead, refer to http://infinispan.org/documentation.

Please update your bookmarks accordingly.

Skip to end of metadata
Go to start of metadata

Introduction

This lab was developed for Devoxx 2011, by Pete Muir, Mircea Markus and Sanne Grinovero. It is designed to last around 1h 45m, and has an accompanying introduction and conclusion. Full slide deck is attached.

The lab has been updated by Galder Zamarreño for Infinispan 5.1 and has been featured in the Neuchatel JBUG and JUDCon India 2012

Setup

Getting setup to run the lab

presented by Pete
5 minutes

  • Using Infinispan 5.1.0.FINAL
  • Download the lab zip from [...]
  • Unzip the lab to your disk to a location of your choice
  • If you are a git user, you can clone the repository:
  • each stage of this lab has a checkpoint which is a branch, you can check out the code for each Checkpoint using. Checkpoints are mentioned in these instructions:

Introduction

Use cases, key features and benefits of Infinispan

slides, presented by Pete
20 minutes

Sample project

Explanation of sample project architecture

presented by Pete
5 minutes

  • The lab is a simple ticket allocation and booking system
  • lab1 contains a project skeleton with the relevant dependencies available. It is a war, that can be deployed on JBoss AS 7. It also use CDI to wire together the app, and JSF for the view layer. JMS is used to provide messaging and EJB to provide a listener for messages we send via JMS.
  • In another console, start JBoss AS - $JBOSS_HOME/bin/standalone.sh
  • Deploy the project to JBoss AS 7 using mvn clean package jboss-as:deploy
  • visit http://localhost:8080/lab1
  • All cache operations hidden by service layer to allow us to swap out caching impls
  • Starts with a HashMap and builds on that
  • Import the project into your IDE, we use Eclipse with m2eclipse installed.
  • Show project

Checkpoint 1

Interlude - Caching in Java EE

JSR-107 (JCACHE) and JSR-347 (Datagrids for Java)

presented by Pete
5 minutes

Topics covered include:

  • TODO

JGroups & Networks

presented by Sanne
10 minutes

Make sure your nodes can see each other

  • In LAB_HOME/nic_test there is the the test-network script. Run it.
  • If all goes well, you'll get two windows in which you can draw up on your screen. Draw on one, see it in both.

How does JGroups work? Why do you need it?

Topics covered include:

  • what is JGroups? library for reliable multicasting ...
  • main features: fragmentation, retransmission, flow control, reordering, group membership (notifications)
  • LAN/WAN based: multicast or TCP for transport

Infinispan as a local cache and JMX

presented by Sanne
10 minutes

Adding Infinispan to the demo

Use Case: Take advantage of the features of Infinispan

  • Uncomment the Infinispan dependencies in pom.xml
  • Copy in Resources.java and TicketAllocationCache.java and explain what they are doing; you will find them in LAB_HOME/lab1/src/samples/java
  • Explain about configuring caches programmatically with qualifier
  • Copy SimpleTicketService to InfinispanTicketService
  • Make SimpleTicketService an alternative

with

to inject the Infinispan cache. Change the allocateTicket method to:

and change the getAllocatedTickets() method to

and change the getTicketAllocation(String id) method to:

Implement getNodeId() properly:

Implement getOwners() properly:

Show Infinispan in use with basic monitoring

Use Case: Can see how our cache is performing

  • Enable JMX - add .jmxStatistics().enable() to the fluent configuration in Resources.
  • Redeploy, and use the app
  • We can see the cache starting in the console
  • Run jconsole or jvisualvm, and select the "jboss-modules" process
  • Open up the Infinispan statistics (via MBeans tab in jvisualvm - you might need to install the MBeans plugin first)
  • Allocate a ticket, show the stores change

Checkpoint 2

Expiration & Eviction

presented by Mircea
10 minutes

Interlude - What is expiration? What is eviction?

Topics covered include:

  • API
  • Configuration
  • Use cases
  • Available eviction mechanisms

Demo

  • Use Case: Have ticket allocations freed up after a period of time*
  • Add expiration to allocateTicket(), so you end up with
  • Run the demo, and you can see that entries disappear after 10s

Checkpoint 3

6. Listeners

presented by Mircea
10 minutes

Use case: Prevent known ticket touts from using the system

  • First, copy in the AbuseListener in
  • Now, we need to register it

Add

to the InfinispanTicketService.

  • this code simply creates a new abuse listener (injected by CDI with a logger!) and registers it with Infinispan. It will do it automatically when the InfinispanTicketService is created

Increase expiration to 3 minutes, otherwise the demo will get tiresome!

Checkpoint 4

Interlude. What can you listen to in Infinispan?

Transactions with Infinispan

presented by Mircea
15 minutes

Transactions in action

Use Case: When ticket is booked, need to atomically take payment and book ticket, and rollback if any errors

  • The webapp collects all the data from the user to process the booking, and then sends the booking to the backend using JMS.
  • JBoss comes with a "test" queue, we'll abuse that so we don't have to configure messaging (not what we are here to talk about).
  • Go to the pom.xml and uncomment JMS dependency
  • Copy the PaymentProcessor into .services
  • Inject JMS into InfinispanTicketService
  • Implement the bookTicket method

This code is in bookTicket.txt in the samples

  • Run the example, show it in action.

Checkpoint 5a

Use case: Introduce XA transactions

  • Add to the configuration (Resources.configureCache):
  • Replace the injection of the Connection Factory with

finally, upgrade the bookTicket method:

  • Interlude - Transactions deep dive

Topics discussed include

  • Transaction types
  • Locking
  • Deadlock detection

Break

15 minutes

Distribution

presented by Sanne
15 minutes

Use case: we have so many tickets being allocated we've run out of heap on one machine, so add some more!

  • During the break we added support for distribution. Take you through the changes now
  • Enable distribution mode in Resources
  • Make JGroups use the loopback interface to avoid network problems! Add
  • Add jgroups.xml from src/sample to src/main/resources (directory needs creating)
  • Explain that this JGroups file is exactly as normal for UDP, except that the jgroups.bind_addr is set to the loopback interface

Interlude - JBoss AS 7

Topics discussed include:

  • Introduce AS7
  • Cover domain mode vs standalone
  • Domain mode a great way to stand up a cluster of nodes!
  • Explain management options (CLI, web, maven plugin, XML, filesystem)
  • Talk about Infinispan as managed service in AS7 vs embedded - we could have used either, but to get started quickly it's easy to embed!
  • Show 5 servers configured in $JBOSS_HOME/domain/configuration/host.xml - explain about port bindings. If you are following along, add only these servers
$JBOSS_HOME/domain/configuration/host.xml
  • Now, define the server groups. We'll also add server group for the REST interface which we'll see in a minute:
$JBOSS_HOME/domain/configuration/domain.xml
  • Note that nodes don't get much memory by default, we need to increase it

Show the cache running in distributed mode

  • Start up 4 JBoss AS 7 nodes with domain.sh. Why? See the JBoss 7 Getting Started guide
  • Build latest using mvn package and in another terminal change into the project and bring up JBoss AS CLI $JBOSS_HOME/bin/jboss-admin.sh --connect
  • Deploy app from console using deploy target/lab1.war --server-groups=main-server-group
  • App now deployed to each node
  • bring up all 4 nodes in a web browser (port offset 100)
  • show each node starting in the console log
  • the contents list now just shows whats locally in the cache
  • explain that as each node comes up, the entries are rehashed to distribute the contents, so we see entries disappear from a node
  • show that we can still find any entry, it's just not local any more
  • show that we can put an entry, and then find it in one of the caches in Infinispan (10 mins)

Interlude - What modes can Infinispan run in? When would you want to use them?

Topics discussed include:

  • What are the different modes?
  • When would you use the modes?
  • How does distribution work?
  • Explain CH, benefits and problems
  • Talk about vnodes to even distribution

L1 cache

presented by Sanne
5 minutes

  • Explain benefits (TODO)
  • Start up 4 JBoss AS 7 nodes with $JBOSS_HOME/bin/domain.sh
  • Build latest using mvn package and in another terminal change into the project and bring up JBoss AS CLI jboss-admin.sh --connect
  • Deploy app from console using deploy target/lab1.war --server-groups=main-server-group
  • App now deployed to each node
  • bring up all 4 nodes in a web browser (port offset 100)
  • Just like before, except that nodes 1 & 2 are still showing all entries locally (they kept them in their cache)
  • Find a node that doesn't have all entries, and query for an entry that isn't on that node. Then hit refresh. Show that this time it's now local (L1 cache)
  • Show the same for putting a new entry - keep adding until you get one that isn't owned by the current node - show that it is in the local node still.

Checkpoint 6

Client Server Modes

presented by Mircea
10 minutes

  • We have a server group set up in JBoss AS 7 that contains a single server. We'll use this for the rest server - no need to have one on each node!
  • Enter jboss admin console and connect to the local server: $JBOSS_HOME/bin/jboss-admin.sh. The type "connect".
  • Deploy infinispan-server-rest.war from the lab to JBoss AS 7 using the JBoss AS 7 CLI deploy <path/to/>infinispan-server-rest.war --server-groups=rest-server-group
  • REST server actually joins the Infinispan cluster as a node, and it needs to know which caches to use, so we added this to the war, and we also needed to add the domain class* * * Visit a couple of the UIs to seed data and start caches
  • check that connection REST is correctly deployed: http://localhost:8080/infinispan-server-rest/
  • Use a rest client to GET http://localhost:9080/infinispan-server-rest/rest/ticketAllocationCache/manik-Best%20of%20Abba

Interlude - what client-server modes does Infinispan offer?

Topics discussed include:

  • various server endpoints
  • benefits of Hot Rod

CacheStores

presented by Mircea
10 minutes

Use case: Persist your data to disk in case of node restart

  • paste the JDBC cache config method from src/sample/java/jdbc.txt
  • Walk through the JDBC cache store set up code
  • Add this to the configuration:
  • Run mvn clean package
  • Deploy the app using deploy lab1/target/lab1.war --server-groups=main-server-group
  • Explain we are using the JBoss AS 7 built in example data source for H2 - configuration found in domain.xml.
  • Vist a node or two to setup some caches and data
  • Explain we are using the h2console.war. Needed a couple of changes to make it run, documentation coming soon
  • Deploy it using deploy h2console.war --server-groups=main-server-group - each node in the cluster owns some data, each h2 database will back that up
  • Visit http://localhost:9080/h2console/
  • Log in sa with password sa
  • execute select * from persistentstore_ticketallocationcache

Checkpoint 7

Interlude - What Cache Stores are available? In what scenarios can they be used?

Topics discussed include:

  • Modes of cache store usage
  • CacheStores available as built in

Bonus topics

Querying Infinispan

presented by Sanne
8 minutes

Topics discussed include:

  • TODO

Hibernate OGM

presented by Sanne
2 minutes

Topics discussed include:

  • TODO

Map-Reduce

presented by Pete
5 minutes

Topics discussed include:

  • TODO

Benchmarking data girds - Radargun

Introducing project Radargun

presented by Mircea
5 minutes

Conclusion

presented by Pete
10 minutes

Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.