Code Monkey home page Code Monkey logo

infinispan-embedded-tutorial's Introduction

Infinispan Embedded Tutorial: Weather App

Overview

This is a tutorial which explains how to use Infinispan embedded in your own application. The application will retrieve the current weather conditions for some cities and store them in a cache, for quicker retrieval. It will also show how to configure the cache for expiration, so that entries get removed as they age. It will then demonstrate how to cluster multiple nodes together and reacting to events in the cluster. Finally, a computation of average temperatures per country will show the power of the map/reduce functionality.

Each tagged commit is a separate lesson teaching a single aspect of Infinispan.

The tutorial instructions are at http://infinispan.org/tutorials/embedded/

N.B. The tutorial connects to OpenWeatherMap (http://openweathermap.org) to retrieve current weather data. The service requires obtaining a free API key. Before launching the application, ensure you've set the OWMAPIKEY environment variable to your API key. If you don't want to register for the service, if you don't have an Internet connection or you are having trouble connecting to the service, just don't set the environment variable, and it will use the RandomWeatherService.

Prerequisites

Git

  • A good place to learn about setting up git is here
  • Git home (download, documentation)

JDK

  • Get a JDK. You will need version 1.8 or higher

Maven

  • Get Maven. You will need version 3.2 or higher

Commits / Tutorial Outline

You can check out any point of the tutorial using git checkout step-?

To see the changes between any two lessons use the git diff command. git diff step-?..step-?

step-0/setup

  • The initial implementation of the Weather application

step-1/cache-manager

  • Adding Infinispan to the project and initializing a cache manager

step-2/cache-put-get

  • Add caching to the weather service

step-3/expiration

  • Store the entries in the cache with an expiration time

step-4/cachemanager-configuration

  • Configure the features of the default cache

step-5/clustering

  • Add a transport to the CacheManager so that it supports clustering

step-6/cachemanager-listener

  • Use CacheManager events to detect changes in the cluster

step-7/cache-listener

  • Detect changes to the cache with a clustered listener

step-8/grouping

  • Group related entries on the same nodes for efficiency

step-9/externalizer

  • Implement a custom externalizer for our value class

step-10/streams

  • Use Distributed Streams to compute temperature averages per country

step-11/declarative-configuration

  • Use the XML configuration instead of the programmatic API

Building and running the tutorial

  • Run mvn clean package to rebuild the application
  • Run mvn exec:exec to execute the application. In case you're running a clustered step, run this from multiple terminals, where each instance will represent a node
  • Run mvn clean package docker:build to build docker image, and then run docker run infinispan-embedded-tutorial/infinispan-embedded-tutorial in 2 different terminals to simulate multiple nodes of distributed cache

Application Directory Layout

docker/             -->
src/                -->
  main/             -->
    java/           -->
    resources/      -->

Contact

For more information on Infinispan please check out http://infinispan.org/

infinispan-embedded-tutorial's People

Contributors

ligangty avatar tristantarrant avatar wburns avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

infinispan-embedded-tutorial's Issues

After enabling clustering cache initialization is too slow

I'm using Ubuntu Linux 16.04.

After steps described in step-5 I've got following warnings in my console:

May 30, 2016 2:03:29 PM org.jgroups.protocols.UDP setBufferSize
WARNING: JGRP000015: the send buffer of socket MulticastSocket was set to 1MB, but the OS only allocated 212.99KB. This might lead to performance problems. Please set your max send buffer in the OS correctly (e.g. net.core.wmem_max on Linux)
May 30, 2016 2:03:29 PM org.jgroups.protocols.UDP setBufferSize
WARNING: JGRP000015: the receive buffer of socket MulticastSocket was set to 20MB, but the OS only allocated 212.99KB. This might lead to performance problems. Please set your max receive buffer in the OS correctly (e.g. net.core.rmem_max on Linux)
May 30, 2016 2:03:29 PM org.jgroups.protocols.UDP setBufferSize
WARNING: JGRP000015: the send buffer of socket MulticastSocket was set to 1MB, but the OS only allocated 212.99KB. This might lead to performance problems. Please set your max send buffer in the OS correctly (e.g. net.core.wmem_max on Linux)
May 30, 2016 2:03:29 PM org.jgroups.protocols.UDP setBufferSize
WARNING: JGRP000015: the receive buffer of socket MulticastSocket was set to 25MB, but the OS only allocated 212.99KB. This might lead to performance problems. Please set your max receive buffer in the OS correctly (e.g. net.core.rmem_max on Linux)

And cache initialization takes much time (around 10 seconds on average).
When running two instances cache lookup is also very slow (about 3 seconds vs 1s on not cached version).

Tags are not present in github repository

There are no tags in this repository so examples from tutorial which refer to tags don't work.

Git don't push tags on remote by default.

In order to fix this you can do the following

$ git push --tags

To check whether it is fixed you can check that
$ git log --tags --decorate=full
shows tags in newly cloned repository

no steps?

Does this tutorial still work? There don't appear to be any tags corresponding to the steps.

$ git checkout step-0
error: pathspec 'step-0' did not match any file(s) known to git.

If I try to build and run the app as is I don't get any output just a rolling set of log messages....

Step 5: wrong explanation or wrong configuration.

Hi there.

I found in the tutorial some confusing text. It says:

Make sure you start the second instance soon after the first one has started, because we have not told either instance to "wait" for the other.

But when I tried it to run, first instance is waiting for new node by writing to log:

---- Waiting for cluster to form ----
---- View changed: [amelnikov-mac-27400, amelnikov-mac-38847] ----
---- Fetching weather information ----

When second node is up the first continued to work normally and quits.

But the second node will not do anything and be waiting for another node:

---- Waiting for cluster to form ----
-- Entry for Como, Italy modified by another node in the cluster
-- Entry for Basel, Switzerland modified by another node in the cluster
-- Entry for Bern, Switzerland modified by another node in the cluster
-- Entry for London, UK modified by another node in the cluster
-- Entry for Newcastle, UK modified by another node in the cluster
-- Entry for Bucarest, Romania modified by another node in the cluster
-- Entry for Cluj-Napoca, Romania modified by another node in the cluster
-- Entry for Ottawa, Canada modified by another node in the cluster
-- Entry for Toronto, Canada modified by another node in the cluster
-- Entry for Lisbon, Portugal modified by another node in the cluster
-- Entry for Porto, Portugal modified by another node in the cluster
-- Entry for Raleigh, USA modified by another node in the cluster
-- Entry for Washington, USA modified by another node in the cluster
-- Entry for Rome, Italy modified by another node in the cluster
-- Entry for Como, Italy modified by another node in the cluster
-- Entry for Basel, Switzerland modified by another node in the cluster
-- Entry for Bern, Switzerland modified by another node in the cluster
-- Entry for London, UK modified by another node in the cluster
-- Entry for Newcastle, UK modified by another node in the cluster
-- Entry for Bucarest, Romania modified by another node in the cluster
-- Entry for Cluj-Napoca, Romania modified by another node in the cluster
-- Entry for Ottawa, Canada modified by another node in the cluster
-- Entry for Toronto, Canada modified by another node in the cluster
-- Entry for Lisbon, Portugal modified by another node in the cluster
-- Entry for Porto, Portugal modified by another node in the cluster
-- Entry for Raleigh, USA modified by another node in the cluster
-- Entry for Washington, USA modified by another node in the cluster
---- View changed: [amelnikov-mac-38847] ----

The second node will continue work only if I start again application as third node. Now the second will finish successfully. But the third will be waiting for another.

I tried version of infinispan-embedded which is specified in pom.xml (8.2.1.Final) and the previous 8.1.4.Final.

Update: Step 6 also have the same problem.

NullPointerException when fetching Newcastle data.

When executing the demo code, a NullPointerException is thrown when fetching data from "Newcastle, UK". The output looks like:

---- Fetching weather information ----
Rome, Italy - Temperature: 6.4° C, Conditions: overcast clouds
Como, Italy - Temperature: 4.6° C, Conditions: few clouds
Basel, Switzerland - Temperature: 1.5° C, Conditions: scattered clouds
Bern, Switzerland - Temperature: 1.2° C, Conditions: broken clouds
London, UK - Temperature: 5.4° C, Conditions: broken clouds
Exception in thread "main" java.lang.NullPointerException

Removing Newcastle from the locations array solves the issue, but I thought you might want to change the array or investigate further.

At Step-5,Cannot marshall 'class org.infinispan.tutorial.embedded.LocationWeather'

At Step-5, after 2nd terminal is started, the WeatherApp raised exceptions as follows.

WARN: ISPN000559: Cannot marshall 'class org.infinispan.tutorial.embedded.LocationWeather'
java.lang.IllegalArgumentException: No marshaller registered for Java type org.infinispan.tutorial.embedded.LocationWeather
at org.infinispan.protostream.impl.SerializationContextImpl.getMarshallerDelegate(SerializationContextImpl.java:279)
at org.infinispan.protostream.WrappedMessage.writeMessage(WrappedMessage.java:240)
at org.infinispan.protostream.ProtobufUtil.toWrappedStream(ProtobufUtil.java:196)
...

I guess "GlobalConfigurationBuilder" needs more configuration.

Fails in step 7

The code is not proceeding with the cluster creation

Terminal A content

INFO: ISPN000079: Channel WeatherApp local address is BLRLRND0447-49832, physical addresses are [x.x.x.x:60206]

---- Waiting for cluster to form ----

Oct 25, 2021 6:21:36 AM org.jgroups.util.SuppressLog log

WARNING: JGRP000011: BLRLRND0447-49832: dropped message 1 from non-member BLRLRND0447-32791 (view=[BLRLRND0447-49832|0] (1) [BLRLRND0447-49832])

Terminal B content

Oct 25, 2021 6:21:36 AM org.infinispan.remoting.transport.jgroups.JGroupsTransport receiveClusterView

INFO: ISPN000094: Received new cluster view for channel WeatherApp: [BLRLRND0447-32791|0] (1) [BLRLRND0447-32791]

Oct 25, 2021 6:21:36 AM org.infinispan.remoting.transport.jgroups.JGroupsTransport startJGroupsChannelIfNeeded

INFO: ISPN000079: Channel WeatherApp local address is BLRLRND0447-32791, physical addresses are [x.x.x.x:61024]

---- Waiting for cluster to form ----

NullPointer Exception when fetching Newcastle

Fix: Newcastle UK -> Newcastle GB

diff --git a/src/main/java/org/infinispan/tutorial/embedded/WeatherApp.java b/src/main/java/org/infinispan/tutorial/embedded/WeatherApp.java
index cc029b8..02973ce 100644
--- a/src/main/java/org/infinispan/tutorial/embedded/WeatherApp.java
+++ b/src/main/java/org/infinispan/tutorial/embedded/WeatherApp.java
@@ -6,7 +6,7 @@ import org.infinispan.manager.EmbeddedCacheManager;
 public class WeatherApp {
 
    static final String[] locations = { "Rome, Italy", "Como, Italy", "Basel, Switzerland", "Bern, Switzerland",
-         "London, UK", "Newcastle, UK", "Bucarest, Romania", "Cluj-Napoca, Romania", "Ottawa, Canada",
+         "London, UK", "Newcastle, GB", "Bucarest, Romania", "Cluj-Napoca, Romania", "Ottawa, Canada",
          "Toronto, Canada", "Lisbon, Portugal", "Porto, Portugal", "Raleigh, USA", "Washington, USA" };
    private final EmbeddedCacheManager cacheManager;
    private final WeatherService weatherService;

Exception in threadException in thread

org.infinispan.manager.EmbeddedCacheManagerStartupException: org.infinispan.commons.CacheConfigurationException: ISPN000085: Error while trying to create a channel using the specified configuration file: default-configs/default-jgroups-udp.xml

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.