JBoss.orgCommunity Documentation

Chapter 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)

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 validator is the component responsible for evaluating a protocol module (org.scribble.model.Module) to determine if it conforms to a set of predefined rules (e.g. wellformedness conditions). As with the parser, any issues will be reported to the supplied org.scribble.logging.IssueLogger.

org.scribble.logging.IssueLogger logger=...;
org.scribble.resources.Resource res=...;
org.scribble.context.ModuleLoader loader=...;
org.scribble.model.Module module=...;

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

org.scribble.validation.ProtocolValidator pv=new org.scribble.validation.ProtocolValidator();

pv.validate(context, module, logger);

Most of the components used in this example validation were introduced in the parser section above. The new components in this example are the ProtocolValidator, which will perform the validation, and the ModuleContext. As discussed in a previous section, the module context provides access to members (e.g. type or protocol definitions) in a particular module, or associated module.

In the context of Scribble, projection is the term used to describe extracting the local endpoint behaviour of a role defined within a global protocol. The global protocol describes the interactions between multiple parties, whereas the local protocol described the interactions from a particular role’s perspective.

Being able to filter out just the responsibilies of an individual role, from the potentially complex set of interactions that may be defined in a global protocol between many participants, is important - primarily for being able to determine whether an implementation of that role (endpoint) is statically or dynamically conforming to the expected behaviour.

org.scribble.logging.IssueLogger logger=...;
org.scribble.resources.Resource res=...;
org.scribble.context.ModuleLoader loader=...;
org.scribble.model.Module module=...;

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

org.scribble.projection.ProtocolProjector projector=new org.scribble.projection.ProtocolProjector();

java.util.Set<Module> projected=projector.project(context, module, logger);

The code is very similar to the validation example, with the exception that we are creating a ProtocolProjector and the projection results in a set of modules representing the local protocol definitions.