<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flexpert to the rescue &#187; LiveCycle Data Services</title>
	<atom:link href="http://www.flexpert.be/tag/lcds/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.flexpert.be</link>
	<description>Blog site about all things Adobe</description>
	<lastBuildDate>Sun, 05 Feb 2012 21:58:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Floating license policy for Flex applications</title>
		<link>http://www.flexpert.be/2009/10/floating-license-policy-for-flex-applications/</link>
		<comments>http://www.flexpert.be/2009/10/floating-license-policy-for-flex-applications/#comments</comments>
		<pubDate>Sun, 04 Oct 2009 20:40:10 +0000</pubDate>
		<dc:creator>Steven Peeters</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[LiveCycle Data Services]]></category>
		<category><![CDATA[floating license]]></category>
		<category><![CDATA[RTMP]]></category>

		<guid isPermaLink="false">http://www.flexpert.be/?p=292</guid>
		<description><![CDATA[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&#8217;s say 10 [...]]]></description>
			<content:encoded><![CDATA[<p>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 <strong>floating license policy</strong>. This means that a certain company buys let&#8217;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&#8217;s location. How do we accomplish this within a Flex application?</p>
<p>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.</p>
<p>That&#8217;s the easy part. It&#8217;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&#8217;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.</p>
<p>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, &#8230; 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, <strong>the FlexSession, does react to the closing of the browser and therefore can be used to adjust the licensing server in the back end</strong>. To be able to use this, you need to use an <mx:DataService> 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.</p>
<p>Now how do you let your back end service react to the dropping of the FlexSession? Well, all you have to do is<strong> implement the FlexSessionListener interface</strong>. 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&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SessionWatcher <span style="color: #000000; font-weight: bold;">implements</span> FlexSessionListener <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">protected</span> FlexSession session<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> SessionWatcher<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    FlexSession.<span style="color: #006633;">assSessionCreatedListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  @Override
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> sessionCreated<span style="color: #009900;">&#40;</span>FlexSession session<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">session</span> <span style="color: #339933;">=</span> session<span style="color: #339933;">;</span>
    session.<span style="color: #006633;">addSessionDestroyedListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  @Override
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> sessionDestroyed<span style="color: #009900;">&#40;</span>FlexSession session<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    system.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Session &quot;</span> <span style="color: #339933;">+</span> session.<span style="color: #006633;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; has been destroyed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.flexpert.be/2009/10/floating-license-policy-for-flex-applications/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

