Zaiku

@Zaiku

Build Versatile and Intelligent Distributed Systems with Grid Ops — Part 2

What Is Grid Ops?

In post [1] we introduced Grid Ops as an open source Java toolkit for creating advanced distributed systems. We also wrote that Grid Ops consists of a set of core tools for the implementation of distributed systems in general, and a set of commonly used distributed systems infrastructure services.

Our mission is to help developers get distributed systems up and running with just few lines of code. Although we started with a Java implementation, in future we hope to be able to make implementations in other languages such as C# and D. The main components of Grid Ops are:

  • TcpServer
  • TcpSocketsPort
  • Host
  • NodeContainer

These four components form the basic foundations of Grid Ops as illustrated below:

1. The TcpServer is one of the ways messages can enter a Host. The Host reads messages via a TcpSocketsPort and passes them on to the NodeContainer.

2. The TcpSocketsPort manages one or more TCP sockets internally. These TCP sockets can come from a TcpServer or be opened by the application as client connections (outgoing connections). Thus the TcpSocketsPort can be used as an interface to both incoming and outgoing connections, meaning as both an interface to a server and a client.

3. The NodeContainer routes the messages it receives to the correct node internally. You can plug in node reactors, protocol reactors and message reactors into the NodeContainer. That is how developers can implement multi-tenancy and multi-protocol applications.

In nutshell, the NodeContainer class in Grid Ops functions can route incoming messages to the components that are to process them. The NodeContainer will look at the node id in the incoming message and forward the message to the corresponding NodeReactor. The NodeReactor will look at the semantic protocol id + version and forward the message to the corresponding protocol reactor. The protocol reactor will look at the message type of the incoming message and forward the message to the corresponding message reactor.

Messages are received from the outside, typically via a TcpServer and a TcpSocketsPort, and then given to the NodeContainer, which internally routes the messages to the correct MessageReactor (via the NodeReactor and ProtocolReactor instances).

What About Threads?

Well a TcpServer has its own thread which accepts incoming connections. This thread does not read anything from the incoming connections.

The Host also has its own thread which pulls the messages out of the TcpSocketsPort and passes them on to the NodeContainer. There is a NodeContainer's react() method that is called by the same thread which runs the Host loop. That way the reading and processing of messages happens by the same, single thread. Thus developers can code their node reactors, protocol reactors and message reactors assuming a single-threaded concurrency model.

Grid Ops Stack Overview

This is it for now, we will continue with more details in future posts. If you would like to play with Grid Ops please visit our Github page and for code please check here. We are gearing up for the launch of some of the services, if you would like to receive beta invite pleaseSubscribe here.

Hacker Noon is how hackers start their afternoons. We’re a part of the @AMI family. We are now accepting submissions and happy to discuss advertising & sponsorship opportunities.
If you enjoyed this story, we recommend reading our latest tech stories and trending tech stories. Until next time, don’t take the realities of the world for granted!

More by Zaiku

Topics of interest

More Related Stories