Title: Distributed Programming in Java
1Distributed Programming in Java
2Topics
- Concurrency
- Networking and event handling
- Baseline architecture
- Remote objects
- Web services
- Space-based computing
3Remote Objects
- What problems?
- location transparency
- What mechanisms and Java constructs?
- RMI
- What patterns?
- broker, client-server-dispatcher, proxy, and
active object
4Broker
- Separate communication infrastructure from
application functionality via a federation of
brokers that mediates all the communication
between the components of the system
5Broker
- Structure of the Broker pattern
6Separation of Behavior and Implementation
- Remote object behavior defined in an interface
(Service) - Remote object behavior implemented in a server
class (ServiceImpl) - Proxy sends request to remote object
Also see Broker pattern
7Print Server
- Remote server with callbacks to clients
8Active Object
- Objectify service invocations and let server
(active object) schedule the execution
9Applying the Pattern
1
3
2
10PrinterImpl
public void submit(PrinterListener listener,
PrintJob job) throws RemoteException try
job.submittedBy listener jobs.put(job)
catch (InterruptedException e) public
void run() while (true) try PrintJob
job (PrintJob) jobs.take() print(job)
// process next job job.submittedBy. //
get callback client completed(job) //
notify the client catch (Exception e)
11Web Services
- What problems?
- interoperability, deployment
- What mechanisms and Java constructs?
- SOAP, WSDL, Axis
- What patterns?
- service-oriented architecture, architecture
adapter, and business objects - business process, and publish-subscribe
- physical tiers, faux implementation
12Web Services
- What are web services? In essence, a technology
for application integration based on open
standards (HTTP, XML) - In what sense are they related to the Web
(capital W to refer to the WWW)? - In fact, deploying web services over the web is
more of an artefact than a necessity ... - What we care about is the web of services
13Web of Services
- Typical (recursive) composition of web services
as a web of services
14Service-Oriented Architecture
- Servers describe their services in a WSDL
document, and publish them (eg UDDI) - Clients bind to services (create proxies from
WSDL), and invoke using SOAP
15Architecture Adapter
- WS frameworks such as Axis allow you to be fully
WS-agnostic to access WS from Java use method
calls via architecture adapters
16Business Objects
- Objects are marginalized in the SOA
- Web services require a flat object model
- If objects are passed as parameters, they need to
be implemented as beans - In Axis, beans can be defined through
ltbeanmappinggt tags in WSDD - Also applied to flow logic by moving it out from
the programming language (BPEL !)
17Using Axis Step by Step
- Provide a Java interface or class that describes
the service interface - Create WSDL using Java2WSDL tool
- Create bindings through WSDL2Java tool
- Implement the service interface
- Deploy the service
- Implement clients using generated stubs
18Retailer
public void submitOrder(OrderHolder orderHolder)
throws NoSuchProductException,
NoItemCanBeShipped ... SupplierService
service new SupplierServiceLocator() //
contact the first supplier Supplier port1
service.getSupplier( new URL("http//localhost9
091/axis/services/Supplier")) port1.placeOrder(o
rderHolder) // check if order has been
satisfied if (!orderSatisfied(orderHolder.valu
e)) Supplier port2 service.getSupplier( n
ew URL("http//localhost9092/axis/services/Suppli
er")) port2.placeOrder(orderHolder) ...
19Deployment
ltdeployment xmlns"http//xml.apache.org/axis/wsdd
/" xmlnsjava"http//xml.apache.org/axis/wsdd/p
roviders/java"gt ltservice name"Retailer"
provider"javaRPC"gt ltparameter
name"className" value"a3.retailer.RetailerImpl"/
gt ltparameter name"scope" value"Application"/gt
ltparameter name"allowedMethods"
value"submitOrder"/gt ltbeanMapping
qname"nsOrder" xmlnsns"urnRetailer"
languageSpecificType"javaa3.util.Order"/gt
ltoperation name"submitOrder"gt ltparameter
name"order" mode"INOUT"/gt lt/operationgt
ltbeanMapping qname"nsNoSuchProductException"
xmlnsns"urnRetailer" languageSpecificType"jav
aa3.retailer.NoSuchProductException"/gt
ltbeanMapping qname"nsNoItemCanBeShipped"
xmlnsns"urnRetailer" languageSpecificType"jav
aa3.retailer.NoItemCanBeShipped"/gt lt/servicegt
lt/deploymentgt
20Business Process
21Participants
- BusinessProcess
- Interface to the business process
- BusinessProcessImpl
- Logic of the business process, which can be a
simple ActivitySequence - BusinessActivity
- Unit of work in the business process
- Data
- Captures side effects of business activities (in
this pattern a common pool)
22Publish-Subscribe
23Participants
- Subscriber
- Interface that event service calls to notify a
client about an event it subscribed for - SubscriberImpl register with distinct URLs for
receiving update messages - EventService
- Subscribers can subscribe to events
- Publishers can publish events, and events and
data will be forwarded to subs
24Space-Based Computing
- What problems?
- coordination
- What mechanisms and Java constructs?
- tuple spaces
- What patterns?
- supervisor-worker
25Space-Based Computing
- A space is a high-level coordination tool for
glueing agents into an application - Different programming paradigm
- Instead of relying on message-passing,
- applications cooperate through the flow of
objects in and out of spaces - Space-based models (JavaSpaces, TSpaces) based on
tuple space concepts
26CameraBuyer
public class CameraBuyer public static void
main(String args) try System.setSecurit
yManager(new RMISecurityManager()) TupleSpace
space (TupleSpace) Naming.lookup("rmi//"
args0 "/" args1) String make
args2 Tuple cameraTemplate new
Tuple("camera", new Field("make",
make), new Field("price", Integer.class))
System.out.println("Buyer.in "
cameraTemplate) Tuple camera
space.in(cameraTemplate) System.out.println("M
atch " camera) System.out.println("Camera.p
rice " camera.getField("price"))
catch (Exception e) System.err.println(e)
27Agenda Parallelism
- Work units organized around activities
- Processes masters and workers
Master
Workers