Eclipse Yoxos Services Downloads Blogs About
Home > Blogs >

Posts Tagged ‘rap’

on Jun 20th, 2011Using OSGi services to single-source an RCP and RAP Application

Probably one of RAP’s best known features is its single-sourcing capabilities. Some time ago we created a guide on Single-Sourcing RCP and RAP applications. The guide recommended a technique where a facade and fragments were used to invoke the RCP or RAP implementation during runtime. With this post I want to show you how to achieve the same the OSGi way.

For single-sourcing a RAP or RCP application, its straightforward to use the power of OSGi because it’s included in both platforms out-of-the-box. OSGi has a central concept called services which are simply POJOs and are used to allow communication between modules. And, you can register or resolve services at any time in your code.

The basic Idea behind using OSGi services for single-sourcing is as follows. We need to extract all the things that vary into separate, platform specific bundles. To use the different implementations, we have to create an interface in a “common” bundle that contains the methods we want to use. The platform specific bundles have to register an implementation of this interface as a service. In the “common” bundle we can reference the registered services and use them to get the platform specific stuff. More specifically, we register a RAP implementation in a “rap” bundle and an RCP implementation in an “rcp” bundle. The only thing we need to do then is to start the right bundles on the associated platform to get the right service.

With this solution we can extract the platform specific stuff into separate bundles and we don’t have to rely on fragments. So enough talking. Let’s look at some code. I decided to create a very simple single-sourcing interface which can be used to get the WidgetUtil.CUSTOM_VARIANT constant value. This constant exists only in RAP so, it’s a good example for showing how to handle the differences.

public interface ISingleSourcingService {
  String getCustomVariantString();
}

I have created three bundles: one that contains the application which is entitled “com.eclipsesource.app” and one for each platform. These are called “com.eclipsesource.app.rap” and “com.eclipsesource.app.rcp”. Both platform bundles implement the interface.
RAP:

  @Override
  public String getCustomVariantString() {
    return WidgetUtil.CUSTOM_VARIANT;
  }

RCP:

  @Override
  public String getCustomVariantString() {
    // There are no custom variants in RCP
    return "";
  }

And both bundles are registering the service in their Activator during the start method call.

  public void start( BundleContext bundleContext ) throws Exception {
    Activator.context = bundleContext;
    registration = context.registerService( ISingleSourcingService.class.getName(),
                                            new RAPSingelSourcingService(),
                                            null);
  }

When it comes to using the service in the common “app” bundle we can use a ServiceTracker to get the service implementation (you can also use DS).

  private ISingleSourcingService getSingleSourcingService() {
    // We use a tracker to get the service. We also can use DS to get it.
    Bundle bundle = FrameworkUtil.getBundle( getClass() );
    BundleContext context = bundle.getBundleContext();
    ServiceTracker tracker
      = new ServiceTracker( context,
                            ISingleSourcingService.class.getName(),
                            null );
    tracker.open();
    ISingleSourcingService service = tracker.getService();
    tracker.close();
    return service;
  }

The only thing we have to do now is to create two launch configurations which contain the associated platform-specific bundle.

That’s it! You can find the sources in this github repository. Have fun using OSGi services to single-source applications.

 

on Jun 16th, 2011High availability clustering for RAP/RWT in Eclipse Juno

cluster High availability clustering for RAP/RWT in Eclipse Juno

Computer cluster, taken from http://thefullwiki.org/Parallel_programming

While most of us are busy with that latest bits of the Indigo release, some have the joy to work on one of the next new features in RAP: support for high availablity clusters.

Let me briefly mark out what we mean by clustering support and what we don’t. Load balancing clusters are used if you whish to provide your applications to a large number of users. If your application provides critical servies you may also want to make it fail safe by running it in a high availablity cluster.

A high availability cluster operates by having redundant nodes. So that if one node crashes, the service as a whole is unafected as other nodes take over the work. Whereas load balancing RAP applications is possible since ever, failover clusters put further requirements on the framework.

To be able to migrate sessions between nodes in a cluster, all session data has to be serializable. Also, the current implementation preserves the server-side execution flow within a UIThread in order to single-source RCP applications. These two form the main work areas.

  • All session data must be prepared for distributing sessions among cluster nodes for failsafe operation.
  • A new life cycle for processing requests without a UIThread was implemented and RAP can be configured to run with either of them.

The new life cycle also makes it easier to access security or transaction contexts and is conform to the JEE Specification. If you don’t use blocking dialogs or workbench features and want to be able to eventually run your application in a cluster – then this is for you.

For more details, see the RAP Wiki.

on Jun 7th, 2011jQuery timeago in Java with RAP

A few weeks ago I showed you how easy it is to integrate jQuery into RAP using the browser widget. I’d like to show you another example of what can be integrated. Last time I created a carousel widget; this time the demo is something smaller but still really cool.

Yesterday I came across a github repository by Ryan McGeary. He has created a very clever jQuery plug-in called “timeago“. What this plug-in does is simple. It takes a timestamp and displays a text string instead of the stamp that describes the difference between the actual time and the one in the timestamp.  We’ve all seen the messages, “about a minute ago.”  The cool thing about this plug-in is that it refreshes automatically. I mean, it isn’t new to transform timestamps in this way, but it is usually done just once. So, when you visit a website in the morning and leave the tab open until evening, it still says something like, “The page was opened about minute ago” icon wink jQuery timeago in Java with RAP . This can’t happen with McGeary’s plug-in.

While having a jQuery plug-in is nice for javascript developers, it’s not as nice if you’re a Java Developer. But, fortunately we can integrate jQuery painlessly into RAP. As a result I wrote a RWT/SWT widget that simply maps the functionality of the timeago plug-in. You can set a date from the server and read the displayed text from the client.
timeago jQuery timeago in Java with RAP
If you like this idea you can grab the sources at github. Of course this is just a demo. Let me know if you would like to work with me on an implementation for productive use. Have fun with timeago icon wink jQuery timeago in Java with RAP

on May 4th, 2011Launch an OSGi app and automatically kill its running instance

If you use Eclipse to develop OSGi based applications you may use the OSGi Launcher provided by the PDE Tooling. It’s cool tooling because it gives you full control over the OSGi instance to be launched.  You can choose the OSGi framework (e.g. Equinox or Felix), select the bundles to install and much more.

But this launcher has one drawback that hurts every time I run across it. It appears when an OSGi application uses the OSGi HttpService. When you used this service you may have configured a port for it via the property “org.osgi.service.http.port” VM Argument.  I use this configuration all the time.

When I launch the application everything works fine the first time. But, during development I often come to the point where I need to relaunch the application. When I forget to kill the previous running instance I get a java.net.BindException because the address is already in use. So, to fix this I have to kill both instances and launch it again. This happens to me a lot just because I forget to terminate the previous instance. Of course this isn’t a bug because it’s often useful to launch a second instance of the same configuration. But, not when it comes to developing with the HttpService.

bindException Launch an OSGi app and automatically kill its running instance

There is a fix now (though not necessarily for my forgetfulness icon wink Launch an OSGi app and automatically kill its running instance ).  Luckily we live in a modular world in Eclipse. As a result, I was able to develop a separate bundle called the “OSGi Eliminator” (what a descriptive name icon smile Launch an OSGi app and automatically kill its running instance ). The bundle contributes the functionality to automatically terminate a running OSGi Instance when you try to launch the same instance a second time. This functionality already existed in the RAP launcher created by Rüdiger Hermann. All I did was to refactor the functionality out to make it run in a separate bundle and contribute to the OSGi Launcher instead of the RAP Launcher. This solves an annoying problem for me – maybe for you as well?

You can find this bundle on GitHub. I also created a p2 repository that lets you install the OSGi Eliminator directly into Eclipse.

on Apr 27th, 2011Key Bindings in RAP

Support for key bindings (bug 282449) has been one of the most requested features for RAP. So I’m happy to say that since 1.4 M5, RAP implements the JFace key bindings API, provides the org.eclipse.ui.bindings extension point, and enables most of the default workbench key bindings. As a result, you can now use most* of the key shortcuts of your application also in the browser–if your application uses the workbench. But many use RAP without using the workbench. So how can you enable key bindings in a plain RWT application?

In M7, we now introduce a simple way of doing this. Let’s first have a look on how you would implement a key binding in SWT. You would have to register a global listener for key events on the display like this:

display.addFilter( SWT.KeyDown, new Listener() {
  public void handleEvent( Event event ) {
    if( event.stateMask == 0 && event.keyCode == SWT.ESCAPE ) {
      // handle escape key
    }
  }
} );

Well, you can now use the same code in RWT.

But there’s one more thing to it: RWT is a client-server architecture and we don’t want the browser client to send a request for each and every key stroke. The server should only be notified when the user presses one of the key sequences that we are really interested in. Therefore, we have to inform the client, which key sequences should be active. This information can now be attached to the display using Display.setData() with the new constant RWT.ACTIVE_KEYS as property key. The value of this property must be an array of strings, each one representing a single active key sequence. The syntax is the same that you know from key binding extensions for the workbench. So if you want to enable some simple key bindings like, for example, “c” for compose and “x” for delete, and maybe some more advanced key sequences like “Ctrl+F11″ for power-users, you could write something like this:

display.setData( RWT.ACTIVE_KEYS, new String[] { "C", "X", "CTRL+F11" } );
display.addFilter( SWT.KeyDown, new Listener() {
  public void handleEvent( Event event ) {
    if( event.stateMask == 0 && event.character == 'C' ) {
      handleCompose();
    } else if( event.stateMask == 0 && event.character == 'X' ) {
      handleDelete();
    } else if( event.stateMask == SWT.CTRL && event.keyCode == SWT.F11 ) {
      doSomeAdvancedStuff();
    }
  }
} );

Only the first line is RAP-specific. So for a single-sourcing RWT/SWT application, you only have to care about the constant. I’m sure you have an idea how to do that. M7 will be available on May 7–easy to remember.

*) Some shortcuts may be reserved by some browsers and cannot be used. Other shortcuts will override browser actions, like Ctrl-N (new window) Ctrl-T (new tab) etc. You also may not like to disable C&P in form fields by adding key bindings for Ctrl-C etc. So you have to choose your web key bindings wisely… Ah, and sequences of key strokes like Ctrl+X T are not yet supported.

on Apr 17th, 2011CSS3 and Shadows in RAP

RAP already offers advanced styling features including customizable cross-browser gradients, rounded borders and animations. We now complete this feature set by introducing advanced, configurable shadows, giving your RAP application a modern, subtle 3D-look.

Screenshot CSS3 and Shadows in RAP

Unlike other frameworks, RAP does not rely on pre-rendered images to create those effects. Instead it does all the rendering itself based on CSS declarations, using multiple browser-native technologies for drawing. Up until now this always involved several complex vector-graphic operations. However, this is 2011, and support for mordern web standards is becoming widely available. By using the CSS3 capabilities of modern browsers, we no longer need to use any vector graphics in Safari, Google Chrome and Firefox 4+. Internet Explorer 9 will follow soon.

Of course, RAP will continue to support all its theming features (including shadows) in browsers without CSS3 capabilities. Shadows and CSS3-support will be part of RAP 1.4 M7, coming on May 7.

on Mar 18th, 2011Sovereign – clustering RAP applications

sovereign logo 11 300x167 Sovereign   clustering RAP applicationsOnly a few days remain until EclipseCon 2011 starts. We are eagerly anticipating our chance to present you an introduction to our ongoing research project Sovereign.

The talk, “Migrating Java Threads to Improve Availability of Web Applications” demonstrates an innovative solution how RAP applications can run on a cluster for failsafe operation.

After our first test run (75 minutes icon wink Sovereign   clustering RAP applications for a 20 minutes talk) we decided to put some of the technical details on our brand new Sovereign homepage, where you can have a look at them in a spare minute. This way we can stick with our two demonstrations that will provide you a better picture of what Sovereign really is about than just low level details.

Markus and Johannes hope to see you there…

on Mar 16th, 2011See you at EclipseCon 2011

web header logo 20111 See you at EclipseCon 2011Over the last few days I’ve read many blogs from folks who are speaking at EclipseCon next week in Santa Clara. Everytime I find it really interesting to hear about the ideas behind the talks. So, with this post I want to show you what you can expect from the EclipseSource folks at EclipseCon.

First we’ll have a chance to meet every morning. EclipseSource is the activity sponsor again this year. What does this mean? This means that the first 50 people will get a cool running shirt and everyone will get the opportunity to meet Eclipse committers away from the conference stress. After the jogging you won’t have to wait long to hear from us again.

The first event is on Tuesday at 2:00 pm. You can meet Ian Bull and listen to him speaking about growing an open source project. He will show you how easy it is to get in touch with your favorite open source project by contributing to it.  He will demo how to overcome the major hurdles to becoming a first class contributor.

If you can’t get enough of Ian you will have a second chance to listen to him after a short break. On Tuesday at 4:00 pm he will show you everything you need to know about p2 together with Kim Moir and Pascal Rapicault. They will show you how to get around the biggest pain points in p2 and pointers for best practices.

If p2 is not your favorite topic and you want to go deep into some hardcore stuff, then I recommend attending Johannes Eickhold’s talk. It’s in the same slot as the p2 talk and is entitled, “Sovereign: Migrating Java Threads to Improve Availability of Web Applications“.  Johannes will describe two technical strategies on how to improve availability in RAP, a very interesting problem with big implications for RAP.

rap See you at EclipseCon 2011Because EclipseCon is full of good talks, you don’t have to wait long for the next one. Take a look ahead at RAP together with Ralf Sternberg at 4:30 pm. He will take you on a tour inside our plans with RAP and show some really cool demos. This talk also marks the end of this packed Tuesday for us.

But luckily the Wednesday is not far away.  Meet Ian again at 5:30 pm icon wink See you at EclipseCon 2011 . He will show you some really cool demos on the hot new products showcase reception. This is a great opportunity to go into detail together with Ian.

After meeting Ian again you can take a break from us. But, only until 7:30 pm. Ralf will moderate the RAP BoF and right after this you can join me on the RTP BoF.  The BoFs will give us a full hour to propose ideas and discuss concepts or internals. So, don’t miss them.

RTP logo small See you at EclipseCon 2011Because RTP is a hot new Eclipse Project icon wink See you at EclipseCon 2011 , in addition to the BoF, you will also have the chance to attend a presentation by me on Thursday 2:30 pm.  As you might already know,  we created the RTP project to enable more developers to use EclipseRT. In my talk,  “Eclipse Runtimes out of the Box“, you can hearing everything there is to know about RTP in 20 minutes.

In addition to this schedule there is more. Of course, you will find all of us at the Hyatt every evening icon wink See you at EclipseCon 2011 .  I’m really looking forward to meeting you there…

on Feb 21st, 2011An open source visual editor for Rich Internet Applications – the Eclipse way

A few weeks ago Google announced their WindowBuilder contribution to the Eclipse Foundation. The WindowBuilder was originally created by Instantiations and moved to Google after they swallowed Instantiations back in 2010. Anyway, the WindowBuilder is a first class visual editor for creating UIs and will be maintained by Google. It contains an Editor for three UI toolkits: GWT, Swing and SWT. And the coolest thing about the WindowBuilder is that it’s completely open source because it’s an Eclipse project now.

So, you probably know that there is a Rich Internet Application technology under the umbrella of Eclipse too. It’s called Rich Ajax Platform (RAP). RAP provides the SWT API which is also used within Eclipse. As a result, theoretically it should be no problem to use the WindowBuilder’s SWT Designer to create RAP applications and with it a Rich Internet Application. Today I found some time to check it out and I’m happy to say that it works like a charm.

All I had to do was create an Eclipse Plug-In project, change the dependency from org.eclipse.ui to org.eclipse.rap.ui and I could start designing my UI.

windowBuilder1 1024x620 An open source visual editor for Rich Internet Applications   the Eclipse way

On the screenshot above you can see my little experiment. It’s an SWT Shell with a group box and some TabItems filled with random Controls. One nice feature of the SWT Designer is that it provides a preview of the UI. So, the UI will look very similar to the one on my Mac below.

windowBuilder2 An open source visual editor for Rich Internet Applications   the Eclipse way

The next step after designing this UI (I know it’s really a masterful work icon wink An open source visual editor for Rich Internet Applications   the Eclipse way ) was to create a RAP launch configuration that would start the application in a browser. And poof, there it was: a RAP application completely created with the WindowBuilder.

windowBuilder3 An open source visual editor for Rich Internet Applications   the Eclipse way

I don’t know if the Google guys know this, but their WindowBuilder actually supports 4 UI toolkits. The three mentioned above and RWT, the SWT port for RAP.

To try it yourself,  I recommend that you download the latest Eclipse package containing RAP from here. After installing you can use the WindowBuilder’s software site to install it into your IDE.  You can use my example project which already contains a launch configuration (don’t forget to switch your target before launching.)

Have fun clicking the UI together icon wink An open source visual editor for Rich Internet Applications   the Eclipse way .

on Feb 7th, 2011How to build a Server-Side Equinox/RAP Application

RAP Logo small How to build a Server Side Equinox/RAP ApplicationWhen you face the task of building a Server-Side Equinox or a RAP application (which is just a Server-Side Equinox application) you need to choose a build system from a fairly diverse palette. This choice is never easy because every build system has its pros and cons. In the end it comes down to which one you and others, love or hate.

To make this task a little easier we created a small github project called “RAP build examples”. It provides examples of how to build a RAP application with different build systems. Currently the following systems are covered:

PDE Build:

The goal of PDE Build is to facilitate the automation of plug-in build processes. Essentially, PDE Build produces Ant scripts based on development-time information provided by, for example, the plugin.xml and build.properties files. The generated Ant scripts, can fetch the relevant projects from a CVS repository, build jars, Javadoc, source zips, put everything together in a format ready to ship and send it out to a remote location (e.g., a local network or a downloads server). read more…

Tycho:

tycho logo How to build a Server Side Equinox/RAP ApplicationTycho is focused on a Maven-centric, manifest-first approach to building Eclipse plug-ins, features, update sites, RCP applications and OSGi bundles. Tycho is a set of Maven plugins and extensions for building Eclipse plugins and OSGi bundles with Maven. Eclipse plugins and OSGi bundles have their own metadata for expressing dependencies, source folder locations, etc. that are normally found in a Maven POM. Tycho uses native metadata for Eclipse plugins and OSGi bundles and uses the POM to configure and drive the build. read more…

WAR Products Tooling:

The WAR Products are similar to Eclipse Products but much more lightweight. All you have to do to export a RAP application is to create a .warproduct based on a working launch configuration and press ‘export’. The exported .war file is ready to deploy. There is a function included that validates your .war file content before you’ve exported it. read more…

All the examples in the git repository follow the same pattern. They provide a simple RAP Application (the famous mail demo) and the files you need for the build. You can read the instructions on how to run each build in the README file which is provided for every example. For those of you who are not using git we’ve also created a zip file which contains the whole repository. You can download it here.

We plan to extend the examples in the future. A Buckminster example is on its way shortly. If you have experience with other systems please feel free to leave a comment and we can create an example together.

© EclipseSource 2008 - 2011