Your SlideShare is downloading. ×

New School Enterprise Architecture

534

Published on

Speaker: Lars Röwekamp …

Speaker: Lars Röwekamp
JAX 2013
23.4.2013 | 16.15 - 17.15 Uhr

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.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
534
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
27
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. JavaNew School Enterprise ArchitectureLars Röwekamp | open knowledge GmbH@mobileLarson@_openknowledge
  • 2. „Fachlichkeit im Fokus!“„Java EE 6 und 7 erlauben nebenInfrastructure Injection auchBusiness Injection.“Was sie mitnehmen sollten ...NewSchool Enterprise Architecture
  • 3. „Fachlichkeit im Fokus!“„Java EE 6 und 7 erlauben nebenInfrastructure Injection auchBusiness Injection.“Was sie mitnehmen sollten ...NewSchool Enterprise Architecture
  • 4. Ok, was heißt das?
  • 5. NewSchoolCall 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 versendenDer Use CaseEnterprise Architecture
  • 6. NewSchoolCall 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 versendenDer Use CaseEnterprise Architecture
  • 7. Old School
  • 8. NewSchoolUse Case: Kunde neu erfassen‣ JSF View ruft UI Controller via U-EL‣ UI Controller ruft CustomerService EJB‣ UI Controller ruft MailService EJBEnterprise ArchitectureOld School Ansatz
  • 9. NewSchool Enterprise ArchitectureOld School AnsatzUIServiceDataJSF ViewCreateCustomer
  • 10. NewSchool Enterprise ArchitectureOld School AnsatzUIServiceDataJSF ViewCreateCustomerCustService MailService
  • 11. NewSchool Enterprise ArchitectureOld School AnsatzUIServiceDataJSF ViewCreateCustomerCustService MailServiceCustomer Mail
  • 12. NewSchool Enterprise ArchitectureOld School Ansatz// JSF UI Controller@javax.faces.bean.RequestScoped@javax.faces.bean.ManagedBean(name=“createCustomerController“)public class CreateCustomerController {@EJBprivate CustomerService customerService;@EJBprivate MailService mailService;private Customer customer;public String createCustomer() {customerService.create(customer);mailService.sendWelcomeMail(customer);return CUSTOMER_CREATED;}// getter / setter for customer...}
  • 13. NewSchool Enterprise ArchitectureOld School Ansatz// JSF UI Controller@javax.faces.bean.RequestScoped@javax.faces.bean.ManagedBean(name=“createCustomerController“)public class CreateCustomerController {@EJBprivate CustomerService customerService;@EJBprivate MailService mailService;private Customer customer;public String createCustomer() {customerService.create(customer);mailService.sendWelcomeMail(customer);return CUSTOMER_CREATED;}// getter / setter for customer...}Und was ist mit demCall Center Agent?
  • 14. NewSchoolUse 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 AuthenticationControllerEnterprise ArchitectureOld School Ansatz
  • 15. NewSchool Enterprise ArchitectureOld School AnsatzJSF ViewCreateCustomer AuthController
  • 16. NewSchool Enterprise ArchitectureOld School AnsatzJSF ViewCreateCustomerCCAgentAuthServiceAuthController
  • 17. NewSchool Enterprise ArchitectureOld School AnsatzJSF ViewCreateCustomerCCAgentAuthServiceCustomerCustServiceAuthController
  • 18. NewSchool Enterprise ArchitectureOld School AnsatzJSF ViewCreateCustomerCCAgentAuthServiceMailMailServiceCustomerCustServiceAuthController
  • 19. NewSchool Enterprise ArchitectureOld School Ansatz// 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...}
  • 20. NewSchool Enterprise ArchitectureOld School Ansatz// 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 dieTransaktion aufgezogen?
  • 21. NewSchoolUse 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 EJBEnterprise ArchitectureOld School Ansatz
  • 22. NewSchool Enterprise ArchitectureOld School AnsatzCreateCustomerAuthServiceCCAgentAuthController
  • 23. NewSchool Enterprise ArchitectureOld School AnsatzCreateCustomerCustFacadeAuthServiceCCAgentAuthController
  • 24. TXNewSchool Enterprise ArchitectureOld School AnsatzCreateCustomerCustFacadeAuthServiceCCAgentAuthController
  • 25. TXNewSchool Enterprise ArchitectureOld School AnsatzCreateCustomerCustFacadeAuthServiceCCAgentCustService MailServiceCustomer MailAuthController
  • 26. NewSchool Enterprise ArchitectureOld School Ansatz// JSF UI Controller@javax.faces.bean.RequestScoped@javax.faces.ManagedBean(name=“createCustomerController“)public class CreateCustomerController {@EJBprivate 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;}...}
  • 27. NewSchool Enterprise ArchitectureOld School Ansatz// EJB Service Facade@Statelesspublic class CustomerFacade {@EJBprivate CustomerService customerService@EJBprivate MailService mailService;// Transactional by defaultpublic void createCustomer(Customer customer,CallCenterAgent currentCallCenterAgent) {customer.setAuditInformation(currentCallCenterAgent);customerService.create(customer);mailService.sendWelcomeMail(customer);}...}
  • 28. NewSchool Enterprise ArchitectureOld School Ansatz// EJB Service Facade@Statelesspublic class CustomerFacade {@EJBprivate CustomerService customerService@EJBprivate MailService mailService;// Transactional by defaultpublic void createCustomer(Customer customer,CallCenterAgent currentCallCenterAgent) {customer.setAuditInformation(currentCallCenterAgent);customerService.create(customer);mailService.sendWelcomeMail(customer);}...}Fühlt sich nicht gut an!Alternativen sind aberauch nicht viel schöner!
  • 29. NewSchool Enterprise ArchitectureOld School AnsatzJSF ViewCreateCustomerAuthServiceCCAgentAuthController
  • 30. NewSchool Enterprise ArchitectureOld School AnsatzJSF ViewCustServiceCreateCustomerAuthServiceCCAgentAuthController
  • 31. NewSchool Enterprise ArchitectureOld School AnsatzJSF ViewCustServiceCreateCustomerAuthServiceCCAgentMailServiceCustomer MailAuthController
  • 32. NewSchoolUse 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‣ ...Enterprise ArchitectureOld School Ansatz
  • 33. NewSchool Enterprise ArchitectureOld School AnsatzUIServiceDataJSF View 1DeleteCustomer
  • 34. NewSchool Enterprise ArchitectureOld School AnsatzUIServiceDataJSF View 1DeleteCustomerJSF View 2
  • 35. NewSchool Enterprise ArchitectureOld School AnsatzUIServiceDataJSF View 1DeleteCustomerCustService MailServiceCustomer MailJSF View 2
  • 36. NewSchool Enterprise ArchitectureOld School Ansatz// JSF UI Controller@javax.faces.bean.SessionScoped@javax.faces.bean.ManagedBean(name=“deleteCustomerController“)public class DeleteCustomerController implements Serializable {// @EJB CustomerService, AuthenticationService and MailServiceprivate Customer customerToDelete;public String askForDeletion(Customer customer) {customerToDelete = customer;return SHOW_DELETE_CONFIRMATION;}public String deleteCustomer() {... // call backend services and delete customerreturn CUSTOMER_DELETED;}...}
  • 37. NewSchool Enterprise ArchitectureOld School Ansatz// JSF UI Controller@javax.faces.bean.SessionScoped@javax.faces.bean.ManagedBean(name=“deleteCustomerController“)public class DeleteCustomerController implements Serializable {// @EJB CustomerService, AuthenticationService and MailServiceprivate Customer customerToDelete;public String askForDeletion(Customer customer) {customerToDelete = customer;return SHOW_DELETE_CONFIRMATION;}public String deleteCustomer() {... // call backend services and delete customerreturn CUSTOMER_DELETED;}...} Wann kommt der Datensatzaus der Session wieder raus?
  • 38. NewSchoolProblemkind 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?Enterprise ArchitectureOld School Ansatz
  • 39. NewSchool Enterprise ArchitectureOld School AnsatzUIServiceDataJSF View@ManagedBean (JSF)Session EJB Session EJBEntityManager EntityTX
  • 40. NewSchool Enterprise ArchitectureAlternativer AnsatzUIDomainJSF ViewUseCaseControllerBusiness ObjectBusiness ObjectBusiness ObjectTX
  • 41. NewSchool Enterprise ArchitectureAlternativer AnsatzUIDomainJSF ViewUseCaseControllerBusiness ObjectBusiness ObjectBusiness ObjectTX
  • 42. Migration Guide
  • 43. New School
  • 44. NewSchoolMigration 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“Enterprise ArchitectureMigration Guide
  • 45. NewSchoolMigration 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“Enterprise ArchitectureMigration Guide
  • 46. NewSchool// JSF UI Controller@javax.faces.bean.RequestScoped@javax.faces.bean.ManagedBean(name=“createCustomerController“)public class CreateCustomerController {// inject CustomerService and MailService via @EJB@EJBprivate 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...}Migration GuideTechnology Independence
  • 47. NewSchool// JSF UI Controller@javax.enterprise.context.RequestScoped@javax.inject.Named(“createCustomerController“)public class CreateCustomerController {// inject CustomerService and MailService via @Inject@Injectprivate 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...}Migration GuideTechnology Independence
  • 48. NewSchoolMigration 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“Enterprise ArchitectureMigration Guide
  • 49. NewSchoolCDI Producer Methods & Fields‣ Factory Method Pattern für Objekte‣ @Producer als Mittel zum Zweck‣ @Qualifier als Mittel zur Typ-Qualifizierung‣ ermöglicht fachliche Injektion@Inject @Current CallCenterAgentMigration Guide
  • 50. NewSchool// JSF UI Controller@javax.enterprise.context.RequestScoped@javax.inject.Named(“createCustomerController“)public class CreateCustomerController {// inject CustomerService and MailService via @Inject@Injectprivate 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...}Migration Guide@Inject @Current CallCenterAgent
  • 51. NewSchool// JSF UI Controller@javax.enterprise.context.RequestScoped@javax.inject.Named(“createCustomerController“)public class CreateCustomerController {// inject CustomerService and MailService via @Inject@Inject @Currentprivate CallCenterAgent currentCallCenterAgent;private Customer customer;public String createCustomer() {customer.setAuditInformation(currentCallCenterAgent);customerService.create(customer);mailService.sendWelcomeMail(customer);return CUSTOMER_CREATED;}// getter / setter for customer...}Migration Guide@Inject @Current CallCenterAgent
  • 52. NewSchool// Authentication Controller@SessionScoped@Named(“authenticationController“)public class AuthenticationController implements Serializable {private CallCenterAgent authenticatedCallCenterAgent;public String authenticate() {...}@Produces @Currentpublic CallCenterAgent getAuthenticatedCallCenterAgent() {return authenticatedCallCenterAgent;}...}Migration Guide@Inject @Current CallCenterAgent
  • 53. NewSchool// Authentication Controller@SessionScoped@Named(“authenticationController“)public class AuthenticationController implements Serializable {private CallCenterAgent authenticatedCallCenterAgent;public String authenticate() {...}@Produces @Currentpublic CallCenterAgent getAuthenticatedCallCenterAgent() {return authenticatedCallCenterAgent;}...}Migration Guide@Inject @Current CallCenterAgent@Inject @Current CallCenterAgent
  • 54. NewSchool// Authentication Controller@SessionScoped@Named(“authenticationController“)public class AuthenticationController implements Serializable {private CallCenterAgent authenticatedCallCenterAgent;public String authenticate() {...}@Produces @Currentpublic CallCenterAgent getAuthenticatedCallCenterAgent() {return authenticatedCallCenterAgent;}...}Migration Guide@Inject @Current CallCenterAgent@RequestScoped@Inject @Current CallCenterAgent
  • 55. NewSchoolpackage de.openknowldege.qualifierimport ...// self-made qualifier to indicate current instance of something@Qualifier@Target({TYPE, METHOD, PARAMETER, FIELD})@Retention(RUNTIME)public @interface Current{}Migration Guide@Inject @Current CallCenterAgent
  • 56. NewSchool// JSF UI Controller@javax.enterprise.context.RequestScoped@javax.inject.Named(“createCustomerController“)public class CreateCustomerController {// inject CustomerService and MailService via @Inject@Inject @Currentprivate CallCenterAgent currentCallCenterAgent;private Customer customer;public String createCustomer() {customer.setAuditInformation(currentCallCenterAgent);customerService.create(customer);mailService.sendWelcomeMail(customer);return CUSTOMER_CREATED;}// getter / setter for customer...}Migration Guide@Inject @Current CallCenterAgent
  • 57. NewSchool// Customer Service EJB@Statelesspublic class CustomerService {@Inject @Currentprivate CallCenterAgent currentCallCenterAgent;@PersistenceContextprivate EntityManager em;// transactional by defaultpublic void createCustomer(Customer customer) {customer.setAuditInformation(currentCallCenterAgent);em.persist(customer);}...}Migration Guide@Inject @Current CallCenterAgent
  • 58. NewSchoolMigration 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“Enterprise ArchitectureMigration Guide
  • 59. NewSchoolInjizierbare CDI Ressourcen‣ normale Java Klassen - optional mit @Namedund/oder @Qualifier markiert‣ EJBs - Stateless, Stateful, Singleton‣ sonstige Java EE Resources -UserTransaction, PersistenceContext, ...No more EJBsMigration Guide
  • 60. NewSchool// Customer Service EJB@Statelesspublic class CustomerService {@Inject @Currentprivate CallCenterAgent currentCallCenterAgent;@PersistenceContextprivate EntityManager em;// transactional by defaultpublic void createCustomer(Customer customer) {customer.setAuditInformation(currentCallCenterAgent);em.persist(customer);}...}Migration GuideNo more EJBs
  • 61. NewSchool// Customer Service EJB - no annotation required!@Statelesspublic class CustomerService {@Inject @Currentprivate CallCenterAgent currentCallCenterAgent;@PersistenceContextprivate EntityManager em;// transactional by defaultpublic void createCustomer(Customer customer) {customer.setAuditInformation(currentCallCenterAgent);em.persist(customer);}...}Migration GuideNo more EJBs
  • 62. NewSchool// Customer Service EJB - no annotation required!@Statelesspublic class CustomerService {@Inject @Currentprivate CallCenterAgent currentCallCenterAgent;@PersistenceContextprivate EntityManager em;// transactional by defaultpublic void createCustomer(Customer customer) {customer.setAuditInformation(currentCallCenterAgent);em.persist(customer);}...}Migration GuideOk, aber wo bekommen wiedie Transaktion jetzt her?No more EJBs
  • 63. NewSchool// Customer Service EJB - no annotation required!@Statelesspublic class CustomerService {@Inject @Currentprivate CallCenterAgent currentCallCenterAgent;@PersistenceContextprivate EntityManager em;@Transactionalpublic void createCustomer(Customer customer) {customer.setAuditInformation(currentCallCenterAgent);em.persist(customer);}...}Migration GuideNo more EJBs
  • 64. NewSchool// Customer Service EJB - no annotation required!@Statelesspublic class CustomerService {@Inject @Currentprivate CallCenterAgent currentCallCenterAgent;@PersistenceContextprivate EntityManager em;@Transactionalpublic void createCustomer(Customer customer) {customer.setAuditInformation(currentCallCenterAgent);em.persist(customer);}...}Migration GuideJTA 1.2 oder DeltaSpike oderals Self-Made CDI-InterceptorNo more EJBs
  • 65. NewSchool@InterceptorBinding@Target({TYPE, METHOD})@Retention(RUNTIME)public @interface Transactional {@Nonbindingpublic TransactionalType value()default TransactionalType.REQUIRED;}Migration GuideNo more EJBs
  • 66. NewSchool@Transactional@Interceptorpublic class TransactionAdvice {@Injectprivate UserTransaction utx;@AroundInvokepublic Object applyTransaction(InvocationContext ic) throws Throwable {... // 1. implement utx.begin()ic.proceed(); // 2. call original method... // 3. implement utx.commit()}Migration GuideNo more EJBs*XML registration omitted
  • 67. NewSchool// Customer Service - no annotation required!public class CustomerService {@Inject @Currentprivate CallCenterAgent currentCallCenterAgent;@PersistenceContextprivate EntityManager em;@Transactionalpublic void createCustomer(Customer customer) {customer.setAuditInformation(currentCallCenterAgent);em.persist(customer);}...}Migration GuideNo more EJBs
  • 68. NewSchool// Customer Service - no annotation required!public class CustomerService {@Inject @Currentprivate CallCenterAgent currentCallCenterAgent;@PersistenceContextprivate EntityManager em;@Transactionalpublic void createCustomer(Customer customer) {customer.setAuditInformation(currentCallCenterAgent);em.persist(customer);}...}Migration GuideNo more EJBs
  • 69. NewSchool Enterprise ArchitectureUIServiceDataJSF ViewUsecaseControllerService ServiceEntityManager EntityTXNo more EJBs
  • 70. NewSchool Enterprise ArchitectureUIServiceDataJSF ViewUsecaseControllerService ServiceEntityManager EntityTXNo more EJBs
  • 71. NewSchool// JSF UI Controller@javax.enterprise.context.RequestScoped@javax.inject.Named(“createCustomerController“)public class CreateCustomerController {@Injectprivate CustomerService customerService;private Customer customer;@Transactionalpublic String createCustomer() {customerService.create(customer);... // some additional use case “tx“ related workreturn CUSTOMER_CREATED;}// getter / setter for customer...}Migration GuideNo more EJBs
  • 72. NewSchoolMigration 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“Enterprise ArchitectureMigration Guide
  • 73. NewSchoolAnti-Pattern „alles in die Session“‣ RequestScoped ist leider zu kurz‣ ViewScoped irgendwie auch‣ SessionScoped aus Mangel an AlternativenNo more pumped up SessionMigration Guide
  • 74. NewSchool Migration GuideOld School Ansatz// JSF UI Controller@javax.enterprise.context.SessionScoped@javax.inject.Named(“deleteCustomerController“)public class DeleteCustomerController implements Serializable {// @EJB CustomerService, AuthenticationService and MailServiceprivate Customer customerToDelete;public String askForDeletion(Customer customer) {customerToDelete = customer;return SHOW_DELETE_CONFIRMATION;}public String deleteCustomer(Customer customer) {... // call backend servicesreturn CUSTOMER_DELETED;}...}
  • 75. NewSchool Migration GuideOld School Ansatz// JSF UI Controller@javax.context.enterprise.ConversationScoped@javax.inject.Named(“deleteCustomerController“)public class DeleteCustomerController implements Serializable {private Customer customerToDelete;@Injectprivate Conversation conversation;public String askForDeletion(Customer customer) {conversation.begin();customerToDelete = customer;return SHOW_DELETE_CONFIRMATION;}public String deleteCustomer(Customer customer) {conversation.end();... // call backend servicesreturn CUSTOMER_DELETED;}...}
  • 76. NewSchoolMigration 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“Enterprise ArchitectureMigration Guide
  • 77. NewSchoolViews sind nach wie vor ein Problem‣ Injection via U-EL‣ Injection von UI ControllernNo more Infrastructure in ViewsMigration Guide
  • 78. NewSchool Enterprise Architecture<html ...><h:body><h:form>Vorname: <h:inputTextvalue=“#{createCustomerController.customer.firstname}"/>Name: <h:inputTextvalue=“#{createCustomerController.customer.lastname}"/></h:form></h:body></html>No more Infrastructure in Views
  • 79. NewSchool Enterprise Architecture<html ...><h:body><h:form>Vorname: <h:inputTextvalue=“#{createCustomerController.customer.firstname}"/>Name: <h:inputTextvalue=“#{createCustomerController.customer.lastname}"/></h:form></h:body></html>No more Infrastructure in ViewsInfrastruture in derView
  • 80. NewSchool Enterprise Architecture<html ...><h:body><h:form>Vorname: <h:inputTextvalue=“#{customerToCreate.firstname}"/>Name: <h:inputTextvalue=“#{customerToCreate.lastname}"/></h:form></h:body></html>No more Infrastructure in Views
  • 81. NewSchool Enterprise Architecture<html ...><h:body><h:form>Vorname: <h:inputTextvalue=“#{customerToCreate.firstname}"/>Name: <h:inputTextvalue=“#{customerToCreate.lastname}"/></h:form></h:body></html>No more Infrastructure in ViewsFachlichkeit in derView
  • 82. NewSchool// JSF UI Controller@javax.enterprise.context.RequestScoped@javax.inject.Named(“createCustomerController“)public class CreateCustomerController {@Injectprivate CustomerService customerService;private Customer customer;// getter for customer@javax.inject.Produces@javax.inject.Named(“customerToCreate“)public Customer getCustomer {return customer;}...}Migration GuideNo more Infrastructure in Views
  • 83. NewSchoolMigration 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“Enterprise ArchitectureMigration Guide
  • 84. NewSchoolEin Use Case kommt selten allein‣ Primärer Use Case - Create Customer‣ Sekundärer Use Case - Send Welcome Mail‣ Sekundärer Use Case - ...‣ Sekundärer Use Case - ...No more doAll() Business MethodsMigration Guide
  • 85. NewSchoolCDI Events zur losen Kopplung, d.hJava EE Observer Patten inkl. ...‣ Event Object & Event Producer‣ Observer Method‣ schichtenneutral für POJOs‣ ggf. transaktionsgebunden‣ synchrone InteraktionNo more doAll() Business MethodsMigration Guide
  • 86. NewSchool Migration GuideEvent/MessageProducerCDI Bean ManagerObserver MethodObserver MethodObserver MethodNo more doAll() Business Methods
  • 87. NewSchool Migration GuideEvent/MessageProducerCDI Bean ManagerObserver MethodObserver MethodObserver MethodNo more doAll() Business MethodsUSERCREATED
  • 88. NewSchool Migration GuideEvent/MessageProducerCDI Bean ManagerObserver MethodObserver MethodObserver MethodNo more doAll() Business MethodsUSERCREATEDinteressantok, dankegut zuwissen
  • 89. NewSchoolOK, 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?No more doAll() Business MethodsMigration Guide
  • 90. NewSchool// JSF UI Controller@javax.enterprise.context.RequestScoped@javax.inject.Named(“createCustomerController“)public class CreateCustomerController {@Injectprivate CustomerService customerService;@Inject @Createdprivate Event<Customer> eventSource;private Customer customer;@Transactionalpublic String createCustomer() {customerService.create(customer);eventSource.fire(customer);return CUSTOMER_CREATED;}...}Migration GuideNo more doAll() Business Methods
  • 91. NewSchool// JSF UI Controller@javax.enterprise.context.RequestScoped@javax.inject.Named(“createCustomerController“)public class CreateCustomerController {@Injectprivate CustomerService customerService;@Inject @Createdprivate Event<Customer> eventSource;private Customer customer;@Transactionalpublic String createCustomer() {customerService.create(customer);eventSource.fire(customer);return CUSTOMER_CREATED;}...}Migration GuideNo more doAll() Business MethodsWow! Geht danoch mehr?
  • 92. NewSchool Enterprise Architecture@ApplicationScopedpublic class MailService implements Serializable {public void sendWelcomeMail(@Observes@Created Customer customer) {// do some work with the customer object...}...}‣ Wie fange ich es?No more doAll() Business Methods
  • 93. NewSchool Enterprise Architecture@ApplicationScopedpublic class MailService implements Serializable {// Conditional Observer Method that takes// - Transaction status, e.g. AFTER_SUCCESS, AFTER_FAILURE// - Bean instance status, e.g. ALLWAYS// into accountpublic void sendWelcomeMail(@Observes(receive=ALLWAYS, // beanduring=AFTER_SUCCESS // tx)@Created Customer customer) {...}}‣ Conditional ObserverNo more doAll() Business Methods
  • 94. NewSchool Enterprise ArchitectureAlternativer AnsatzUIDomainJSF ViewUseCaseControllerBusiness ObjectBusiness ObjectBusiness ObjectTX
  • 95. NewSchool Enterprise ArchitectureAlternativer AnsatzUIDomainJSF ViewUseCaseControllerBusiness ObjectBusiness ObjectBusiness ObjectTX
  • 96. NewSchoolNew School Enterprise Architecture‣ mit CDI‣ typensicher‣schichtenneutral‣ fachliche und technologische Injection‣ eventgetriebene EntwicklungFazitEnterprise Architecture
  • 97. JavaNew School Enterprise ArchitectureLars Röwekamp | open knowledge GmbH@mobileLarson@_openknowledge

×