New School Enterprise Architecture
Upcoming SlideShare
Loading in...5
×
 

New School Enterprise Architecture

on

  • 376 views

Dank des aktuellen Java-EE-Stacks lassen sich heute Architekturen realisieren, von denen man zu Zeiten von J2EE nur träumen durfte. Nahezu losgelöst von technologischen und schichtenbedingten ...

Dank des aktuellen Java-EE-Stacks lassen sich heute Architekturen realisieren, von denen man zu Zeiten von J2EE nur träumen durfte. Nahezu losgelöst von technologischen und schichtenbedingten Restriktionen kommen völlig neue Patterns zum Tragen. Im Gegenzug dazu kann auf "lieb gewonnene" Workarounds - aka J2EE-Pattern - verzichtet werden. Die Session gibt einen Einblick in die vielfältigen Möglichkeiten und möchte so zu neuen Denkmustern im Java-EE-Architekturdesign anregen.

Speaker: Lars Röwekamp

5. November 2013 |W-JAX München

Statistics

Views

Total Views
376
Views on SlideShare
332
Embed Views
44

Actions

Likes
0
Downloads
1
Comments
0

1 Embed 44

http://www.openknowledge.de 44

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

New School Enterprise Architecture New School Enterprise Architecture Presentation Transcript

  • Java @mobileLarson @_openknowledge New School Enterprise Architecture Lars Röwekamp | open knowledge GmbH
  • New chool S Was sie mitnehmen sollten ... Enterprise Architecture „Fachlichkeit im Fokus!“ „Java EE 6 und 7 erlauben neben Infrastructure Injection auch Business Injection.“
  • New chool S Was sie mitnehmen sollten ... Enterprise Architecture „Fachlichkeit im Fokus!“ „Java EE 6 und 7 erlauben neben Infrastructure Injection auch Business Injection.“
  • Ok, was heißt das?
  • New chool S Der Use Case Enterprise Architecture Call Center Anwendung ‣ Kunde neu erfassen und speichern ‣ Call Center Agent als Audit Info mit speichern ‣ Begrüßungs-EMail an Neukunden versenden ‣ Kunde löschen inkl. Sicherheitsabfrage ‣ Call Center Agent als Audit Info mit speichern ‣ EMail an ehemaligen Kunden versenden
  • New chool S Der Use Case Enterprise Architecture Call Center Anwendung ‣ Kunde neu erfassen und speichern ‣ Call Center Agent als Audit Info mit speichern ‣ Begrüßungs-EMail an Neukunden versenden ‣ Kunde löschen inkl. Sicherheitsabfrage ‣ Call Center Agent als Audit Info mit speichern ‣ EMail an ehemaligen Kunden versenden
  • Old School
  • New chool S Old School Ansatz Enterprise Architecture Use Case: Kunde neu erfassen ‣ JSF View ruft UI Controller via U-EL ‣ UI Controller ruft CustomerService EJB ‣ UI Controller ruft MailService EJB
  • New chool S Old School Ansatz Enterprise Architecture JSF View CreateCustomer UI Service Data
  • New chool S Old School Ansatz Enterprise Architecture JSF View CreateCustomer CustService MailService UI Service Data
  • New chool S Old School Ansatz Enterprise Architecture JSF View UI CreateCustomer CustService Customer MailService Mail Service Data
  • New chool S Old School Ansatz Enterprise Architecture // JSF UI Controller @javax.faces.bean.RequestScoped @javax.faces.bean.ManagedBean(name=“createCustomerController“) public class CreateCustomerController { @EJB private CustomerService customerService; @EJB private MailService mailService; private Customer customer; public String createCustomer() { customerService.create(customer); mailService.sendWelcomeMail(customer); return CUSTOMER_CREATED; } // getter / setter for customer ... }
  • New chool S Old School Ansatz Enterprise Architecture // JSF UI Controller @javax.faces.bean.RequestScoped @javax.faces.bean.ManagedBean(name=“createCustomerController“) public class CreateCustomerController { @EJB private CustomerService customerService; @EJB private MailService mailService; private Customer customer; Und was ist mit dem Call Center Agent? public String createCustomer() { customerService.create(customer); mailService.sendWelcomeMail(customer); return CUSTOMER_CREATED; } // getter / setter for customer ... }
  • New chool S Old School Ansatz Enterprise Architecture Use Case: Kunde neu erfassen ‣ JSF View ruft UI Controller via U-EL ‣ UI Controller ruft CustomerService EJB ‣ UI Controller ruft MailService EJB ‣ UI Controller ruft AuthenticationController
  • New chool S Old School Ansatz Enterprise Architecture JSF View CreateCustomer AuthController
  • New chool S Old School Ansatz Enterprise Architecture JSF View CreateCustomer AuthController AuthService CCAgent
  • New chool S Old School Ansatz Enterprise Architecture JSF View CreateCustomer AuthController CustService AuthService Customer CCAgent
  • New chool S Old School Ansatz Enterprise Architecture JSF View CreateCustomer AuthController CustService MailService AuthService Customer Mail CCAgent
  • New chool S Old School Ansatz Enterprise Architecture // JSF UI Controller @javax.faces.bean.RequestScoped @javax.faces.bean.ManagedBean(name=“createCustomerController“) public class CreateCustomerController { // inject CustomerService and MailService via @EJB @ManagedProperty(value=“#{authenticationController}“) private AuthenticationController authController; ... public String createCustomer() { CallCenterAgent currentCallCenterAgent; currentCallCenterAgent = authController.getLoggedInUser(); customer.setAuditInformation(currentCallCenterAgent); customerService.create(customer); mailService.sendWelcomeMail(customer); return CUSTOMER_CREATED; } // getter / setter for customer ... }
  • New chool S Old School Ansatz Enterprise Architecture // JSF UI Controller @javax.faces.bean.RequestScoped @javax.faces.bean.ManagedBean(name=“createCustomerController“) public class CreateCustomerController { // inject CustomerService and MailService via @EJB @ManagedProperty(value=“#{authenticationController}“) private AuthenticationController authController; ... public String createCustomer() { CallCenterAgent currentCallCenterAgent; currentCallCenterAgent = authController.getLoggedInUser(); customer.setAuditInformation(currentCallCenterAgent); customerService.create(customer); mailService.sendWelcomeMail(customer); return CUSTOMER_CREATED; } // getter / setter for customer ... } Ok, aber wo wird die Transaktion aufgezogen?
  • New chool S Old School Ansatz Enterprise Architecture Use Case: Kunde neu erfassen ‣ JSF View ruft UI Controller via U-EL ‣ UI Controller ruft AuthenticationController ‣ UI Controller ruft CustomerFacade EJB ‣ Delegate EJB ruft CustomerService EJB ‣ Delegate EJB ruft MailService EJB
  • New chool S Old School Ansatz Enterprise Architecture CreateCustomer AuthController AuthService CCAgent
  • New chool S Old School Ansatz Enterprise Architecture CreateCustomer AuthController CustFacade AuthService CCAgent
  • New chool S Old School Ansatz Enterprise Architecture CreateCustomer AuthController TX CustFacade AuthService CCAgent
  • New chool S Old School Ansatz Enterprise Architecture CreateCustomer AuthController TX CustFacade CustService MailService AuthService Customer Mail CCAgent
  • New chool S Old School Ansatz Enterprise Architecture // JSF UI Controller @javax.faces.bean.RequestScoped @javax.faces.ManagedBean(name=“createCustomerController“) public class CreateCustomerController { @EJB private CustomerFacade customerFacade; @ManagedProperty(value=“#{authenticationController}“) private AuthenticationController authController; private Customer customer; public String createCustomer() { CallCenterAgent currentCallCenterAgent; currentCallCenterAgent = authController.getLoggedInUser(); customerFacade.create(customer, currentCallCenterAgent); return CUSTOMER_CREATED; } ... }
  • New chool S Old School Ansatz Enterprise Architecture // EJB Service Facade @Stateless public class CustomerFacade { @EJB private CustomerService customerService @EJB private MailService mailService; // Transactional by default public void createCustomer(Customer customer, CallCenterAgent currentCallCenterAgent) { customer.setAuditInformation(currentCallCenterAgent); customerService.create(customer); mailService.sendWelcomeMail(customer); } ... }
  • New chool S Old School Ansatz Enterprise Architecture // EJB Service Facade @Stateless public class CustomerFacade { Fühlt sich nicht gut an! Alternativen sind aber auch nicht viel schöner! @EJB private CustomerService customerService @EJB private MailService mailService; // Transactional by default public void createCustomer(Customer customer, CallCenterAgent currentCallCenterAgent) { customer.setAuditInformation(currentCallCenterAgent); customerService.create(customer); mailService.sendWelcomeMail(customer); } ... }
  • New chool S Old School Ansatz Enterprise Architecture JSF View CreateCustomer AuthController AuthService CCAgent
  • New chool S Old School Ansatz Enterprise Architecture JSF View CreateCustomer CustService AuthController AuthService CCAgent
  • New chool S Old School Ansatz Enterprise Architecture JSF View CreateCustomer AuthController CustService MailService AuthService Customer Mail CCAgent
  • New chool S Old School Ansatz Enterprise Architecture Use Case: Kunde löschen ‣ JSF View ruft UI Controller via U-EL ‣ UI Controller „merkt“ sich Kunde in Session ‣ UI Controller navigiert zu Bestätigungsseite ‣ UI Controller bekommt Bestätigung ‣ UI Controller ruft CustomerService EJB ‣ ...
  • New chool S Old School Ansatz Enterprise Architecture JSF View 1 DeleteCustomer UI Service Data
  • New chool S Old School Ansatz Enterprise Architecture JSF View 1 JSF View 2 DeleteCustomer UI Service Data
  • New chool S Old School Ansatz Enterprise Architecture JSF View 1 JSF View 2 UI DeleteCustomer CustService Customer MailService Mail Service Data
  • New chool S Old School Ansatz Enterprise Architecture // JSF UI Controller @javax.faces.bean.SessionScoped @javax.faces.bean.ManagedBean(name=“deleteCustomerController“) public class DeleteCustomerController implements Serializable { // @EJB CustomerService, AuthenticationService and MailService private Customer customerToDelete; public String askForDeletion(Customer customer) { customerToDelete = customer; return SHOW_DELETE_CONFIRMATION; } public String deleteCustomer() { ... // call backend services and delete customer return CUSTOMER_DELETED; } ... }
  • New chool S Old School Ansatz Enterprise Architecture // JSF UI Controller @javax.faces.bean.SessionScoped @javax.faces.bean.ManagedBean(name=“deleteCustomerController“) public class DeleteCustomerController implements Serializable { // @EJB CustomerService, AuthenticationService and MailService private Customer customerToDelete; public String askForDeletion(Customer customer) { customerToDelete = customer; return SHOW_DELETE_CONFIRMATION; } public String deleteCustomer() { ... // call backend services and delete customer return CUSTOMER_DELETED; } ... } Wann kommt der Datensatz aus der Session wieder raus?
  • New chool S Old School Ansatz Enterprise Architecture Problemkind Schichtenmodell ‣ UI Controller via JSF Managed Beans ‣ Service Facade und Services via EJBs ‣ Persistenz via EntityManager und Entities ‣ Alles nur Infrastruktur! ‣ Wo steckt eigentlich die fachliche Domain?
  • New chool S Old School Ansatz Enterprise Architecture JSF View @ManagedBean (JSF) UI TX Session EJB EntityManager Session EJB Entity Service Data
  • New chool S Alternativer Ansatz Enterprise Architecture JSF View UseCaseController UI TX Business Object Business Object Business Object Domain
  • New chool S TX Alternativer Ansatz Enterprise Architecture JSF View UseCaseController Business Object Business Object Business Object UI Domain
  • Migration Guide
  • New School
  • New chool S Migration Guide Enterprise Architecture Migration Steps: ‣ „Technology Independence“ ‣ „@Inject Business Objects“ ‣ „No more EJBs for Transactions only“ ‣ „No more pumped up Sessions“ ‣ „No more Infrastructure in Views“ ‣ „No more doAll( ) Business Methods“
  • New chool S Migration Guide Enterprise Architecture Migration Steps: ‣ „Technology Independence“ ‣ „@Inject Business Objects“ ‣ „No more EJBs for Transactions only“ ‣ „No more pumped up Sessions“ ‣ „No more Infrastructure in Views“ ‣ „No more doAll( ) Business Methods“
  • New chool S Technology Independence Migration Guide // JSF UI Controller @javax.faces.bean.RequestScoped @javax.faces.bean.ManagedBean(name=“createCustomerController“) public class CreateCustomerController { // inject CustomerService and MailService via @EJB @EJB private AuthenticationService authenticationService; private Customer customer; public String createCustomer() { currentCallCenterAgent = authenticationService.getLoggedInUser(); customer.setAuditInformation(currentCallCenterAgent); customerService.create(customer); mailService.sendWelcomeMail(customer); return CUSTOMER_CREATED; } // getter / setter for customer ... }
  • New chool S Technology Independence Migration Guide // JSF UI Controller @javax.enterprise.context.RequestScoped @javax.inject.Named(“createCustomerController“) public class CreateCustomerController { // inject CustomerService and MailService via @Inject @Inject private AuthenticationService authenticationService; private Customer customer; public String createCustomer() { currentCallCenterAgent = authenticationService.getLoggedInUser(); customer.setAuditInformation(currentCallCenterAgent); customerService.create(customer); mailService.sendWelcomeMail(customer); return CUSTOMER_CREATED; } // getter / setter for customer ... }
  • New chool S Migration Guide Enterprise Architecture Migration Steps: ‣ „Technology Independence“ ‣ „@Inject Business Objects“ ‣ „No more EJBs for Transactions only“ ‣ „No more pumped up Sessions“ ‣ „No more Infrastructure in Views“ ‣ „No more doAll( ) Business Methods“
  • New chool S @Inject @Current CallCenterAgent Migration Guide CDI Producer Methods & Fields ‣ Factory Method Pattern für Objekte ‣ @Producer als Mittel zum Zweck ‣ @Qualifier als Mittel zur Typ-Qualifizierung ‣ ermöglicht fachliche Injektion
  • New chool S @Inject @Current CallCenterAgent Migration Guide // JSF UI Controller @javax.enterprise.context.RequestScoped @javax.inject.Named(“createCustomerController“) public class CreateCustomerController { // inject CustomerService and MailService via @Inject @Inject private AuthenticationService authenticationService; private Customer customer; public String createCustomer() { currentCallCenterAgent = authenticationService.getLoggedInUser(); customer.setAuditInformation(currentCallCenterAgent); customerService.create(customer); mailService.sendWelcomeMail(customer); return CUSTOMER_CREATED; } // getter / setter for customer ... }
  • New chool S @Inject @Current CallCenterAgent Migration Guide // JSF UI Controller @javax.enterprise.context.RequestScoped @javax.inject.Named(“createCustomerController“) public class CreateCustomerController { // inject CustomerService and MailService via @Inject @Inject @Current private CallCenterAgent currentCallCenterAgent; private Customer customer; public String createCustomer() { customer.setAuditInformation(currentCallCenterAgent); customerService.create(customer); mailService.sendWelcomeMail(customer); return CUSTOMER_CREATED; } // getter / setter for customer ... }
  • New chool S @Inject @Current CallCenterAgent Migration Guide // Authentication Controller @SessionScoped @Named(“authenticationController“) public class AuthenticationController implements Serializable { private CallCenterAgent authenticatedCallCenterAgent; public String authenticate() {...} @Produces @Current public CallCenterAgent getAuthenticatedCallCenterAgent() { return authenticatedCallCenterAgent; } ... }
  • New chool S @Inject @Current CallCenterAgent Migration Guide // Authentication Controller @SessionScoped @Named(“authenticationController“) public class AuthenticationController implements Serializable { private CallCenterAgent authenticatedCallCenterAgent; public String authenticate() {...} @Produces @Current public CallCenterAgent getAuthenticatedCallCenterAgent() { return authenticatedCallCenterAgent; } ... } @Inject @Current CallCenterAgent
  • New chool S @Inject @Current CallCenterAgent Migration Guide // Authentication Controller @SessionScoped @Named(“authenticationController“) public class AuthenticationController implements Serializable { private CallCenterAgent authenticatedCallCenterAgent; public String authenticate() {...} @Produces @Current @RequestScoped public CallCenterAgent getAuthenticatedCallCenterAgent() { return authenticatedCallCenterAgent; } ... } @Inject @Current CallCenterAgent
  • New chool S @Inject @Current CallCenterAgent Migration Guide package de.openknowldege.qualifier import ... // self-made qualifier to indicate current instance of something @Qualifier @Target({TYPE, METHOD, PARAMETER, FIELD}) @Retention(RUNTIME) public @interface Current{ }
  • New chool S @Inject @Current CallCenterAgent Migration Guide // JSF UI Controller @javax.enterprise.context.RequestScoped @javax.inject.Named(“createCustomerController“) public class CreateCustomerController { // inject CustomerService and MailService via @Inject @Inject @Current private CallCenterAgent currentCallCenterAgent; private Customer customer; public String createCustomer() { customer.setAuditInformation(currentCallCenterAgent); customerService.create(customer); mailService.sendWelcomeMail(customer); return CUSTOMER_CREATED; } // getter / setter for customer ... }
  • New chool S @Inject @Current CallCenterAgent Migration Guide // JSF UI Controller @javax.enterprise.context.RequestScoped @javax.inject.Named(“createCustomerController“) public class CreateCustomerController { // inject CustomerService and MailService via @Inject @Inject @Current private CallCenterAgent currentCallCenterAgent; private Customer customer; public String createCustomer() { customer.setAuditInformation(currentCallCenterAgent); customerService.create(customer); mailService.sendWelcomeMail(customer); return CUSTOMER_CREATED; } // getter / setter for customer ... }
  • New chool S @Inject @Current CallCenterAgent Migration Guide // Customer Service EJB @Stateless public class CustomerService { @Inject @Current private CallCenterAgent currentCallCenterAgent; @PersistenceContext private EntityManager em; // transactional by default public void createCustomer(Customer customer) { customer.setAuditInformation(currentCallCenterAgent); em.persist(customer); } ... }
  • New chool S Migration Guide Enterprise Architecture Migration Steps: ‣ „Technology Independence“ ‣ „@Inject Business Objects“ ‣ „No more EJBs for Transactions only“ ‣ „No more pumped up Sessions“ ‣ „No more Infrastructure in Views“ ‣ „No more doAll( ) Business Methods“
  • New chool S No more EJBs Migration Guide Injizierbare CDI Ressourcen ‣ normale Java Klassen - optional mit @Named und/oder @Qualifier markiert ‣ EJBs - Stateless, Stateful, Singleton ‣ sonstige Java EE Resources UserTransaction, PersistenceContext, ...
  • New chool S No more EJBs Migration Guide // Customer Service EJB @Stateless public class CustomerService { @Inject @Current private CallCenterAgent currentCallCenterAgent; @PersistenceContext private EntityManager em; // transactional by default public void createCustomer(Customer customer) { customer.setAuditInformation(currentCallCenterAgent); em.persist(customer); } ... }
  • New chool S No more EJBs Migration Guide // Customer Service EJB - no annotation required! @Stateless public class CustomerService { @Inject @Current private CallCenterAgent currentCallCenterAgent; @PersistenceContext private EntityManager em; // transactional by default public void createCustomer(Customer customer) { customer.setAuditInformation(currentCallCenterAgent); em.persist(customer); } ... }
  • New chool S No more EJBs Migration Guide // Customer Service EJB - no annotation required! @Stateless public class CustomerService { @Inject @Current private CallCenterAgent currentCallCenterAgent; @PersistenceContext private EntityManager em; // transactional by default public void createCustomer(Customer customer) { customer.setAuditInformation(currentCallCenterAgent); em.persist(customer); } ... } Ok, aber wo bekommen wie die Transaktion jetzt her?
  • New chool S No more EJBs Migration Guide // Customer Service EJB - no annotation required! @Stateless public class CustomerService { @Inject @Current private CallCenterAgent currentCallCenterAgent; @PersistenceContext private EntityManager em; @Transactional public void createCustomer(Customer customer) { customer.setAuditInformation(currentCallCenterAgent); em.persist(customer); } ... }
  • New chool S No more EJBs Migration Guide // Customer Service EJB - no annotation required! @Stateless public class CustomerService { @Inject @Current private CallCenterAgent currentCallCenterAgent; @PersistenceContext private EntityManager em; @Transactional public void createCustomer(Customer customer) { customer.setAuditInformation(currentCallCenterAgent); em.persist(customer); } ... } JTA 1.2 oder DeltaSpike oder als Self-Made CDI-Interceptor
  • New chool S No more EJBs Migration Guide @InterceptorBinding @Target({TYPE, METHOD}) @Retention(RUNTIME) public @interface Transactional { @Nonbinding public TransactionalType value() default TransactionalType.REQUIRED; }
  • New chool S No more EJBs Migration Guide @Transactional @Interceptor public class TransactionAdvice { @Inject private UserTransaction utx; @AroundInvoke public Object applyTransaction( InvocationContext ic) throws Throwable { ... ic.proceed(); ... } *XML registration omitted // 1. implement utx.begin() // 2. call original method // 3. implement utx.commit()
  • New chool S No more EJBs Migration Guide // Customer Service - no annotation required! public class CustomerService { @Inject @Current private CallCenterAgent currentCallCenterAgent; @PersistenceContext private EntityManager em; @Transactional public void createCustomer(Customer customer) { customer.setAuditInformation(currentCallCenterAgent); em.persist(customer); } ... }
  • New chool S No more EJBs Migration Guide // Customer Service - no annotation required! public class CustomerService { @Inject @Current private CallCenterAgent currentCallCenterAgent; @PersistenceContext private EntityManager em; @Transactional public void createCustomer(Customer customer) { customer.setAuditInformation(currentCallCenterAgent); em.persist(customer); } ... }
  • New chool S No more EJBs Enterprise Architecture JSF View UsecaseController UI TX Service EntityManager Service Entity Service Data
  • New chool S No more EJBs Enterprise Architecture JSF View TX UsecaseController Service EntityManager Service Entity UI Service Data
  • New chool S No more EJBs Migration Guide // JSF UI Controller @javax.enterprise.context.RequestScoped @javax.inject.Named(“createCustomerController“) public class CreateCustomerController { @Inject private CustomerService customerService; private Customer customer; @Transactional public String createCustomer() { customerService.create(customer); ... // some additional use case “tx“ related work return CUSTOMER_CREATED; } // getter / setter for customer ... }
  • New chool S Migration Guide Enterprise Architecture Migration Steps: ‣ „Technology Independence“ ‣ „@Inject Business Objects“ ‣ „No more EJBs for Transactions only“ ‣ „No more pumped up Sessions“ ‣ „No more Infrastructure in Views“ ‣ „No more doAll( ) Business Methods“
  • New chool S No more pumped up Session Migration Guide Anti-Pattern „alles in die Session“ ‣ RequestScoped ist leider zu kurz ‣ ViewScoped irgendwie auch und „JSF only“ ‣ SessionScoped aus Mangel an Alternativen
  • New chool S No more pumped up Session Migration Guide Anti-Pattern „alles in die Session“ ‣ RequestScoped ist leider zu kurz ‣ ViewScoped irgendwie auch und „JSF only“ ‣ SessionScoped aus Mangel an Alternativen ‣ ViewScoped ab Java EE 7 auch als „CDI“ ‣ FlowScoped ab Java EE 7
  • New chool S Old School Ansatz Migration Guide // JSF UI Controller @javax.enterprise.context.SessionScoped @javax.inject.Named(“deleteCustomerController“) public class DeleteCustomerController implements Serializable { // @EJB CustomerService, AuthenticationService and MailService private Customer customerToDelete; public String askForDeletion(Customer customer) { customerToDelete = customer; return SHOW_DELETE_CONFIRMATION; } public String deleteCustomer(Customer customer) { ... // call backend services return CUSTOMER_DELETED; } ... }
  • New chool S Old School Ansatz Migration Guide // JSF UI Controller @javax.context.enterprise.ConversationScoped @javax.inject.Named(“deleteCustomerController“) public class DeleteCustomerController implements Serializable { private Customer customerToDelete; @Inject private Conversation conversation; public String askForDeletion(Customer customer) { conversation.begin(); customerToDelete = customer; return SHOW_DELETE_CONFIRMATION; } public String deleteCustomer(Customer customer) { conversation.end(); ... // call backend services return CUSTOMER_DELETED; } ... }
  • New chool S Old School Ansatz Migration Guide // JSF UI Controller @javax.context.enterprise.ConversationScoped @javax.inject.Named(“deleteCustomerController“) public class DeleteCustomerController implements Serializable { private Customer customerToDelete; @Inject private Conversation conversation; public String askForDeletion(Customer customer) { conversation.begin(); customerToDelete = customer; return SHOW_DELETE_CONFIRMATION; } public String deleteCustomer(Customer customer) { conversation.end(); ... // call backend services return CUSTOMER_DELETED; } ... } Was ist, wenn schon aktiv? Was ist, wenn nicht aktiv?
  • New chool S Migration Guide Enterprise Architecture Migration Steps: ‣ „Technology Independence“ ‣ „@Inject Business Objects“ ‣ „No more EJBs for Transactions only“ ‣ „No more pumped up Sessions“ ‣ „No more Infrastructure in Views“ ‣ „No more doAll( ) Business Methods“
  • New chool S No more Infrastructure in Views Migration Guide Views sind nach wie vor ein Problem ‣ Injection via U-EL ‣ Injection von UI Controllern
  • New chool S No more Infrastructure in Views Enterprise Architecture <html ...> <h:body> <h:form> Vorname: <h:inputText value=“#{createCustomerController.customer.firstname}"/> Name: <h:inputText value=“#{createCustomerController.customer.lastname}"/> </h:form> </h:body> </html>
  • New chool S <html ...> <h:body> <h:form> No more Infrastructure in Views Enterprise Architecture Infrastruture in der View Vorname: <h:inputText value=“#{createCustomerController.customer.firstname}"/> Name: <h:inputText value=“#{createCustomerController.customer.lastname}"/> </h:form> </h:body> </html>
  • New chool S No more Infrastructure in Views Enterprise Architecture <html ...> <h:body> <h:form> Vorname: <h:inputText value=“#{customerToCreate.firstname}"/> Name: <h:inputText value=“#{customerToCreate.lastname}"/> </h:form> </h:body> </html>
  • New chool S <html ...> <h:body> <h:form> No more Infrastructure in Views Enterprise Architecture Fachlichkeit in der View Vorname: <h:inputText value=“#{customerToCreate.firstname}"/> Name: <h:inputText value=“#{customerToCreate.lastname}"/> </h:form> </h:body> </html>
  • New chool S No more Infrastructure in Views Migration Guide // JSF UI Controller @javax.enterprise.context.RequestScoped @javax.inject.Named(“createCustomerController“) public class CreateCustomerController { @Inject private CustomerService customerService; private Customer customer; // getter for customer @javax.inject.Produces @javax.inject.Named(“customerToCreate“) public Customer getCustomer { return customer; } ... }
  • New chool S Migration Guide Enterprise Architecture Migration Steps: ‣ „Technology Independence“ ‣ @Inject Business Objects ‣ „No more EJBs for Transactions only“ ‣ „No more pumped up Sessions“ ‣ „No more Infrastructure in Views“ ‣ „No more doAll( ) Business Methods“
  • New chool S No more doAll() Business Methods Migration Guide Ein Use Case kommt selten allein ‣ Primärer Use Case - Create Customer ‣ Sekundärer Use Case - Send Welcome Mail ‣ Sekundärer Use Case - Für Mandant X ... ‣ Sekundärer Use Case - ...
  • New chool S No more doAll() Business Methods Migration Guide CDI Events zur losen Kopplung, d.h Java EE Observer Patten inkl. ... ‣ Event Object & Event Producer ‣ Observer Method ‣ schichtenneutral für POJOs ‣ ggf. transaktionsgebunden ‣ synchrone Interaktion
  • New chool S No more doAll() Business Methods Migration Guide Event/Message Producer CDI Bean Manager Observer Method Observer Method Observer Method
  • New chool S No more doAll() Business Methods Migration Guide USER CREATED Event/Message Producer CDI Bean Manager Observer Method Observer Method Observer Method
  • New chool S No more doAll() Business Methods Migration Guide USER CREATED Event/Message Producer gut zu wissen CDI Bean Manager interessant Observer Method Observer Method Observer Method ok, danke
  • New chool S No more doAll() Business Methods Migration Guide OK, CDI Events - klingt super, aber ... ‣ Wie sieht ein solches Event aus? ‣ Und wie fange ich es ab? ‣ Und vor allem: Wie löse ich es aus?
  • New chool S No more doAll() Business Methods Migration Guide // JSF UI Controller @javax.enterprise.context.RequestScoped @javax.inject.Named(“createCustomerController“) public class CreateCustomerController { @Inject private CustomerService customerService; @Inject @Created private Event<Customer> eventSource; private Customer customer; @Transactional public String createCustomer() { customerService.create(customer); eventSource.fire(customer); return CUSTOMER_CREATED; } ... }
  • New chool S No more doAll() Business Methods Enterprise Architecture @ApplicationScoped public class MailService implements Serializable { public void sendWelcomeMail( @Observes @Created Customer customer) { // do some work with the customer object ... } ... } ‣ Wie fange ich es?
  • New chool S No more doAll() Business Methods Enterprise Architecture @ApplicationScoped public class MailService implements Serializable { public void sendWelcomeMail( @Observes @Created Customer customer) { // do some work with the customer object ... } ... } ‣ Wie fange ich es? Wow! Geht da noch mehr?
  • New chool S No more doAll() Business Methods Enterprise Architecture @ApplicationScoped public class MailService implements Serializable { public void sendWelcomeMail( @Observes @TenantId(“4711“) @Created Customer customer) { // do some work with the customer object for tenant 4711 ... } ... } ‣ Wie fange ich es?
  • New chool S No more doAll() Business Methods Migration Guide // JSF UI Controller @javax.enterprise.context.RequestScoped @javax.inject.Named(“createCustomerController“) public class CreateCustomerController { @Inject private CustomerService customerService; @Inject @Created private Event<Customer> eventSource; @Inject @TenantId private String tenantId; private Customer customer; @Transactional public String createCustomer() { customerService.create(customer); eventSource.select(new TenantIdQualifier(tenantid)).fire(customer); return CUSTOMER_CREATED; } ... }
  • New chool S No more doAll() Business Methods Migration Guide // JSF UI Controller @javax.enterprise.context.RequestScoped @javax.inject.Named(“createCustomerController“) public class CreateCustomerController { @Inject private CustomerService customerService; @Inject @Created private Event<Customer> eventSource; @Inject @TenantId private String tenantId; private Customer customer; @Transactional public String createCustomer() { customerService.create(customer); eventSource.select(new TenantIdQualifier(tenantid)).fire(customer); return CUSTOMER_CREATED; } ... } extends AnnotationLiteral<TenandId> implemnts TenandId
  • New chool S No more doAll() Business Methods Enterprise Architecture @ApplicationScoped public class MailService implements Serializable { // Conditional Observer Method that takes // - Transaction status, e.g. AFTER_SUCCESS, AFTER_FAILURE // - Bean instance status, e.g. ALLWAYS // into account public void sendWelcomeMail( @Observes( receive=ALLWAYS, // bean during=AFTER_SUCCESS // tx ) @Created Customer customer) { ... } } ‣ Conditional Observer
  • New chool S Alternativer Ansatz Enterprise Architecture JSF View UseCaseController UI TX Business Object Business Object Business Object Domain
  • New chool S TX Alternativer Ansatz Enterprise Architecture JSF View UseCaseController Business Object Business Object Business Object UI Domain
  • New chool S Fazit Enterprise Architecture New School Enterprise Architecture ‣ mit CDI ‣ typensicher ‣ schichtenneutral ‣ fachliche und technologische Injection ‣ eventgetriebene Entwicklung
  • Java @mobileLarson @_openknowledge New School Enterprise Architecture Lars Röwekamp | open knowledge GmbH