Class org.as2lib.io.conn.local.server.LocalServerServiceProxy

org.as2lib.core.BasicClass
   +--org.as2lib.io.conn.core.server.AbstractServerServiceProxy
      +--org.as2lib.io.conn.local.server.LocalServerServiceProxy

Implemented Interfaces

ServerServiceProxy

Description

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.

Method Index

new LocalServerServiceProxy()

addErrorListener(), getConnection(), getPath(), getService(), invokeMethodByNameAndArguments(), invokeMethodByNameAndArgumentsAndResponseService(), isRunning(), removeErrorListener(), run(), setConnection(), stop()

Inherited from AbstractServerServiceProxy

generateServiceUrl(), invokeMethod()

Inherited from BasicClass

toString()

Constructor Detail

LocalServerServiceProxy

public function LocalServerServiceProxy(path:String, service)

Constructs a new LocalServerServiceProxy instance.

Parameters

paththe path of this service
serviceobject that provides the service's operations

Throws

IllegalArgumentExceptionif path is null, undefined or an empty string or if service is null or undefined

Method Detail

getConnection

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.

Return

the currently used connection

setConnection

public function setConnection(connection:EnhancedLocalConnection):Void

Sets a new connection.

If connection is null or undefined, getConnection will return the default connection.

Parameters

connectionthe new connection

run

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.

Parameters

hostthe host to run the service on

Throws

ReservedServiceExceptionif a service on the passed-in host with the service's path is already in use

Specified By

run() in org.as2lib.io.conn.core.server.ServerServiceProxy

stop

public function stop(Void):Void

Stops this service.

Specified By

stop() in org.as2lib.io.conn.core.server.ServerServiceProxy

invokeMethodByNameAndArguments

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:

  • A method with the passed-in methodName does not exist on the wrapped service.
  • The service method threw an exception.

Parameters

methodNamethe name of the method to invoke on the service
argsthe arguments to use as parameters when invoking the method

Specified By

invokeMethodByNameAndArguments() in org.as2lib.io.conn.core.server.ServerServiceProxy

invokeMethodByNameAndArgumentsAndResponseService

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:

  • onReturn(returnValue):Void
  • onError(errorCode:Number, exception):Void

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 method threw an exception.
  • The method does not exist on the service.

The error listeners will be informed of a failure if:

  • A method with the passed-in methodName does not exist on the wrapped service.
  • The service method threw an exception.
  • The response server with the given responseServiceUrl does not exist.
  • The return value is too big to send over a local connection.
  • An unknown failure occured when trying to send the response.

Parameters

methodNamethe name of the method to invoke on the service
argsthe arguments to use as parameters when invoking the method
responseServiceUrlthe url to the service that handles the response

Specified By

invokeMethodByNameAndArgumentsAndResponseService() in org.as2lib.io.conn.core.server.ServerServiceProxy

getService

public function getService(Void)

Returns the wrapped service.

Return

the wrapped service

Specified By

getService() in org.as2lib.io.conn.core.server.ServerServiceProxy

getPath

public function getPath(Void):String

Returns the path of this service.

Specified By

getPath() in org.as2lib.io.conn.core.server.ServerServiceProxy

isRunning

public function isRunning(Void):Boolean

Returns whether this service is running or not.

Return

true if this service is running else false

Specified By

isRunning() in org.as2lib.io.conn.core.server.ServerServiceProxy

addErrorListener

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.

Parameters

errorListenerthe new error listener to add

Specified By

addErrorListener() in org.as2lib.io.conn.core.server.ServerServiceProxy

removeErrorListener

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.

Parameters

errorListenerthe error listener to remove

Specified By

removeErrorListener() in org.as2lib.io.conn.core.server.ServerServiceProxy