JavaNew School Enterprise ArchitectureLars Röwekamp | open knowledge GmbH@mobileLarson@_openknowledge
„Fachlichkeit im Fokus!“„Java EE 6 und 7 erlauben nebenInfrastructure Injection auchBusiness Injection.“Was sie mitnehmen ...
„Fachlichkeit im Fokus!“„Java EE 6 und 7 erlauben nebenInfrastructure Injection auchBusiness Injection.“Was sie mitnehmen ...
Ok, was heißt das?
NewSchoolCall Center Anwendung‣ Kunde neu erfassen und speichern‣ Call Center Agent als Audit Info mit speichern‣ Begrüßun...
NewSchoolCall Center Anwendung‣ Kunde neu erfassen und speichern‣ Call Center Agent als Audit Info mit speichern‣ Begrüßun...
Old School
NewSchoolUse Case: Kunde neu erfassen‣ JSF View ruft UI Controller via U-EL‣ UI Controller ruft CustomerService EJB‣ UI Co...
NewSchool Enterprise ArchitectureOld School AnsatzUIServiceDataJSF ViewCreateCustomer
NewSchool Enterprise ArchitectureOld School AnsatzUIServiceDataJSF ViewCreateCustomerCustService MailService
NewSchool Enterprise ArchitectureOld School AnsatzUIServiceDataJSF ViewCreateCustomerCustService MailServiceCustomer Mail
NewSchool Enterprise ArchitectureOld School Ansatz// JSF UI Controller@javax.faces.bean.RequestScoped@javax.faces.bean.Man...
NewSchool Enterprise ArchitectureOld School Ansatz// JSF UI Controller@javax.faces.bean.RequestScoped@javax.faces.bean.Man...
NewSchoolUse Case: Kunde neu erfassen‣ JSF View ruft UI Controller via U-EL‣ UI Controller ruft CustomerService EJB‣ UI Co...
NewSchool Enterprise ArchitectureOld School AnsatzJSF ViewCreateCustomer AuthController
NewSchool Enterprise ArchitectureOld School AnsatzJSF ViewCreateCustomerCCAgentAuthServiceAuthController
NewSchool Enterprise ArchitectureOld School AnsatzJSF ViewCreateCustomerCCAgentAuthServiceCustomerCustServiceAuthController
NewSchool Enterprise ArchitectureOld School AnsatzJSF ViewCreateCustomerCCAgentAuthServiceMailMailServiceCustomerCustServi...
NewSchool Enterprise ArchitectureOld School Ansatz// JSF UI Controller@javax.faces.bean.RequestScoped@javax.faces.bean.Man...
NewSchool Enterprise ArchitectureOld School Ansatz// JSF UI Controller@javax.faces.bean.RequestScoped@javax.faces.bean.Man...
NewSchoolUse Case: Kunde neu erfassen‣ JSF View ruft UI Controller via U-EL‣ UI Controller ruft AuthenticationController‣ ...
NewSchool Enterprise ArchitectureOld School AnsatzCreateCustomerAuthServiceCCAgentAuthController
NewSchool Enterprise ArchitectureOld School AnsatzCreateCustomerCustFacadeAuthServiceCCAgentAuthController
TXNewSchool Enterprise ArchitectureOld School AnsatzCreateCustomerCustFacadeAuthServiceCCAgentAuthController
TXNewSchool Enterprise ArchitectureOld School AnsatzCreateCustomerCustFacadeAuthServiceCCAgentCustService MailServiceCusto...
NewSchool Enterprise ArchitectureOld School Ansatz// JSF UI Controller@javax.faces.bean.RequestScoped@javax.faces.ManagedB...
NewSchool Enterprise ArchitectureOld School Ansatz// EJB Service Facade@Statelesspublic class CustomerFacade {@EJBprivate ...
NewSchool Enterprise ArchitectureOld School Ansatz// EJB Service Facade@Statelesspublic class CustomerFacade {@EJBprivate ...
NewSchool Enterprise ArchitectureOld School AnsatzJSF ViewCreateCustomerAuthServiceCCAgentAuthController
NewSchool Enterprise ArchitectureOld School AnsatzJSF ViewCustServiceCreateCustomerAuthServiceCCAgentAuthController
NewSchool Enterprise ArchitectureOld School AnsatzJSF ViewCustServiceCreateCustomerAuthServiceCCAgentMailServiceCustomer M...
NewSchoolUse Case: Kunde löschen‣ JSF View ruft UI Controller via U-EL‣ UI Controller „merkt“ sich Kunde in Session‣ UI Co...
NewSchool Enterprise ArchitectureOld School AnsatzUIServiceDataJSF View 1DeleteCustomer
NewSchool Enterprise ArchitectureOld School AnsatzUIServiceDataJSF View 1DeleteCustomerJSF View 2
NewSchool Enterprise ArchitectureOld School AnsatzUIServiceDataJSF View 1DeleteCustomerCustService MailServiceCustomer Mai...
NewSchool Enterprise ArchitectureOld School Ansatz// JSF UI Controller@javax.faces.bean.SessionScoped@javax.faces.bean.Man...
NewSchool Enterprise ArchitectureOld School Ansatz// JSF UI Controller@javax.faces.bean.SessionScoped@javax.faces.bean.Man...
NewSchoolProblemkind Schichtenmodell‣ UI Controller via JSF Managed Beans‣ Service Facade und Services via EJBs‣ Persisten...
NewSchool Enterprise ArchitectureOld School AnsatzUIServiceDataJSF View@ManagedBean (JSF)Session EJB Session EJBEntityMana...
NewSchool Enterprise ArchitectureAlternativer AnsatzUIDomainJSF ViewUseCaseControllerBusiness ObjectBusiness ObjectBusines...
NewSchool Enterprise ArchitectureAlternativer AnsatzUIDomainJSF ViewUseCaseControllerBusiness ObjectBusiness ObjectBusines...
Migration Guide
New School
NewSchoolMigration Steps:‣ „Technology Independence“‣ „@Inject Business Objects“‣ „No more EJBs for Transactions only“‣ „N...
NewSchoolMigration Steps:‣ „Technology Independence“‣ „@Inject Business Objects“‣ „No more EJBs for Transactions only“‣ „N...
NewSchool// JSF UI Controller@javax.faces.bean.RequestScoped@javax.faces.bean.ManagedBean(name=“createCustomerController“)...
NewSchool// JSF UI Controller@javax.enterprise.context.RequestScoped@javax.inject.Named(“createCustomerController“)public ...
NewSchoolMigration Steps:‣ „Technology Independence“‣ „@Inject Business Objects“‣ „No more EJBs for Transactions only“‣ „N...
NewSchoolCDI Producer Methods & Fields‣ Factory Method Pattern für Objekte‣ @Producer als Mittel zum Zweck‣ @Qualifier als ...
NewSchool// JSF UI Controller@javax.enterprise.context.RequestScoped@javax.inject.Named(“createCustomerController“)public ...
NewSchool// JSF UI Controller@javax.enterprise.context.RequestScoped@javax.inject.Named(“createCustomerController“)public ...
NewSchool// Authentication Controller@SessionScoped@Named(“authenticationController“)public class AuthenticationController...
NewSchool// Authentication Controller@SessionScoped@Named(“authenticationController“)public class AuthenticationController...
NewSchool// Authentication Controller@SessionScoped@Named(“authenticationController“)public class AuthenticationController...
NewSchoolpackage de.openknowldege.qualifierimport ...// self-made qualifier to indicate current instance of something@Qual...
NewSchool// JSF UI Controller@javax.enterprise.context.RequestScoped@javax.inject.Named(“createCustomerController“)public ...
NewSchool// Customer Service EJB@Statelesspublic class CustomerService {@Inject @Currentprivate CallCenterAgent currentCal...
NewSchoolMigration Steps:‣ „Technology Independence“‣ „@Inject Business Objects“‣ „No more EJBs for Transactions only“‣ „N...
NewSchoolInjizierbare CDI Ressourcen‣ normale Java Klassen - optional mit @Namedund/oder @Qualifier markiert‣ EJBs - Statel...
NewSchool// Customer Service EJB@Statelesspublic class CustomerService {@Inject @Currentprivate CallCenterAgent currentCal...
NewSchool// Customer Service EJB - no annotation required!@Statelesspublic class CustomerService {@Inject @Currentprivate ...
NewSchool// Customer Service EJB - no annotation required!@Statelesspublic class CustomerService {@Inject @Currentprivate ...
NewSchool// Customer Service EJB - no annotation required!@Statelesspublic class CustomerService {@Inject @Currentprivate ...
NewSchool// Customer Service EJB - no annotation required!@Statelesspublic class CustomerService {@Inject @Currentprivate ...
NewSchool@InterceptorBinding@Target({TYPE, METHOD})@Retention(RUNTIME)public @interface Transactional {@Nonbindingpublic T...
NewSchool@Transactional@Interceptorpublic class TransactionAdvice {@Injectprivate UserTransaction utx;@AroundInvokepublic ...
NewSchool// Customer Service - no annotation required!public class CustomerService {@Inject @Currentprivate CallCenterAgen...
NewSchool// Customer Service - no annotation required!public class CustomerService {@Inject @Currentprivate CallCenterAgen...
NewSchool Enterprise ArchitectureUIServiceDataJSF ViewUsecaseControllerService ServiceEntityManager EntityTXNo more EJBs
NewSchool Enterprise ArchitectureUIServiceDataJSF ViewUsecaseControllerService ServiceEntityManager EntityTXNo more EJBs
NewSchool// JSF UI Controller@javax.enterprise.context.RequestScoped@javax.inject.Named(“createCustomerController“)public ...
NewSchoolMigration Steps:‣ „Technology Independence“‣ „@Inject Business Objects“‣ „No more EJBs for Transactions only“‣ „N...
NewSchoolAnti-Pattern „alles in die Session“‣ RequestScoped ist leider zu kurz‣ ViewScoped irgendwie auch‣ SessionScoped a...
NewSchool Migration GuideOld School Ansatz// JSF UI Controller@javax.enterprise.context.SessionScoped@javax.inject.Named(“...
NewSchool Migration GuideOld School Ansatz// JSF UI Controller@javax.context.enterprise.ConversationScoped@javax.inject.Na...
NewSchoolMigration Steps:‣ „Technology Independence“‣ „@Inject Business Objects“‣ „No more EJBs for Transactions only“‣ „N...
NewSchoolViews sind nach wie vor ein Problem‣ Injection via U-EL‣ Injection von UI ControllernNo more Infrastructure in Vi...
NewSchool Enterprise Architecture<html ...><h:body><h:form>Vorname: <h:inputTextvalue=“#{createCustomerController.customer...
NewSchool Enterprise Architecture<html ...><h:body><h:form>Vorname: <h:inputTextvalue=“#{createCustomerController.customer...
NewSchool Enterprise Architecture<html ...><h:body><h:form>Vorname: <h:inputTextvalue=“#{customerToCreate.firstname}"/>Nam...
NewSchool Enterprise Architecture<html ...><h:body><h:form>Vorname: <h:inputTextvalue=“#{customerToCreate.firstname}"/>Nam...
NewSchool// JSF UI Controller@javax.enterprise.context.RequestScoped@javax.inject.Named(“createCustomerController“)public ...
NewSchoolMigration Steps:‣ „Technology Independence“‣ @Inject Business Objects‣ „No more EJBs for Transactions only“‣ „No ...
NewSchoolEin Use Case kommt selten allein‣ Primärer Use Case - Create Customer‣ Sekundärer Use Case - Send Welcome Mail‣ S...
NewSchoolCDI Events zur losen Kopplung, d.hJava EE Observer Patten inkl. ...‣ Event Object & Event Producer‣ Observer Meth...
NewSchool Migration GuideEvent/MessageProducerCDI Bean ManagerObserver MethodObserver MethodObserver MethodNo more doAll()...
NewSchool Migration GuideEvent/MessageProducerCDI Bean ManagerObserver MethodObserver MethodObserver MethodNo more doAll()...
NewSchool Migration GuideEvent/MessageProducerCDI Bean ManagerObserver MethodObserver MethodObserver MethodNo more doAll()...
NewSchoolOK, CDI Events - klingt super, aber ...‣ Wie sieht ein solches Event aus?‣ Und wie fange ich es ab?‣ Und vor alle...
NewSchool// JSF UI Controller@javax.enterprise.context.RequestScoped@javax.inject.Named(“createCustomerController“)public ...
NewSchool// JSF UI Controller@javax.enterprise.context.RequestScoped@javax.inject.Named(“createCustomerController“)public ...
NewSchool Enterprise Architecture@ApplicationScopedpublic class MailService implements Serializable {public void sendWelco...
NewSchool Enterprise Architecture@ApplicationScopedpublic class MailService implements Serializable {// Conditional Observ...
NewSchool Enterprise ArchitectureAlternativer AnsatzUIDomainJSF ViewUseCaseControllerBusiness ObjectBusiness ObjectBusines...
NewSchool Enterprise ArchitectureAlternativer AnsatzUIDomainJSF ViewUseCaseControllerBusiness ObjectBusiness ObjectBusines...
NewSchoolNew School Enterprise Architecture‣ mit CDI‣ typensicher‣schichtenneutral‣ fachliche und technologische Injection...
JavaNew School Enterprise ArchitectureLars Röwekamp | open knowledge GmbH@mobileLarson@_openknowledge
Upcoming SlideShare
Loading in...5
×

New School Enterprise Architecture

565

Published on

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
565
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
28
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

New School Enterprise Architecture

  1. 1. JavaNew School Enterprise ArchitectureLars Röwekamp | open knowledge GmbH@mobileLarson@_openknowledge
  2. 2. „Fachlichkeit im Fokus!“„Java EE 6 und 7 erlauben nebenInfrastructure Injection auchBusiness Injection.“Was sie mitnehmen sollten ...NewSchool Enterprise Architecture
  3. 3. „Fachlichkeit im Fokus!“„Java EE 6 und 7 erlauben nebenInfrastructure Injection auchBusiness Injection.“Was sie mitnehmen sollten ...NewSchool Enterprise Architecture
  4. 4. Ok, was heißt das?
  5. 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. 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. 7. Old School
  8. 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. 9. NewSchool Enterprise ArchitectureOld School AnsatzUIServiceDataJSF ViewCreateCustomer
  10. 10. NewSchool Enterprise ArchitectureOld School AnsatzUIServiceDataJSF ViewCreateCustomerCustService MailService
  11. 11. NewSchool Enterprise ArchitectureOld School AnsatzUIServiceDataJSF ViewCreateCustomerCustService MailServiceCustomer Mail
  12. 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. 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. 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. 15. NewSchool Enterprise ArchitectureOld School AnsatzJSF ViewCreateCustomer AuthController
  16. 16. NewSchool Enterprise ArchitectureOld School AnsatzJSF ViewCreateCustomerCCAgentAuthServiceAuthController
  17. 17. NewSchool Enterprise ArchitectureOld School AnsatzJSF ViewCreateCustomerCCAgentAuthServiceCustomerCustServiceAuthController
  18. 18. NewSchool Enterprise ArchitectureOld School AnsatzJSF ViewCreateCustomerCCAgentAuthServiceMailMailServiceCustomerCustServiceAuthController
  19. 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. 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. 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. 22. NewSchool Enterprise ArchitectureOld School AnsatzCreateCustomerAuthServiceCCAgentAuthController
  23. 23. NewSchool Enterprise ArchitectureOld School AnsatzCreateCustomerCustFacadeAuthServiceCCAgentAuthController
  24. 24. TXNewSchool Enterprise ArchitectureOld School AnsatzCreateCustomerCustFacadeAuthServiceCCAgentAuthController
  25. 25. TXNewSchool Enterprise ArchitectureOld School AnsatzCreateCustomerCustFacadeAuthServiceCCAgentCustService MailServiceCustomer MailAuthController
  26. 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. 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. 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. 29. NewSchool Enterprise ArchitectureOld School AnsatzJSF ViewCreateCustomerAuthServiceCCAgentAuthController
  30. 30. NewSchool Enterprise ArchitectureOld School AnsatzJSF ViewCustServiceCreateCustomerAuthServiceCCAgentAuthController
  31. 31. NewSchool Enterprise ArchitectureOld School AnsatzJSF ViewCustServiceCreateCustomerAuthServiceCCAgentMailServiceCustomer MailAuthController
  32. 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. 33. NewSchool Enterprise ArchitectureOld School AnsatzUIServiceDataJSF View 1DeleteCustomer
  34. 34. NewSchool Enterprise ArchitectureOld School AnsatzUIServiceDataJSF View 1DeleteCustomerJSF View 2
  35. 35. NewSchool Enterprise ArchitectureOld School AnsatzUIServiceDataJSF View 1DeleteCustomerCustService MailServiceCustomer MailJSF View 2
  36. 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. 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. 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. 39. NewSchool Enterprise ArchitectureOld School AnsatzUIServiceDataJSF View@ManagedBean (JSF)Session EJB Session EJBEntityManager EntityTX
  40. 40. NewSchool Enterprise ArchitectureAlternativer AnsatzUIDomainJSF ViewUseCaseControllerBusiness ObjectBusiness ObjectBusiness ObjectTX
  41. 41. NewSchool Enterprise ArchitectureAlternativer AnsatzUIDomainJSF ViewUseCaseControllerBusiness ObjectBusiness ObjectBusiness ObjectTX
  42. 42. Migration Guide
  43. 43. New School
  44. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 65. NewSchool@InterceptorBinding@Target({TYPE, METHOD})@Retention(RUNTIME)public @interface Transactional {@Nonbindingpublic TransactionalType value()default TransactionalType.REQUIRED;}Migration GuideNo more EJBs
  66. 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. 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. 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. 69. NewSchool Enterprise ArchitectureUIServiceDataJSF ViewUsecaseControllerService ServiceEntityManager EntityTXNo more EJBs
  70. 70. NewSchool Enterprise ArchitectureUIServiceDataJSF ViewUsecaseControllerService ServiceEntityManager EntityTXNo more EJBs
  71. 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. 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. 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. 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. 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. 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. 77. NewSchoolViews sind nach wie vor ein Problem‣ Injection via U-EL‣ Injection von UI ControllernNo more Infrastructure in ViewsMigration Guide
  78. 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. 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. 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. 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. 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. 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. 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. 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. 86. NewSchool Migration GuideEvent/MessageProducerCDI Bean ManagerObserver MethodObserver MethodObserver MethodNo more doAll() Business Methods
  87. 87. NewSchool Migration GuideEvent/MessageProducerCDI Bean ManagerObserver MethodObserver MethodObserver MethodNo more doAll() Business MethodsUSERCREATED
  88. 88. NewSchool Migration GuideEvent/MessageProducerCDI Bean ManagerObserver MethodObserver MethodObserver MethodNo more doAll() Business MethodsUSERCREATEDinteressantok, dankegut zuwissen
  89. 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. 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. 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. 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. 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. 94. NewSchool Enterprise ArchitectureAlternativer AnsatzUIDomainJSF ViewUseCaseControllerBusiness ObjectBusiness ObjectBusiness ObjectTX
  95. 95. NewSchool Enterprise ArchitectureAlternativer AnsatzUIDomainJSF ViewUseCaseControllerBusiness ObjectBusiness ObjectBusiness ObjectTX
  96. 96. NewSchoolNew School Enterprise Architecture‣ mit CDI‣ typensicher‣schichtenneutral‣ fachliche und technologische Injection‣ eventgetriebene EntwicklungFazitEnterprise Architecture
  97. 97. JavaNew School Enterprise ArchitectureLars Röwekamp | open knowledge GmbH@mobileLarson@_openknowledge
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×