<?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>Flash Remoting for Ruby on Rails &#187; SSR</title>
	<atom:link href="http://blog.rubyamf.org/category/ssr/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.rubyamf.org</link>
	<description>Ruby AMF - Flash Remoting for Ruby on Rails</description>
	<lastBuildDate>Tue, 25 Aug 2009 12:23:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SSR 2 Breakdown</title>
		<link>http://blog.rubyamf.org/2008/01/28/ssr-2-breakdown/</link>
		<comments>http://blog.rubyamf.org/2008/01/28/ssr-2-breakdown/#comments</comments>
		<pubDate>Tue, 29 Jan 2008 04:36:47 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[AMF]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Remoting]]></category>
		<category><![CDATA[SSR]]></category>

		<guid isPermaLink="false">http://blog.rubyamf.org/?p=103</guid>
		<description><![CDATA[John Farrar had asked about SSR 2 &#8211; more information on SSR and what benefits / things you get with it. I thought I&#8217;d be a little more specific and outline what it is and what you get. Bare with me if I start out by pointing out the obvious.
So, I guess here&#8217;s the obvious. [...]]]></description>
			<content:encoded><![CDATA[<p>John Farrar had asked about SSR 2 &#8211; more information on SSR and what benefits / things you get with it. I thought I&#8217;d be a little more specific and outline what it is and what you get. Bare with me if I start out by pointing out the obvious.</p>
<p>So, I guess here&#8217;s the obvious. SSR is a small AS3 remoting library. Stands for &#8220;Super Simple Remoting&#8221; because it&#8217;s simple. My goal when writing it was to make one library that works in Flash and Flex and handle logic that should be in every application. Personally I like using this in both Flash and Flex because I don&#8217;t forget how to use it. I always forget how to use RemoteObject so this makes a standard library for either.</p>
<p>So here&#8217;s an example of a bare minimum setup of SSR to make a remoting call.</p>
<pre>
import com.niarbtfel.remoting.RemotingConnection;
import com.niarbtfel.remoting.RemotingService;
import com.niarbtfel.remoting.events.FaultEvent;
import com.niarbtfel.remoting.events.ResultEvent;

var rc:RemotingConnection = new RemotingConnection("http://localhost/myGateway",3);
//gateway
//3 is the amf format

var rs:RemotingService = new RemotingService(rc,"MyService",4000,3,true);
//rc is the remoting connection to use for this service
//"MyService" is the service target on the server.
//4000 is the amount of time a call waits before retrying the call.
//3 is the amount of retries to attempt per call.
//true turns on call limiting, which means that the same exact call can't be made while one is waiting for a response or timeout.

//callbacks for calls, keep reading.
function onr(re:ResultEvent):void{}
function onf(fe:FaultEvent):void{}

//callbacks for calls, keep reading.
function onrArgs(re:ResultEvent,args:Array):void{}
function onfArgs(fe:FaultEvent,args:Array):void{}

rs.myMethod([],onr,onf,false); //make a call
//[] = call arguments
//onr is the result callback
//onf is the fault callback
//false - don't return the original arguments sent in the request to the callback functions

var mym:String = "myMethod";
rs.apply(mym,[],onrArgs,onfArgs,true); //make a call
//[] = call arguments
//onr is the result callback
//onf is fault callback
//true - return the original arguments sent in the request to the callback functions
</pre>
<p>This is the simplest form of setting up flash remoting with SSR without any event listeners on the RemotingConnection or RemotingService. Events for RemotingConnection and RemotingService are documented in the class files. You get events for things like disconnects, retries, timeouts, etc.</p>
<p>Each RemotingService can have a timeout specified for each call going to that service, as well as a maximum attempts allowed per call. If one call is made, but doesn&#8217;t receive a response within the timeout specified, it&#8217;s tried again. This happens over and over until the maximum attempts is reached, and a timeout event is dispatched.</p>
<p>RemotingService has an option to turn on call limiting. Which makes the remoting service smart about what to call and what not to call. If you made a call to &#8220;MyService.myMethod&#8221; with parameters ["something","something else"], it would not let you make that same call until the first one has completed, or has timed out. You&#8217;d still be able to make calls to any other service method.</p>
<p>Another new feature is caching. Say you make calls to some service numerous times, but the data is always the same. Instead of doing that you can enable the service to use caching. Here&#8217;s a snippet from above with caching in place:</p>
<pre>
var rs:RemotingService = new RemotingService(rc,"MyService",4000,1,true);
rs.remotingCache = new RemotingCache(-1);
//-1 specifies that the cache should never expire. (supply a time in milliseconds for an expiration if needed)
</pre>
<p>Now every call made through this remoting service will be cached. If the exact same call is made, the results are pulled from cache instead.</p>
<p>SSR also has paging built in with a RemotingPager. Here&#8217;s a snippet on how that works:</p>
<pre>
import com.niarbtfel.remoting.RemotingConnection;
import com.niarbtfel.remoting.RemotingService;
import com.niarbtfel.remoting.events.FaultEvent;
import com.niarbtfel.remoting.events.ResultEvent;
import com.niarbtfel.remoting.paging.RemotingPager;
import com.niarbtfel.remoting.paging.PageResponder;

var rc:RemotingConnection = new RemotingConnection("http://localhost/myGateway",3);
var rs:RemotingService = new RemotingService(rc,"MyService",4000,3,true);
var rp:RemotingPager;
var pr:PageResponder // just to include in compilation

var totalRecordsOnServer:int = 400; //should come from server instead.

//callbacks for calls, keep reading.
function onrArgs(re:ResultEvent,args:Array):void
{
  rp = new RemotingPager(rs,"myMethod",PageResponder,["someParameter"],re.result as Array,totalRecordsOnServer,50,2,1);
  myButton.addEventListener(MouseEvent.CLICK, onbc);
}
function onfArgs(fe:FaultEvent,args:Array):void{}

function onbc(me:MouseEvent):void
{
   if(rp.hasNext())
   {
     trace(rp.next());
   }
   else
   {
     trace("no more pages");
   }
}

rs.myMethod(["someParameter",0,50],onrArgs,onfArgs,true); //make a call to get the initial data.
//0 is the offset
//50 is the pagesize
</pre>
<p>In this example, a remoting pager is created in the result callback of the first call. A remoting pager needs at least the first page in order to be created. The RemotingPager takes care of &#8220;pre-fetching&#8221; pages with buffer options. In the above example, where the RemotingPager is created, 50 is the pagesize to grab, 2 is the amount of pages to buffer / pre-fetch. And 1 is the amount of pages that are left in the buffer before triggering another buffer fill / pre-fetch. This is the simplest form of paging, but the RemotingPager has methods for getting certain pages, getting them all, seeking, etc.</p>
<p><strong>UPDATE: I forgot to mention RemotingService.MaxTimeoutsBeforeHault.</strong></p>
<p>With RemotingService.MaxTimeoutsBeforeHault, you can control how many timeouts are allowed from any call, before all remoting calls are stopped. Here&#8217;s a snippet:</p>
<pre>
RemotingService.MaxTimeoutsBeforeHault = 3;
var rs:RemotingService = new RemotingService(rc,"MyService",4000,3,true);
rs.addEventListener(CallEvent.SERVICES_HALTED, onch);
function onch(ce:CallEvent):void{}
rs.myMethod([],onR,onF,true);
</pre>
<p>When you set this property, any call that causes a timeout, is kept track of, and if 3 timeouts happen from any call, no other remoting calls will be made. Each attempt after the services are halted, dispatches the CallEvent.SERVICES_HALTED event.</p>
<p>In conclusion &#8211; SSR gives you logic out of the box that should be available anytime we are using Flash Remoting. And gives you numerous other features. SSR 2 is documented very well in the source files.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rubyamf.org/2008/01/28/ssr-2-breakdown/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>SSR 2</title>
		<link>http://blog.rubyamf.org/2008/01/27/ssr-2/</link>
		<comments>http://blog.rubyamf.org/2008/01/27/ssr-2/#comments</comments>
		<pubDate>Sun, 27 Jan 2008 07:56:27 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[AMF]]></category>
		<category><![CDATA[SSR]]></category>

		<guid isPermaLink="false">http://blog.rubyamf.org/?p=102</guid>
		<description><![CDATA[I&#8217;ve beefed-up SSR with numerous new features and improvements. I&#8217;ve updated OSFlash with new examples, and included a couple examples in the download. I&#8217;ve also changed the package structure, as I&#8217;m untying myself from the rubyamf package. Download and enjoy.
UPDATE: Check out the SSR 2 Breakdown.
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve beefed-up SSR with numerous new features and improvements. I&#8217;ve updated <a href="http://www.osflash.org/projects/ssr/">OSFlash</a> with new examples, and included a couple examples in the download. I&#8217;ve also changed the package structure, as I&#8217;m untying myself from the rubyamf package. <a href="http://blog.rubyamf.org/downloads/ssr.zip">Download and enjoy</a>.</p>
<p>UPDATE: Check out the <a href="http://blog.rubyamf.org/?p=103">SSR 2 Breakdown</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rubyamf.org/2008/01/27/ssr-2/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>SSR Relocation</title>
		<link>http://blog.rubyamf.org/2007/10/16/ssr-relocation/</link>
		<comments>http://blog.rubyamf.org/2007/10/16/ssr-relocation/#comments</comments>
		<pubDate>Tue, 16 Oct 2007 16:24:18 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[SSR]]></category>

		<guid isPermaLink="false">http://blog.rubyamf.org/?p=78</guid>
		<description><![CDATA[I just discovered that the SSR page on RIAForge is gone. Looks like a DNS issue. The new official place to read about it is on osflash.
]]></description>
			<content:encoded><![CDATA[<p>I just discovered that the <a href="http://ssr.riaforge.org">SSR page on RIAForge</a> is gone. Looks like a DNS issue. The new official place to read about it is on <a href="http://osflash.org/projects/ssr">osflash</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rubyamf.org/2007/10/16/ssr-relocation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSR Updates</title>
		<link>http://blog.rubyamf.org/2007/08/28/ssr-updates/</link>
		<comments>http://blog.rubyamf.org/2007/08/28/ssr-updates/#comments</comments>
		<pubDate>Wed, 29 Aug 2007 06:22:05 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[SSR]]></category>

		<guid isPermaLink="false">http://blog.rubyamf.org/?p=39</guid>
		<description><![CDATA[I put up a new version of SSR earlier today. It includes two bug fixes.
1. Connection fault handlers were not being called correctly. On status errors was not catching NetConnection.Call.Failure codes, as I had put NetConnection.Connect.Failure.
2. Fixed a try catch statement in the onResult function of RemotingCall.as.
http://ssr.riaforge.org/
]]></description>
			<content:encoded><![CDATA[<p>I put up a new version of SSR earlier today. It includes two bug fixes.</p>
<p>1. Connection fault handlers were not being called correctly. On status errors was not catching NetConnection.Call.Failure codes, as I had put NetConnection.Connect.Failure.<br />
2. Fixed a try catch statement in the onResult function of RemotingCall.as.</p>
<p><a href="http://ssr.riaforge.org/">http://ssr.riaforge.org/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rubyamf.org/2007/08/28/ssr-updates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSR Updates &#8211; Authentication Failure Event</title>
		<link>http://blog.rubyamf.org/2007/07/06/ssr-updates-authentication-failure-event/</link>
		<comments>http://blog.rubyamf.org/2007/07/06/ssr-updates-authentication-failure-event/#comments</comments>
		<pubDate>Fri, 06 Jul 2007 20:46:01 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Remoting]]></category>
		<category><![CDATA[RubyAMF]]></category>
		<category><![CDATA[SSR]]></category>

		<guid isPermaLink="false">http://blog.rubyamf.org/?p=28</guid>
		<description><![CDATA[Nice new feature for SSR. Authentication failure events. Heres an EX:

import org.rubyamf.remoting.ssr.*;
var service = new RemotingService('http://localhost:8024/gateway.rb','some.package.MyService',3);
service.setCredentials('userid','pass');
service.addEventListener(FaultEvent.AUTHENTICATION_FAILED, handleAuthFailure);

function handleAuthFailure(e:*)
{
  trace("AUTHENTICATION FAILED");
}

There are a couple ways you can tell the Flash client that authentication failed. Here are RubyAMF examples:

EX: 1
import RUBYAMF_SERVICES + 'fault_object'
class MyService
 def _authenticate(user,pass)
   FaultObject.new(1,'Authentication Failed')
 end
end

EX: 2
class MyService

 def before_filter
  [...]]]></description>
			<content:encoded><![CDATA[<p>Nice new feature for SSR. Authentication failure events. Heres an EX:</p>
<pre>
import org.rubyamf.remoting.ssr.*;
var service = new RemotingService('http://localhost:8024/gateway.rb','some.package.MyService',3);
service.setCredentials('userid','pass');
service.addEventListener(FaultEvent.AUTHENTICATION_FAILED, handleAuthFailure);

function handleAuthFailure(e:*)
{
  trace("AUTHENTICATION FAILED");
}
</pre>
<p>There are a couple ways you can tell the Flash client that authentication failed. Here are RubyAMF examples:</p>
<pre>
EX: 1
import RUBYAMF_SERVICES + 'fault_object'
class MyService
 def _authenticate(user,pass)
   FaultObject.new(1,'Authentication Failed')
 end
end

EX: 2
class MyService

 def before_filter
  @auth = false
 end

 def auth_fail
  return FaultObject.new(1, 'Authentication Failed')
 end

 def _authenticate(user,pass)
  if #someprocessing
   @auth = true
  else
   false #returning false from _authenticate triggers the exception back to the flash player as well
  end
 end

 def myRestrictedMethod
  if !@auth
   auth_fail
  else
   #some processing
  end
 end
end
</pre>
<p>You can also trigger authentication errors from AMFPHP. EX:</p>
<pre>
&lt;?php
class MyService
 function someMethod
  return {'faultString' => 'Authentication Failed', 'faultCode' => 1};
 end
end
?&gt;
</pre>
<p>All of these examples will trigger the authentication failed event. Using this for authentication failure is nice so that you can handle authentication errors in on place. Not having to handle them in every onFault handler.</p>
<p><a href="http://ssr.riaforge.org">Download the latest</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rubyamf.org/2007/07/06/ssr-updates-authentication-failure-event/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
