Core J2EE Patterns 2

Embed Size (px)

Citation preview

  • 8/7/2019 Core J2EE Patterns 2

    1/81

    [email protected]

    Patterns & Design Expertise Center

    Sun Software Services

    Core J2EE Patterns, Frameworks andMicro Architectures

    January 2004

  • 8/7/2019 Core J2EE Patterns 2

    2/81

    Agenda

    Patterns Core J2EE Pattern Catalog Background

    J2EE Progressive Refactoring

    Pattern Frameworks

    Micro Architecture Web Worker Micro Architecture Example

    Messaging Micro Architecture Example Q&A

  • 8/7/2019 Core J2EE Patterns 2

    3/81

    Architectural Decisions Produce

    Varying Results

    .Net J2EE

  • 8/7/2019 Core J2EE Patterns 2

    4/81

  • 8/7/2019 Core J2EE Patterns 2

    5/81

    What Is A Pattern?

    Solution to a recurring problem in a context

    Context : What is the environment like? Problem : What do I want to do? Solution : How do I do it?

  • 8/7/2019 Core J2EE Patterns 2

    6/81

    Patterns are...

    Abstractions Discovered, not created

    Difficult to see the appropriategranularity

    Mined from good designs

    Refactoring targets

  • 8/7/2019 Core J2EE Patterns 2

    7/81

    Core J2EE Patterns

    Core J2EE Patterns are platform patterns. The context is bounded by the J2EE platform Built upon non-platform patterns GoF

  • 8/7/2019 Core J2EE Patterns 2

    8/81

    Core J2EE Patterns Book

    1

    st

    Edition June 2001 15 Patterns categorized bytiers: Presentation Business

    Integration Lots of Code Samples Design Considerations Bad Practices Refactorings

    2nd Edition JavaOne, June 2003 21 patterns Micro-architecture

  • 8/7/2019 Core J2EE Patterns 2

    9/81

    Core J2EE Patterns Book

    Client TierBrowser, Applets, Applications, Clients

    Presentation TierJSP, Servlets, UI Elements

    Business TierEJB and Business Objects

    Integration Tier

    JDBC, JMS, Connectors

    Resource TierDatabases, Systems Legacy

    J2EE Pattern Catalog

    Addresses 3 Tiers

  • 8/7/2019 Core J2EE Patterns 2

    10/81

    Pattern Format

    Extensibility

    Problem Forces

    Solution Structure

    Interaction

    Consequences

    Strategies

  • 8/7/2019 Core J2EE Patterns 2

    11/81

    Pattern Strategies

    Pattern is abstract and a strategy is(more) concrete

    Extensibility

  • 8/7/2019 Core J2EE Patterns 2

    12/81

    Pattern Relationships

  • 8/7/2019 Core J2EE Patterns 2

    13/81

    Presentation-Tier Patterns

    Intercepting Filter Front Controller

    Composite View

    View Helper

    Service to Worker

    Dispatcher View Context Object

    Application Controller

    new

    new

  • 8/7/2019 Core J2EE Patterns 2

    14/81

    Business Tier Patterns Business Delegate

    Session Facade

    Service Locator

    Transfer Object

    Composite Entity

    Transfer Object Assembler

    Value List Handler

    Business Object

    Application Service new

    new

  • 8/7/2019 Core J2EE Patterns 2

    15/81

    Integration Patterns

    Data Access Object Service Activator

    Domain Store

    Web Service Broker

    new

    new

  • 8/7/2019 Core J2EE Patterns 2

    16/81

    New Patterns Facts

    Patterns represent abstractions emerging fromusing existing patterns in complexapplications and flesh out pattern language(Context Object, Application Controller,

    Business Object, etc.). New patterns rely on POJO stereotype

    New patterns identify a web container only

    scenario Domain Store addresses Transparent

    Persistence (JDO and the like)

    Updated for J2EE 1.4 and Web Services

  • 8/7/2019 Core J2EE Patterns 2

    17/81

    Presentation Tier Patterns Intercepting Filter

    Front Controller

    Context Object

    Application Controller View Helper

    Composite View

    Service To Worker

    Dispatcher View

  • 8/7/2019 Core J2EE Patterns 2

    18/81

    Context Object

    Problem: You want to avoid using protocol-specific system

    information outside of its relevant context

    Forces:

    You have components and services that need access tosystem information

    You want to decouple application components andservices from the protocol specifics of systeminformation

    You want to expose only the relevant APIs within acontext

  • 8/7/2019 Core J2EE Patterns 2

    19/81

    Context Object

    Solution: Use a Context Object to encapsulate state in a

    protocol-independent way to be sharedthroughout your application

  • 8/7/2019 Core J2EE Patterns 2

    20/81

    Context Object Strategies Request Context Strategies

    Request Context Map Strategy

    Request Context POJO Strategy

    Request Context Validation Strategy

    Configuration Context Strategies

    JSTL Configuration Strategy

    Security Context Strategies

    General Context Object Strategies

    Context Object Factory Strategy

    Context Object Auto-population Strategy

  • 8/7/2019 Core J2EE Patterns 2

    21/81

    Application Controller

    Problem: You want to centralize and modularize action

    and view management

    Forces:

    You want to reuse action-management andview-management code

    You want to improve code modularity andmaintainability

    You want dynamic lookup and dispatch to target

  • 8/7/2019 Core J2EE Patterns 2

    22/81

    Application Controller

    Solution: Use an Application Controller to centralize

    retrieval and invocation of request-processingcomponents, such as commands and views.

  • 8/7/2019 Core J2EE Patterns 2

    23/81

    Application Controller:Command Handler Strategy

  • 8/7/2019 Core J2EE Patterns 2

    24/81

    Business Tier Patterns

    Business Delegate Service Locator

    Session Facade

    Business Object Application Service

    Composite Entity

    Transfer Object

    Transfer Object Assembler

    Value List Handler

  • 8/7/2019 Core J2EE Patterns 2

    25/81

    Business Object

    Problem: You have a conceptual domain model with

    business logic and relationships

    Forces:

    You have a conceptual model containingstructured, interrelated composite objects,complex business logic, validation, rules

    You want to centralize business logic and statein an application

    You want to increase reusability of businesslogic and avoid duplication of code

  • 8/7/2019 Core J2EE Patterns 2

    26/81

    Business Object

    Solution: Use Business Objects to separate business data

    and logic using an object model

  • 8/7/2019 Core J2EE Patterns 2

    27/81

    Application Service

    Problem: You want to centralize business logic across

    several business-tier components and services

    Forces: You want to minimize business logic in service

    facades

    You have business logic acting on multiple

    Business Objects or services You want to encapsulate use case-specific logic

    outside of individual Business Objects

  • 8/7/2019 Core J2EE Patterns 2

    28/81

    Application Service

    Solution: Use an Application Service to centralize and

    aggregate behavior to provide a uniform servicelayer

  • 8/7/2019 Core J2EE Patterns 2

    29/81

    Integration Tier Patterns

    Data Access Object

    Service Activator

    Domain Store Web Service Broker

  • 8/7/2019 Core J2EE Patterns 2

    30/81

    Domain Store

    Problem: You want to separate persistence from yourobject model

    Forces: You want to avoid putting persistencedetails in your Business Objects

    You do not want to use entity beans

    Your application might be running in a webcontainer

    Your object model uses inheritance andcomplex relationships

  • 8/7/2019 Core J2EE Patterns 2

    31/81

    Domain Store

    Solution: Use Domain Store to separate persistence from the

    object model

  • 8/7/2019 Core J2EE Patterns 2

    32/81

    Web Service Broker

    Problem: You want to provide access to one or more

    services using XML and web protocols

    Forces: You want to reuse and expose existing services

    to clients

    You want to monitor and potentially limit the

    usage of exposed services

    Your services must be exposed using openstandards

  • 8/7/2019 Core J2EE Patterns 2

    33/81

    Web Service Broker

    Solution: Use a Web Service Broker to expose and broker

    one or more services using XML and webprotocols

  • 8/7/2019 Core J2EE Patterns 2

    34/81

    Web Service Broker: Strategies

    Custom XML Messaging Strategy

    Java Binding Strategy

    JAX-RPC Strategy

  • 8/7/2019 Core J2EE Patterns 2

    35/81

    Agenda

    Patterns Core J2EE Pattern Catalog Background

    J2EE Progressive Refactoring Scenarios

    Pattern Frameworks Micro Architecture

    Web Worker Micro Architecture Example

    Messaging Micro Architecture Example Q&A

  • 8/7/2019 Core J2EE Patterns 2

    36/81

    J2EE Refactoring

    14 Refactorings in the book Presentation Tier:

    Hide Presentation Tier specifics from Business

    Tier Introduce Synchronizer Token

    Business Tier:

    Wrap Entities with Session Merge Session Beans

  • 8/7/2019 Core J2EE Patterns 2

    37/81

    Hide Presentation Tier specifics...

    PresentationComponent

    BusinessComponent

    HttpServletRequest HttpServletRequest

    PresentationTier

    BusinessTier

    PresentationComponent

    BusinessComponent

    HttpServletRequest HttpServletRequest

    PresentationTier

    BusinessTier

    PresentationComponent

    BusinessComponent

    HttpServletRequest UserInfo

    PresentationTier

    BusinessTier

    PresentationComponent

    BusinessComponent

    HttpServletRequest UserInfo

    PresentationTier

    BusinessTier

  • 8/7/2019 Core J2EE Patterns 2

    38/81

    Introduce Synchronizer Token

    DuplicateAllowed

    Controller

    Presentation

    Tier

    JSPClient

    Request

    Duplicate

    2

    1

    2

    1

    Controller

    Presentation

    Tier

    JSPClient

    Request

    Duplicate

    2

    1

    2

    1

    2

    1

    Controller

    Presentation

    Tier

    JSPClient

    Request

    Duplicate

    2

    1

    2

    1

    DuplicateDisallowed

    No

    Access

    TOKENTOKEN

  • 8/7/2019 Core J2EE Patterns 2

    39/81

    Wrap Entities With Session

    EntityBean

    A

    EntityBean

    B

    EntityBean

    C

    Client

    BusinessLogic

    TransactionLogic

    ClientBusiness

    Logic

    SessionFacade

    EntityBean

    A

    EntityBean

    B

    EntityBeanCTransaction Logic:

    Bean ManagedorContainer Managed

    BusinessTier

    BusinessTier

    BusinessTier

    Client orPresentation

    Tier

    Client orPresentation

    Tier

    Client orPresentation

    Tier

    Client orPresentation

    Tier

  • 8/7/2019 Core J2EE Patterns 2

    40/81

    Merge Session Beans

    BusinessTier

    BusinessTier

    Client orPresentation

    Tier

    Client orPresentation

    Tier

    Client orPresentation

    Tier

    Client orPresentation

    Tier

    BusinessTier

    BusinessTier

    ClientInteraction

    #1

    Client

    Interaction#2

    ClientInteraction

    #3

    ClientInteraction

    #1

    Client

    Interaction#2

    ClientInteraction

    #3

    Session

    Session

    Session

    Entity

    Entity

    Entity

    Facade

    Facade

    Entity

    Entity

    Entity

  • 8/7/2019 Core J2EE Patterns 2

    41/81

    Progressive Refactoring Scenarios

    Direct Access Introduce DAO

    Introduce Application Service

    Introduce Service Facade

    Introduce Business Objects

  • 8/7/2019 Core J2EE Patterns 2

    42/81

    Direct Access

    Database

    Command

    Helper

  • 8/7/2019 Core J2EE Patterns 2

    43/81

    Introduce DAO

    Database

    Command

    Helper

    DAO

  • 8/7/2019 Core J2EE Patterns 2

    44/81

    Introduce Application ServicePOJO Architecture

    Database

    Command

    Helper

    DAOApplication

    Service

  • 8/7/2019 Core J2EE Patterns 2

    45/81

    Introduce Application ServiceEJB Architecture

    Command

    Business

    Delegate

    Session

    Facade

    Helper

    Application

    Service

    DAO

  • 8/7/2019 Core J2EE Patterns 2

    46/81

    Design Note: Service Facades

    Remote and non-Remote business tier

    RemoteFacade

    LocalFacade

    POJOFacade

    SessionFacade

    ServiceFacade

  • 8/7/2019 Core J2EE Patterns 2

    47/81

    Introduce Service FacadeNon-Remote Business Tier

    Service Facade >>Local Facade >>

    Local Session Bean | POJO

    Command

    Service

    Facade

    Helper

    DAO

  • 8/7/2019 Core J2EE Patterns 2

    48/81

    Introduce Service FacadeRemote Business Tier

    PhysicalBoundary

    Service Facade >>Remote Facade >>

    Remote Session Bean

    Command

    Business

    Delegate

    Service

    Facade

    Helper

    DAO

  • 8/7/2019 Core J2EE Patterns 2

    49/81

    Introduce Business Objects

    Command

    Business

    Delegate

    Session

    Facade

    Business

    Object

    Domain

    Store

    Helper

    Application

    Service

    DAO

  • 8/7/2019 Core J2EE Patterns 2

    50/81

  • 8/7/2019 Core J2EE Patterns 2

    51/81

    Agenda

    Patterns Core J2EE Pattern Catalog Background

    J2EE Progressive Refactoring Scenarios

    Pattern Frameworks Micro Architecture

    Web Worker Micro Architecture Example

    Messaging Micro Architecture Example

    Q&A

  • 8/7/2019 Core J2EE Patterns 2

    52/81

    Pattern Framework

    Set of cooperating patterns Targeting macro problem

    Basis for pattern driven design

  • 8/7/2019 Core J2EE Patterns 2

    53/81

    Pattern Realization

    Realizing patterns to code

  • 8/7/2019 Core J2EE Patterns 2

    54/81

    Agenda

    Patterns Core J2EE Pattern Catalog Background

    J2EE Progressive Refactoring Scenarios

    Pattern Frameworks Micro Architecture

    Web Worker Micro Architecture Example

    Messaging Micro Architecture Example

    Q&A

  • 8/7/2019 Core J2EE Patterns 2

    55/81

    Micro Architectures

    Micro-architectures are building blocks for designingapplications

    They represent a higher level of abstraction than theindividual patterns described in the catalog, and areexpressed by a combination of patterns to solve aproblem

    Micro-architecture is a prescriptive design leveragingpatterns to solve a larger problem, such as designing asubsystem

    Micro-Architectures:

    WebWorker Micro Architecture

    Messaging Micro Architecture

  • 8/7/2019 Core J2EE Patterns 2

    56/81

    Micro Architectures

  • 8/7/2019 Core J2EE Patterns 2

    57/81

    Web Worker Micro Architecture Problem:

    How do you integrate a J2EE application and a workflowsystem and have the workflow system direct users to theappropriate web page

    User 1 User 2 User 3

    J2EE

    Use Case 1

    Page

    Logic

    Use Case 2

    Page

    Logic

    Use Case 3

    Page

    Logic

    Workflow

  • 8/7/2019 Core J2EE Patterns 2

    58/81

    Hire Employee Workflow

    i l ll b i

  • 8/7/2019 Core J2EE Patterns 2

    59/81

    Hire Employee Collaborationwith Adapters

  • 8/7/2019 Core J2EE Patterns 2

    60/81

    i

  • 8/7/2019 Core J2EE Patterns 2

    61/81

    Work Adapter Class Diagram

    Application Controller

  • 8/7/2019 Core J2EE Patterns 2

    62/81

    Messaging Micro Architecture

    Messaging >> Async, Web Services

    Problem:

    How do you provide async, doc-based webservices in J2EE

    How do you orchestrate these web services

    h i

  • 8/7/2019 Core J2EE Patterns 2

    63/81

    Async WS OrchestrationWith J2EE

    Invoke

    Async Reply(sometime later)Business

    Process

    Orchestration

    (BPEL)

    J2EE

    WebService

    J2EE

    WebService

    J2EE

    WebService

    Shi i l

  • 8/7/2019 Core J2EE Patterns 2

    64/81

    Shipping Example

    Shi i E l

  • 8/7/2019 Core J2EE Patterns 2

    65/81

    Shipping Example

    Shipper Transporter

    A W b S i O h t ti

  • 8/7/2019 Core J2EE Patterns 2

    66/81

    Async Web Service Orchestration

    Shipping Company contracts Transportersto ship products

    Client Web AppOrchestration

    Server

    Transport 1

    Transport 2

    Transport 3

    Micro ArchitectureMicro Architecture

    Bid Request

    Bid

    Mi A hit t d f P tt

  • 8/7/2019 Core J2EE Patterns 2

    67/81

    Micro Architecture composed of Patterns

    ContextObject

    InterceptingFilter

    Web ServiceBroker

    ApplicationController

    TransporterMessage Context

    Message Handler

    Service Endpoint, Broker/Mediator, Validation

    Routing

    ServiceActivator

    OrchestrationServer

    ApplicationService

    Service

    W b S i B k

  • 8/7/2019 Core J2EE Patterns 2

    68/81

    Web Service Broker

    G t Bid I t ti E Ch t

  • 8/7/2019 Core J2EE Patterns 2

    69/81

    Get Bids Interaction Eye-Chart

    G t Bid I t ti P t 1

  • 8/7/2019 Core J2EE Patterns 2

    70/81

    Get Bids Interaction Part 1Transporter

    Web Service

    Get Bids Interaction Part 2

  • 8/7/2019 Core J2EE Patterns 2

    71/81

    Get Bids Interaction Part 2

    Create Bid Interaction E e Chart

  • 8/7/2019 Core J2EE Patterns 2

    72/81

    Create Bid Interaction Eye-Chart

    Create Bid Interaction Part 1

  • 8/7/2019 Core J2EE Patterns 2

    73/81

    Create Bid Interaction Part 1Bid App

    Create Bid Interaction Part 2

  • 8/7/2019 Core J2EE Patterns 2

    74/81

    Create Bid Interaction Part 2

    Bid App

  • 8/7/2019 Core J2EE Patterns 2

    75/81

    ACE: Design To Deplo Ser ice

  • 8/7/2019 Core J2EE Patterns 2

    76/81

    ACE: Design To Deploy Service Rapid intuitive design of enterprise

    applications

    Focus on design rather than coding

    Builds upon best practices, patternsand frameworks

    Fewer resources, faster development

    Automated deployment

    DASL S ifi ti L

  • 8/7/2019 Core J2EE Patterns 2

    77/81

    DASL: Specification Language

    ACE uses a high level domain

    modeling language called DASL

    DASL is used to specify:

    Business Objects, relationships

    Core reusable business logic

    User interaction

    Transactions and Persistence

    DASL G hi t l

  • 8/7/2019 Core J2EE Patterns 2

    78/81

    DASL: Graphic tools

    Summary

  • 8/7/2019 Core J2EE Patterns 2

    79/81

    Summary Patterns are great! Use them effectively to improve

    software quality

    Build New Architecture

    Analyse / understand existing Architecture

    Refactor Avoid re-inventing the wheel

    Promote design re-use

    Increase developer productivity, communication

    Micro Architectures leverage patterns

    Large and growing community around patterns

    Stay Connected:

  • 8/7/2019 Core J2EE Patterns 2

    80/81

    Stay Connected:

    Check out CJP:

    http://www.corej2eepatterns.com

    Subscribe:

    http://archives.java.sun/j2eepatterns-interest.html

    Write to us:

    [email protected]

    Java.Net Patterns Community

  • 8/7/2019 Core J2EE Patterns 2

    81/81

    [email protected] January 2004

    Thanks!