Floating license policy for Flex applications

Published on: October 4, 2009
Comments: 9 Comments

Sometimes in Flex projects you need to be able to include some licensing policy. In a lot of cases this will be a simple user identification for registered users. But sometimes there is a request for a floating license policy. This means that a certain company buys let’s say 10 licenses, but they are not user specific. So in fact, maybe 50 users within that company can use the product legally, but only 10 users can connect at the same time. I know some programs that do this, but they are not web based and have their own licensing server installed at the company’s location. How do we accomplish this within a Flex application?

Well, the first step is having a user identification system that keeps track of how many users have already logged in for the same company as the user that is currently trying to log in. This part is fairly easy and can be accomplished be using a counter at company level. The licensing can then easily be managed by a non-public admin console. Each time a user tries to log in, the counter is checked against the maximum allowed concurrent users. Depending on the fact whether or not the maximum number of users is reached, the user gets an error message or the counter is updated as the user is verified.

That’s the easy part. It’s the logging out that can give you some headaches. If you provide a logout button, it is again fairly easy to attach a remote back end call to update the counter again, so it reaches zero when all the users for that company have logged out. But unfortunately users don’t always do what they are expected to do. So a lot of times they will just close the browser and your counter remains unchanged. And this poses the biggest problem, because the user has actually closed the application, but now the licensing part has been corrupted. Fortunately, LiveCycle Data Services has a nice feature called RTMP (Real-Time Messaging Protocol), which allows you to monitor a session on the server and act upon it when the session has been dropped.

Now, there are 2 types of sessions available on the server side: HTTPSession and FlexSession. The first one is actually a browser session. A browser session does not automatically close when the user closes the browser. It is a common misconception, but a lot of server technologies work in this way; be it LCDS, ColdFusion, … The browser session actually needs to timeout before it is closed. So it could very well remain in server memory for a couple of hours even before closing, depending on the server settings. The later one, the FlexSession, does react to the closing of the browser and therefore can be used to adjust the licensing server in the back end. To be able to use this, you need to use an to be able to use the RTMP channel. Another option would be to use the messaging service over RTMP connected to a Java Adapter. The advantage of using the DataService is that in the mean time you can also use it to implement server pushed data synchronisation, which is a very nice feature.

Now how do you let your back end service react to the dropping of the FlexSession? Well, all you have to do is implement the FlexSessionListener interface. You need to override the sessionCreated() method in which you save the session for later use and to add an event listener for the sessionDestroyed event. This event is fired when the user closes the Flex application by closing the browser window. You can find the code below in the SessionWatcher class I created for demonstration purpose, but you can include this functionality in any Java class that is connected using the data management feature. Enjoy…

public class SessionWatcher implements FlexSessionListener {
  protected FlexSession session;
  public SessionWatcher() {
  public void sessionCreated(FlexSession session) {
    this.session = session;
  public void sessionDestroyed(FlexSession session) {
    system.out.println("Session " + session.getId() + " has been destroyed");
9 Comments - Leave a comment
  1. […] This post was mentioned on Twitter by HowDo.us and Adobe Systems Inc. Adobe Systems Inc said: Floating license policy for Flex applications: Sometimes in Flex projects you need to be able to include some l.. http://bit.ly/q9eqS […]

  2. […] Read the rest here: Flexpert to the rescue | Floating license policy for Flex applications […]

  3. TheCraig says:

    Hi, sorry for this offtopic question but i dont find the RSS Feed Link to add this Blog to my Feedreader. Could you please give me the URL? Thanks a lot.

    Greetings from Switzerland

  4. admin says:

    You can find the RSS link in the menu on the right side of the website, next to the “Article Categories” title…

  5. Rajeev Goel says:

    Flex session woudl work only if http channel is being used. It is not created for RTMP channel.

  6. admin says:

    Well, I’m actually using this in a project that needs this floating licences policy, so it actually does work. Has been tried and tested with the code provided and if you look at the LiveCycle Data Services server logging, you will see the RTMP session being dropped.

    You’re right when you say it is created using the HTTP communication, but then the session is only dropped when the session gets timed out on the server. This is similar to the session manager in ColdFusion. But by using the RTMP channel, the server immediately detects the dropped session, because it maintains a connection in both directions.

  7. Brendan says:

    Great article clearing up how the listener override works. However, I’m looking at implementing this into an existing CF8/LCDS installation. I already have a CFC which gets called @ login to set some CF session variables, and would like to incorporate the floating license concept into this. I’m stuck at how a Java class like the one you provide can integrate into a CFC file to accomplish this.

    Really hoping you can shed some light on this… thank you in advance!


  8. Hey Brendan,

    The first thing you need to know before getting started on this is what your license policy is. I was lucky to have a meeting with someone from Adobe last night and he told me that you should be able to do this, as long as you can make sure that the LCDS part of ColdFusion uses only 1 physical CPU (can be multicore). If you want to know more about the licensing and legal issues, the EULA (http://www.adobe.com/products/eulas/pdfs/AdobeColdFusion8EULA_06-06-2007-FINAL_Combined.pdf) is always a good read. In this case, I think you will be most interested in section 10.1a.

    As for getting it to work, I’ve looked at your question in the Adobe forums, which had some more explanation about what you tried to do. If I understand it correctly, you are trying to incorporate the session detection into an existing CFC. What you apparently are doing is incorporating the Java class as an object in your CFC. That won’t work. The FlexSession has to be captured in the object that is called via the services. That means that the event handlers need to be located in your CFC.

    What I’ve done in my project is create a separate service which is used only to monitor the session and act appropriately when the session is destroyed. Maybe that’s a route you can take?

    I’ve also looked into the possibility of extending a Java class using a CFC, but apparently that’s not possible. So I think you’re either stuck with creating a separate service or creating your service entirely in Java.

    I’ll take this up with some people at Adobe to see if there’s another way of doing this.


  9. Hey Brendan,

    I’ve just heard from people at Adobe that what you are trying to do is not really possible. You’ll have to write that service completely in Java instead of using a CFC.


Leave a comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Welcome , today is Sunday, March 18, 2018