Errai: The browser as a platform

Saturday, October 16, 2010

Slides from JUDCon Berlin

"Errai offers a set of components for building rich web applications using The Google Web Toolkit. The framework provides a unified federation and RPC infrastructure with true, uniform, asynchronous messaging across the client and server.

It extends the Google Web Toolkit in two distinct areas:

- True asynchronous bi-directional communication between GWT clients and backend systems
- Integration with enterprise component models and technologies.


In this session we'll look at CDI integration module. It offers seamless integration of CDI backend components with GWT client applications. Build as an extension to the Errai core framework, it allows you to transparently access CDI beans while harnessing the power of the core framework.

Beans that are deployed to a CDI container (i.e. JBoss 6) will automatically be registered with Errai and exposed to your GWT client application. Communication between GWT client components and CDI beans can be done in several ways:

- RPC style invocations on beans through a typed interface
- Access beans in a publish/subscribe manner
- Wiring up your GWT application with the CDI event subsystem


After this session you should have a good idea about the core framework capabilities and CDI integration in particular."


Thursday, September 23, 2010

Errai at JUDCon Berlin, October 2010

We'll be presenting Errai at the JBoss Developer Conference in Berlin next month.
Besides the core framework features we'll take a particular look at the CDI integration capabilities.
Bring your laptops, because we'll wait for you at the hackfest Thursday night.

More information here

Thursday, August 19, 2010

Enjoy the benefits of the Java EE 6 component model using GWT as an alternative view layer technology.


 

The CDI integration module offers seamless integration of CDI backend components with GWT client applications. Build as an extension to the Errai core framework, it allows you to transparently access CDI beans while harnessing the power of the core framework.

Beans that are deployed to a CDI container (i.e. JBoss 6) will automatically be registered with Errai and exposed to your GWT client application. Communication between GWT client components and CDI beans can be done in several ways:
  • RPC style invocations on beans through a typed interface
  • Access beans in a publish/subscribe manner
  • Wiring up your GWT application with the CDI event subsystem
RPC Style Invocations
When chosing RPC style invocations on beans, you basically rely on a typed java interface the CDI managed bean needs to expose. A GWT client component can then create an invocation proxy based on this interface. For more information see chapter on RPC mechanism.

Publish/Subscribe with CDI managed components
If you chose publish/subscribe then your CDI bean needs to implement the MessageCallback interface, as described in chapter 'Messaging'. Any bean exposed in this way can be accessed through the MessageBuilder API.

Integration with the CDI event subsystem
Any CDI managed component may produce and consume events. This allows beans to interact in a completely decoupled fashion. Beans consume events by registering for a particular event type and qualifier. The Errai CDI extension simply extends this concept into the client tier. A GWT client application can simply register an Observer for a particular event type and thus receive events that are produced on the server side. Likewise GWT clients can produce events that are consumed by a server side component.

Let's take a look at an example GWT component:

public class FraudClient extends LayoutPanel {

@Inject
public Event event; (1)

private HTML responsePanel;

public FraudClient() {
super(new BoxLayout(BoxLayout.Orientation.VERTICAL));

Button button = new Button("Create activity", new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
event.fire(new AccountActivity());
}
});

responsePanel = new HTML();

add(button);
add(responsePanel);
}


public void processFraud(@Observes Fraud fraudEvent) { (2)
responsePanel.setText("Fraud detected: " + fraudEvent.getTimestamp());
}
}
Two things are notable in this example:
  1. Injection of an event dispatcher proxy
  2. Creation of an Oberserver method for a particular event type
Event dispatcher proxy
The event dispatcher is responsible to send events created on the client side to the server side event subsystem (CDI container). This means any event that is fired through a dispatcher will eventually be consumed by a CDI managed bean. If there is an Observer registered for it on the server side.

Client side observer methods
In order to consume events that are created on the server side you need to declare an Observer method for a particular event type. In case an event is fired on the server side this method will be invoked with an event instance of the type you declared.

To complete this exercise, let's look at the corresponding CDI managed bean as well:

@ApplicationScoped
public class AccountService {
@Inject @Any
Event event;

public void watchActivity(@Observes @Inbound AccountActivity activity) {
Fraud payload = new Fraud(System.currentTimeMillis());
event.fire(new Outbound(payload));
}
}

Whetting your appetite? Here are some links to get you going:

"Fueling the rocket" - Approaching 1.1-Final







Ready for lift-off? The 1.1 Candidate Release has been released today. We got plenty of goodies baked into this one:

  • Serialization
    Plenty of bugfixes and performance improvements.
    Up to 40% performance gain and a much better memory footprint.

  • Deployment
    Complete replacement for the meta data facilities and deployment hooks. This a fixes a lot of problems with nested deployment artifacts (i.e. WAR inside EAR)

  • Monitoring
    Improvement activity monitoring tools. Added capabilities to query for certain message types/payload patterns.

  • CDI Integration
    Seamless integration of CDI backend components with GWT client applications.

  • And much more ...
    Check the Userguide for a complete reference of new features.


Download it now.
Browse the Userguide.
Get the sources.

Have fun,
the Errai Team





Image from "Fortress on a Skyhook" written and illustrated by Frank Tinsley, Mechanix Illustrated April, 1949

Monday, July 19, 2010

Dependency Injection in the Browser!

One of the things that will be coming in Errai 1.1 is our new IOC module which provides a dependency injection framework, based on JSR-330 in the browser. Now, this is not just Gin packaged with Errai. Rather, it's an implementation which has been built specifically to intermix with Errai's code generation infrastructure and provide a boiler-plate free experience.

When we release 1.1, gone will be the days of having to access the bus or the dispatchers through static factories. Rather, your client-side code will look even more like your server-side code.

Check out our new HelloWorld example built atop our new DIfoundations.

@EntryPoint @Service
public class HelloWorld extends VerticalPanel implements MessageCallback
{
    private Button sayHello;
    private Label label;

    private MessageBus bus;

    @Inject
    public HelloWorld(MessageBus bus) {
        this.bus = bus;
    }

    public void callback(Message message) {
        label.setText(SimpleMessage.get(message));
    }

    @PostConstruct
    public void init() {
        sayHello = new Button("Say Hello!");

        /**
         * Register click handler.
         */

        sayHello.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                MessageBuilder.createMessage()
                        .toSubject("HelloWorldService")
                        .with(MessageParts.ReplyTo, "HelloWorld")
                        .done().sendNowWith(bus);
            }
        });

        label = new Label();

        add(sayHello);
        add(label);

        RootPanel.get().add(this);
    }
}


Notice use of the @EntryPoint annotation. When you use @EntryPoint you don't need to implement your own GWT EntryPoint class, we build that for you.

You're probably already wondering if you can provide your own arbitrary providers to inject custom services, widgets and other components. And the answer is yes. We've provided a simple Provider interface that you can annotate to be discovered by the container at compile time to provide an injectable dependency. In fact both MessageBus and RequestDispatcher plug-in using this mechanism. Here's the provider for MessageBus:

@Provider
@Singleton
public class MessageBusProvider implements TypeProvider<MessageBus> {
    public MessageBus provide() {
        return ErraiBus.get();
    }
}


Pretty cool, huh? Doing more sophisticated things requires tying into the code generator which is used to generate the wiring code, and there will be documentation on how to do that. But the code generation interfaces will be surprisingly easy to use if you want to do anything particularly advanced, such as provide custom annotations for the container to process during the bootstrap process.

This is just one of the many cool features coming to Errai 1.1. Stay tuned for more!