You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ca...@apache.org on 2018/10/15 11:11:07 UTC
[royale-asjs] branch develop updated: Add CompressedRemoteObject
version for mx:RemoteObject
This is an automated email from the ASF dual-hosted git repository.
carlosrovira pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
The following commit(s) were added to refs/heads/develop by this push:
new 66ef8c6 Add CompressedRemoteObject version for mx:RemoteObject
66ef8c6 is described below
commit 66ef8c62a4944af8c0b1ea0d3dff9f524d9f551e
Author: Carlos Rovira <ca...@apache.org>
AuthorDate: Mon Oct 15 13:10:59 2018 +0200
Add CompressedRemoteObject version for mx:RemoteObject
---
.../src/main/resources/mx-royale-manifest.xml | 1 +
.../mx/rpc/remoting/CompressedRemoteObject.as | 175 +++++++++++++++++++++
2 files changed, 176 insertions(+)
diff --git a/frameworks/projects/MXRoyale/src/main/resources/mx-royale-manifest.xml b/frameworks/projects/MXRoyale/src/main/resources/mx-royale-manifest.xml
index 36b8f1f..0b0b659 100644
--- a/frameworks/projects/MXRoyale/src/main/resources/mx-royale-manifest.xml
+++ b/frameworks/projects/MXRoyale/src/main/resources/mx-royale-manifest.xml
@@ -56,6 +56,7 @@
<component id="CanvasLayout" class="mx.containers.beads.CanvasLayout" />
<component id="TitleWindow" class="mx.containers.TitleWindow"/>
<component id="ColorPicker" class="mx.controls.ColorPicker"/>
+ <component id="CompressedRemoteObject" class="mx.rpc.remoting.CompressedRemoteObject" />
<component id="RemoteObject" class="mx.rpc.remoting.mxml.RemoteObject" />
<component id="RemoteObjectOperation" class="mx.rpc.remoting.mxml.Operation"/>
<component id="HTTPService" class="mx.rpc.http.mxml.HTTPService" />
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/rpc/remoting/CompressedRemoteObject.as b/frameworks/projects/MXRoyale/src/main/royale/mx/rpc/remoting/CompressedRemoteObject.as
new file mode 100644
index 0000000..951b1e8
--- /dev/null
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/rpc/remoting/CompressedRemoteObject.as
@@ -0,0 +1,175 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 mx.rpc.remoting
+{
+ COMPILE::SWF
+ {
+ import flash.utils.ByteArray;
+ }
+
+ import mx.collections.IList;
+ import mx.rpc.AbstractOperation;
+
+ import org.apache.royale.net.remoting.amf.AMFBinaryData;
+ import org.apache.royale.reflection.getQualifiedClassName;
+
+ /**
+ * A RemoteObject that performs automatic serialization/deserialization of results.
+ *
+ * It deserializes the compressed ByteArray in order to optimize the transfer time.
+ * TODO improve to serialize the sending.
+ */
+ public class CompressedRemoteObject extends RemoteObject
+ {
+ [ArrayElementType("String")]
+ /**
+ * @royalesuppresspublicvarwarning
+ */
+ public static var includePackages:Array = ["org.apache.royale."];
+
+ [ArrayElementType("String")]
+ /**
+ * @royalesuppresspublicvarwarning
+ */
+ public static var includeClasses:Array;
+
+ [ArrayElementType("String")]
+ /**
+ * @royalesuppresspublicvarwarning
+ */
+ public static var excludeClasses:Array;
+
+ [ArrayElementType("String")]
+ /**
+ * @royalesuppresspublicvarwarning
+ */
+ public var includePackages:Array;
+
+ [ArrayElementType("String")]
+ /**
+ * @royalesuppresspublicvarwarning
+ */
+ public var includeClasses:Array;
+
+ [ArrayElementType("String")]
+ /**
+ * @royalesuppresspublicvarwarning
+ */
+ public var excludeClasses:Array;
+
+ /**
+ * Uses the pako library for the zlib compression algorithm
+ *
+ * <inject_html>
+ * <script src="https://cdnjs.cloudflare.com/ajax/libs/pako/1.0.6/pako.min.js"></script>
+ * </inject_html>
+ */
+ public function CompressedRemoteObject(destination:String = null)
+ {
+ super(destination);
+ }
+
+ override public function initialize():void
+ {
+ super.initialize();
+ convertParametersHandler = serializeParameters;
+ convertResultHandler = deserializeResult;
+ }
+
+ private function serializeParameters(parameters:Array):Array
+ {
+ var includePackages:Array = this.includePackages ? this.includePackages : CompressedRemoteObject.includePackages;
+ var includeClasses:Array = this.includeClasses ? this.includeClasses : CompressedRemoteObject.includeClasses;
+ var excludeClasses:Array = this.excludeClasses ? this.excludeClasses : CompressedRemoteObject.excludeClasses;
+ for (var i:int = 0; i < parameters.length; i++) {
+ var parameter:Object = parameters[i];
+ if (parameter is Array && (parameter as Array).length > 0) {
+ parameter = parameter[0];
+ } else if (parameter is IList && IList(parameter).length > 0) {
+ parameter = parameter[0];
+ }
+ var parameterClassName:String = getQualifiedClassName(parameter).replace("::", ".");
+ var included:Boolean;
+ if (includePackages && includePackages.length > 0) {
+ //var lastDotIndex:int = parameterClassName.lastIndexOf(".");
+ //var packageName:String = lastDotIndex != -1 ? parameterClassName.slice(0, lastDotIndex) : "";
+ for each (var includePackage:String in includePackages) {
+ if (parameterClassName.indexOf(includePackage) >= 0) {
+ included = true;
+ break;
+ }
+ }
+ }
+ if (!included && includeClasses && includeClasses.length > 0) {
+ included = includeClasses.indexOf(parameterClassName) != -1;
+ }
+ if (included && excludeClasses && excludeClasses.length > 0) {
+ included = excludeClasses.indexOf(parameterClassName) == -1;
+ }
+ if (included) {
+ COMPILE::SWF{
+ var byteArray:ByteArray = new ByteArray();
+ byteArray.writeObject(parameters[i]);
+ byteArray.compress();
+ parameters[i] = byteArray;
+ }
+ COMPILE::JS
+ {
+ // var bytearray:AMFBinaryData = new AMFBinaryData();
+ // bytearray.writeObject(parameter[i]);
+ // window["pako"].deflate(bytearray)
+ // parameter[i] = bytearray;
+ }
+ }
+ }
+ return parameters;
+ }
+
+ private function deserializeResult(result:*, operation:AbstractOperation):* // NO PMD
+ {
+ COMPILE::SWF{
+ if (result is ByteArray) {
+ var byteArray:ByteArray = result as ByteArray;
+ byteArray.uncompress();
+ return byteArray.readObject();
+ } else {
+ return result;
+ }
+ }
+
+ COMPILE::JS
+ {
+ if (result is Array)
+ {
+ // --- Transform the number array into a bytearray
+ var bytearray:Uint8Array = new Uint8Array(result);
+ // --- uncompress the bytearray to get the real object (tree) and create the AMFBinaryData with it
+ var data:AMFBinaryData = new AMFBinaryData(window["pako"].inflate(bytearray));
+ // --- store the inflated data object in result
+ result = data.readObject();
+ return result;
+ }
+ else
+ {
+ return result;
+ }
+ }
+ }
+ }
+}
\ No newline at end of file