Monday, January 25, 2016

Enable failover with OpenWebBeans (>= 1.5.1)

Since OWB 1.5.1 you don't need any configuration or FailOverFilter anymore as the beans are directly stored in the HttpSession :)

Saturday, September 21, 2013

Session replication / clustering / failover with Tomcat (Part 1 - Overview)

This is my first post of a series about Tomcat and clustering.
In this post i will explain some different replication mechanism.

NOTE: A common drawback of replication, like it's defined in the specs, is that only HttpSession#setAttribute(...) triggers replication.
This means that if you store a container object in the session and if you change a variable inside the object, you must HttpSession#setAttribute(...) again to replicate the modified object again.
Many frameworks implements a simple workaround for it - i will write about it another post.

All to all replication / DeltaManager 

With this mode, Tomcat just replicates the session to all registered nodes.

  • No single point of failure at software level
  • Every node holds all sessions
  • In theory, all other nodes can be turned off
  • No extra software is needed
  • Synchronous or Asynchronous replication
  • Open Source
  • Enterprise-Support available
  • High memory usage and network traffic because all nodes holds all sessions
  • Objects which are stored in the session must be triggered manually to replicate again if a property has been changed
  • Slower session serialization

Primary/Secondary Replication (Buddy Replication) / BackupManager

The sessions will be replicated to the next neighbor. If one Tomcat is not available anymore, the neighbor still holds the sessions.

  • No single point of failure at software level
  • Lower memory usage and network traffic because the session is not stored on all nodes
  • No extra software is needed
  • Synchronous or Asynchronous replication
  • Open Source
  • Enterprise-Support available
  • Not quite as battle tested as the All-to-all replication (see Tomcat documentation)
  • Objects which are stored in the session must be triggered manually to replicate again if a property has been change
  • Slower session serialization


Each Tomcat replicates all sessions to N (multiple) Memcached nodes.
If a session is not available on the local Tomcat, the memcached-session-manager tries to lookup the session from the Memcached nodes.

  • No single point of failure at software level
  • More scalability
  • Session will be replicated to N “Memcached” nodes – The sessions are still available if all webservers are down
  • Automatically handles “Memcached” nodes failover
  • Sticky mode: Lower memory usage because every node holds only the current used sessions
  • Non-Sticky mode: Lowest memory usage because Tomcat does not hold the sessions anymore. Session will be received from memcached for each request
  • MSM will automatically trigger replication if a property in a session stored object has been changed
  • Faster session serialization – Changeable mechanism
  • Synchronous or Asynchronous replication
  • Open Source
  • Enterprise-Support available for Tomcat
  • Extra software needed (“Memcached” plugin and nodes)
  • Cannot switch to another Java Webserver which does not automatically check changed values in the session - but only if the used framework has no implemented workaround
  • AFAIK no Enterprise-Support available for the Memcached plugin but Martin Grotzke is very active on the mailing list

Thursday, September 19, 2013

Enable failover with OpenWebBeans (> 1.2.0)

In my first post i already explained how it's possible to enable failover (aka clustering) with OpenWebBeans > 1.1.3: Enable failover with OpenWebBeans (> 1.1.3)

Because we moved the clustering logic to own module, we must include this module since OWB 1.2.0:

You still need the org.apache.webbeans.web.failover.FailOverFilter but if you include this module, you must NOT add a custom anymore. It will be registered automatically.

Wednesday, September 18, 2013

PrimeFaces Extensions 1.0

This week, Oleg released a RC of PrimeFaces Extensions as you can read here: PrimeFaces Extensions 1.0.0.RC1 released

To be honest, i had not much time to improve anything in PrimeFaces Extensions.
I'm PrimeFaces committer since January 2013 and it was more fun to implement new features, working on complex stuff together with Çağatay or improve performance directly in PrimeFaces Core.
I also will blog about some of this features the next weeks.

The biggest of my changes in PrimeFaces Extensions 1.0 are the PrimeFaces 4.0 compatibility and a new CKEditor version (4.2.1 now).

It's not sooo easy to marry CKEditor and the resource handling of JSF. I had to adjust some of there code and created some issues on their side.
If they will improve it and fix those issues, updating CKEditor will much easier in the future.
CKEditor removed and introduced new skins. Supported skins are "kama" and "moono" now.

We also added support for "my" new Search Expression Framework of PrimeFaces 4.0 in all our components.

We were also able to clean up some code because i could move some features or API changes directly to PrimeFaces Core.

Stay tuned for the final release!

Friday, December 14, 2012

Dynamical switching of JSF state saving method

By default, it's only possible to configure the state saving method (client or server) globally for all views in your application.

This is sometimes really annoying as server side performs better but needs more memory.
Also with server side state saving, it's not possible to cache views (if they have actions) because you will get a ViewExpiredException soon.

So what about using client-side state for some views and using server-side state for all other views?

Currently this is only possible with MyFaces (since 2.1.9). Mojarra doesn't support this feature.
I created a specifiation improvement ticket ( and hopefully this will be supported in Mojarra soon.

So how can we use this feature?

To switch the state saving method, we just need to overwrite/wrap the following method: StateManager#isSavingStateInClient(FacesContext).

In my application i combined this feature with CODI ViewConfig.

Create a ViewMetaData:
@ViewMetaData(override = true)
public @interface StateSaving {

  Method value();

  enum Method {

Wrap the StateManager:
public class ExtensionsStateManager extends StateManagerWrapper {

  public boolean isSavingStateInClient(final FacesContext context) {
    boolean isSavingStateInClient;

    final StateSaving stateSaving = getStateSavingAnnotationViaCodiViewConfigResolver(context);
    if (stateSaving == null) {
      isSavingStateInClient = getWrapped().isSavingStateInClient(context);
    } else {
      isSavingStateInClient = stateSaving.value() == StateSaving.Method.CLIENT;

    return isSavingStateInClient;

Configure that JSF should use our StateManager:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns=""

@Page(navigation = NavigationMode.REDIRECT)
public interface Pages extends ViewConfig {

  class ViewA implements Pages { }
  class View implements Pages { }

Currently i'm not a member of a library/framework, where i could add this nice feature.
Maybe i will release my own lib for such stuff someday.

Thursday, October 25, 2012

Speedup jetty-maven-plugin startup time

  • Create a own profile - this allows more flexibility
  • <profile>
  • Add jetty-maven-plugin to the profile. We also configure the plugin to get all resources from the src directory and only scan the java sources
  • <plugin>
  • Skip unit testing via profile property
  • <properties>
  • Skip building the WAR file
  • <plugin>
  • If you optimize and aggregate your javascript or CSS files, skip this too! Compression of this files is on localhost just prevents debugging. We created an own servlet which merges the files on-the-fly. Changes on JS or CSS will be also available after F5 in your browser - that's the nice side effect of the servlet :)
    • Skip optimzation (we use the primefaces-extensions plugin for this)
    • <plugin>
    • Create a servlet to merge the resources (we also implemented a init-param called includeDirectory to read all source files)
    • @Override
      protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
          throws ServletException, IOException
          final OutputStream ouputStream = response.getOutputStream();
          final List<File> filesToMerge = getFiles(getServletContext().getRealPath(getServletConfig().getInitParameter("includeDirectory")));
          for (final File fileToMerge : filesToMerge) {
          final FileInputStream inputStream = new FileInputStream(fileToMerge);
              IOUtils.copy(inputStream, ouputStream);
    • For example, if your optimizer plugin aggregates your javascript files to "/javascript/bundle.js", we must overwrite this URL via a servlet mapping.
      We just create a second web.xml (this is just for localhost and jetty) with the name "web-localhost.xml" in your "src/main/webapp/WEB-INF" directory with the following servlet mapping
    • <servlet>
          <servlet-name>Merge Javascript Servlet</servlet-name>
          <servlet-name>Merge Javascript Servlet</servlet-name>
    • Now we configure jetty to use our "web-localhost.xml" as overrideDescriptor
    • <plugin>
Finished! You will be able to start jetty now via "mvn package -P jetty-run".

Wednesday, October 3, 2012

Introducing PrimeFaces Extensions

In march 2011, I founded my first open source project called "PrimeFaces Extensions".

Our new application required a functionality to resize/rotate images and select a part of the image to do OCR (Optical Character Recognition), both with client-server communication.

I already had experience with JSF2 and PrimeFaces 2.2, so I decided to develop those components in my spare time based on PrimeFaces and commit it to a open source platform (Google Code).

After talking to Cagatay Civici (PrimeFaces founder and lead developer), I got green light to start the "PrimeFaces Extensions" project.

The first release contained this two components: ImageRotateAndResize and ImageAreaSelect.

Months later Oleg Varaksin joined my project as second lead and developer.
For the first big release (0.2), we developed many new components like CKEditor, MasterDetail, ResetInput and Layout.

Nevertheless, after 1,5 years of hard work, we can proudly say that we created some really unique and useful components which are used by many PrimeFaces users and also used in real-world applications!

Currently we are 6 developers around the world and we have about 25 components, functions, behaviors and converters.

Also some of our components and enhancements are now part of PrimeFaces and we also have a little influence on JSF 2.2 with our ResetInput component (JIRA Issue).

Thanks to Cagatay for PrimeFaces, Oleg for the great cooperation and the other PrimeFaces Extensions developers for their great work!