org.as2lib.core.BasicClass +--org.as2lib.io.conn.core.server.AbstractServerServiceProxy +--org.as2lib.io.conn.local.server.LocalServerServiceProxy
ServerServiceProxy
LocalServerServiceProxy
handles client requests to a certain service and
its responses.
This client requests normally come from a client service proxy because this class is designed to interact with this type of client.
You can setup your service proxy as follows to await client requests:
var service:LocalServerServiceProxy = new LocalServerServiceProxy("myService", new MyService());
service.run();
A client may then invoke a method on this service proxy.
var client = new LocalClientServiceProxy("myService");
var callback:MethodInvocationCallback = client.myMethod("firstArgument", "secondArgument");
You may choose to combine multiple services in one server for easier usage.
var server:LocalServer = new LocalServer("local.as2lib.org");
server.addService(new LocalServerServiceProxy("myServiceOne", new MyServiceOne()));
server.addService(new LocalServerServiceProxy("myServiceTwo", new MyServiceTwo()));
server.run();
A client must then prefix the service's name with the host of the server.
var client = new LocalClientServiceProxy("local.as2lib.org/myService");
var callback:MethodInvocationCallback = client.myMethod("firstArgument", "secondArgument");
If the client invokes a method with arguments on this service that are not of
type Number
, String
, Boolean
or Array
which are
converted dynamically to the correct type, Flash just creates a new object of type
Object
and populates it with the instance variables of the passed object.
To receive an instance of correct type you must thus register the class. Note
that the client must register the same class with the same name. This registration
must also be done for return values on the client and the server.
Object.registerClass("MyClass", MyClass);
The received object will now be of correct type. But you still have to be aware
of some facts.
Flash creates a new object in the background and sets the instance variables of
the sent instance to the new object. It then registers this object to the appropriate
class (if registered previously) and applies the constructor of that class to the
new object passing no arguments. This means if the constructor sets instance variables
it overwrites the ones set previously by undefined
.
generateServiceUrl(), invokeMethod()
public function LocalServerServiceProxy(path:String, service)
Constructs a new LocalServerServiceProxy
instance.
path | the path of this service |
service | object that provides the service's operations |
IllegalArgumentException | if path is null , undefined
or an empty string or if service is null or undefined
|
public function getConnection(Void):EnhancedLocalConnection
Returns the currently used connection.
This is either the connection set via the setConnection method or the default one which is an instance of class EnhancedLocalConnection.
the currently used connection
public function setConnection(connection:EnhancedLocalConnection):Void
Sets a new connection.
If connection
is null
or undefined
, getConnection
will return the default connection.
connection | the new connection |
public function run(host:String):Void
Runs this service proxy on the passed-in host
.
This service proxy will be restarted if it is already running. This means it it first stops itself and starts itself again.
Only the path of this service proxy is used to connect if the passed-in host
is null
, undefined
or an empty string.
host | the host to run the service on |
ReservedServiceException | if a service on the passed-in host with
the service's path is already in use
|
public function invokeMethodByNameAndArguments(methodName:String, args:Array):Void
Handles incoming 'remote' method invocations on the service.
The method corresponding to the passed-in methodName
is invoked on the
wrapped service.
The error listeners will be informed of a failure if:
methodName
does not exist on the wrapped
service.
methodName | the name of the method to invoke on the service |
args | the arguments to use as parameters when invoking the method |
invokeMethodByNameAndArguments() in org.as2lib.io.conn.core.server.ServerServiceProxy
public function invokeMethodByNameAndArgumentsAndResponseService(methodName:String, args:Array, responseServiceUrl:String):Void
Handles incoming 'remote' method invocations on the service and responses through
the responseServiceUrl
.
The method corresponding to the passed-in methodName
is invoked on the
service and the response of this invocation is passed through the
responseServiceUrl
to the client.
If the response service url is null
or an empty string the
invokeMethodByNameAndArguments method is invoked instead.
The response service is supposed to implement two methods with the following signature:
The onReturn
method is invoked on the response service if the method
returned successfully.
The onError
method is invoked on the response service if:
The error listeners will be informed of a failure if:
methodName
does not exist on the wrapped
service.
responseServiceUrl
does not exist.
methodName | the name of the method to invoke on the service |
args | the arguments to use as parameters when invoking the method |
responseServiceUrl | the url to the service that handles the response |
invokeMethodByNameAndArgumentsAndResponseService() in org.as2lib.io.conn.core.server.ServerServiceProxy
public function getService(Void)
Returns the wrapped service.
the wrapped service
getService() in org.as2lib.io.conn.core.server.ServerServiceProxy
public function getPath(Void):String
Returns the path of this service.
getPath() in org.as2lib.io.conn.core.server.ServerServiceProxy
public function isRunning(Void):Boolean
Returns whether this service is running or not.
true
if this service is running else false
isRunning() in org.as2lib.io.conn.core.server.ServerServiceProxy
public function addErrorListener(errorListener:MethodInvocationErrorListener):Void
Adds an error listener.
Error listeners are notified when a client tried to invoke a method on this service and something went wrong.
errorListener | the new error listener to add |
addErrorListener() in org.as2lib.io.conn.core.server.ServerServiceProxy
public function removeErrorListener(errorListener:MethodInvocationErrorListener):Void
Removes an error listener.
Error listeners are notified when a client tried to invoke a method on this service and something went wrong.
errorListener | the error listener to remove |
removeErrorListener() in org.as2lib.io.conn.core.server.ServerServiceProxy