com.wowza.wms.plugin.flashremoting
Class FlashRemoteSession

Object
  extended by com.wowza.wms.plugin.flashremoting.FlashRemoteSession
All Implemented Interfaces:
Runnable

public class FlashRemoteSession
extends Object
implements Runnable

FlashRemoteSession: Main interface into Flash Remoting API. The remote calls can either be make synchronously (the default) or asynchronously (by call FlashRemoteSession.setAsynchronous(true)). In synchronous mode FlashRemoteSession.flush() must be called to send the request to the remote server. In asynchronous mode requests are sent immediately but responses are delivered asynchronously using the virtual host handler thread pool.

Here is an example of a synchronous session:

String url = "http://localhost/amfphp/gateway.php";
FlashRemoteSession remoteSession = FlashRemoteSession.createInstance(appInstance.getVHost(), url);

class MyResponse implements IFlashRemoteResponse
{
        public void onFailure(String handlerName, int statusCode, String responseMsg)
        {
                System.out.println("MyResponse.onFailure["+handlerName+"]: "+statusCode+":"+responseMsg);
        }

        public void onResult(String handlerName, AMFData res)
        {
                System.out.println("MyResponse.onResult["+handlerName+"]: "+(res==null?"null":res.toString()));
        }
}

IFlashRemoteResponse responseHandler = new MyResponse();

remoteSession.call("HelloWorld.say", responseHandler, "My First Hello World Message");
remoteSession.call("Counter.increment", responseHandler);
remoteSession.call("DataGrid.getDataSet", responseHandler);
remoteSession.flush();

remoteSession.call("HelloWorld.say", responseHandler, "My Second Hello World Message");
remoteSession.call("Counter.increment", responseHandler);
remoteSession.flush();

remoteSession.close();

An asynchronous session looks like this:

String url = "http://localhost/amfphp/gateway.php";
FlashRemoteSession remoteSession = FlashRemoteSession.createInstance(appInstance.getVHost(), url);

class MyResponse implements IFlashRemoteResponse
{
        public void onFailure(String handlerName, int statusCode, String responseMsg)
        {
                System.out.println("MyResponse.onFailure["+handlerName+"]: "+statusCode+":"+responseMsg);
        }

        public void onResult(String handlerName, AMFData res)
        {
                System.out.println("MyResponse.onResult["+handlerName+"]: "+(res==null?"null":res.toString()));
        }
}

IFlashRemoteResponse responseHandler = new MyResponse();

remoteSession.call("HelloWorld.say", responseHandler, "My First Hello World Message");
remoteSession.call("Counter.increment", responseHandler);
remoteSession.call("DataGrid.getDataSet", responseHandler);
remoteSession.call("HelloWorld.say", responseHandler, "My Second Hello World Message");
remoteSession.call("Counter.increment", responseHandler);
remoteSession.flush();


Field Summary
static String APPENDTOURL
           
static int CRLFTEST
           
 
Constructor Summary
FlashRemoteSession()
           
 
Method Summary
 void addHTTPHeader(String key, String value)
          Add an HTTP header to all future HTTP requests.
 java.util.Set<String> addHTTPHeaderNames()
          Get a list of the HTTP header names
 void addListener(IFlashRemotingNotify listener)
          Add a listener to this session (see IFlashRemotingNotify)
 void call(String handlerName, IFlashRemoteResponse response, Object... params)
          Call a remote method
 void call(String handlerName, Object... params)
          Call a remote method
 void close()
          Close this session
static FlashRemoteSession createInstance(com.wowza.wms.vhost.IVHost vhost, String url)
          Creates a new Flash Remote session that uses the sources of vhost and connects to the server specified by url.
 void flush()
          Flush the current calls.
 int getConnectionTimeout()
          Get the HTTP connection timeout (milliseconds)
 String getHTTPHeader(String key)
          Get an HTTP header value
 boolean isAsynchronous()
          Return true is session is asynchronous
 void removeListener(IFlashRemotingNotify listener)
          Remove a listener to this session (see IFlashRemotingNotify)
 void run()
          Internal for asynchronous operation
 void setAsynchronous(boolean asynchronous)
          Set the session to be either synchronous or asynchronous (default is false)
 void setConnectionTimeout(int connectionTimeout)
          Set the HTTP connection timeout (milliseconds)
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

APPENDTOURL

public static final String APPENDTOURL
See Also:
Constant Field Values

CRLFTEST

public static final int CRLFTEST
See Also:
Constant Field Values
Constructor Detail

FlashRemoteSession

public FlashRemoteSession()
Method Detail

addHTTPHeader

public void addHTTPHeader(String key,
                          String value)
Add an HTTP header to all future HTTP requests. Might be used for authentication.

Parameters:
key - header name
value - header value

addHTTPHeaderNames

public java.util.Set<String> addHTTPHeaderNames()
Get a list of the HTTP header names

Returns:
list of the header names

addListener

public void addListener(IFlashRemotingNotify listener)
Add a listener to this session (see IFlashRemotingNotify)

Parameters:
listener - listener

call

public void call(String handlerName,
                 IFlashRemoteResponse response,
                 Object... params)
Call a remote method

Parameters:
handlerName - method name
response - response handler
params - parameters

call

public void call(String handlerName,
                 Object... params)
Call a remote method

Parameters:
handlerName - method name
params - parameters

close

public void close()
Close this session


createInstance

public static FlashRemoteSession createInstance(com.wowza.wms.vhost.IVHost vhost,
                                                String url)
Creates a new Flash Remote session that uses the sources of vhost and connects to the server specified by url.

Parameters:
vhost - virutal host
url - remote url
Returns:
new FlashRemoteSession

flush

public void flush()
Flush the current calls. If synchronous wait for responses.


getConnectionTimeout

public int getConnectionTimeout()
Get the HTTP connection timeout (milliseconds)

Returns:
HTTP connection timeout (milliseconds)

getHTTPHeader

public String getHTTPHeader(String key)
Get an HTTP header value

Parameters:
key - header name
Returns:
header value

isAsynchronous

public boolean isAsynchronous()
Return true is session is asynchronous

Returns:
true is session is asynchronous

removeListener

public void removeListener(IFlashRemotingNotify listener)
Remove a listener to this session (see IFlashRemotingNotify)

Parameters:
listener - listener

run

public void run()
Internal for asynchronous operation

Specified by:
run in interface Runnable

setAsynchronous

public void setAsynchronous(boolean asynchronous)
Set the session to be either synchronous or asynchronous (default is false)

Parameters:
asynchronous - is asynchronous

setConnectionTimeout

public void setConnectionTimeout(int connectionTimeout)
Set the HTTP connection timeout (milliseconds)

Parameters:
connectionTimeout - HTTP connection timeout (milliseconds)