03 December 2019

Pipeline Pattern

Many times we need to implement a workflow/pipeline in our code (i.e.: Java) this brings us bad design by using too many nested loops, if/switch, etc.

One way is to use a BPM however this has boilerplate config/code, a leaner solution is to implement Pipeline Pattern:

Definition of the Pipeline Pattern

 Each of the sequence of calculations is performed by having the first stage of the pipeline perform the first step, and then the second stage the second step, and so on.
 As each stage completes a step of a calculation, it passes the calculation-in-progress to the next stage and begins work on the next calculation.”


https://www.cise.ufl.edu/research/ParallelPatterns/PatternLanguage/AlgorithmStructure/Pipeline.htm

This is almost the same than:

Pipeline, Pipes and filters:

https://www.enterpriseintegrationpatterns.com/patterns/messaging/PipesAndFilters.html

https://www.codeproject.com/articles/1094513/pipeline-and-filters-pattern-using-csharp




gist:
https://stackoverflow.com/questions/39947155/pipeline-design-pattern-implementation

Spring contexts and Servlets


applicationContext.xml defines the beans for the "root webapp context", i.e. the context associated with the webapp. This means is transversal.

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
  </context-param>
 


The spring-servlet.xml (or whatever else you call it) defines the beans for one servlet's app context. There can be many of these in a webapp, one per Spring servlet (e.g. spring1-servlet.xml for servlet spring1, spring2-servlet.xml for servlet spring2).

Therefore resources that need to be injected transversal can be set in applicationContext.xml, ie:

  <import resource="classpath*:spring/jwt-security-context.xml"/>
  

from: https://stackoverflow.com/questions/3652090/difference-between-applicationcontext-xml-and-spring-servlet-xml-in-spring-frame



Also Servelts using Spring DI:

- https://stackoverflow.com/questions/35255052/spring-service-not-injected-in-web-servlet
- http://www.javavillage.in/spring-ioc-on-servlets.php

My Blog List

Blog Archive

Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.