GithubHelp home page GithubHelp logo

javamagreact's Introduction

JavaMagAkka

This repository contains example code for an article in the German Java Magazin about different reactive programming models.

The article explores the impact of reactive programming on a simple use case: reading a file from the file system. It shows different implementations for this task (blocking and non-blocking) using plain Java and the reactive frameworks Vert.x and Akka.

A multi-module Gradle build is provided to build the whole project. The examples are logically grouped into sub projects.

Plain Java

The plainJava module contains example code that only uses Java and has no external dependencies. Main classes are provided which can be invoked directly. The classes expect a path to a file as command line argument. They read this file and dump the content to the console. The following examples are available:

  • BlockingFileReader: A simple blocking implementation to read a file.
  • AsyncFileReaderMain: Reads a file asynchronously using the Java nio package.

Vert.x

The vertx module contains examples based on the Vert.x framework. Running these classes is a bit special because they are verticles that have to run under the control of Vert.x. Therefore, the project provides the VertxStartup class which starts the framework and deploys all demo verticles. In addition, it adds the Vert.x Shell, so that interaction from the outside is possible. The verticles register themselves as listeners on the event bus and react on string messages pointing to the files to be read or processed. Via the shell corresponding messages can be sent, for instance:

%bus-send react.file.read /path/to/my/file.txt

The table below lists the demo verticles and the event bus addresses they listen on:

Verticle class Event bus address Purpose
ReadFileVerticle react.file.read Demonstrates a simple asynchronous file read operation.
ProcessFileVerticleCB react.file.process Processes a file in multiple steps using nested callbacks. Shows the downsides of the callback approach.
ProcessFileVerticleFuture react.file.process.future Does the same processing as ProcessFileVerticleCB, but uses futures to combine the single steps.

Akka

The single example in this module, is written in Scala and demonstrates file processing using the streaming API offered by Akka. It is an application which can be called directly. It expects two command line arguments for the input file and the output file.

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.