Class org.as2lib.io.conn.local.core.EnhancedLocalConnection

Description

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); }

Method Index

new EnhancedLocalConnection()
addErrorListener(), close(), connect(), connectionExists(), removeErrorListener(), send(), sendByConnectionAndMethod(), sendByConnectionAndMethodAndArguments(), sendByConnectionAndMethodAndArgumentsAndListener(), sendByConnectionAndMethodAndListener()

Inherited from BasicClass

Constructor Detail

EnhancedLocalConnection

public function EnhancedLocalConnection()

Method Detail

connectionExists

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.

Parameters

connectionNamethe name of the connection

Return

true if the connection exists else false

connect

public function connect(connectionName:String):Void

Prepares 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.

Parameters

connectionNamename of the connection the client uses to send method calls

Throws

IllegalArgumentExceptionif the passed-in connectionName is null, undefined or an empty string
ReservedConnectionExceptionif a connection with the passed-in connectionName is already in use

close

public function close(Void):Void

Closes this connection.

send

public function send():MethodInvocationErrorListener

sendByConnectionAndMethod

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.

Parameters

connectionNamethe name of the connection to invoke the method on
methodNamethe name of the method to invoke on the connection

Return

an error listener that informs you of occuring errors if you set the onError method on it

Throws

IllegalArgumentExceptionif connectionName or methodName are null, undefined or an empty string
UnknownConnectionExceptionif a connection with the passed-in connectionName does not exist

sendByConnectionAndMethodAndArguments

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.

Parameters

connectionNamethe name of the connection to invoke the method on
methodNamethe name of the method to invoke on the connection
argsthe arguments to pass as parameters when invoking the connection

Return

an error listener that informs you of occuring errors if you set the onError method on it

Throws

IllegalArgumentExceptionif connectionName or methodName are null, undefined or an empty string
UnknownConnectionExceptionif a connection with the passed-in connectionName does not exist
MethodInvocationExceptionif the arguments you try to pass are out of size

sendByConnectionAndMethodAndListener

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.

Parameters

connectionNamethe name of the connection to invoke a method on
methodNamethe name of the method to invoke on the connection
listenerthe listener to notify if the method invocation failed out of an asynchron unknwon reason

Return

either the passed-in listener if it was not null or undefined, or a new listener

Throws

IllegalArgumentExceptionif connectionName or methodName are null, undefined or an empty string
UnknownConnectionExceptionif a connection with the passed-in connectionName does not exist
MethodInvocationExceptionif the arguments you try to pass are out of size

sendByConnectionAndMethodAndArgumentsAndListener

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.

Parameters

connectionNamethe name of the connection to invoke a method on
methodNamethe name of the method to invoke on the connection
argsthe arguments to pass as parameters when invoking the method
listenerthe listener to notify if the method invocation failed out of an asynchron unknwon reason

Return

either the passed-in listener if it was not null or undefined, or a new listener

Throws

IllegalArgumentExceptionif connectionName or methodName are null, undefined or an empty string
UnknownConnectionExceptionif a connection with the passed-in connectionName does not exist
MethodInvocationExceptionif the arguments you try to pass are out of size

addErrorListener

public function addErrorListener(listener:MethodInvocationErrorListener):Void

Adds a new error listener.

Error listener is invoked if an asynchron error occured. This is mostly when you try to invoke a remote method.

Parameters

listenerthe new error listener to add

removeErrorListener

public function removeErrorListener(listener:MethodInvocationErrorListener):Void

Removes an error listener.

Error listener is invoked if an asynchron error occured. This is mostly when you try to invoke a remote method.

Parameters

listenerthe error listener to remove