Distributed adaptive document system example

Distributed adaptive document system

Description

The example proposed here is taken from R. Pawlak et al. JAC: an aspect-based distributed dynamic framework as a pragmatic assessment on the expressiveness of the AIOC language with relation to distributed dynamic aspect-oriented systems.

In the scenario proposed in the paper, the authors describe the classic server-client interaction in which the server serves documents to clients. The server implements three "methods" to interact with documents, namely:

  • Search, which allows a client to search a certain string on a document;
  • Read, which returns the content of a document;
  • Write, which modifies the content of a document.

Pointcuts

First, we model one of the basic concepts of AOP which is pointcut. A pointcut describes a set of join points. Each time the execution of a program reaches one of the join points relative to a pointcut, a piece of code associated with the pointcut is executed. We implement pointcuts as empty scopes defined before each operation. The empty scopes make use of the feature roles{...} that allows us to specify additional roles in the scope. Additional roles do not take an active part in the scope they are added in, but their behaviour relative to that scope can be changed by an adaptation rule. In the example, if the adaptation rule N.scope_name = log applies, we allow a logger to count the number of interactions relative to search, read, and write operations.

scope @client{ skip	}	
prop { N.scopename = "log" } 
roles { logger };
rule {
	include log, getLoadBalancing from "socket://localhost:8000"
	on { N.scopename == "log" }
	do {
		log: client( r ) -> logger( log );
		_r@logger = log( log );
		if( log == "S" )@logger {	
		search_balance@logger = getLoadBalancing( log )	};
		if( log == "R" )@logger { 
		read_balance@logger = getLoadBalancing( log )	}
	} 
}

Dynamic wrappers

Dynamic wrappers, as defined in JAC, are software entities that allow the modification or the enhancement of the semantics of some base objects. They provide the ability to add code before, after, or around existing methods.

In the proposed example, the authors suggest to apply distributed aspects to avoid the overload of a single server. Namely, they introduce aspects that manage distribution of documents, load-balancing, and coherence among copies of the same document.

As for pointcuts, we make use of the feature roles{...} to include in the interaction of each operation a balancer and an additional server (rserver). Then, in the adaptation rules the balancer routes the operations between the two servers to balance the load. Furthermore, in order to preserve coherence among documents, each time a write operation is executed, the server that applied the modifications notifies the other to synchronise the state of the copy of the document.

Code

Click on the buttons below to download the code of this example.

Distributed adaptive document system with dirty read control (rules)

Description

On the same example described above, we introduce a new set of rules that implement a dirty-read control system. These rules can be used to replace the set of rules defined before. In this example we model an optimisation of the previous scenario in which performances are preferred over coherence between copies of documents.

When the balancer redirects search or read operations towards the first server, that server checks whether its copy of the document is up-to-date. In case the second server has a newer version of the document -- i.e., the version of the first one is dirty --, the first one requires a copy from the second one. Then the first updates its own version of the document and serves it to the client.

Concordantly, the write operation no longer synchronises the copies of the same document between the servers, but simply notifies the dirty state of the document.

In the example we simulate the presence of a "dirty" document by passing the string "dirty" as argument of operations read and search.

Code

Click on the buttons below to download the code of this example.