Pages

Showing posts with label architecture. Show all posts
Showing posts with label architecture. Show all posts

Monday, October 24, 2016

Robo4j introduction to the reactive "real-time" micro-services based IoT system development

  
Robo4j testing system : camera unit, ultra-sonic, gyro, color and touch sensors. Whole system contains also one  Raspberry Pi, Lego Brick and CuBox i4Pro (4-core CPU) with 500GB hard-drive as re-usable data-storage. Whole system is powered by 2x2500mAh and one 25000mAh unit.
  What is going to be discussed in this article is the high level perspective of the upcoming robo4j.io framework and the Internet Of Things (IoT) system design, so let’s move forward.
  Over the last few years has been one of the most emerging topic micro-services (and still is) followed by reactive manifesto, which explains how to design non-blocking highly responsive, resilient, elastic and message driven parts of the application. From my perspective, all those articles have been focused on the web applications of middle and big sizes. Most of the articles have been describing the best practices about how to split the monolithic systems or how to employ the news trends in micro-services and non-blocking design patterns. 
  Only few of them have been touching other emerging technologies around Internet of Things (IoT) in the way I’ve been searching for. 
  Over the years, reading many of them, I got a strong feeling that the way how we intend to develop IoT systems is, that we take already developed robust technologies and we make them smaller.  These days we have on the market good examples of the successes, we do use Spring-boot, Netty, Vert.x or others.  Those frameworks allow us basically to connect the developed system with different types of databases, analysed and react on events or data, obtained from the data storages. 
The question is still there,  is this really enough ? 
Is such kind of abstraction good enough that it could allows us to develop robust IoT systems ? 
  The IoT systems that can react on incoming events, sorts them properly and in special cases forwards them to the proper system parts, which could process and execute such events ? 
  I don’t think so or I’ve not found anything like this on the market.

  We can go further in questioning ourselves about the IoT possibilities, which can quite soon turn into the Artificial Intelligence discussion. In my opinion, the AI question is not relevant for the article, because even most of the currently available IoT systems can’t still exhibit its intelligence in the manner of intelligent (independent) decisions. This question is reserved for another IoT focused article. 
  Let’s go back to the main topic: advanced Internet of Things system development and design. Before we start here a small review of the definition taken from Wikipedia: 
   “The Internet of Things (IoT) is the internetworking of physical devices, vehicles, buildings and other items—embedded with electronics, software, sensors, actuators, and network connectivity that enable these objects to collect and exchange data”. In other words IoT are objects that are connected to the internet or other networks and those objects are allowed to receive and process data. 

   The definition looks pretty cool and good so far, until you try to use some of those connected “smart” objects together. Now is the IoT system the collection of the independent IoT units and suddenly nothing works as expected due to connection instability, communicaiton protocols message ordering etc. 
  Although such a system has been assembled from cutting edge parts, altogether they simply don’t work, due to previously touched issues or other ones we are not even aware of. The whole development may turn into the really FUZZY mode.  
Such a style of development I normally call try, push, deploy development (TPDD) but this style may not fully satisfy the expectations or needs, it simply doesn’t work in a long term perspective. PS: there is still a chance that I may be wrong.
The described situation can become really frustrating and stressful, especially when there are not so many possibilities on the market. You may use ROS (Robot Operating System) but … let’s go back.

  The lack of proper tools on the market was main motivation to develop robo4j.io framework which satisfies the following needs: 
  1. The robo4j.io is capable to synchronise incoming asynchronous events/messages under the dynamically changing conditions at “real-time” . 
  2. The robo4j.io framework should be able to allow and enforce rapid micro-sevices based system development.
  3. The robo4j.io should be a light framework that is capable to run on any hardware supported by JVM. It means on any Java Powered device and it provides full performance
  4. The robo4j.io should be independent, not hardware specific, it must be flexible to extend
  5. The robo4j.io should have a control over all running units inside the robo4j.io eco-system 
  6. The robo4.io should enforce communication with external systems
  7. The robo4j.io should be easy to use
   All those seven mentioned points are really challenging. Any of them is trivial as it may seem.  I’ve taken this challenge and I’ve developed such a tool that satisfies all of them. I’ve developed already the mentioned robo4j.io framework.
  The robo4j.io framework allows to connect and control any device that is accessible over the specific type of network (Ethernet, WiFi, Bluetooth etc.) or wire. And moreover,  robo4j.io enforce the usage of any of technology running on JVM with its natural language (Scala, Groovy etc.).
   
  Now it’s time to take a look at the basic framework architecture from a high level perspective which is the main intent of this article. The image below shows the high perspective reaction between the different parts inside the robo4j eco-system. It’s important to see the differences between the inputs to the system.
Robo4j framework high-perspective architecture
  Such input could be provided by Sensors, Motors (Engines) or RoboSockets types. The incoming messages is then processed by the system itself and serialised in the manner that the result can be executed on the connected hardware.
Inside the message process stage the system may use different types of datastorages that are available to a specific RoboUnit. This means, that each RoboUnit may have or not it’s specific data resource or each RoboUnit may share them with another one in reactive, non-blocking manner. 
  The Robo4j Message Bus is not dependent on the order, how any specific message is processed. The bus consumes the messages in order of their arrival. The bus may dynamically change the conditions in real time. The pre-results are then moved into the MessageReactors parts. Those parts have again connections to the datastorages, where their results can be stored. The final result can be executed on the real hardware or can involve the whole system state inside the predefined cloud. 
  Finally we are at the end of the motivaiton article about robo4j.io framework. The whole text should motivate you to use it, because the Internet of Things is the future of IT. 
The future of IoT includes the communicaiton security, different kinds of messages processing and reaction on them. The Robo4j framework is supposed to be part of this future.
Stay tuned.
Robo4j IoT system (robot) is discovering a park



   

Wednesday, August 20, 2014

HowTo:: Spring 4 Scala MVC without Web.XML - Tiles3 : static resources and front-end templating

Img.1.:: project structure - Tiles3 with localised messages and simple template 
This blogpost is fully focused on simple spring 4 scala project Tiles configuration and how to give access to the localised messages (see. Img.1.). 
In the WebConfig scala class is also configured:
1.  messageSource @Bean :
@Bean(name = Array("messageSource"))
def getMessageSource: MessageSource = {
  val msgSrc:ReloadableResourceBundleMessageSource = new ReloadableResourceBundleMessageSource()
  msgSrc.setBasename("classpath:/messages/message")
  msgSrc
}
Such bean give us access to the messages place in the "resource" project folder.
2.  default displayed locale by the "localeResolver" bean:
@Bean(name = Array("localeResolver"))
def getLocaleResolver: LocaleResolver = {
  val cookieLocaleResolver: CookieLocaleResolver = new CookieLocaleResolver()
  cookieLocaleResolver.setDefaultLocale(new Locale("en"))
  cookieLocaleResolver
}
3. access to the static project resources as is mentioned in to one of previous posts 

Let's start on the front-end dev. with the default tiles.xml file in the ../pages directory

  
 
 
  
  
 
 
  
  
    
    
  

  The example project has two page to display based on "standardLayout" which consists from header and footer
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>


  
     <fmt:message>
 <tiles:insertAttribute name="title" />
     </fmt:message>
     <link rel="stylesheet" href="<c:url value="/app/css/style.css" />" >
  


Take a look into github example project
After having also *.jsp pages defined we can run our Tomcat7 container
container:start
and open the web browser and call the applicaiton: 
1. http://localhost:9090/?lang=de
2. http://localhost:9090/test/web?lang=de
3. http://localhost:9090/test/web?lang=en
4. http://localhost:9090/test/web

Enjoy Tiles 3 and take a look on my github example project to get more information around

Tuesday, August 19, 2014

Spring 4 Scala MVC without Web.XML - Tiles3 : WebConfig class configuration with Localisation


Img.1.:: Spring 4 Scala project structure with Tiles 3 and l18n(l10n) 
  Enabling Apache Tiles3 needs little more changes in the project (Img.1.) configuration. The WebConfig scala class needs to extended by WebMvcConfigurerAdapter (already touched in the previous post: Scala Spring 4 MVC without Web.XML configuration with static resources handling). 
  We also define the set of annotations we do need to be scanned over the project package. The reason of such definition is to show possibilities of Scala configuration of the Spring Framework itself.
@Configuration
@ComponentScan(basePackages = Array("miko.scala.helloexample"), useDefaultFilters = false, includeFilters = Array(
  new ComponentScan.Filter(`type` = FilterType.ANNOTATION,
    value = Array(classOf[Controller], classOf[Service]))))
@EnableWebMvc
class WebConfig extends WebMvcConfigurerAdapter{
...
  In WebConfig we do replace @Bean setupViewResolver(), which implements the ViewResolver interface that allows directly resolved symbolic view names,  by getTilesConfigurer @Bean, which provide TilesConfigurer
  The TilesConfigurer class provide the tempting mechanism for web project (application) using JSP and other front-end engines. 
@Bean
def getTilesConfigurer: TilesConfigurer = {
  val configurer:TilesConfigurer = new TilesConfigurer()
  configurer.setCheckRefresh(true)
  configurer.setDefinitions({"/WEB-INF/pages/tiles.xml"})
  configurer
}
 And additionally we have  to define ViewResolver for Tiles by getTilesViewResolver @Bean definition
@Bean
def getTilesViewResolver: ViewResolver = {
  val resolver:TilesViewResolver = new TilesViewResolver()
  resolver.setContentType("text/html")
  resolver
}
The full configuration needs to define and override also couple of other Beans connected with our localisation (l10n/l18n) intent. The final WebConfig Scala class will look in following manner. 
@Configuration
@ComponentScan(basePackages = Array("miko.scala.helloexample"), useDefaultFilters = false, includeFilters = Array(
  new ComponentScan.Filter(`type` = FilterType.ANNOTATION,
    value = Array(classOf[Controller], classOf[Service]))))
@EnableWebMvc
class WebConfig extends WebMvcConfigurerAdapter{

  private val logger = LoggerFactory.getLogger(getClass)

  override def configureDefaultServletHandling(configurer: DefaultServletHandlerConfigurer) = {
    configurer.enable()
  }

  override def addViewControllers(registry: ViewControllerRegistry): Unit ={
    registry.addViewController("/")
  }

  @Bean
  def getTilesViewResolver: ViewResolver = {
    val resolver:TilesViewResolver = new TilesViewResolver()
    resolver.setContentType("text/html")
    resolver
  }

  @Bean
  def getTilesConfigurer: TilesConfigurer = {
    val configurer:TilesConfigurer = new TilesConfigurer()
    configurer.setCheckRefresh(true)
    configurer.setDefinitions({"/WEB-INF/pages/tiles.xml"})
    configurer
  }

  override def addInterceptors(registry:InterceptorRegistry) = {
    val localeChangeInterceptor = new LocaleChangeInterceptor()
    localeChangeInterceptor.setParamName("lang")
    registry.addInterceptor(localeChangeInterceptor)
  }

  /**
   * equivalents for  tags
   * @param registry
   */
  override def addResourceHandlers(registry: ResourceHandlerRegistry) = {
    logger.debug("Resources HANDLER")
    registry.addResourceHandler("/app/**").addResourceLocations("/app/").setCachePeriod(31550522)
    registry.addResourceHandler("/WEB-INF/layouts/**").addResourceLocations("/WEB-INF/layouts/").setCachePeriod(31550522);
    registry.addResourceHandler("/WEB-INF/pages/template/**").addResourceLocations("/WEB-INF/pages/template/").setCachePeriod(31550522);
  }

  @Bean(name = Array("localeResolver"))
  def getLocaleResolver: LocaleResolver = {
    val cookieLocaleResolver: CookieLocaleResolver = new CookieLocaleResolver()
    cookieLocaleResolver.setDefaultLocale(new Locale("en"))
    cookieLocaleResolver
  }

  override def configureContentNegotiation(configurer: ContentNegotiationConfigurer) = {
    configurer.favorPathExtension(true).ignoreAcceptHeader(true)
        .useJaf(false).defaultContentType(MediaType.TEXT_HTML)
        .mediaType("html", MediaType.TEXT_HTML)
        .mediaType("xml", MediaType.APPLICATION_XML)
        .mediaType("json", MediaType.APPLICATION_JSON)
  }

  @Bean(name = Array("messageSource"))
  def getMessageSource: MessageSource = {
    val msgSrc:ReloadableResourceBundleMessageSource = new ReloadableResourceBundleMessageSource()
    msgSrc.setBasename("classpath:/messages/message")
    msgSrc
  }
}
  After having enabled Tiles with l10n/l18n on the back-end side we can move to front-end and tell Tiles which kind of template it should use to display pages correctly to the user (Img.1. ~ project structure). Of course, with CSS or possible JavaScript libraries. 
But I'll do this in next blog post. 
  Now Enjoy configuring your WebConfig scala class. 

project: miko-spring-scala on github

Spring 4 Scala MVC without Web.XML - Tiles3 with SBT Tomcat7 configuration

  In the one of previously published blogposts I've written about Spring Container running on Jetty (Scala Spring 4 MVC without Web.XML configuration with static resources,  update: Scala Spring 4 MVC without Web.XML - logging with Log4j and SLF4j)

  The next example Spring 4 Scala MVC without Web.XML with Apache Tiles3 runs on Tomcat7 using Java Servlet 3.x but before we need to configure SBT to provide us such functionality: 

1. configure project build.sbt file in following example way
libraryDependencies ++= Seq(
  "org.springframework" % "spring-webmvc" % "4.0.6.RELEASE",
  "org.springframework" % "spring-context" % "4.0.6.RELEASE",
  "org.springframework" % "spring-context-support" % "4.0.6.RELEASE",
  "org.apache.tiles" % "tiles-jsp" % "3.0.4",
  "javax.servlet" % "javax.servlet-api" % "3.0.1" % "provided",
  "javax.servlet" % "jstl" % "1.2" % "compile",
  "org.slf4j" % "jcl-over-slf4j" % "1.7.5" ,
  "org.slf4j" % "slf4j-api" % "1.7.5" ,
  "org.slf4j" % "slf4j-log4j12" % "1.7.5",
  "log4j" % "log4j" % "1.2.17" excludeAll(
        ExclusionRule(organization = "com.sun.jdmk"),
        ExclusionRule(organization = "com.sun.jmx"),
        ExclusionRule(organization = "javax.jms")
      ),
  "org.apache.tomcat.embed"% "tomcat-embed-core"% "7.0.40"% "container",
  "org.apache.tomcat.embed"% "tomcat-embed-logging-juli"% "7.0.40"% "container",
  "org.apache.tomcat.embed"% "tomcat-embed-jasper"% "7.0.40"% "container"
)

tomcat(port = 9090)
important part is about tomcat related libraries which allow us:

2. by having running sbt such configuration makes possible to use following command 
container:start
stopping server is by exchanging word after :

Enjoy SBT Tomcat 7 development !

project: miko-spring-scala on github

Spring 4 Scala MVC without Web.XML - Tiles3 with more services @Autowired

  Let's make one more update before I'll do the push of Spring 4 Scala Tiles 3 example project to my GiTHub. We know that Scala is kind of hype nowadays (which is great for any application evolution), true is that the functional approach is reachable with other languages (java, python, ruby .... javascript ;), only Scala has been developed in functional manner since its basics. Such fact could great to hear for JavaScript developers because it could be easier to enter back-end development world ;). Since my experiences with Scala it does make sense to push the mind into functional design pattern thinking -> makes whole life much easier.   

  The most of times is not impossible to start any enterprise project from scratch. The acceptable way is smart refactoring with possible new technologies or techniques usage and improving the code quality which should go hand in hand. 

  Spring stack (framework, integration, spring-data and more projects supporting dependency injection DI<IoC>) is well know in the enterprise world and it's also excited turning project parts into the Scala world. 

  Let's show how to use @Autowired annotation to give spring scala controller more responsibility. 
1. define example Service
//a. define interface ~ trait 
trait ExampleImportService {
  def name: String
}
...
//b. define class ~ service functionality 
@Service("exampleImportService")
class ExampleImportServiceImpl extends ExampleImportService{
  override def name: String = "Imported service over XML"
}
2. Autowire services with the Controller 
@Controller
@RequestMapping(Array("/"))
class HelloExampleController @Autowired() (exampleService: ExampleService, exampleImportService: ExampleImportService){

  private val logger = LoggerFactory.getLogger(getClass)

  @RequestMapping(method =  Array(RequestMethod.GET))
  def printMain( model: ModelAndView): ModelAndView = {
    model.addObject("message", "Here is Scala with ServiceName = " + exampleService.serviceName)
    model.addObject("importMessage", "Here is Scala with ServiceImportName = " + exampleImportService.name)
    model.setViewName("main")
    model
  }

  @RequestMapping(method =  Array(RequestMethod.GET), value = Array[String]{"/test/web"})
  def printTest(model: ModelMap): String = {
    logger.info("PrintTest Start")
    "test"
  }
}
  The controller "HellolExampleController" defines different return types (callbacks -> ModelAndView holder and String) based on specific request handling. Both return types are resolved then by our simple DispatcherServlet configuration.
 val servlet: Dynamic = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx))
 servlet.addMapping("/")
 servlet.setLoadOnStartup(1)
  The example project uses Java Servlet 3.0 (intro) with interface ServletRegistration.Dynamic and runs on Tomcat 7.x using SBT building tool (next blog post how to enable tomcat(port = 9090))
Let's start and stop:
1. sbt -> container:start
2. sbt -> container:stop
and Enjoy spring 4 scala!  

project: miko-spring-scala on github

Saturday, August 9, 2014

update: Scala Spring 4 MVC without Web.XML - logging with Log4j and SLF4j

  This is small update to the previous blogpost (Scala Spring 4 MVC without Web.XML). It shows how to add commonly used Java libraries into the Spring scala project. 
In this example is log4j 1.x used but any change can be easily done when you clone my git hub project. Basically this post shows how to add commonly used libraries into any scala project.

  Let's import last version of Simple Logging Facede 4 Java (SLF4J) and not thin Scala (SLF4S) wrapper to it which is written by Heiko Seeberger.

  We do whole example update in several steps:
1. we need to update our build.sbt file and import appropriate library dependencies
libraryDependencies ++= Seq(
  "org.springframework" % "spring-webmvc" % "4.0.6.RELEASE",
  "org.springframework" % "spring-context" % "4.0.6.RELEASE",
  "org.springframework" % "spring-context-support" % "4.0.6.RELEASE",
  "javax.servlet" % "javax.servlet-api" % "3.0.1" % "provided",
  "javax.servlet" % "jstl" % "1.2" % "compile",
  
  "org.slf4j" % "jcl-over-slf4j" % "1.7.5" ,
  "org.slf4j" % "slf4j-api" % "1.7.5" ,
  "org.slf4j" % "slf4j-log4j12" % "1.7.5",
  "log4j" % "log4j" % "1.2.17" excludeAll(
        ExclusionRule(organization = "com.sun.jdmk"),
        ExclusionRule(organization = "com.sun.jmx"),
        ExclusionRule(organization = "javax.jms")
      ),
  
  "org.eclipse.jetty" % "jetty-webapp" % "9.1.0.v20131115" % "container, compile",
  "org.eclipse.jetty" % "jetty-jsp" % "9.1.0.v20131115" % "container"
)

2. in the resources folder we configure log4j logger and some properties (Img.1.). Example configuration is done for Tomcat server.
Img.1.:: Spring 4 Scala project structure with logging configuration
 3. org.slf4j.LoggerFactory is now available for import into HelloExampleController and to log Controller behaviour.
...
private val logger = LoggerFactory.getLogger(getClass)

@RequestMapping(method =  Array(RequestMethod.GET))
def hello( model: Model) = {
  logger.info("Info Test")
  logger.debug("Debug Test")
  logger.error("Error Test")
...

All code is available over my github for testing. Small hint could be Log4j 2 which promises significant improvements over its predecessor, logback and etc.
Enjoy!


Friday, August 8, 2014

Spring 4 MVC without Web.XML configuration - static resources handling

This short post is the update to the previous ones: 
    Previously was only defined the way how to link symbolic links and components location  to scan which are normally defined by specific ServletContext *.xml file as in following example :
...
    
    
        
        
    
...
and we've transformed such *.xml file into the Java code in github project miko-s4netty:
@Configuration
@ComponentScan("com.miko.s4netty")
@EnableWebMvc
public class WebConfig {
    @Bean
    public UrlBasedViewResolver setupViewResolver() {
        UrlBasedViewResolver resolver = new UrlBasedViewResolver();
        resolver.setPrefix("/WEB-INF/pages/");
        resolver.setSuffix(".jsp");
        resolver.setViewClass(JstlView.class);
        return resolver;
    }
}

Let's give *.jsp pages access to the static resources and consider following project structure (Img.1.)
Img.1. - part of project structure with static resources
From the Img.1. comes the necessity to link the two folders ("/app", "/lib") which will by available for the front-end development after the application deployment. In such case we need to extend the implementation of the WebConfig class and configure callback methods to correctly customise Java-based configuration of the project. 

1. WebConfig extends WebMvcConfiguredAdapter which give us possibility to directly override necessary methods from WebMvcConfigurerWebMvcConfigurer is normally imported by adding @EnableWebMvc annotation to @Configuration application class. The result it then delegated to WebMvcConfigurationSupport which provides Java-based config possibility. 
@Configuration
@ComponentScan("com.miko.s4netty")
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
2. XML tag annotation for handling servlet requests <mvc:default-servlet-handler /> needs to be reflected in the WebConfig class by overriding  configureDefaultServletHandling method


...
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
   configurer.enable();
}
...
3. Also resources request handling needs to be reflected by overriding appropriate method in the class WebConfig. This is normally done by XML tags <mvc:resources/> 


...
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
   registry.addResourceHandler("/app/**").addResourceLocations("/app/").setCachePeriod(31550522);
   registry.addResourceHandler("/lib/**").addResourceLocations("/lib/").setCachePeriod(31550522);
}
...
The last WebConfig class modification opens the possibility to continue building front-end application with appropriate resources. 
The final result of WebConfig class according to the front-end project structure (Img.1.) can looks like following example.
@Configuration
@ComponentScan("com.miko.s4netty")
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/app/**").addResourceLocations("/app/").setCachePeriod(31550522);
        registry.addResourceHandler("/lib/**").addResourceLocations("/lib/").setCachePeriod(31550522);
    }

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    @Bean
    public UrlBasedViewResolver setupViewResolver() {
        UrlBasedViewResolver resolver = new UrlBasedViewResolver();
        resolver.setPrefix("/WEB-INF/pages/");
        resolver.setSuffix(".jsp");
        resolver.setViewClass(JstlView.class);
        return resolver;
    }
}
Enjoy building rich front-end application!

Monday, July 21, 2014

Lego Mindstorm EV3 -> Java8, LeJOS and Gradle with taste of Maven

Img.1. - Let's turn on the LegoBrick again and make remote project based on Gradle
The previous post about Lego MindStorm EV3 has been focused on its installation. I've touched how to install JavaJDK setup Wifi on LegoBrick + small sample "hello world" project.
This blog post is about setting up little more advanced project.

The simple HelloWorldGradle Remote project uses:
The legoBrick, connected to the WiFi, is possible to access remotely without problem using Java Remote Method Invocation, shortly RMI.
RemoteEV3 ev3Brick = new RemoteEV3(EV3BRICK_IP);
ev3Brick.setDefault();
Before we start working on the sample source code we create Gradle project. We can randomly choose the project as HelloWorldGradle. Important is to setup Gradle property file "build.gradle" correctly
apply plugin: 'java'
apply plugin: 'idea'
sourceCompatibility = 1.8
version = '1.0'
repositories {
    mavenCentral()
    mavenLocal()
}
dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
    compile 'lejos:ev3classes:1.0-SNAPSHOT'
    compile ('log4j:log4j:1.2.17'){
        exclude group: "com.sun.jdmk", module: "jmxtools"
        exclude group: "javax.jms", module: "jms"
        exclude group: "com.sun.jmx", module: "jmxri"
    }
    compile 'org.slf4j:slf4j-log4j12:1.7.5'
}
jar library "ev3classes" is very important!
This library creates the gateway into the lego hardware by using RMI because EV3 acts as the RMI Registry. You need to create it by yourself.
lejos
  ev3classes
  jar
  1.0-SNAPSHOT
  
    
      lejos
      dbusjava
      1.0-SNAPSHOT
    
    
      net.java.dev.jna
      jna
      3.2.7
    
  
  
    ${basedir}/src
    ev3classes
    install
    
      
        maven-compiler-plugin
        ${maven.compiler.version}
        
          ${java.version}
          ${java.version}
        
      
      
        org.apache.maven.plugins
        maven-jar-plugin
        ${maven.jar.version}
      
      
        maven-assembly-plugin
        ${maven.assembly.version}
        
          ${project.build.finalName}-${project.version}.jar
          
            jar-with-dependencies
          
        
        
          
            make-assembly
            package
            
              single
            
          
        
      
    
  
This library can be created by maven with usage of maven-assembly-plugin. The final *.jar file can then easily imported into the local maven cache.
Now we are ready to remotely access our Lego MindStorm robot and in our case let him to play some short song.
RemoteEV3 ev3Brick = new RemoteEV3(EV3BRICK_IP);
            ev3Brick.setDefault();
            Audio soundProcessor = ev3Brick.getAudio();
            List tones = new ArrayList<>(asList(0,1,2,3,4,5));
            tones.forEach(tone -> {
                soundProcessor.systemSound(tone);
            });
The sample LejOS remote project HelloWorldGradle is available here (GITHub).
Enjoy !

Sunday, July 20, 2014

Distributed systems: from mechanic to the IT infrastructure

Img.1.:: Complex Distribute System ~ new tools definition
Many things that we know in IT these days could be partly taken as the reflection of the mechanical tools evolution (Img.2.). Such evolution is continually happening over last centuries. Physical and other laws define the world we are currently living in. These laws also playing significant role in the future discoveries and related new tool definitions (Img.1.).
Img.2.: Codex Madrid I by Leonardo da Vinci - Device for Calculation :: Leonard's mechanism maintains a constant ratio of ten to one in each of it's 13 digit-registering wheels...
There is no surprise to hear the argument about the tools simplicity or easy to control which are reflecting the past compare to current situation.
Img.3.: Python-based open source toolkit for magnetic resonance connectome mapping, data management, sharing and analysis (http://www.cmtk.org/) 
Argument maybe true but it's omitting minimally two key variables.
  1. The resources sharing variable which could be directly projected into any individual learning curve
  2. Visualisation variable which helps faster connect system with purpose (Img.3.) and understand the role.
The increasing speed of the information sharing (massages exchange process) supporting the general fact that many current systems are becoming to be more and more distributed + complex.
Similarly to the visualisation needs which helps to connect situation to the appropriate state of art.  ps: At the mechanic age the visualisation was not a big issue as all parts were almost always clearly visible (Img.2.).

Such evolution process can be highly observable in the IT industry as the whole IT industry has cradle in Mechanical Engineering followed by Chemistry with taste of Physics (Computer Science).

The distributed systems (DS) design itself has also evolved (Img.4.) based on possibilities and needs according to the evolution time line. The design itself is connecting more different aspects together which makes whole design process complex, challenging and hard.
Img.4.: Client-Server ~ the centralised system architecture where both has communication Interfaces.  This relation can be also taken as the building cell of the much bigger system so it become to be "Client-Server Unit". This cell has it's own life cycle. 
What it a distributed system ? 
A distributed system is a software system in which components located on networked computer communicate and coordinate their own action by passing messages. The components interact with each other to achieve a appropriate goal. (link)

According to the distributed system definition that DS is the software (includes algorithms, data-structures, design patterns etc. ), we can move Server-Client architecture as the building cell of the another system (Img.4.) ~ "Client-Server Unit" (CSUnit)
Img.5.: Traditional Three-tier architecture pattern - support different levels of abstractions.   
Even more because the current technologies state allows us to define both part ("Client-Server Unit") into appropriate tiers (Img.5.).  Those tiers could be evaluated and tested according to their purposes.  

How the client application could be divided into such tiers ? 
Good example shows AngularJS framework which is superheroic JavaScript Model-View-Whatever Framework (data-binding, Model-View-Controller or Model-View-ViewModel pattern) offering junit testing on the client side. 

The natural necessity of appropriate server functionality, stability... testing is self understandable independently on used technologies. 
Img.6. Possible Cloud Computing abstraction where individual process are invisible to the user (Laptop, Server, Desktop, Phone, Table) and result is provided as a service
Let's take a look at cloud computing as the services~product delivery and divide such "product" into general parts (applications, platform, infrastructure).
Each of those parts have their own definitions and over all when we take the Img.1. and do the extension, according to the cloud computing, we can can end up with new system abstraction (img.6.)

Every cell becomes to be it's own sustainable unit with its specific functionality and we should still keep in mind couple of questions that needs be answered : Cost, Availability, Reliability, Performance, Scalability and Manageability related with such new unit.

From general perspective in this model (Img.6.) aren't only presented "Client-Server Units", there is new unit type: "Client-Server-Client Unit" (CSCUnit) . 

"Client-Server-Client Unit" means that the server inside the CSCUnit maybe in the client position for another service at any time of its life cycle. Example of Peer2Peer technologies present in the cloud be Infinispan, scalable map-like data-structure distributed among the grid of servers. The Infinispan now plays the role of distributed memory without necessity of central coordination. 

As the final cloud system is obviously collection of different smaller parts another questions become to be more and more important then ever before eg.: individual system part transparency, communication related to others, how concurrency between them and how big is the resistance agains the any part failure (fault tolerance). 

Conclusion: I wanted to highlight relation between the mechanical engineering and IT branch evolution according to the new technologies which are coming continually on a market. I hope I was more then partly successful because the way how we look at Mechanical equipment and IT ones is sometimes question only about to changing view perspective (Img.7.). 
Img.7.: Leonardo da Vinci - Codex Madrid I - counting machine