VII.1 Component based distributed systems
Jan 08, 2016
VII.1
Component based distributed systems
VII.2
Component technologies under Java
• Traditional object-oriented languages (Smalltalk, C++, but also Java) enable re-use only in limited mode (dependent on specifics of superior classes etc.)
• Therefore: advanced encapsulation techniques on the basis of components:– Interface (s)
– explicit management of system-tied properties (for instance, corresponding to transactions and security)
– Events (optional)
• Concrete approaches under Java:– JavaBeans (Client)
– Enterprise JavaBeans (Server)
• Alternative: .NET-Components
VII.3
Properties of JavaBeans
• Introspection: inspection of the Bean-structure via Tools (via BeanInfo-Class respectively Patterns)
• Customization: adaptability of appearance and behavior
• Events: interaction between Beans
• Properties: attributes of Beans
• Persistence: persistent saving and re-use of Beans
More powerful than conventional class approach
VII.4
JavaBeans: component model
Public Methods of the ObjectEvent classes and
EventListener-classes
for Java Event Model
Constituents of the local status (Attributes):
• property (get/set)• indexed Property• bound property• constrained property
JAR Archive
- Classes as bytecode(also Events, Listener) - optional resources (data, media objects)
for graphic tools for definition of Properties
JavaBean Components
Introspection: information about Bean
(for instance, Icon, Methods, Events, Description)
VII.5
Development support
• Beans Development Kit (BDK) in co-operation with JDK
• Integration in other tools like for instance, IBM Websphere Studio, BEA Weblogic Workshop
• Graphical processing of Beans, Windows with List of the installed Beans, Beanbook, Editors
• Integration of ActiveX-Controls in JavaBeans (and vice versa) possible, however with limitations, for instance, corresponding to security model
VII.6Development support: example
VII.7
Enterprise JavaBeans
• Server component model
• Non-visual components, distribution
• Container as Runtime-Environment (system resources, services)
• Composition of components via Tools
• Supporting of transactional applications
• Mapping of component interactions on protocols like CORBA IIOP / RMI / SOAP
VII.8
Usage scenario
Goal: transfer of processing logic to the server;
implicit transactions
Client 1
Client 2
Distributed transactions
EJB
EJB
Transactionmonitor/DBMS
EJB Container
EJB-Server
Java RMI
VII.9EJB-Container
• Management of life cycle of Enterprise Bean• Providing of a Factory-interface for creation of new EJB-instances
(HomeInterface)• Generating of EJBObject-interface for remote use of Bean-Methods
(RemoteInterface)• Additionally: LocalInterface for efficient Comm. within a Container,
Realization via Application Server and Transaction monitors (for instance, BEA Weblogic, IBM WebSphere etc.)
Client
EJBObject
EJBFactoryEnterprise
Bean
methods
ejbCreateejbLookup
ejbDestroyDeveloped byBean Provider
EJB-Container Transaction mgmtState MgmtSecurity
<methods>
create(), finderXXX()
lookup(),destroy ()
Supported by EJBContainer
VII.10EJB: Session Beans and Entity Beans
• Session Beans: non-persistent; control of dialogues with Business-Objects of the application; interface to the Client(frequently one Session Bean per Client); Variants: Stateless Session Bean / Stateful Session Bean
• Entity Beans: persistent; represent Business-Objects with interface to data level; unique primary key with Mapping to data base; integration in transactions
Client
Session Bean (for instance,
Customer Support)
Entity Bean (for instance,
Account)
EJB-Container
VII.11
Enterprise JavaBeans
Session BeansMessage-driven
beansEntity Beans
StatelessSession Beans
StatefulSession Beans
Container Managed
Persistence
Bean Managed
Persistence
Stateless Service,
for instance,
Search engine
Processing with
internal state,
for instance, shopping
Durable data,
automatic Per-
sistence mechan.
Durable data,
own persistence
decision of the appl.
Multicast-Communication (1:n)
VII.12Persistence
Persistent storage of contents of Entity Beans
Bean Managed PersistenceContainer Managed Persistence
• Bean itself provides storage, for instance, via JDBC• Precise knowledge about life cycle necessary• Container generates a transaction to keep the data base consistent
• Container saves Bean Attribute, Realization for instance via EJB QL (Query Language)• Bean is informed about state of data by Container• Simple to use, as a rule preferable
Possible alternatives: JDO (Java Data Objects): Mapping of complex data objects between Database and Container
VII.13
Installation of Enterprise JavaBeans
• Delivering as JAR-files
• Constituents:– Bean-Components
– Deployment Descriptor ( (static) settings of security properties, transaction properties, environment properties, persistence properties)
– Home Interface (for instance, create, destroy etc.)
– Remote Interface (call interface)
• Instantiation via EJB-Factory
• Recording of properties of the installed EJBs in Directory Service via JNDI
VII.14Deployment Descriptor: example
<ejb-jar> <enterprise-beans> <session>
<ejb-name>bank</ejb-name> <home>BankHome</home> <remote>BankRemote</remote><ejb-class>BankBean</ejb-class> <transaction-type>Container</transaction-type> <session-type>Stateful</session-type>
<resource-ref> ...
</resource-ref> </session> </enterprise-beans> <assembly-descriptor>
......... </assembly-descriptor> </ejb-jar>
VII.15
Interface-Definitions: example
import javax.ejb.*;
import java.rmi.RemoteException;
public interface BankHome extends EJBHome {
public BankSession create() throws CreateException, RemoteException;
}
import javax.ejb.*;
import java.rmi.RemoteException;
public interface BankSession extends EJBObject {
public void transferRequest(AccountIdentification accountident, float amount, TransferOrder transOrder) throws RemoteException, TransferException;
}
VII.16
Implementation: exampleimport java.rmi.*;import javax.ejb.*;public class BankSession implements SessionBean { public void ejbCreate()throws RemoteException,CreateException{ } public void transferRequest(AccountIdentification accountIdent, float amount, TransferOrder transOrder) throws
RemoteException,TransferException { Account accountFrom = AccountHome.findAccountByNumber(accountIdent.accountNumber); //hold account accountFrom.checkAccount(accountIdent.pin, accountIdent.name); //proof access rights try { BankHome.findBankByBLZ(transOrder.bankSortingCodeNumber); } catch(FinderException) { throw new TransferException(„Bank not found“); } Account accountTo = AccountHome.findAccountByNumber(transOrder.accountNumber); accountFrom.debit(amount); accountTo.credit(amount); } public void ejbActivate()throws RemoteException { } public void ejbPassivate()throws RemoteException { } public void ejbRemove()throws RemoteException { } public void setSessionContext(SessionContext sessionContext) throws RemoteException { this.sessionContext = sessionContext; }}
VII.17
Localization
1. Home Interface implemented by Home Object
2. Home Object registered by Name Service
3. Client sends query to Name Service
4. Client obtains Reference5. Client calls Home Object6. Forwarding to Bean7. Create Bean Instance8. Assign Reference to EJB
Object9. Call business logic methods
VII.18
Transaction management
• Requirements: Distributed Transactions with 2-Phase-Commit must be supported by the basic infrastructure (EJB-Server)
• Use of Java Transaction Service (JTS), i.e. Java Binding of CORBA OTS (Object Transaction Service)
• Different transaction modes (for instance, optional, compulsory or implicit transactions)
VII.19
Transaction control
TX_NOT_SUPPORTED: Bean cannot be used inside of transactions (temporary suspension of a transaction)
TX_SUPPORTS: Using of the Bean in transaction context possible
TX_REQUIRED: Transaction possible; implicit starting of a new transaction (if there are no active transactions)
TX_REQUIRES_NEW: Transaction compulsory, new transaction started during method call of the Bean (temporary suspension of a existing transaction)
TX_MANDATORY: Transaction compulsory, must already exist before (otherwise exception notification)
VII.20
Security aspects• Implicit mechanisms which are controlled via so called
Security Descriptor Objects, relatively simply;
Example:
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.2//EN“ "http://java.sun.com/j2ee/dtds/ejb_1_2.dtd">
<ejb-jar>
...
<assembly-descriptor>
<security-role> <role-name>Administrator</role-name> </security-role>
<method-permission>
<role-name>Administrator</role-name>
<method>
<ejb-name>BankBean</ejb-name> <method-name>*</method-name>
</method>
</method-permission>
</assembly-descriptor>
</ejb-jar>
VII.21
• Authentication (user name/ password)
• Authorization (role-based, configurable but no Instance- based access control)
• Basis: JAAS (Java Authentication and Authorization Service)
• Integrity and confidentiality via encryption using SSL and TSL
• Administration of security services via proprietary decisions inside the Application Server
Security aspects: general overview
VII.22
Java Messaging Service (JMS)
• Standard based Messaging-Programming interface• Mapping on products like MQ Series• Support of communication models:
– Point-to-Point
– Publish/Subscribe (also several receivers - Multicast)
• Part of Java Enterprise Edition• Integrable with JTS (Java Transaction Service), JNDI (Java Naming and
Directory Interface) and EJB (Enterprise Java Beans)• Trusted, heterogenic Program-to-Program-communication• Asynchronous with optional confirmations• Atomic delivery of messages and persistent storage possible
VII.23
JMS: Example
Sender („Supplier“)
Queue bankQueue = (Queue) naming.lookup(“Bank“);
QueueSender sender = session.createSender(bankQueue);
TextMessage statusMessage = session.createTextMessage(“Statusabfrage“);
sender.send(statusMessage);
Receiver („Consumer“)
Queue bankQueue = (Queue) naming.lookup(“Bank“);
QueueReceiver receiver = session.createReceiver(bankQueue);
TextMessage statusMessage = (TextMessage) receiver.receive();
...
statusMessage.acknowledge(); // optional confirmation to sender
VII.24
Integration concept
Client
TransactionMonitor JM
AP
I
JND
I
JTS
JID
L
JMS
JDB
C
Enterprise JavaBeans
BusinessApplication
DatabaseIIOP / RMI, SOAP,further protocols
• JMAPI - Java Management API• JNDI - Java Naming & Directory
Services• JTS - Java Transactional Services• JIDL - Java IDL• JMS - Java Messaging Service• JDBC - Java Database Connectivity• JDO – Java Data Objects
Java as integration technology,however extensive infrastructure services necessary
JDO