EnhancedLocalConnection provides enhanced local connection functionalities.
These functionalities are proper listener support for asynchronous failures and comprehensible exceptions on synchronous errors like reserved and unknown connections and oversized arguments. Refer to the specific method for further descriptions.
You can set up a connection to receive 'remote' method invocations as follows:
var service:EnhancedLocalConnection = new EnhancedLocalConnection();
service["myMethod"] = function(myArg1:String, myArg2:String):Void {
trace("invoked myMethod(" + myArg1 + ", " + myArg2 + ")");
}
service.connect("myService");
While the above example works it is not as neat as it could be. It would be
better to use another instance as service and the connection only to set it up
to receive 'remote' method calls.
var service:MyService = new MyService();
var connection:EnhancedLocalConnection = new EnhancedLocalConnection(service);
connection.connect("myService");
The service is set up now to receive 'remote' method invocations. You can now
invoke a method on it as follows:
var client:EnhancedLocalConnection = new EnhancedLocalConnection();
var listener:MethodInvocationErrorListener = client.send("myService", "myMethod", ["arg1", "arg2"]);
listener.onError = function(errorInfo:MethodInvocationErrorInfo):Void {
trace("Error occured: " + errorInfo);
}
static public function connectionExists(connectionName:String):Boolean
Checks if a connection with the passed-in connectionName exists.
false will always be returned if the connectionName is null,
undefined or an empty string.
connectionName | the name of the connection |
true if the connection exists else false
public function connect(connectionName:String):VoidPrepares this connection to receive 'remote' method invocations.
Closes this connection if it is currenlty running and opens a new one.
If you specified a target, the 'remote' method invocations will be led directly to it.
connectionName | name of the connection the client uses to send method calls |
| IllegalArgumentException | if the passed-in connectionName is
null, undefined or an empty string
|
| ReservedConnectionException | if a connection with the passed-in
connectionName is already in use
|
public function sendByConnectionAndMethod(connectionName:String, methodName:String):MethodInvocationErrorListener
Invokes a method remotely on the connection specified by the passed-in
connectionName, passing no arguments.
Error listeners are informed if the 'remote' method invocation failed asynchron of an unknown reason.
A new MethodInvocationErrorListener instance is created and returned.
You can set the onError method on it to be informed of occuring errors.
connectionName | the name of the connection to invoke the method on |
methodName | the name of the method to invoke on the connection |
an error listener that informs you of occuring errors if you set the
onError method on it
| IllegalArgumentException | if connectionName or methodName
are null, undefined or an empty string
|
| UnknownConnectionException | if a connection with the passed-in
connectionName does not exist
|
public function sendByConnectionAndMethodAndArguments(connectionName:String, methodName:String, args:Array):MethodInvocationErrorListener
Invokes a method remotely on the connection specified by the passed-in
connectionName passing args as parameters.
Error listeners are informed if the 'remote' method invocation failed asynchron of an unknown reason.
A new MethodInvocationErrorListener instance is created and returned.
You can set the onError method on it to be informed of occuring errors.
connectionName | the name of the connection to invoke the method on |
methodName | the name of the method to invoke on the connection |
args | the arguments to pass as parameters when invoking the connection |
an error listener that informs you of occuring errors if you set the
onError method on it
| IllegalArgumentException | if connectionName or methodName
are null, undefined or an empty string
|
| UnknownConnectionException | if a connection with the passed-in
connectionName does not exist
|
| MethodInvocationException | if the arguments you try to pass are out of size |
public function sendByConnectionAndMethodAndListener(connectionName:String, methodName:String, listener:MethodInvocationErrorListener):MethodInvocationErrorListener
Invokes a method remotely on the connection specified by the passed-in
connectionName passing args as parameters.
Error listeners are informed if the 'remote' method invocation failed asynchron of an unknown reason.
A new MethodInvocationErrorListener instance is created and returned,
if the passed-in listener is null. Otherwise the passed-in one
is returned. You can set the onError method on it to be informed of
occuring errors.
connectionName | the name of the connection to invoke a method on |
methodName | the name of the method to invoke on the connection |
listener | the listener to notify if the method invocation failed out of an asynchron unknwon reason |
either the passed-in listener if it was not null or undefined,
or a new listener
| IllegalArgumentException | if connectionName or methodName
are null, undefined or an empty string
|
| UnknownConnectionException | if a connection with the passed-in
connectionName does not exist
|
| MethodInvocationException | if the arguments you try to pass are out of size |
public function sendByConnectionAndMethodAndArgumentsAndListener(connectionName:String, methodName:String, args:Array, listener:MethodInvocationErrorListener):MethodInvocationErrorListener
Invokes a method remotely on the connection specified by the passed-in
connectionName passing args as parameters.
Error listeners are informed if the 'remote' method invocation failed asynchron of an unknown reason.
A new MethodInvocationErrorListener instance is created and returned,
if the passed-in listener is null. Otherwise the passed-in one
is returned. You can set the onError method on it to be informed of
occuring errors.
connectionName | the name of the connection to invoke a method on |
methodName | the name of the method to invoke on the connection |
args | the arguments to pass as parameters when invoking the method |
listener | the listener to notify if the method invocation failed out of an asynchron unknwon reason |
either the passed-in listener if it was not null or undefined,
or a new listener
| IllegalArgumentException | if connectionName or methodName
are null, undefined or an empty string
|
| UnknownConnectionException | if a connection with the passed-in
connectionName does not exist
|
| MethodInvocationException | if the arguments you try to pass are out of size |
public function addErrorListener(listener:MethodInvocationErrorListener):VoidAdds a new error listener.
Error listener is invoked if an asynchron error occured. This is mostly when you try to invoke a remote method.
listener | the new error listener to add |
public function removeErrorListener(listener:MethodInvocationErrorListener):VoidRemoves an error listener.
Error listener is invoked if an asynchron error occured. This is mostly when you try to invoke a remote method.
listener | the error listener to remove |