...
Refer to the information above in the "running-tuscany" section to find the various options for installing these sample contributions. We present an single default approach for each sample as an example.
async
This sample demonstrates invocation of services offered in both synchronous and asynchronous forms. Asynchroncity is possible by either callback to or polling by the original service invoker.
sample-contribution-implementation-java-calculator-async
In the composite file src/main/resources/Calculator.composite the references "calculatorServiceRefSync" and "calculatorServiceRefAsync" make use of the alternative implementations of the Calculator service described in the CalculatorSync and CalculatorAsync components and implemented in the calculator.CalculatorServiceSyncImpl and calculator.CalculatorServiceAsyncImpljava classes.
embedded-jse-async-sample-launcher
demonstrates the SCA asynchronous progamming model in action as typified by services that are configured with the asyncInvocation intent. For example, from calculator-contribution
Code Block |
---|
@Remotable
@AsyncInvocation
public interface CalculatorServiceAsync {
void calculateAsync(Integer n1, ResponseDispatch<String> response);
}
|
A client component can access an asynchronous service either synchronously or asynchronously. Asynchronous reference interfaces also have a special form, again from calculator-contribution:Note that the launcher simply starts and stops a node running the contribution. Within the contribution the CalculatorClient java class, marked with the @EagerInit annotation, runs its calculate method (marked with the @Init annotation), thereby triggering the calculation service to be performed. The calculator service is actually performed by the injected instance of CalculatorServiceProxyImpl, which uses both of its references (one for the sync service, one for the async) to perform calculations. The calculations are then performed by instances of CalculatorServiceSyncImpl and CalculatorServiceAsyncImpl. Note that the Tuscany runtime views the following two interfaces as compatible.
Code Block |
---|
@Remotable public interface CalculatorServiceCalculateReferenceAsync { // Sync public String calculate(Integer i1); // Aysnc Poll public Response<String> calculateAsync(Integer i1); // Async Callback public StringFuture<String> calculatecalculateAsync(Integer i1, AsyncHandler<String> n1handler); } @Remotable @AsyncInvocation public interface CalculatorServiceAsync { void calculateAsync(Integer n1, ResponseDispatch<String> response); } |
binding-comet
calculator-contribution
This contribution defines synchronous and asynchronous component services and a client component which references both. During the test the client component exercise all three styles of reference interface operation against both the synchronous and asynchronous service.
The contribution can be built as follows:
Code Block |
---|
cd learning-more/async/calculator-contribution
ant
|
The contribution can be installed and the composite it contains run as follows
Code Block |
---|
cd running-tuscany/embedded-jse
ant sample-implementation-java-calculator-async-contribution
|
binding-comet
The Comet protocol Executing the command "mvn" in this sample project creates a web archive suitable for deployment to Tomcat. It makes use of the tuscany coment binding. Comet support allows a servlet to process IO asynchronously, receiving events when data is available for reading on the connection (rather than always using a blocking read), and writing data back on connections asynchronously (most likely responding to some event raised from some other source).to some event raised from some other source).
weather-webapp
Executing the command "mvn" in this sample project creates a web archive suitable for deployment to Tomcat. It makes use of the tuscany comet binding.
The webappcan be built as follows:
Code Block |
---|
cd learning-more/binding-commet/weather-webapp
mvn
|
The webapp can be installed and run as follows:
Code Block | ||
---|---|---|
cd learning-more/binding-commet/weather-webapp
cp target/sample-binding-comet-1.0.war <your_container_deployment-dir>
start the container as appropriate
| ||
Warning | ||
| ||
Needs expert review/update |
binding-jsonrpc
This sample demonstrates using a simple calculator service component which makes use of four services for the basic arithmetic functions. In this variant of the calculator sample you can see by looking in the src/main/resources/Calculator.composite xml file that the AddService is configured to be invoked using the json rpc protocol.
...