JBoss.orgCommunity Documentation

Scribble Java Developer Guide


1. Protocol
1.1. Common Components (maven artifact id scribble-core)
1.1.1. Issue Logging
1.1.2. Context
1.1.3. Resources
1.1.4. Protocol Model
1.2. Parsing (artifact id scribble-parser)
1.3. Validating (artifact id scribble-validation)
1.4. Projection (artifact id scribble-projection)
2. Monitor
2.1. Converting a Protocol into a Monitor State Machine
2.2. Dynamically Monitoring Message Exchanges
2.2.1. Managing session instances
2.2.2. Verifying behaviour
3. Simulation
3.1. Defining a Trace
3.2. Performing a Simulation

This section explains how to make use of the Scribble Java tools to parse, validate and project a Scribble protocol. The following sections of this document explain how applications can then make use of these validated (and potentially projected) protocols to perform further tasks, such as monitoring message exchanges to ensure they conform to a defined protocol, or simulating message traces against endpoint simulators.

The Java tools make use of maven to store its artifacts (i.e. jars). These are associated with the group id org.scribble and the artifact id scribble-<component>, where the <component> is the individual area represented by the artifact. As well as there being an artifact per component of the tooling, there is an additional scribble-core artifact that contains items shared by all of the components.

This artifact contains general interfaces/classes for issue logging, context, resources and the protocol model (local and global variants).

The parser is the component responsible for taking a text based description of a Scribble protocol and transforming it into an object model. As part of this process, it will verify that the syntax of the protocol description is valid, and report any errors using the supplied org.scribble.logging.IssueLogger.

String path=....;		// Colon separate directory paths where scribble modules are located
java.io.InputStream is=....;	// Input stream containing text description of scribble protocol

org.scribble.parser.ProtocolParser pp=new org.scribble.parser.ProtocolParser();
org.scribble.logging.IssueLogger logger=new org.scribble.logging.ConsoleIssueLogger();
org.scribble.resources.DirectoryResourceLocator locator=new org.scribble.resources.DirectoryResourceLocator(path);

org.scribble.context.ModuleLoader loader=new org.scribble.parser.ProtocolModuleLoader(pp, locator, logger);

org.scribble.resources.Resource res=new org.scribble.resources.InputStreamResource(path, is);

org.scribble.model.Module module=pp.parse(res, loader, logger);

The last line of this example shows the parser being involved. It takes three parameters:

  • the resource, containing the text based scribble protocol description
  • the loader, to load any additional modules (or potentially other resources) that may be required to support the parsing of the module
  • the logger, to report any issues that arise from parsing the protocol description

If the parser returns a module, then it means that it was successfully parsed. Otherwise the syntax errors will be reported to the issue logger and no module will be returned.

The monitoring capability is used to ensure that a system conforms to a protocol description at runtime. This is a form of dynamic validation, or conformance checking.

To efficiently monitor a running system, to ensure that it is conformed to one or more roles within a protocol description, it is necessary to transform the text based description (and even the object model representation) into a form that can more effectively be used to drive a runtime monitoring solution.

org.scribble.context.ModuleLoader loader=...;
org.scribble.resources.Resource res=...;

org.scribble.model.local.LProtocolDefinition lp=...;	// Obtain the required local protocol definition

org.scribble.monitor.export.MonitorExporter exporter=new org.scribble.monitor.export.MonitorExporter();

org.scribble.context.ModuleContext context=new org.scribble.context.DefaultModuleContext(res, lp.getModule(), loader);

org.scribble.monitor.model.SessionType type=exporter.export(context, lp);

The first step is to obtain the module that contains the local protocol definition to be monitored. This can ether be achieved by parsing a textual representation of a local protocol definition, or by projecting the local modules from a global module.

Once the module is obtained, then the specific local protocol definition can be retrieved. As a module may contain multiple local protocol definitions, it is important to select the one that represents the initial (or top level) protocol definition from the perspective of what needs to be monitored.

Once the exporter has been instantiated, invoke the export method with the selected local protocol definition. This will export the protocol definition into a state machine representation associated with the returned org.scribble.monitor.model.SessionType object. This object will be used in subsequent runtime monitoring session instances to define the behavioural type being verified.

It is currently out of the scope of the Scribble monitor to manage session instances. It is up to the application invoking the monitor to determine:

  • When a new session instance must be created and initialized

In this situation, the application should instantiated an instance of the org.scribble.monitor.SessionInstance class and supply it, along with the relevant org.scribble.monitor.model.SessionType object (defining the behavioural type to be monitored), to the initializeInstance method of the monitor, e.g.

org.scribble.monitor.Monitor monitor=new org.scribble.monitor.DefaultMonitor();
org.scribble.monitor.model.SessionType sessionType=....;

org.scribble.monitor.SessionInstance instance=new org.scribble.monitor.SessionInstance();

monitor.initializeInstance(sessionType, instance);

The new session instance should then be stored by the application, associated with some relevant key that can be used to retrieve it later.

  • When an existing session instance should be retrieved

If a key is obtained from the interaction being monitored, possibly by extracting relevant information from the message content or header, then it can be used to locate an existing session instance.

  • When a session instance is no longer required

The org.scribble.monitor.SessionInstance class has a method called hasCompleted which will return a boolean result, indicating whether the session instance has completed.

This should be checked after any processing of the session instance by the Scribble monitor. If this method returns true, then the session instance object should be removed from the set of application managed session instances.

When behaviour is detected, and an appropriate session instance object created or retrieved, then the behaviour can be verified using the Scribble monitor. Currently the following types of verification can be performed:

  • Message Sent

The following is an example of how to verify a sent message:

org.scribble.monitor.Monitor monitor=....;
org.scribble.monitor.model.SessionType sessionType=....;
org.scribble.monitor.SessionInstance instance=....;

String toRole=....;
org.scribble.monitor.Message mesg=new org.scribble.monitor.Message();

mesg.setOperator("placeOrder");
mesg.getTypes().add("{http://acme.org/ordermgmt}Order");
mesg.getValues().add("<order xmlns=\"http://acme.org/ordermgmt\" id=\"xyz\" />");

boolean result=monitor.sent(sessionType, instance, mesg, toRole);

The first lines are simply present to identify the types associated with the parameters to the sent method.

The next block would identify the toRole, i.e. the role that the message is being sent to, and the message details. The message includes an operator name, and a list of parameter types/values.

Note

Currently the values are not used, so it is not necessary to supply them, but in the future they will be used in the evaluation of assertions.

The monitor is then invoked using the sent method, supplying the session type and instance, as well as the message and to role. The result of this method is a boolean value indicating whether the monitor considered it to be valid or not.

  • Message Received

The following is an example of how to verify a received message:

org.scribble.monitor.Monitor monitor=....;
org.scribble.monitor.model.SessionType sessionType=....;
org.scribble.monitor.SessionInstance instance=....;

String fromRole=....;
org.scribble.monitor.Message mesg=new org.scribble.monitor.Message();

mesg.setOperator("placeOrder");
mesg.getTypes().add("{http://acme.org/ordermgmt}Order");
mesg.getValues().add("<order xmlns=\"http://acme.org/ordermgmt\" id=\"xyz\" />");

boolean result=monitor.received(sessionType, instance, mesg, fromRole);

The first lines are simply present to identify the types associated with the parameters to the received method.

The next block would identify the fromRole, i.e. the role that the message is been received from, and the message details. The message includes an operator name, and a list of parameter types/values.

Note

Currently the values are not used, so it is not necessary to supply them, but in the future they will be used in the evaluation of assertions.

The monitor is then invoked using the received method, supplying the session type and instance, as well as the message and from role. The result of this method is a boolean value indicating whether the monitor considered it to be valid or not.

Simulation is performed by defining a trace file, containing a sequence of actions (e.g. message transfers), and one or more simulation definitions identifying how each role should be simulated.

The trace model can be serialized as a JSON representation, e.g.

{
	"name":"RequestResponse-1",
	"steps":[{
		"type":"MessageTransfer",
		"message":{
			"operator":"buy",
			"types":["{http://scribble.org/example}OrderRequest"],
			"values":[""]
		},
		"fromRole":"Buyer",
		"toRoles":["Seller"]
	},{
		"type":"MessageTransfer",
		"message":{
			"operator":"buy",
			"types":["{http://scribble.org/example}OrderResponse"],
			"values":[""]
		},
		"fromRole":"Seller",
		"toRoles":["Buyer"]
	}],
	"simulations":[{
		"roleSimulators":{
			"Buyer":{
				"type":"MonitorRoleSimulator",
				"module":"scribble.examples.RequestResponse",
				"role":"Buyer",
				"protocol":"First"
			},
			"Seller":{
				"type":"MonitorRoleSimulator",
				"module":"scribble.examples.RequestResponse",
				"role":"Seller",
				"protocol":"First"
			}
		}
	}]
}

In this example trace file, two steps (or actions) are defined. The first is representing the order request being sent from the Buyer role to the Seller role. The second is representing an order response being returned from the Seller role to the Buyer role. The message component defined the operator, list of parameter types, and list of parameter values. The values are currently optional - however once assertions are supported, the value will need to be provided.

The simulations section defines a list of simulations. Each simulation defined an optional name, and a map of role names to role simulators.

In this example, the only role simulator type used is MonitorRoleSimulator which uses the Scribble monitor to verify that the message transfers defined in the trace conform to the Scribble protocol identified by the module, role and protocol.

Note

If a trace contains steps associated with roles that are not defined within the role simulator map, then those roles will be ignored when performing the simulation.