rudimentary SWF implementation of AMF in FlexJS. Now I know what needs to be done on the JS side
Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/029d87f1 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/029d87f1 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/029d87f1 Branch: refs/heads/feature/amf Commit: 029d87f166d06796ea91953e1103bc4187f6408a Parents: 98f992c Author: Alex Harui <aha...@apache.org> Authored: Tue Aug 22 18:13:59 2017 -0700 Committer: Alex Harui <aha...@apache.org> Committed: Tue Aug 22 18:17:10 2017 -0700 ---------------------------------------------------------------------- .../Network/src/main/flex/NetworkClasses.as | 5 + .../flex/org/apache/flex/net/RemoteObject.as | 169 +++- .../org/apache/flex/net/remoting/Operation.as | 116 +++ .../net/remoting/messages/AbstractMessage.as | 781 +++++++++++++++++++ .../net/remoting/messages/AcknowledgeMessage.as | 148 ++++ .../flex/net/remoting/messages/AsyncMessage.as | 272 +++++++ .../net/remoting/messages/CommandMessage.as | 581 ++++++++++++++ .../flex/net/remoting/messages/IMessage.as | 222 ++++++ .../net/remoting/messages/RemotingMessage.as | 95 +++ 9 files changed, 2365 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/029d87f1/frameworks/projects/Network/src/main/flex/NetworkClasses.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Network/src/main/flex/NetworkClasses.as b/frameworks/projects/Network/src/main/flex/NetworkClasses.as index aeb8e42..8dd2e36 100644 --- a/frameworks/projects/Network/src/main/flex/NetworkClasses.as +++ b/frameworks/projects/Network/src/main/flex/NetworkClasses.as @@ -30,6 +30,11 @@ package import org.apache.flex.net.HTTPConstants; HTTPConstants; import org.apache.flex.net.events.ResultEvent; ResultEvent; import org.apache.flex.net.events.FaultEvent; FaultEvent; + + import org.apache.flex.net.remoting.messages.AsyncMessage; AsyncMessage; + import org.apache.flex.net.remoting.messages.CommandMessage; CommandMessage; + import org.apache.flex.net.remoting.messages.RemotingMessage; RemotingMessage; + import org.apache.flex.net.remoting.messages.AcknowledgeMessage; AcknowledgeMessage; } } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/029d87f1/frameworks/projects/Network/src/main/flex/org/apache/flex/net/RemoteObject.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/RemoteObject.as b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/RemoteObject.as index b57be6f..846731e 100755 --- a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/RemoteObject.as +++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/RemoteObject.as @@ -18,16 +18,30 @@ //////////////////////////////////////////////////////////////////////////////// package org.apache.flex.net { - import org.apache.flex.net.events.FaultEvent; - import org.apache.flex.net.events.ResultEvent; - - import org.apache.flex.events.EventDispatcher; - import org.apache.flex.reflection.getClassByAlias; - import org.apache.flex.reflection.registerClassAlias; + COMPILE::SWF + { + import flash.events.AsyncErrorEvent; + import flash.events.IOErrorEvent; + import flash.events.NetStatusEvent; + import flash.events.SecurityErrorEvent; + import flash.net.NetConnection; + import flash.net.Responder; + import flash.net.ObjectEncoding; + } + + + import org.apache.flex.core.IBead; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.EventDispatcher; + import org.apache.flex.net.events.FaultEvent; + import org.apache.flex.net.events.ResultEvent; + import org.apache.flex.net.remoting.Operation; + import org.apache.flex.reflection.getClassByAlias; + import org.apache.flex.reflection.registerClassAlias; [Event(name="result", type="org.apache.flex.net.events.ResultEvent")] [Event(name="fault", type="org.apache.flex.net.events.FaultEvent")] - public class RemoteObject extends EventDispatcher + public class RemoteObject extends EventDispatcher implements IBead { private var _endPoint:String; private var _destination:String; @@ -41,8 +55,24 @@ package org.apache.flex.net */ public function RemoteObject() { + COMPILE::SWF + { + nc = new NetConnection(); + nc.objectEncoding = ObjectEncoding.AMF3; + nc.client = this; + } } + private var _strand:IStrand; + + public function set strand(value:IStrand):void + { + _strand = value; + } + + COMPILE::SWF + public var nc:NetConnection; + public function set endPoint(value:String):void { _endPoint = value; @@ -70,8 +100,19 @@ package org.apache.flex.net return _source; } - public function send(operation:String , params:Array):void + public function send(operation:String, params:Array):void { + COMPILE::SWF + { + nc.addEventListener(NetStatusEvent.NET_STATUS, statusHandler); + nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); + nc.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); + nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler); + nc.connect(endPoint); + + var op:Operation = new Operation(operation, this, params); + op.send(); + } COMPILE::JS { var amfClient:Object = new ((window as Object).amf).Client(_destination, _endPoint); @@ -80,28 +121,56 @@ package org.apache.flex.net } } - private function resultHandler(param:Object):void + COMPILE::SWF + private function statusHandler(event:NetStatusEvent):void + { + trace("statusHandler", event.info.code); + } + + COMPILE::SWF + private function securityErrorHandler(event:SecurityErrorEvent):void + { + trace("securityErrorHandler", event); + } + + COMPILE::SWF + private function ioErrorHandler(event:IOErrorEvent):void + { + trace("ioErrorHandler", event); + } + + COMPILE::SWF + private function asyncErrorHandler(event:AsyncErrorEvent):void + { + trace("asyncErrorHandler", event); + } + + public function resultHandler(param:Object):void { - if(param is Object && param.hasOwnProperty("_explicitType")) - { - param = typeUntypedObject(param); - } - else if (param is Array && param.length > 0) - { - for(var i:uint ; i < param.length ; i++) - { - var typedObj:Object = typeUntypedObject(param[i]); - param[i] = typedObj; - } - } - dispatchEvent(new ResultEvent(ResultEvent.RESULT,param)); + COMPILE::JS + { + if(param is Object && param.hasOwnProperty("_explicitType")) + { + param = typeUntypedObject(param); + } + else if (param is Array && param.length > 0) + { + for(var i:uint ; i < param.length ; i++) + { + var typedObj:Object = typeUntypedObject(param[i]); + param[i] = typedObj; + } + } + } + dispatchEvent(new ResultEvent(ResultEvent.RESULT,param.body)); } - private function faultHandler(param:Object):void + public function faultHandler(param:Object):void { dispatchEvent(new FaultEvent(FaultEvent.FAULT,param)); } + COMPILE::JS private function typeUntypedObject(unTypeObject:Object):Object { registerClassAlias(unTypeObject['_explicitType'],getClassByAlias(unTypeObject['_explicitType'])); @@ -119,5 +188,57 @@ package org.apache.flex.net return typedInstance; } + + /** + * @private + * Special handler for legacy AMF packet level header "AppendToGatewayUrl". + * When we receive this header we assume the server detected that a session was + * created but it believed the client could not accept its session cookie, so we + * need to decorate the channel endpoint with the session id. + * + * We do not modify the underlying endpoint property, however, as this session + * is transient and should not apply if the channel is disconnected and re-connected + * at some point in the future. + */ + COMPILE::SWF + public function AppendToGatewayUrl(value:String):void + { + if (value != null && value != "") + { + nc.removeEventListener(NetStatusEvent.NET_STATUS, statusHandler); + trace("disconnecting because AppendToGatewayUrl called"); + nc.close(); + trace("disconnecting returned from close()"); + var url:String = endPoint; + // WSRP support - append any extra stuff on the wsrp-url, not the actual url. + + // Do we have a wsrp-url? + var i:int = url.indexOf("wsrp-url="); + if (i != -1) + { + // Extract the wsrp-url in to a string which will get the + // extra info appended to it + var temp:String = url.substr(i + 9, url.length); + var j:int = temp.indexOf("&"); + if (j != -1) + { + temp = temp.substr(0, j); + } + + // Replace the wsrp-url with a version that has the extra stuff + url = url.replace(temp, temp + value); + } + else + { + // If we didn't find a wsrp-url, just append the info + url += value; + } + nc.addEventListener(NetStatusEvent.NET_STATUS, statusHandler); + trace("reconnecting with " + url); + nc.connect(url); + trace("reconnecting returned from connect()"); + } + } + } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/029d87f1/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/Operation.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/Operation.as b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/Operation.as new file mode 100755 index 0000000..1110a46 --- /dev/null +++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/Operation.as @@ -0,0 +1,116 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.net.remoting +{ + COMPILE::SWF + { + import flash.events.AsyncErrorEvent; + import flash.events.IOErrorEvent; + import flash.events.NetStatusEvent; + import flash.events.SecurityErrorEvent; + import flash.net.Responder; + } + + + import org.apache.flex.events.EventDispatcher; + import org.apache.flex.net.RemoteObject; + import org.apache.flex.net.remoting.messages.CommandMessage; + import org.apache.flex.net.remoting.messages.RemotingMessage; + import org.apache.flex.net.events.FaultEvent; + import org.apache.flex.net.events.ResultEvent; + import org.apache.flex.reflection.getClassByAlias; + import org.apache.flex.reflection.registerClassAlias; + + + public class Operation extends EventDispatcher + { + private var _name:String; + private var _args:Array; + private var _ro:RemoteObject; + + public function Operation(name:String, remoteObject:RemoteObject, args:Array) + { + _name = name; + _args = args; + _ro = remoteObject; + } + + public function send():void + { + COMPILE::SWF + { + _ro.nc.addEventListener(NetStatusEvent.NET_STATUS, statusHandler); + _ro.nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); + _ro.nc.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); + _ro.nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler); + var connectMessage:CommandMessage = new CommandMessage(); + connectMessage.destination = _ro.destination; + connectMessage.operation = CommandMessage.TRIGGER_CONNECT_OPERATION; + _ro.nc.call(null, new Responder(destinationResultHandler, destinationFaultHandler), connectMessage); + } + COMPILE::JS + { + var amfClient:Object = new ((window as Object).amf).Client(_destination, _endPoint); + var amfReq:Object = amfClient.invoke(_source, operation, params[0]); + amfReq.then(resultHandler , faultHandler); + } + } + + COMPILE::SWF + private function statusHandler(event:NetStatusEvent):void + { + trace("statusHandler", event); + } + + COMPILE::SWF + private function securityErrorHandler(event:SecurityErrorEvent):void + { + trace("securityErrorHandler", event); + } + + COMPILE::SWF + private function ioErrorHandler(event:IOErrorEvent):void + { + trace("ioErrorHandler", event); + } + + COMPILE::SWF + private function asyncErrorHandler(event:AsyncErrorEvent):void + { + trace("asyncErrorHandler", event); + } + + private function destinationResultHandler(param:Object):void + { + var message:RemotingMessage = new RemotingMessage(); + message.operation = _name; + message.body = _args; + message.source = _ro.source; + message.destination = _ro.destination; + _ro.nc.call(null, new Responder(_ro.resultHandler, _ro.faultHandler), message); + + } + + private function destinationFaultHandler(param:Object):void + { + trace("destination fault handler", param); + } + + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/029d87f1/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/messages/AbstractMessage.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/messages/AbstractMessage.as b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/messages/AbstractMessage.as new file mode 100644 index 0000000..9b913a2 --- /dev/null +++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/messages/AbstractMessage.as @@ -0,0 +1,781 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +package org.apache.flex.net.remoting.messages +{ + +COMPILE::SWF +{ + import flash.utils.ByteArray; + import flash.utils.IDataInput; + import flash.utils.IDataOutput; + import flash.utils.getQualifiedClassName; +} + +import org.apache.flex.utils.ObjectUtil; +import org.apache.flex.utils.UIDUtil; + +/* +import mx.core.mx_internal; +import mx.utils.RPCObjectUtil; +import mx.utils.RPCStringUtil; +import mx.utils.RPCUIDUtil; + +use namespace mx_internal; +*/ + +/** + * Abstract base class for all messages. + * Messages have two customizable sections; headers and body. + * The <code>headers</code> property provides access to specialized meta + * information for a specific message instance. + * The <code>headers</code> property is an associative array with the specific + * header name as the key. + * <p> + * The body of a message contains the instance specific data that needs to be + * delivered and processed by the remote destination. + * The <code>body</code> is an object and is the payload for a message. + * </p> + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ +public class AbstractMessage implements IMessage +{ + //-------------------------------------------------------------------------- + // + // Static Constants + // + //-------------------------------------------------------------------------- + + /** + * Messages pushed from the server may arrive in a batch, with messages in the + * batch potentially targeted to different Consumer instances. + * Each message will contain this header identifying the Consumer instance that + * will receive the message. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const DESTINATION_CLIENT_ID_HEADER:String = "DSDstClientId"; + + /** + * Messages are tagged with the endpoint id for the Channel they are sent over. + * Channels set this value automatically when they send a message. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const ENDPOINT_HEADER:String = "DSEndpoint"; + + /** + * This header is used to transport the global FlexClient Id value in outbound + * messages once it has been assigned by the server. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const FLEX_CLIENT_ID_HEADER:String = "DSId"; + + /** + * Messages sent by a MessageAgent can have a priority header with a 0-9 + * numerical value (0 being lowest) and the server can choose to use this + * numerical value to prioritize messages to clients. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const PRIORITY_HEADER:String = "DSPriority"; + + /** + * Messages that need to set remote credentials for a destination + * carry the Base64 encoded credentials in this header. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const REMOTE_CREDENTIALS_HEADER:String = "DSRemoteCredentials"; + + /** + * Messages that need to set remote credentials for a destination + * may also need to report the character-set encoding that was used to + * create the credentials String using this header. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const REMOTE_CREDENTIALS_CHARSET_HEADER:String = "DSRemoteCredentialsCharset"; + + /** + * Messages sent with a defined request timeout use this header. + * The request timeout value is set on outbound messages by services or + * channels and the value controls how long the corresponding MessageResponder + * will wait for an acknowledgement, result or fault response for the message + * before timing out the request. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const REQUEST_TIMEOUT_HEADER:String = "DSRequestTimeout"; + + /** + * A status code can provide context about the nature of a response + * message. For example, messages received from an HTTP based channel may + * need to report the HTTP response status code (if available). + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const STATUS_CODE_HEADER:String = "DSStatusCode"; + + + //-------------------------------------------------------------------------- + // + // Private Static Constants for Serialization + // + //-------------------------------------------------------------------------- + + /* + private static const HAS_NEXT_FLAG:uint = 128; + private static const BODY_FLAG:uint = 1; + private static const CLIENT_ID_FLAG:uint = 2; + private static const DESTINATION_FLAG:uint = 4; + private static const HEADERS_FLAG:uint = 8; + private static const MESSAGE_ID_FLAG:uint = 16; + private static const TIMESTAMP_FLAG:uint = 32; + private static const TIME_TO_LIVE_FLAG:uint = 64; + private static const CLIENT_ID_BYTES_FLAG:uint = 1; + private static const MESSAGE_ID_BYTES_FLAG:uint = 2; + */ + + //-------------------------------------------------------------------------- + // + // Constructor + // + //-------------------------------------------------------------------------- + + /** + * Constructs an instance of an AbstractMessage with an empty body and header. + * This message type should not be instantiated or used directly. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public function AbstractMessage() + { + super(); + } + + //-------------------------------------------------------------------------- + // + // Properties + // + //-------------------------------------------------------------------------- + + //---------------------------------- + // body + //---------------------------------- + + /** + * @private + */ + private var _body:Object = {}; + + /** + * The body of a message contains the specific data that needs to be + * delivered to the remote destination. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public function get body():Object + { + return _body; + } + + /** + * @private + */ + public function set body(value:Object):void + { + _body = value; + } + + //---------------------------------- + // clientId + //---------------------------------- + + /** + * @private + */ + private var _clientId:String; + + /** + * @private + */ + COMPILE::SWF + private var clientIdBytes:ByteArray; + + /** + * The clientId indicates which MessageAgent sent the message. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public function get clientId():String + { + return _clientId; + } + + /** + * @private + */ + public function set clientId(value:String):void + { + _clientId = value; + COMPILE::SWF + { + clientIdBytes = null; + } + } + + //---------------------------------- + // destination + //---------------------------------- + + /** + * @private + */ + private var _destination:String = ""; + + /** + * The message destination. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public function get destination():String + { + return _destination; + } + + /** + * @private + */ + public function set destination(value:String):void + { + _destination = value; + } + + //---------------------------------- + // headers + //---------------------------------- + + /** + * @private + */ + private var _headers:Object; + + /** + * The headers of a message are an associative array where the key is the + * header name and the value is the header value. + * This property provides access to the specialized meta information for the + * specific message instance. + * Core header names begin with a 'DS' prefix. Custom header names should start + * with a unique prefix to avoid name collisions. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public function get headers():Object + { + if (_headers == null) + _headers = {}; + + return _headers; + } + + /** + * @private + */ + public function set headers(value:Object):void + { + _headers = value; + } + + //---------------------------------- + // messageId + //---------------------------------- + + /** + * @private + */ + private var _messageId:String; + + /** + * @private + */ + COMPILE::SWF + private var messageIdBytes:ByteArray; + + /** + * The unique id for the message. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public function get messageId():String + { + if (_messageId == null) + _messageId = UIDUtil.createUID(); + + return _messageId; + } + + /** + * @private + */ + public function set messageId(value:String):void + { + _messageId = value; + COMPILE::SWF + { + messageIdBytes = null; + } + } + + //---------------------------------- + // timestamp + //---------------------------------- + + /** + * @private + */ + private var _timestamp:Number = 0; + + /** + * Provides access to the time stamp for the message. + * A time stamp is the date and time that the message was sent. + * The time stamp is used for tracking the message through the system, + * ensuring quality of service levels and providing a mechanism for + * message expiration. + * + * @see #timeToLive + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public function get timestamp():Number + { + return _timestamp; + } + + /** + * @private + */ + public function set timestamp(value:Number):void + { + _timestamp = value; + } + + //---------------------------------- + // timeToLive + //---------------------------------- + + /** + * @private + */ + private var _timeToLive:Number = 0; + + /** + * The time to live value of a message indicates how long the message + * should be considered valid and deliverable. + * This value works in conjunction with the <code>timestamp</code> value. + * Time to live is the number of milliseconds that this message remains + * valid starting from the specified <code>timestamp</code> value. + * For example, if the <code>timestamp</code> value is 04/05/05 1:30:45 PST + * and the <code>timeToLive</code> value is 5000, then this message will + * expire at 04/05/05 1:30:50 PST. + * Once a message expires it will not be delivered to any other clients. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public function get timeToLive():Number + { + return _timeToLive; + } + + /** + * @private + */ + public function set timeToLive(value:Number):void + { + _timeToLive = value; + } + + //-------------------------------------------------------------------------- + // + // Methods + // + //-------------------------------------------------------------------------- + + /** + * @private + * + * While this class itself does not implement flash.utils.IExternalizable, + * ISmallMessage implementations will typically use IExternalizable to + * serialize themselves in a smaller form. This method supports this + * functionality by implementing IExternalizable.readExternal(IDataInput) to + * deserialize the properties for this abstract base class. + */ + /* LATER + public function readExternal(input:IDataInput):void + { + var flagsArray:Array = readFlags(input); + + for (var i:uint = 0; i < flagsArray.length; i++) + { + var flags:uint = flagsArray[i] as uint; + var reservedPosition:uint = 0; + + if (i == 0) + { + if ((flags & BODY_FLAG) != 0) + readExternalBody(input); + else + body = null; // default body is {} so need to set it here + + if ((flags & CLIENT_ID_FLAG) != 0) + clientId = input.readObject(); + + if ((flags & DESTINATION_FLAG) != 0) + destination = input.readObject() as String; + + if ((flags & HEADERS_FLAG) != 0) + headers = input.readObject(); + + if ((flags & MESSAGE_ID_FLAG) != 0) + messageId = input.readObject() as String; + + if ((flags & TIMESTAMP_FLAG) != 0) + timestamp = input.readObject() as Number; + + if ((flags & TIME_TO_LIVE_FLAG) != 0) + timeToLive = input.readObject() as Number; + + reservedPosition = 7; + } + else if (i == 1) + { + if ((flags & CLIENT_ID_BYTES_FLAG) != 0) + { + clientIdBytes = input.readObject() as ByteArray; + clientId = RPCUIDUtil.fromByteArray(clientIdBytes); + } + + if ((flags & MESSAGE_ID_BYTES_FLAG) != 0) + { + messageIdBytes = input.readObject() as ByteArray; + messageId = RPCUIDUtil.fromByteArray(messageIdBytes); + } + + reservedPosition = 2; + } + + // For forwards compatibility, read in any other flagged objects to + // preserve the integrity of the input stream... + if ((flags >> reservedPosition) != 0) + { + for (var j:uint = reservedPosition; j < 6; j++) + { + if (((flags >> j) & 1) != 0) + { + input.readObject(); + } + } + } + } + } + */ + + /** + * Returns a string representation of the message. + * + * @return String representation of the message. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public function toString():String + { + return ObjectUtil._toString(this); + } + + /** + * @private + * + * While this class itself does not implement flash.utils.IExternalizable, + * ISmallMessage implementations will typically use IExternalizable to + * serialize themselves in a smaller form. This method supports this + * functionality by implementing IExternalizable.writeExternal(IDataOutput) + * to efficiently serialize the properties for this abstract base class. + */ + /* + public function writeExternal(output:IDataOutput):void + { + var flags:uint = 0; + + // Since we're using custom serialization, we have to invoke the + // messageId getter to ensure we have a valid id for the message. + var checkForMessageId:String = messageId; + + if (clientIdBytes == null) + clientIdBytes = RPCUIDUtil.toByteArray(_clientId); + + if (messageIdBytes == null) + messageIdBytes = RPCUIDUtil.toByteArray(_messageId); + + if (body != null) + flags |= BODY_FLAG; + + if (clientId != null && clientIdBytes == null) + flags |= CLIENT_ID_FLAG; + + if (destination != null) + flags |= DESTINATION_FLAG; + + if (headers != null) + flags |= HEADERS_FLAG; + + if (messageId != null && messageIdBytes == null) + flags |= MESSAGE_ID_FLAG; + + if (timestamp != 0) + flags |= TIMESTAMP_FLAG; + + if (timeToLive != 0) + flags |= TIME_TO_LIVE_FLAG; + + if (clientIdBytes != null || messageIdBytes != null) + flags |= HAS_NEXT_FLAG; + + output.writeByte(flags); + + flags = 0; + + if (clientIdBytes != null) + flags |= CLIENT_ID_BYTES_FLAG; + + if (messageIdBytes != null) + flags |= MESSAGE_ID_BYTES_FLAG; + + // This is only read if the previous flag has HAS_NEXT_FLAG set + if (flags != 0) + output.writeByte(flags); + + if (body != null) + writeExternalBody(output); + + if (clientId != null && clientIdBytes == null) + output.writeObject(clientId); + + if (destination != null) + output.writeObject(destination); + + if (headers != null) + output.writeObject(headers); + + if (messageId != null && messageIdBytes == null) + output.writeObject(messageId); + + if (timestamp != 0) + output.writeObject(timestamp); + + if (timeToLive != 0) + output.writeObject(timeToLive); + + if (clientIdBytes != null) + output.writeObject(clientIdBytes); + + if (messageIdBytes != null) + output.writeObject(messageIdBytes); + } + */ + + //-------------------------------------------------------------------------- + // + // Protected Methods + // + //-------------------------------------------------------------------------- + + /** + * @private + */ + /* + protected function addDebugAttributes(attributes:Object):void + { + attributes["body"] = body; + attributes["clientId"] = clientId; + attributes["destination"] = destination; + attributes["headers"] = headers; + attributes["messageId"] = messageId; + attributes["timestamp"] = timestamp; + attributes["timeToLive"] = timeToLive; + } + */ + + /** + * @private + */ + /* + final protected function getDebugString():String + { + var result:String = "(" + getQualifiedClassName(this) + ")"; + + var attributes:Object = {}; + addDebugAttributes(attributes); + + var propertyNames:Array = []; + for (var propertyName:String in attributes) + { + propertyNames.push(propertyName); + } + propertyNames.sort(); + + var length:int = propertyNames.length; + for (var i:uint = 0; i < length; i++) + { + var name:String = String(propertyNames[i]); + var value:String = RPCObjectUtil.toString(attributes[name]); + result += RPCStringUtil.substitute("\n {0}={1}", name, value); + } + + return result; + } + */ + + /** + * @private + */ + /* + protected function readExternalBody(input:IDataInput):void + { + body = input.readObject(); + } + */ + + /** + * @private + * To support efficient serialization for ISmallMessage implementations, + * this utility method reads in the property flags from an IDataInput + * stream. Flags are read in one byte at a time. Flags make use of + * sign-extension so that if the high-bit is set to 1 this indicates that + * another set of flags follows. + * + * @return The Array of property flags. Each flags byte is stored as a uint + * in the Array. + */ + /* + protected function readFlags(input:IDataInput):Array + { + var hasNextFlag:Boolean = true; + var flagsArray:Array = []; + + while (hasNextFlag && input.bytesAvailable > 0) + { + var flags:uint = input.readUnsignedByte(); + flagsArray.push(flags); + + if ((flags & HAS_NEXT_FLAG) != 0) + hasNextFlag = true; + else + hasNextFlag = false; + } + + return flagsArray; + } + */ + + /** + * @private + */ + /* + protected function writeExternalBody(output:IDataOutput):void + { + output.writeObject(body); + } + */ +} + +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/029d87f1/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/messages/AcknowledgeMessage.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/messages/AcknowledgeMessage.as b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/messages/AcknowledgeMessage.as new file mode 100644 index 0000000..99261fa --- /dev/null +++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/messages/AcknowledgeMessage.as @@ -0,0 +1,148 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +package org.apache.flex.net.remoting.messages +{ + +COMPILE::SWF +{ +import flash.utils.IDataInput; +import flash.utils.IDataOutput; +} + +[RemoteClass(alias="flex.messaging.messages.AcknowledgeMessage")] + +/** + * An AcknowledgeMessage acknowledges the receipt of a message that + * was sent previously. + * Every message sent within the messaging system must receive an + * acknowledgement. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ +public class AcknowledgeMessage extends AsyncMessage // implements ISmallMessage +{ + //-------------------------------------------------------------------------- + // + // Static Constants + // + //-------------------------------------------------------------------------- + + /** + * Header name for the error hint header. + * Used to indicate that the acknowledgement is for a message that + * generated an error. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const ERROR_HINT_HEADER:String = "DSErrorHint"; + + //-------------------------------------------------------------------------- + // + // Constructor + // + //-------------------------------------------------------------------------- + + /** + * Constructs an instance of an AcknowledgeMessage with an empty body and header. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public function AcknowledgeMessage() + { + super(); + } + + //-------------------------------------------------------------------------- + // + // Overridden Methods + // + //-------------------------------------------------------------------------- + + /** + * @private + */ + /* + override public function getSmallMessage():IMessage + { + var o:Object = this; + if (o.constructor == AcknowledgeMessage) + return new AcknowledgeMessageExt(this); + return null; + } + */ + + /** + * @private + */ + /* + override public function readExternal(input:IDataInput):void + { + super.readExternal(input); + + var flagsArray:Array = readFlags(input); + for (var i:uint = 0; i < flagsArray.length; i++) + { + var flags:uint = flagsArray[i] as uint; + var reservedPosition:uint = 0; + + // For forwards compatibility, read in any other flagged objects + // to preserve the integrity of the input stream... + if ((flags >> reservedPosition) != 0) + { + for (var j:uint = reservedPosition; j < 6; j++) + { + if (((flags >> j) & 1) != 0) + { + input.readObject(); + } + } + } + } + } + */ + + /** + * @private + */ + /* + override public function writeExternal(output:IDataOutput):void + { + super.writeExternal(output); + + var flags:uint = 0; + output.writeByte(flags); + } + */ + +} + +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/029d87f1/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/messages/AsyncMessage.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/messages/AsyncMessage.as b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/messages/AsyncMessage.as new file mode 100644 index 0000000..0aeb5a1 --- /dev/null +++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/messages/AsyncMessage.as @@ -0,0 +1,272 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +package org.apache.flex.net.remoting.messages +{ + +COMPILE::SWF +{ +import flash.utils.ByteArray; +import flash.utils.IDataInput; +import flash.utils.IDataOutput; +} + +[RemoteClass(alias="flex.messaging.messages.AsyncMessage")] + +/** + * AsyncMessage is the base class for all asynchronous messages. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ +public class AsyncMessage extends AbstractMessage // implements ISmallMessage +{ + //-------------------------------------------------------------------------- + // + // Static Constants + // + //-------------------------------------------------------------------------- + + /** + * Messages sent by a MessageAgent with a defined <code>subtopic</code> + * property indicate their target subtopic in this header. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const SUBTOPIC_HEADER:String = "DSSubtopic"; + + //-------------------------------------------------------------------------- + // + // Private Static Constants for Serialization + // + //-------------------------------------------------------------------------- + + /* + private static const CORRELATION_ID_FLAG:uint = 1; + private static const CORRELATION_ID_BYTES_FLAG:uint = 2; + */ + + //-------------------------------------------------------------------------- + // + // Constructor + // + //-------------------------------------------------------------------------- + + /** + * Constructs an instance of an AsyncMessage with an empty body and header. + * In addition to this default behavior, the body and the headers for the + * message may also be passed to the constructor as a convenience. + * An example of this invocation approach for the body is: + * <code>var msg:AsyncMessage = new AsyncMessage("Body text");</code> + * An example that provides both the body and headers is: + * <code>var msg:AsyncMessage = new AsyncMessage("Body text", {"customerHeader":"customValue"});</code> + * + * @param body The optional body to assign to the message. + * + * @param headers The optional headers to assign to the message. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public function AsyncMessage(body:Object = null, headers:Object = null) + { + super(); + + //correlationId = ""; + if (body != null) + this.body = body; + + if (headers != null) + this.headers = headers; + } + + //-------------------------------------------------------------------------- + // + // Variables + // + //-------------------------------------------------------------------------- + + //---------------------------------- + // correlationId + //---------------------------------- + + /** + * @private + */ + /* + private var _correlationId:String; + */ + + /** + * @private + */ + /* + private var correlationIdBytes:ByteArray; + */ + + /** + * Provides access to the correlation id of the message. + * Used for acknowledgement and for segmentation of messages. + * The <code>correlationId</code> contains the <code>messageId</code> of the + * previous message that this message refers to. + * + * @see mx.messaging.messages.AbstractMessage#messageId + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + /* + public function get correlationId():String + { + return _correlationId; + } + */ + + /** + * @private + */ + /* + public function set correlationId(value:String):void + { + _correlationId = value; + correlationIdBytes = null; + } + */ + + //-------------------------------------------------------------------------- + // + // Overridden Methods + // + //-------------------------------------------------------------------------- + + /** + * @private + */ + /* + public function getSmallMessage():IMessage + { + // If it is a subclass, it will need to override this itself if it wants to use + // small messages. + var o:Object = this; + if (o.constructor == AsyncMessage) + return new AsyncMessageExt(this); + return null; + } + */ + + /** + * @private + */ + /* + override public function readExternal(input:IDataInput):void + { + super.readExternal(input); + + var flagsArray:Array = readFlags(input); + for (var i:uint = 0; i < flagsArray.length; i++) + { + var flags:uint = flagsArray[i] as uint; + var reservedPosition:uint = 0; + + if (i == 0) + { + if ((flags & CORRELATION_ID_FLAG) != 0) + correlationId = input.readObject() as String; + + if ((flags & CORRELATION_ID_BYTES_FLAG) != 0) + { + correlationIdBytes = input.readObject() as ByteArray; + correlationId = RPCUIDUtil.fromByteArray(correlationIdBytes); + } + + reservedPosition = 2; + } + + // For forwards compatibility, read in any other flagged objects + // to preserve the integrity of the input stream... + if ((flags >> reservedPosition) != 0) + { + for (var j:uint = reservedPosition; j < 6; j++) + { + if (((flags >> j) & 1) != 0) + { + input.readObject(); + } + } + } + } + } + */ + + /** + * @private + */ + /* + override public function writeExternal(output:IDataOutput):void + { + super.writeExternal(output); + + if (correlationIdBytes == null) + correlationIdBytes = RPCUIDUtil.toByteArray(_correlationId); + + var flags:uint = 0; + + if (correlationId != null && correlationIdBytes == null) + flags |= CORRELATION_ID_FLAG; + + if (correlationIdBytes != null) + flags |= CORRELATION_ID_BYTES_FLAG; + + output.writeByte(flags); + + if (correlationId != null && correlationIdBytes == null) + output.writeObject(correlationId); + + if (correlationIdBytes != null) + output.writeObject(correlationIdBytes); + } + */ + + /** + * @private + */ + /* + override protected function addDebugAttributes(attributes:Object):void + { + super.addDebugAttributes(attributes); + attributes["correlationId"] = correlationId; + } + */ + +} + +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/029d87f1/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/messages/CommandMessage.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/messages/CommandMessage.as b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/messages/CommandMessage.as new file mode 100644 index 0000000..dcd0f85 --- /dev/null +++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/messages/CommandMessage.as @@ -0,0 +1,581 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +package org.apache.flex.net.remoting.messages +{ + +COMPILE::SWF +{ +import flash.utils.IDataInput; +import flash.utils.IDataOutput; +} + +[RemoteClass(alias="flex.messaging.messages.CommandMessage")] + +/** + * The CommandMessage class provides a mechanism for sending commands to the + * server infrastructure, such as commands related to publish/subscribe + * messaging scenarios, ping operations, and cluster operations. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ +public class CommandMessage extends AsyncMessage +{ + //-------------------------------------------------------------------------- + // + // Static Constants + // + //-------------------------------------------------------------------------- + + /** + * This operation is used to subscribe to a remote destination. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const SUBSCRIBE_OPERATION:uint = 0; + + /** + * This operation is used to unsubscribe from a remote destination. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const UNSUBSCRIBE_OPERATION:uint = 1; + + /** + * This operation is used to poll a remote destination for pending, + * undelivered messages. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const POLL_OPERATION:uint = 2; + + /** + * This operation is used by a remote destination to sync missed or cached messages + * back to a client as a result of a client issued poll command. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const CLIENT_SYNC_OPERATION:uint = 4; + + /** + * This operation is used to test connectivity over the current channel to + * the remote endpoint. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const CLIENT_PING_OPERATION:uint = 5; + + /** + * This operation is used to request a list of failover endpoint URIs + * for the remote destination based on cluster membership. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const CLUSTER_REQUEST_OPERATION:uint = 7; + + /** + * This operation is used to send credentials to the endpoint so that + * the user can be logged in over the current channel. + * The credentials need to be Base64 encoded and stored in the <code>body</code> + * of the message. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const LOGIN_OPERATION:uint = 8; + + /** + * This operation is used to log the user out of the current channel, and + * will invalidate the server session if the channel is HTTP based. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const LOGOUT_OPERATION:uint = 9; + + /** + * Endpoints can imply what features they support by reporting the + * latest version of messaging they are capable of during the handshake of + * the initial ping CommandMessage. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const MESSAGING_VERSION:String = "DSMessagingVersion"; + + /** + * This operation is used to indicate that the client's subscription with a + * remote destination has timed out. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const SUBSCRIPTION_INVALIDATE_OPERATION:uint = 10; + + /** + * Used by the MultiTopicConsumer to subscribe/unsubscribe for more + * than one topic in the same message. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const MULTI_SUBSCRIBE_OPERATION:uint = 11; + + /** + * This operation is used to indicate that a channel has disconnected. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const DISCONNECT_OPERATION:uint = 12; + + /** + * This operation is used to trigger a ChannelSet to connect. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const TRIGGER_CONNECT_OPERATION:uint = 13; + + /** + * This is the default operation for new CommandMessage instances. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const UNKNOWN_OPERATION:uint = 10000; + + /** + * The server message type for authentication commands. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const AUTHENTICATION_MESSAGE_REF_TYPE:String = "flex.messaging.messages.AuthenticationMessage"; + + /** + * Subscribe commands issued by a Consumer pass the Consumer's <code>selector</code> + * expression in this header. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const SELECTOR_HEADER:String = "DSSelector"; + + /** + * Durable JMS subscriptions are preserved when an unsubscribe message + * has this parameter set to true in its header. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const PRESERVE_DURABLE_HEADER:String = "DSPreserveDurable"; + + /** + * Header to indicate that the Channel needs the configuration from the + * server. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const NEEDS_CONFIG_HEADER:String = "DSNeedsConfig"; + + /** + * Header used in a MULTI_SUBSCRIBE message to specify an Array of subtopic/selector + * pairs to add to the existing set of subscriptions. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const ADD_SUBSCRIPTIONS:String = "DSAddSub"; + + /** + * Like the above, but specifies the subtopic/selector array of to remove + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const REMOVE_SUBSCRIPTIONS:String = "DSRemSub"; + + /** + * The separator string used for separating subtopic and selectors in the + * add and remove subscription headers. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const SUBTOPIC_SEPARATOR:String = "_;_"; + + /** + * Header to drive an idle wait time before the next client poll request. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const POLL_WAIT_HEADER:String = "DSPollWait"; + + /** + * Header to suppress poll response processing. If a client has a long-poll + * parked on the server and issues another poll, the response to this subsequent poll + * should be tagged with this header in which case the response is treated as a + * no-op and the next poll will not be scheduled. Without this, a subsequent poll + * will put the channel and endpoint into a busy polling cycle. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const NO_OP_POLL_HEADER:String = "DSNoOpPoll"; + + /** + * Header to specify which character set encoding was used while encoding + * login credentials. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const CREDENTIALS_CHARSET_HEADER:String = "DSCredentialsCharset"; + + /** + * Header to indicate the maximum number of messages a Consumer wants to + * receive per second. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public static const MAX_FREQUENCY_HEADER:String = "DSMaxFrequency"; + + /** + * Header that indicates the message is a heartbeat. + */ + public static const HEARTBEAT_HEADER:String = "DS<3"; + + //-------------------------------------------------------------------------- + // + // Private Static Constants for Serialization + // + //-------------------------------------------------------------------------- + + private static const OPERATION_FLAG:uint = 1; + + //-------------------------------------------------------------------------- + // + // Static Variables + // + //-------------------------------------------------------------------------- + + /** + * @private + * Map of operations to semi-descriptive operation text strings. + */ + private static var operationTexts:Object = null; + + + //-------------------------------------------------------------------------- + // + // Constructor + // + //-------------------------------------------------------------------------- + + /** + * Constructs an instance of a CommandMessage with an empty body and header + * and a default <code>operation</code> of <code>UNKNOWN_OPERATION</code>. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public function CommandMessage() + { + super(); + operation = UNKNOWN_OPERATION; + } + + //-------------------------------------------------------------------------- + // + // Variables + // + //-------------------------------------------------------------------------- + + /** + * Provides access to the operation/command for the CommandMessage. + * Operations indicate how this message should be processed by the remote + * destination. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public var operation:uint; + + //-------------------------------------------------------------------------- + // + // Overridden Methods + // + //-------------------------------------------------------------------------- + + /** + * @private + */ + /* + override public function getSmallMessage():IMessage + { + // We shouldn't use small messages for PING or LOGIN operations as the + // messaging version handshake would not yet be complete... for now just + // optimize POLL operations. + if (operation == POLL_OPERATION) + { + return new CommandMessageExt(this); + } + + return null; + } + */ + + /** + * @private + */ + /* + override protected function addDebugAttributes(attributes:Object):void + { + super.addDebugAttributes(attributes); + attributes["operation"] = getOperationAsString(operation); + } + */ + + /** + * Returns a string representation of the message. + * + * @return String representation of the message. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + /* + override public function toString():String + { + return getDebugString(); + } + */ + + //-------------------------------------------------------------------------- + // + // Methods + // + //-------------------------------------------------------------------------- + + /** + * Provides a description of the operation specified. + * This method is used in <code>toString()</code> operations on this + * message. + * + * @param op One of the CommandMessage operation constants. + * + * @return Short name for the operation. + * + * @example + * <code><pre> + * var msg:CommandMessage = CommandMessage(event.message); + * trace("Current operation -'"+ + * CommandMessage.getOperationAsString(msg.operation)+ "'."); + * </pre></code> + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + /* + public static function getOperationAsString(op:uint):String + { + if (operationTexts == null) + { + operationTexts = {}; + operationTexts[SUBSCRIBE_OPERATION] = "subscribe"; + operationTexts[UNSUBSCRIBE_OPERATION] = "unsubscribe"; + operationTexts[POLL_OPERATION] = "poll"; + operationTexts[CLIENT_SYNC_OPERATION] = "client sync"; + operationTexts[CLIENT_PING_OPERATION] = "client ping"; + operationTexts[CLUSTER_REQUEST_OPERATION] = "cluster request"; + operationTexts[LOGIN_OPERATION] = "login"; + operationTexts[LOGOUT_OPERATION] = "logout"; + operationTexts[SUBSCRIPTION_INVALIDATE_OPERATION] = "subscription invalidate"; + operationTexts[MULTI_SUBSCRIBE_OPERATION] = "multi-subscribe"; + operationTexts[DISCONNECT_OPERATION] = "disconnect"; + operationTexts[TRIGGER_CONNECT_OPERATION] = "trigger connect"; + operationTexts[UNKNOWN_OPERATION] = "unknown"; + } + var result:* = operationTexts[op]; + return result == undefined ? op.toString() : String(result); + } + */ + + /** + * @private + */ + /* + override public function readExternal(input:IDataInput):void + { + super.readExternal(input); + + var flagsArray:Array = readFlags(input); + for (var i:uint = 0; i < flagsArray.length; i++) + { + var flags:uint = flagsArray[i] as uint; + var reservedPosition:uint = 0; + + if (i == 0) + { + if ((flags & OPERATION_FLAG) != 0) + operation = input.readObject() as uint; + + reservedPosition = 1; + } + + // For forwards compatibility, read in any other flagged objects + // to preserve the integrity of the input stream... + if ((flags >> reservedPosition) != 0) + { + for (var j:uint = reservedPosition; j < 6; j++) + { + if (((flags >> j) & 1) != 0) + { + input.readObject(); + } + } + } + } + } + */ + + /** + * @private + */ + /* + override public function writeExternal(output:IDataOutput):void + { + super.writeExternal(output); + + var flags:uint = 0; + + if (operation != 0) + flags |= OPERATION_FLAG; + + output.writeByte(flags); + + if (operation != 0) + output.writeObject(operation); + } + */ + +} + +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/029d87f1/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/messages/IMessage.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/messages/IMessage.as b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/messages/IMessage.as new file mode 100644 index 0000000..0d7b5f3 --- /dev/null +++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/messages/IMessage.as @@ -0,0 +1,222 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +package org.apache.flex.net.remoting.messages +{ + +/** + * This interface defines the contract for message objects. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ +public interface IMessage +{ + //-------------------------------------------------------------------------- + // + // Properties + // + //-------------------------------------------------------------------------- + + //---------------------------------- + // body + //---------------------------------- + + /** + * The body of a message contains the specific data that needs to be + * delivered to the remote destination. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + function get body():Object; + + /** + * @private + */ + function set body(value:Object):void; + + //---------------------------------- + // clientId + //---------------------------------- + + /** + * The clientId indicates which client sent the message. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + function get clientId():String; + + /** + * @private + */ + function set clientId(value:String):void; + + //---------------------------------- + // destination + //---------------------------------- + + /** + * The message destination. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + function get destination():String; + + /** + * @private + */ + function set destination(value:String):void; + + //---------------------------------- + // headers + //---------------------------------- + + /** + * Provides access to the headers of the message. + * The headers of a message are an associative array where the key is the + * header name. + * This property provides access to specialized meta information for the + * specific message instance. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + function get headers():Object; + + /** + * @private + */ + function set headers(value:Object):void; + + //---------------------------------- + // messageId + //---------------------------------- + + /** + * The unique id for the message. + * The message id can be used to correlate a response to the original + * request message in request-response messaging scenarios. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + function get messageId():String; + + /** + * @private + */ + function set messageId(value:String):void; + + //---------------------------------- + // timestamp + //---------------------------------- + + /** + * Provides access to the time stamp for the message. + * A time stamp is the date and time that the message was sent. + * The time stamp is used for tracking the message through the system, + * ensuring quality of service levels and providing a mechanism for + * expiration. + * + * @see #timeToLive + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + function get timestamp():Number; + + /** + * @private + */ + function set timestamp(value:Number):void; + + //---------------------------------- + // timeToLive + //---------------------------------- + + /** + * The time to live value of a message indicates how long the message + * should be considered valid and deliverable. + * This value works in conjunction with the <code>timestamp</code> value. + * Time to live is the number of milliseconds that this message remains + * valid starting from the specified <code>timestamp</code> value. + * For example, if the <code>timestamp</code> value is 04/05/05 1:30:45 PST + * and the <code>timeToLive</code> value is 5000, then this message will + * expire at 04/05/05 1:30:50 PST. + * Once a message expires it will not be delivered to any other clients. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + function get timeToLive():Number; + + /** + * @private + */ + function set timeToLive(value:Number):void; + + //-------------------------------------------------------------------------- + // + // Methods + // + //-------------------------------------------------------------------------- + + /** + * This method will return a string representation of the message. + * + * @return String representation of the message. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + function toString():String; + +} + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/029d87f1/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/messages/RemotingMessage.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/messages/RemotingMessage.as b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/messages/RemotingMessage.as new file mode 100644 index 0000000..93d3a7d --- /dev/null +++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/messages/RemotingMessage.as @@ -0,0 +1,95 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +package org.apache.flex.net.remoting.messages +{ + +[RemoteClass(alias="flex.messaging.messages.RemotingMessage")] + +/** + * RemotingMessages are used to send RPC requests to a remote endpoint. + * These messages use the <code>operation</code> property to specify which + * method to call on the remote object. + * The <code>destination</code> property indicates what object/service should be + * used. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ +public class RemotingMessage extends AbstractMessage +{ + //-------------------------------------------------------------------------- + // + // Constructor + // + //-------------------------------------------------------------------------- + + /** + * Constructs an uninitialized RemotingMessage. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public function RemotingMessage() + { + super(); + operation = ""; + } + + //-------------------------------------------------------------------------- + // + // Variables + // + //-------------------------------------------------------------------------- + + /** + * Provides access to the name of the remote method/operation that + * should be called. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public var operation:String; + + /** + * This property is provided for backwards compatibility. The best + * practice, however, is to not expose the underlying source of a + * RemoteObject destination on the client and only one source to + * a destination. Some types of Remoting Services may even ignore + * this property for security reasons. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion BlazeDS 4 + * @productversion LCDS 3 + */ + public var source:String; +} + +}