-->

JDon.org

Jdon Framework Architecture

Jdon Framework is a light-weight framework for developing DDD applications.

Jdon Framework = Domain Model + In-memory + Domain Events.

Events implementation of Jdon Framework 6.4 is the Disruptor that it is a concurrent framework can handle 6 million orders per second on a single thread in LMAX recommended by Martin Fowler.

DDD CQRS EventSourcing example source: football Match

Before Domain-Driven Design(DDD) appears , business logic was implemented by the technical component directly, such as service,action and so on, and the model objects were all anaemia model , they are just a data collections, on this way, technical components drive the anaemia models to complete the business logics. this way called "Transaction script".

In DDD there is a big different from the traditional script. Domain models drive the technical components to finish the business logics, domain model is like DNA.

So our architecture can focus on business domain model that is easy to understand ,extend and maintain, in the mean time, domain model also makes our software systems more scalable,and be better performance.

DDD-Oriented Architecture

for easy focus on the business domain,Jdon Framework make domain model easy to living in a software system.

In Memory Domain model

domain model  mainly includes the Entity,Value Object and Service that all focus on the business domain,it is nothing to do with the concrete technical implementation. but we need let them living in the technical system.

In Jdon Framework, these domain models are marked with the @Model annotation, so they are in memory and send asynchronous events or message to the consumers .

de


domain model is the core of our software systems,their lifecycles management is very important, Jdon Framework makes the management of domain model's lifecycles more easily, domain model lives in the in-memory cache ,such as ehcache,oscache,terracotta ....,so the software system will be more scalable with the distributed cache system ,such as terracotta ,memcached.


However,cache is a very low-level technical layer,if we allow the developers to manually interact with cache,then it will easily lead to errors and inconsistecies,so Jdon Framework integrates two interceptors ,one is "CacheInterceptor" ,the other is "DomainCacheInterceptor",they both are configured in the "aspect.xml" file which is a config file of Jdon Framework.


First let's see "CacheInterceptor":

"CacheIntercep"  is between the presentation layer and business layer,when the presentation action invoke the "get*()" method of business service,the CacheInterceptor will intercept the invocation,it first checks  that whether the domain model object already is the cache,if the model object is not in cache,CacheInterceptor will invoke the next interceptor which is in the interceptor chain,and finally the model object will be fetched from persistence datasource,the CacheInterceptor will gain the fetched model object and put it into the cache.


I guess you have understood how the CacheInterceptor works,now i will introduce you how the DomainCacheInteceptor works?

DomainCacheInterceptor is between business layer(domain model live in this layer) and the persistence layer,before the business layer invoking the persistence layer component to fetch the model, the DomainCacheInterceptor will intercept the invocation,it will also check that whether the model has already in the cache,if in,DomainCacheInterceptor just return the cached Model,or else  it will put the model which is retrieved from persistence datasource into the cache.


Last let me see the followed diagram,the diagram describes the relation of the two interceptors.

 

aa

 

 

The architecture components

There are five components model in Jdon Framework, they are:

1. Entity Model with @Model;
2. Service with @Service; technical component
3. Component with @Component ; technical component
4. Prodcuer-Consumer mode with @send @Consumer;
5. Interceptor with @ Interceptor, need with @Introduce;
All  in com.jdon.annotation.*

As mentioned above,Jdon Framework seperates the application architecture into two parts:Domain models and technical components .

domain models lives in the cache ,and the technical components lives in the IOC container.

The technical component's lifecycles management is also important,Jdon Framework use the IOC container to manage the lifecycles of technical components,at the same time,the IOC container is also holded in the context container such as the ServeltContext.

Jdon Framework uses the interceptors to inject the technical components into the domain models.

By the Jdon Framework,it will drive you to develop your application with the OO style,what's more,in this style,The domain models drive the components to finish the business operations,so do you smell the flavor of DDD ?

Domain Events and CQRS or EDA

As the DDD framework,it is essential  to solve the interaction between the domain model and the technical component,Jdon Framework apply the domain event pattern to make the domain models less coupling with technical components.the core architecture diagram as the followed here:

 

As the above diagram description,when domain models trigger some domain events,the domain event will generate proper domain message,at last the messageListener will treat with the event,and assist with the business logic.

Domain Event is a Producer-Consumer or Publisher-Subscriber patterns; Asynchronous; topic or queue (1:N or 1:1) ; Domain Model is a producer; it send events or message to the consumers:

@Send(topicName) => @Consumer(topicName);

the Topic mode is powered by disruptor. that is fast concurrent programming framework that introduced by Martin fowler :LMAX Architecture.

if there are many consumers, their started order is by its class name's alphabetical . such AEventHandler is first be reaction; and then BEventHandler and CEve.......


If you want to use Domain event ,you just need to use three Annotations,@Introduce,@Inject and @Send.for example,we have a model class named MyModel,and a domain event named MyDomainEvent ,the code is as here:

@Model
public class MyModel {

   private Long id;
   private String name;

   @Inject
   private MyModelDomainEvent myModelDomainEvent;

   @Inject
   private MyModelService myModelServiceCommand;

   public Long getId() {
      return id;   
   }

   public void setId(Long id) {
    this.id = id;
   }

   public String getName() {
      if (this.name == null) {

            //this is async method, can be splite twice times calling.
            EventMessage message = myModelDomainEvent.asyncFindName(this);
            this.name = (String) message.getEventResult();
      }  
      return name;
}

……
}

@Introduce("message")
public class MyModelDomainEvent {

   @Send(value="MyModel.findName",asyn=true)
   public DomainMessage asyncFindName(MyModel myModel) {
         return new DomainMessage(myModel);
   }

}

When you retrieve MyModel from service or repository,the CacheInterceptor and the DomainCacheInterceptor will inject the MyModelDomainEvent and MyModelService into MyModel,when injecting the MyModelDomainEvent,@Introduce("message") will  lead MyModelDomainEvent to be enhanced with MessageInterceptor,when myModel.getName() is invoked, the MessageListenner will intercept the invocation,it will choose proper means to drive the MessageListner to response this event request.

domain event programming steps:

1. keep domain model in-memory cache:

@Model
public class User {
   private String userId;
   private String name;
     ....
}
A class with @Model will live in memory, default is Cache (Ehcache). Or Key-value store others.

When a domain model object with @Model is fetch from repository, we need use @Introduce(“modelCache”) to mak the object live in memory.

@Introduce(“modelCache”) must be annotated in the interfaces that @Model objects are created or reconstructed , the interfaces is such as repository class.

This step is very important for domain events working,

cachge

2.annotate producer class with @Model and @Introduce("message")
annotate the method with @Send("mytopic") of the producer class

@Introduce(“message”):"message" is the om.jdon.domain.message.MessageInterceptor configured in aspect.xml It means introducing a MessageInterceptor for this class.

@ Send("mytopic"): "mytopic" is your topic name that equals to the "mytopic" in @Consumer("mytopic");
In this method, you must marshal your data into a DomainMessag that can be unmarshal in consumers.

3.(1) . annotate consumer class with@Consumer("mytopic");
(2). the consumer class need implement com.jdon.domain.message.DomainEventHandler



another domain events sample :

s

@Send(topic) ==> @Component(topic);
the consumer is a class with @Component(topic) that need implement com.jdon.domain.message.MessageListener, Consumer is a future or weight or cron task.

DCI

DCI: Data, Context, Interactions is a programming paradigm invented by Trygve Reenskaug. the domain model is a Data, the domain events producer is a Role of DCI, it includes the interactions of DCI.

Jdon Framework's domain model injection function can inject the role into the domain model, such as above the class UserDomainEvents is a Role, it can be injected into the model UserModel.so it help UserModel implements business function ComputeCount. In runtime, The Role UserDomainEvents will be injected into the Data UserModel.

DDD DCI and Domain Events example


DCI Example:SimpleJdonFrameworkTest.rar

AOP

Using the  DDD,It is the domain models drive the technical components to finish the business logics,and in this design style,the components are just the assistants,which assist the domain models to complete the business operations.So how the domain models gain the needed components,Jdon framework use the @Inject and @Component to inject components and the domain events into models.

As the followed diagram illustrates ,when client invoke the getA("a"),if Model A with a Introduce,the A will be enhanced,and the technical component C will also be injected  into the A ,at the same time,when inject the B,the B will also be enhanced for the @Introduce.

 

How to integrate Jdon Framework with Spring

CES:Context Event and State

Other Details

Jdon is a RAD tool for writing a small/medium stand-alone JavaEE application. it is a IOC/AOP framework too, and includes a lightweight Ioc container based on Picocontainer.the feature of Jdon is that all components are replaceable, even includes the framework itself. you can plug in any java objects, Jdon is a embeddable framework.

Jdon provides Domain Driven Development for data CRUD and batch inquiry (master-details)

Jdon is similar with Rubby + lightweight container, and really simplifies JavaEE development! It can produce high quality applications, faster and at lower cost.

By using cache Jdon optimizes the components running performance, such as the dynamic proxy components. Because of the cache optimization, Jdon potentially improves the application system performance, such as batch inquiry operations. The performance of the JPetstore with Jdon is best among several JPetstores (including iBATIS JPetstore/Spring JPetstore)

Jdon seamlessly supports two services: POJO/EJB , it helps you to build a scalable and extendable small/medium JavaEE system .


Jdon give your JavaEE application a complete quality solution:

Ioc microkernel:
The great thing about objects is they can be replaced. ----Object- Oriented Analysis and Design with Applications, Grady Booch, one of the founding fathers of object-oriented programming

The great thing about Jdon is it helps you replace them((even you can replace jdon itself!).

All framework components include framework infrastructure objects are be managed by a micocontainer made by Picocontainer, you can insert or change any components by change the xml configuration files(such as container.xml/aspect.xml/jdonframework.xml), you can also replace Jdon framework's infrastructure components(this is a strongpoint).

Jdon framework will make your components. the infrastructure components or POJO services collaborate with each other via dependency injection.

When you have hundreds of components/POJO services, Jdon's autowiring function will take care of their invocation relation.

Interceptor :
You can insert a Interceptor by XML files aspect.xml, Jdon has some default interceptos, they are pool interceptor/cache interceptor/stateful interceptor.this interceptos will active before target services are invoked.if you appont a interceptor to a service, the service must implements the interface the interceptor, such as Poolable or Stateful

Service/Componet:
When you want to develop a small system, you can only use POJO services implement logic function. How to get a service instance? two ways: Annotation or XML

First: Annotation:

 

Second: XML

in jdonframework.xml (container.xml) there is such service configuration:

<pojoService name="userDao" class="news.container.UserJdbcDao">

<constructor value="java:/NewsDS"/>

</pojoService>

in code, we can get the service instance by below mode:

UserDao ud = (UserDao)WebAppUtil.getService(“userDao”, request);

Jdon defines four service models: component instance that is singleton, service instance that can be pooled

about Choice with Annotaion and XML in Ioc container:XML in IoC containers: A Hell or A Realm?

More Annotation

@Poolable: get a instance from the class's object pooing, Object Pooling - Determinism vs. Throughput

@Stateful:its instance lifecycle is user session scope

@Singleton: get a singleton instance form the class

RAD Tool

Keep deliberately simple, yet still very powerful, so that your code is kept simple.

Jdon provides a fast development way for model's CRUD(create/read/update/delete) , in presentation layer, in general, you don't need any code, only configure MVC Process in the jdonframework.xml:

 <model key="userId" 
class ="com.jdon.framework.test.model.UserTest">
<actionForm name="userActionForm"/>
<handler>
<service ref="testService">
<getMethod name="getUser" />
<createMethod name="createUser" />
<updateMethod name="updateUser" />
<deleteMethod name="deleteUser" />
</service>
</handler>
</model>

Jdon's presentation layer is based Struts 1.2, so Jdon will generate Action instance at running time.

Multi page query function can be accomplished quickly by Jdon, Jdon provide the multi-page taglib, JDBC template, and Model's cache optimization.

Use Jdon, you can develop a small system in several minutes, here is the system demo:http://www.jdon.com:8080/testWeb/

More details in Architecture Document Step by Step develop a Jdon application

 

Comparison with Ruby on Rails

ror

Domain Driven Development

  When we develop a J2EE application with Jdon Framework,at first we must finish domain object 's design, and then copy the domain object(Model) to presentation layer's ModelForm, and persistence Model in Hibernate/iBatis. Boundary Object = Domain Object = Entity Object(BO).

Less and simple confuration:

  The configuration of jdon Framework is simple, this is the XML DTD, you will find the schemal is very simple, the amount of the schemal is less.
  There are two parts in XML jdonframework.xml: models and services, services part is basic configure, it looks like: <pojoService name="XXX" class="xx.xxx.xx" />, models part is for CRUD as below.
 

CRUD(Create/Read/Update/Delete)

  In Jdon Framework, Business logic can be done in service layer, by below configure xml(such as jdonframework.xml), we can kick off controller layer, the C of MVC is done by configures:

<app>
<models>
<model key="username" class=
"com.jdon.framework.samples.jpetstore.domain.Account">
  <actionForm name=
"accountForm"/> //Boundary Object
  <handler>
    <service ref=
"accountService"> /Business Logic Service Component
      <getMethod name=
"getAccount"/> //read Method of the Service
      <createMethod name=
"insertAccount"/> //Create Method of the Service
      <updateMethod name=
"updateAccount"/> /Update Method of the Service
      <deleteMethod name=
"deleteAccount"/>//delete Method of the Service
    </service>
  </handler>
</model>
</models>
<services>
.......

</services>
</app>

Command patern for calling services

  Like the ActionController of Ruby on Rails, t he function/pattern handles incoming requests from the user's browser and routes them to the correct method of a service class , not a controller class such as Struts's DispatchAction. click here for details.

POJO Services and IOC

consider below code:

§package test;
§ public class BServiceImp implements BService{   
§          AService a;
§§         public B(AService a){ 
§§         §         this.a = a
§§         }
§          public void invoke(){
§                a.myMethod();
§          }
§ }

  There are two way for invoking B:

  Ordinarily way without ioc container:
  BService b = new BServiceImp(new AServiceImp());
  b. invoke();

  Revolution way with jdon ioc container:
  BService b = (BService) WebAppUtil.getService(“bservice”);
  b. invoke();


  Now There is only one A class in B class code, if there are more other classes such as C/D/E... , when we create B instance, we must spend more energy in creating those instances of A/C/D or E ..

  but, with jdon ioc container, we don't need do these stupid works any more. when we need use any class, we can only fetch it and use it.

  certainly, at first we must configure all these class in jdonframework.xml:

<app>
  <models>
    .....
  </models>
  <services>
    <pojoService name="bservice" class="test.BServiceImp"/>
    <pojoService name="aservice" class="test.AServiceImp"/>
    <pojoService name="cservice" class="test.CServiceImp"/>
  </services>
</app>

  in configure xml, we don't need take care of the relations B with A/C/D, this is important difference from Spring, in Spring configure file, we need add "ref local=a" , at this point, Jdon is like HiveMind.

Filter and AOP Interceptor

  Permission and cache can be the Interceptors for the application , here is a sample, in myaspect.xml:

<aspect>

  <interceptor name="jivejdon_permissionInterceptor"       class="com.jdon.jivejdon.service.interceptor.PermissionInterceptor"
       pointcut="pojoServices" />

</aspect>

  in web.xml we need tell jdon framework the interceptors configuration:

<web-app>
  <context-param>
    <param-name>aspectConfigure</param-name>
    <param-value>WEB-INF/myaspect.xml</param-value>
  </context-param>
</web-app>

  all configurations can be found in jdon framework's examples.

Jdon Framework architecture

  Jdon Framework in J2EE Application Architecture:

 

  welcome you join our english document team.

DDD CQRS EventSourcing example source: football Match

CES:Context Event and State

old version :

Step By Step

How to develop Struts-Jdon-JDBC Application

Command patern for calling services

Struts + Jdon + Hibernate video

Blog

DDD DCI and Domain Events example

how to enhance Jdon framework to DCI framework ?

Immutability is everything

how to easily develop a non-blocking concurrent application ?

 

 

Download

Document

Qucik Start

Examples

Github

jivejdon

JdonMVC

Jdon中文

sf

Click here to lend your support to: Jdonframework and make a donation at www.pledgie.com !

Donate Bitcoins

Twitter:
@jdonframework