Search
Calendar
June 2025
S M T W T F S
« May    
1234567
891011121314
15161718192021
22232425262728
2930  
Archives

Posts Tagged ‘tutorial’

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:
    EventTypeEnum getEventEnum();
  • lalou.jonathan.application.web.gwt.animal.handler.EventHandler: generic interface for a component able to handle an event. Abstract method:
    void handleEvent(HandledEvent handledEvent);
  • lalou.jonathan.application.web.gwt.animal.handler.EventHandlerBus: the actual bus. As a concrete class, it has two methods:
    /**
    	 * 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) {
                  // ...
            }

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:
    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;
    	}
    
    }
  • 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:
    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);
    
    			}
    		});
  • Handlers:
    • easy case: the component handles only one type of event: this handler must implement the right interface (eg: AnimalSelectionChangedEventHandler) and its method, eg:
      protected void handleAnimalSelectionChangedEvent(HandledEvent handledEvent) {
          return;
      }
    • 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:
      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
              }
  • PostHeaderIcon Tutorial: Tomcat / OpenJMS integration

    Install and Config

    • Let’s assume you would like to run OpenJMS and Tomcat on the same server, eg myLocalServer
    • Download OpenJMS from this page.
    • Unzip the archive, extract it to C:\exe\openjms-0.7.7-beta-1
    • Set an environment variable:set OPENJMS_HOME=C:\exe\openjms-0.7.7-beta-1
    • Take the archive $OPENJMS_HOME/lib/openjms-tunnel-0.7.7-beta-1.war
      • copy it to: $CATALINA_HOME/webapps
      • rename it as: openjms-tunnel.war
    • Edit OPENJMS_HOME/config/openjms.xml:
      • Before the ending tag</connectors>, add the block:
        <Connector scheme="http">
              <ConnectionFactories>
                <ConnectionFactory name="HTTPConnectionFactory"/>
              </ConnectionFactories>
         </Connector>
      • After the ending tag </connectors>, add the block:
        <HttpConfiguration port="3030" bindAll="true"
               webServerHost="myLocalServer" webServerPort="8080"
               servlet="/openjms-tunnel/tunnel"/>


    Run applications

    • Launch $OPENJMS_HOME/bin/startup.bat. The following output is expected:
      OpenJMS 0.7.7-beta-1
      The OpenJMS Group. (C) 1999-2007. All rights reserved.
      http://openjms.sourceforge.net
      15:15:27.531 INFO  [Main Thread] - Server accepting connections on tcp://myLocalServer:3035/
      15:15:27.547 INFO  [Main Thread] - JNDI service accepting connections on tcp://myLocalServer:3035/
      15:15:27.547 INFO  [Main Thread] - Admin service accepting connections on tcp://myLocalServer:3035/
      15:15:27.609 INFO  [Main Thread] - Server accepting connections on rmi://myLocalServer:1099/
      15:15:27.609 INFO  [Main Thread] - JNDI service accepting connections on rmi://myLocalServer:1099/
      15:15:27.625 INFO  [Main Thread] - Admin service accepting connections on rmi://myLocalServer:1099/
      15:15:27.625 INFO  [Main Thread] - Server accepting connections on http-server://myLocalServer:3030/
      15:15:27.625 INFO  [Main Thread] - JNDI service accepting connections on http-server://myLocalServer:3030/
      15:15:27.625 INFO  [Main Thread] - Admin service accepting connections on http-server://myLocalServer:3030/
    • Launch Tomcat. A webapp with path /openjms-tunnel and display name “OpenJMS HTTP tunnel” should appear.


    Checks

      • Open Console² or an MS-DOS prompt
      • Go to $OPENJMS/examples/basic
      • Run: build. This will compile all the examples.


    Check that OpenJMS is OK:

      • Edit jndi.properties,
        • Comment the property
          java.naming.provider.url
        • Add the line:
          java.naming.provider.url=tcp://myLocalServer:3035
      • Run:
        run Listener queue1
      • Open a second tab
      • Run:
        run Sender queue1 5

        • Expected output in the second tab:
          C:\exe\openjms-0.7.7-beta-1\examples\basic>run Sender queue1 5
          Using OPENJMS_HOME: ..\..
          Using JAVA_HOME:    C:\exe\beaweblo922\jdk150_10
          Using CLASSPATH:    .\;..\..\lib\openjms-0.7.7-beta-1.jar
          Sent: Message 1
          Sent: Message 2
          Sent: Message 3
          Sent: Message 4
          Sent: Message 5
        • Expected output in the first tab:
          C:\exe\openjms-0.7.7-beta-1\examples\basic>run Listener queue1
          Using OPENJMS_HOME: C:\exe\openjms-0.7.7-beta-1
          Using JAVA_HOME:    C:\exe\beaweblo922\jdk150_10
          Using CLASSPATH:    .\;C:\exe\openjms-0.7.7-beta-1\lib\openjms-0.7.7-beta-1.jar
          Waiting for messages...
          Press [return] to quit
          Received: Message 1
          Received: Message 2
          Received: Message 3
          Received: Message 4
          Received: Message 5


    Check that OpenJMS/Tomcat link is OK:


    Manual Check

      • Stop the Listener instance launched sooner
      • Edit jndi.properties,
        • Comment the line
          java.naming.provider.url=tcp://myLocalServer:3035
        • Add the line:
          java.naming.provider.url=http://myLocalServer:8080

          (this is Tomcat manager URL)

      • Run: run Listener queue1
      • Open a second tab
      • Run:
        run Sender queue1 5
      • The expected output are the same as above.


    GUI Check

    • Stop the Listener instance launched sooner
    • Ensure jndi.properties contains the line:
      java.naming.provider.url=http://myLocalServer:8080
    • Run: $OPENJMS_HOME/bin/admin.bat

      • A Swing application should start.
      • Go to:
        Actions > Connections > Online
      • The queue queue1 should be followed by a ‘0’.
      • Run: run Sender queue1 50

        • Action > Refresh
        • The queue queue1 should be followed by a ’50’.
      • Run: run Listener queue1

        • Action > Refresh
        • The queue queue1 should be followed by a ‘0’.

    PostHeaderIcon Use TibcoRV connector with Mule ESB

    Installation

    Prerequisites

    Priori to following the current tutorial, you must have installed

    • a Java JDK/JRE 1.5+, with a parameter JAVA_HOME already set
    • a TibcoRV 8.1, with a parameter TIBRV_HOME already set. You can consult a short tutorial here to perform this.

    Main

    • Get Zip version of “Mule ESB Full Distribution”, version 2.2.1, on this page.
    • Unzip the content in a folder, eg: C:\exe\mule-standalone-2.2.1
    • Add a environment variable MULE_HOME and update your path, eg:
      set MULE_HOME=C:\win32app\mule-standalone-2.2.1
      set PATH=%PATH%;%MULE_HOME%\bin
    • To check the Mule is well installed, you can launch the “Hello World” application:
      %MULE_HOME%\examples\hello\hello.bat

    Specific for TibcoRV

    • Get mule-transport-tibcorv-2.2.1.jar, available at this link.
    • Copy it into %MULE_HOME%/lib/mule
    • Get the jar %TIBRV_HOME%\lib\tibrv.jar
    • Copy and rename it into %MULE_HOME%/lib/opt/tibrvj-8.1.2.jar
    • Tip: to know the exact version of the Jar you have just copied, you can open it, explore and decompile the class com.tibco.tobrv.tibrvj_id. The exact version must appear.
    • Copy %MULE_HOME%/conf/wrapper.conf as %MULE_HOME%/conf/wrapper.conf.old
    • Edit %MULE_HOME%/conf/wrapper.conf:
      • replace
        wrapper.java.library.path.1=%LD_LIBRARY_PATH%
        wrapper.java.library.path.2=%MULE_HOME%/lib/boot

        with:

        wrapper.java.library.path.1=%LD_LIBRARY_PATH%
        wrapper.java.library.path.2=%MULE_HOME%/lib/boot
        wrapper.java.library.path.3=%TIBRV_HOME%/bin

    Here is for the very configuration.

    “Hello world” for “TibcoRV via Mule”

    Configuration file for Mule/TibcoRV “Hello World”

    Code below is commented. Save it into a file named mule-config.xml.

    <?xml version="1.0" encoding="UTF-8" ?>
    <mule xmlns="http://www.mulesource.org/schema/mule/core/2.2"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:spring="http://www.springframework.org/schema/beans"
     xmlns:management="http://www.mulesource.org/schema/mule/management/2.2"
     xmlns:tibcorv="http://www.mulesource.org/schema/mule/tibcorv/2.2"
     xmlns:stdio="http://www.mulesource.org/schema/mule/stdio/2.2"
     xsi:schemaLocation="http://www.mulesource.org/schema/mule/management/2.2
     http://www.mulesource.org/schema/mule/management/2.2/mule-management.xsd
     http://www.mulesource.org/schema/mule/core/2.2
     http://www.mulesource.org/schema/mule/core/2.2/mule.xsd
     http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
     http://www.mulesource.org/schema/mule/vm/2.2
     http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd
     http://www.mulesource.org/schema/mule/tibcorv/2.2
     http://www.mulesource.org/schema/mule/tibcorv/2.2/mule-tibcorv.xsd
     http://www.mulesource.org/schema/mule/stdio/2.2
     http://www.mulesource.org/schema/mule/stdio/2.2/mule-stdio.xsd">
     <!-- The TibcoRV we're listening is on the IP#127.0.0.1 -->
     <tibcorv:connector name="myTibcoConnector" network="127.0.0.1"/>
     <model name="fromTibco2stout">
     <service name="fromTibco">
     <inbound>
     <!-- We follow all subjects, on the TibcoRV connector defined above-->
     <tibcorv:inbound-endpoint connector-ref="myTibcoConnector" subject="*"/>
     </inbound>
     <echo-component/>
     <outbound>
     <pass-through-router>
     <!-- Messages received are displayed on standard output -->
     <stdio:outbound-endpoint address="stdio://OUT"/>
     </pass-through-router>
     </outbound>
     </service>
     </model>
    </mule>
    

    Run TibcoRV

    Launch the daemon

    Launch the daemon on localhost on port 7580:

    %TIBRV_HOME\bin\rvd -http 7580

    Launch a listener

    Possibly, you can run a listener in a separate frame, in order to double check whether messages are sent and received in the right way, independantly of what happens on Mule side.
    Listen to all messages with subject mySubject on localhost:7580

    %TIBRV_HOME\bin\tibrvlisten.exe" -network localhost mySubject

    Launch the Mule

    • Now run the ESB:
      %MULE_HOME%\bin\mule.bat -config path\to\file\mule-config.xml
    • Send a message:
      %TIBRV_HOME\bin\tibrvsend.exe -network 127.0.0.1  mySubject HelloWorld
    • Expected outputs:
      • On sending frame:
        Publishing: subject=mySubject "HelloWorld"
      • On listening frame:
        tibrvlisten: Listening to subject mySubject
        2010-01-21 17:51:43 (2010-01-21 16:51:43.109000000Z): subject=mySubject, message={DATA="HelloWorld"}
      • On Mule ESB frame:
        INFO  2010-01-21 17:53:02,860 [Bus] org.mule.transport.tibrv.TibrvMessageReceiver: message received
        on: *
        INFO  2010-01-21 17:53:02,860 [fromTibco.4] org.mule.transport.tibrv.TibrvMessageAdapter: The newThreadCopy method in AbstractMessageAdapter is being used directly. This code may be susceptible to 'scribbling' issues with messages. Please consider implementing the ThreadSafeAccess interface in the message adapter.
        INFO  2010-01-21 17:53:02,860 [fromTibco.4] org.mule.component.simple.LogComponent:
        ********************************************************************************
        * Message received in service: fromTibco. Content is: '{                       *
        * DATA="HelloWorldOfTheWorld" }'                                               *
        ********************************************************************************
        INFO  2010-01-21 17:53:02,860 [connector.stdio.0.dispatcher.3] org.mule.transport.stdio.StdioMessageDispatcher: Connected: endpoint.outbound.stdio://OUT
        {DATA=HelloWorldOfTheWorld, __send__subject__=mySubject}

    PostHeaderIcon Tibco RendezVous quick-start tutorial

    When I was introduced to TIBCO Rendezvous (also spelled “Tibco Rendez-Vous” or, shorterly, “TiboRV”), I faced a embarrassing issue: the lack of documentation and tutorials on the web.

    The purpose of this -short- tutorial is to guide you until you can send and read a “HelloWorld” message passing through Tibco RendezVous

    Installation

    • Set the variable JAVA_HOME
      Eg, in my case:

      set JAVA_HOME=C:\exe\java\jdk150_10
    • Get the file to be installed:
      TIB_rv_8.1.2_win_x86_vc8.zip
    • Unzip the content in your local drive
    • Launch the installer (.exe)
      • select Custom installation
      • choose the installation folder, eg: C:\exe\tibco
      • keep default options for other requests
    • Set the variable TIBRV_HOME
      Eg, in my case:

      set TIBRV_HOME=C:\exe\tibco\tibrv\8.1

    Main Runnables

    RVD: Daemon

    • Launching the daemon on local host on port 8181 (default port: 7580):
      rvd -http 8181

      You should see the following trace:

      C:\exe\tibco\tibrv\8.1\bin>rvd -http 8181
      
      TIB/Rendezvous daemon
      Copyright 1994-2008 by TIBCO Software Inc.
      All rights reserved.
      
      Version 8.1.2 V8 9/26/2008
      2010-01-19 16:37:02 rvd: Command line: rvd -http 8181
      2010-01-19 16:37:02 rvd: Hostname: MYLOCALMACHINE
      2010-01-19 16:37:02 rvd: Hostname IP address: 123.123.123.123
      2010-01-19 16:37:02 rvd: Detected IP interface: 123.123.123.123 (IP00)
      2010-01-19 16:37:02 rvd: Detected IP interface: 127.0.0.1 (loopback)
      2010-01-19 16:37:02 rvd: Unable to find ticket file tibrv.tkt in PATH
      2010-01-19 16:37:02 rvd: Http interface - http://myLocalMachine.myDomain:8181/

    tibrvsend: send a message

    To send a message on myLocalMachine:7580:

    .\tibrvsend.exe -service 7580 -network MYLOCALMACHINE mySubject myMessage

    Expected output:

    C:\exe\tibco\tibrv\8.1\bin>.\tibrvsend.exe -service 7580 -network MYLOCALMACHINE mySubject myMessage
    Publishing: subject=mySubject "myMessage"
    2010-01-19 16:52:11 RV: TIB/Rendezvous Error Not Handled by Process:
    {ADV_CLASS="WARN" ADV_SOURCE="SYSTEM" ADV_NAME="LICENSE.EXPIRE" ADV_DESC="The license will expire" expiretime=2010-01-19 16:02:11Z host="10.30.226.147"}

    tibrvlisten: listen to messages

    Abstract

    To listed to messages published on MYLOCALMACHINE:7580, related to subject mySubject:

    tibrvlisten -service 7580 -network MYLOCALMACHINE mySubject

    Use case: HelloWorld

    For instance, let’s assume that you launch this command from one frame:

    C:\exe\tibco\tibrv\8.1\bin>.\tibrvsend.exe -service 7580 -network localhost mySubject HelloWorld
    Publishing: subject=mySubject "HelloWorld"

    Here is what appears in the “listening” frame:

    2010-01-19 17:01:32 (2010-01-19 16:01:32.990000000Z): subject=mySubject, message={DATA="HelloWorld"}

    Notice you can have many instances listening to the same messages.

    Other runnables

    Launch the daemon manager

    • Launch:
      cd %TIBRV_HOME%/RVDM
      ./RVDM.bat -http 8282 .
    • You should see following messages, that you can ignore:
      2010-01-19 13:01:48 rvdm: RVDM has activated.
      2010-01-19 13:02:03 RV: TIB/Rendezvous Error Not Handled by Process:
      {ADV_CLASS="WARN" ADV_SOURCE="SYSTEM" ADV_NAME="LICENSE.EXPIRE" ADV_DESC="The license will expire" e
      xpiretime=2010-01-19 12:11:48Z host="123.123.123.123"}
    • To check the daemon is on, you can open the address http://localhost:8282 on your favorite browser.

    Example sources

    Example sources are available in folder %TIBRV_HOME%/src/examples/java

    Misc

    TIBRV_HOME\bin folder fosters a couple of binaries:

    • rvntscfg.exe: Services Configuration Program