Recent Posts
Archives

Posts Tagged ‘architecture’

PostHeaderIcon Tutorial: an Event Bus Handler for GWT / GXT

Overview

Introduction

Let’s consider a application, JonathanGwtApplication, divided in three main panels

  • a panel to select animal name name
  • a panel to display, expand and collapse trees of the animal ancestors
  • a panel of information to display many indicators (colors, ages, etc.).

An issue we encounter is: how to make the different panels communicate? In more technical terms, how to fire events from a panel to another one?

A first solution would be to declare each panel as listener to the other panels. Indeed, this principle may go further, and declare each component as listener to a list of other components…
Main drawbacks:

  • the code becomes hard to read
  • adding or removing a component requires to modify many parts of the code
  • we don’t follow GWT 2’s “philosophy”, which is to use Handlers rather than Listeners.

Hence, these reasons incited us to provide a global EventBusHandler.

The EventBusHandler concept

The EventBusHandler is a global bus which is aware of all events that should be shared between different panels, and fires them to the right components.
The EventBusHandler is a field of JonathanGwtApplicationContext.

Intrastructure

  • lalou.jonathan.application.web.gwt.animal.events.HandledEvent: generic interface for a event. Abstract method:
    [java]EventTypeEnum getEventEnum();[/java]
  • lalou.jonathan.application.web.gwt.animal.handler.EventHandler: generic interface for a component able to handle an event. Abstract method:
    [java]void handleEvent(HandledEvent handledEvent);[/java]
  • lalou.jonathan.application.web.gwt.animal.handler.EventHandlerBus: the actual bus. As a concrete class, it has two methods:
    [java]/**
    * Fires an event to all components declared as listening to this event
    * event type.
    *
    * @param baseEvent
    */
    public void fireEvent(HandledEvent baseEvent) {
    // …
    }

    /**
    * Adds an listener/handler for the event type given as parameter
    *
    * @param eventTypeEnum
    * @param eventHandler
    * @return The List of handlers for the key given as parameter. This list
    * contains the eventHandler that was given as second parameter
    */
    public List<EventHandler> put(EventTypeEnum eventTypeEnum,
    EventHandler eventHandler) {
    // …
    }[/java]

How to use the bus?

  1. Define an event: in JonathanGwtApplication, an event is decribed by two elements:
    • a functionnal entity: eg: “animal”, “food”, “tree node”. The functionnal entity must be isomorph to a technical DTO, eg: AnimalDTO for an entity Animal.(in the scope of this turoriel we assume to have DTOs, even though the entities may ne sufficient)
    • a technical description of the event: “selection changed”, “is expanded”
  2. Add an entry in the enum EventTypeEnum. Eg: “ANIMAL_SELECTION_CHANGED
  3. in lalou.jonathan.application.web.gwt.animal.events, create an event, implementing HandledEvent and its method getEventEnum(). The match between EventTypeEnum and DTO is achieved here. Eg:
    [java]public class AnimalSelectionChangedEvent extends
    SelectionChangedEvent<AnimalDTO> implements HandledEvent {

    public AnimalSelectionChangedEvent(
    SelectionProvider<AnimalDTO> provider,
    List<AnimalDTO> selection) {
    super(provider, selection);
    }

    public EventTypeEnum getEventEnum() {
    return EventTypeEnum.ANIMAL_SELECTION_CHANGED;
    }

    }[/java]

  • When an event that should interest other component is fired, simply call the bus. The bus will identify the event type and dispatch it to the relevant handlers. eg:
    [java]animalComboBox.addSelectionChangedListener(new SelectionChangedListener<AnimalDTO>() {

    @Override
    public void selectionChanged(SelectionChangedEvent<AnimalDTO> se) {
    final AnimalDTO selectedAnimalVersion;
    selectedAnimalVersion= se.getSelectedItem();
    JonathanGwtApplicationContext.setSelectedAnimal(selectedAnimal);

    final AnimalSelectionChangedEvent baseEvent = new AnimalSelectionChangedEvent(
    se.getSelectionProvider(), se.getSelection());
    JonathanGwtApplicationContext.getEventHandlerBus()
    .fireEvent(baseEvent);

    }
    });[/java]

  • Handlers:
    • easy case: the component handles only one type of event: this handler must implement the right interface (eg: AnimalSelectionChangedEventHandler) and its method, eg:
      [java]protected void handleAnimalSelectionChangedEvent(HandledEvent handledEvent) {
      return;
      }[/java]
    • frequent case: the component handles two or more event types. No matter, make the component implement all the needed interfaces (eg: AnimalSelectionChangedEventHandler, FoodSelectionChangedEventHandler). Provide a unique entry point for the method to implement, which is common to both interfaces. Retrieve the event type, and handle it with ad hoc methods. Eg:
      [java]public void handleEvent(HandledEvent handledEvent) {
      final EventTypeEnum eventTypeEnum;

      eventTypeEnum = handledEvent.getEventEnum();

      switch (eventTypeEnum) {
      case ANIMAL_SELECTION_CHANGED:
      handleAnimalSelectionChangedEvent(handledEvent);
      return;
      case FOOD_SELECTION_CHANGED:
      handleFoodSelectionChangedEvent(handledEvent);
      return;
      default:
      break;
      }
      }

      protected void handleAnimalSelectionChangedEvent(HandledEvent handledEvent) {
      // do something
      }
      protected void handleFoodSelectionChangedEvent(HandledEvent handledEvent) {
      // do something else
      }[/java]

  • PostHeaderIcon WebLogic 10.x new features

    Recent history

    BEA WebLogic 9.0, 9.1 and 9.2 were released from 2007: the main features were: a new console, WLST (WebLogic ScriptingTool), deployment plans, WebLogic Diagnostic Framework (WLDF), new security providers (RDBMS, SAML 1.1, etc.), JMS performance improvements, support of Java EE 4, JDK 5, Spring, OpenJPA, Kodo, etc.

    Since this date, some events happened:

    • Oracle bought Sun (2009)
    • Oracle released WebLogic 10.3 (2008)
    • Oracle bought BEA (2008)

    WebLogic Server 10 General Features

    • Developer productivity ehancements
      • JDK 6, Java EE 5
      • Support of EJB3 and JPA
      • BEA enhancements
    • Web Services: more annotations, less XML
      • JAX-RPC Web Services Enhancements
      • JAX-WS 2.0 Web Services Implementation
    • Misc:
      • Better administration console
      • Auto-Record of Admin Console actions as WLST scripts
      • Automatic JTA Transaction Recovery Service (TRS) migration
      • SNMP 3.0
      • Production Application Redeployment enhancements
      • Clustering – Unicast messaging (in addition to Multicast)

    Programmer Perspective

    • New persistence engine: TopLink
    • OEPE (Oracle Entreprise Pack for Eclipse): sequence of tools and plugins for Eclipse: remote deployment, debugging,  editors for weblogic.xml and weblogic-application.xml, wizards, facets, Weblogic ClientGen, WSDLC and JAXB wizards
    • Optimizations for Spring integration and certication
    • Web 2.0:
      • Ajax / Dojo client support
      • Http publish / submit engine for collaborative applications:
        • Bayeux protocol
        • data exchange within applications over persistent connections
        • scalability for Dojo clients
    • Ad-hoc tools for:
      • Oracle Database
      • Spring
      • JAX-WS webservices

    Lightweight WebLogic Server

    WebLogic 10 offers a light weight server:

    • Install only “core” WebLogic server
    • Optionally, startup other services (JDBC, EJB, JMS, etc.)
    • FastSwap: modify classes without requiring redeployment.

    Architect Perspective

    Architects have to consider WebLogic as a complete suite, and not only WebLogic Server:

    • Oracle RAC integration: Connectivity to RAC with load balancing, failover, transactions
    • Enterprise Messaging with JMS: High performance and reliable JMS messaging engine “built-in”
    • ActiveCache with Coherence*Web and EJB/JPA: Coherence Data Grid caching included and integrated
    • Operations Automation: Tools for automating management of applications and servers
    • Operations Insight: Tools for diagnosing problems in development and production
    • Other features
      • Development tools: Choice of tools for developer productivity
      • Web Services: Enterprise Web Services for SOA
      • TopLink: Persist application data to stores with performance and productivity. It works in a way similar to Hibernate L2 cache.
      • Spring: Enable flexible choice of dev frameworks with same WebLogic QOS

    Production and Support Perspective

    WebLogic 10 provides a tool: JRockit Mission Control

    • monitors more than 150 parameters:
    • CPU
      • memory
      • leaks
      • latency spikes
      • threads
      • object references
      • JDBC connections
      • JMS
      • pools
      • clusters
      • configuration files
      • etc.
    • allows to compare WebLogic domains
    • Runtime Analyzer: runtime capture for offline analysis, Garbage Collector analysis, etc.

    Coherence – ActiveCache

    Coherence is the Data Grid offered by Oracle. It allows to store Java objects in memory, and share them between all instances. From a certain viewpoint, Coherence looks like the GigaSpaces.

    Roadmap for Future WebLogic Releases

    • Support of Java EE 6 (ratified by the community in last December)
    • OSGi deployment
    • More native integration for WebLogic Server – Coherence – Oracle Database
    • JRockit Flight Recorder for constant record
    • Virtualization
    • More integration with Maven, Hudson and Cruise Control
    • Shared Library: use the same JAR for many applications, rather than packing the same JAR in different EARs.
    • On long term:
      • IDE
        • NetBeans to be oriented onto J2ME development
        • JDevelopper to remain Oracle strategic IDE
        • Contributions to Eclipse to go on
      • JRockit and Sun HotSpot JVMs to be merged.