Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Colin Alworth
    @niloc132
    (there is also a kotlin backend now too - ostensibly your java can be passed through j2cl to emit kotlin sources)
    @rdeangelis83 i'm sorry, i didnt get around to finishing something, but i'll put up a gist if you want to try what i did sketch out - i think the structure is right, but i didn't get the chance to validate it
    1 reply
    Rocco De Angelis
    @rdeangelis83
    @niloc132 THX 🙏🏻 I will give it tomorrow a try
    Miroslav Pokorny
    @mP1
    always wondered how much of blazor output is actually wasm, especially considering the question of GC.
    Or Goshen
    @Oberonc
    how can I debug server side in a project with client/shared/server ?
    how to attach a debugger ?
    I have a dead lock situation and I have hard time figuring the cause
    Colin Alworth
    @niloc132
    @Oberonc easiest answer is to run the server as normal, whatever you do in production, and attach the debugger to that - typically you just pass an extra jvm arg, but sometimes your IDE has specific integration
    if you need to debug gwt at the same time, sdm can run and let you serve its js from any web server that can serve normal js
    if you are already using gwt's DevMode process, just starting it with your IDE's debug settings will let you debug the server classes normally, but we generally advise against that
    Rocco De Angelis
    @rdeangelis83
    Maybe also helpful for others, I have repaired the Chrome devtools formatters for GWT (orginal code from Sergey Vasilinets):
    https://gist.github.com/rdeangelis83/cec831abb34903fe251ede29fdbe7b12
    The code contains some obfuscated property and method name which maybe needs to be adapted.
    That is something that could be improved in the future.
    Frank Hossfeld
    @FrankHossfeld
    nice work
    Rocco De Angelis
    @rdeangelis83
    @niloc132 "Function Name Property" patch works like a charm :)
    image.png
    Rocco De Angelis
    @rdeangelis83
    @niloc132 do you think that is really necessary to support the old function.displayName property?
    Colin Alworth
    @niloc132
    @rdeangelis83 haven't researched yet to see who else uses it, but probably should leave it in at least a little while for old chrome installs
    John Huss
    @johnthuss
    The possibility of using kotlin as a source language for j2cl is cool. This is one of the things holding me back for diving into kotlin and using it everywhere instead of java.
    Colin Alworth
    @niloc132
    @johnthuss last i checked (about 3 years ago) IJ did a pretty decent job of auto-converting java to kotlin
    it got confused about SAM interfaces for lambdas, but those are worth getting right imho, possibly by hand, rather than giving it a real interface
    Thomas Broyer
    @tbroyer
    Fwiw, the current support for Kotlin is as a target language, not a source language: https://github.com/google/j2cl/blob/10fdd30b2d55c58c71c0fabb4fdc8ebe2bd1f6a0/build_defs/internal_do_not_use/j2kt_library.bzl
    You can target JS with Kotlin/JS then: https://kotlinlang.org/docs/js-overview.html
    John Huss
    @johnthuss
    OK. What is the use case for using kotlin as a target? Is this to improve on IntelliJ's built-in conversion function from java to kotlin sources?
    Thomas Broyer
    @tbroyer
    I have no idea. Possibly a replacement for J2ObjC where Java is transformed to Kotlin and then compiled for iOS through Kotlin/Native?
    Colin Alworth
    @niloc132
    right, sorry i didn't clarify that above, this is a new backend, not a frontend (the only frontends are still jdt for java or javac for java)
    i have not wandered in to the tests or what docs are present to see what kinds of use cases they imply
    Rocco De Angelis
    @rdeangelis83
    @niloc132 what steps are now necessary to get the function name property patch available in the next release? Can I take over something or help you somehow??
    Jens Nehlmeier
    @jnehlmeier
    Is there any way to send an arraybuffer (provided through JS File API, wrapped into an Uint8Array) via GWT-RPC as byte array?
    Jefferson Quesado
    @JeffQuesado_twitter

    Is there any way to send an arraybuffer (provided through JS File API, wrapped into an Uint8Array) via GWT-RPC as byte array?

    I got a workaround for this

        public static byte[] convertBytes(ArrayBuffer buffer) {
            Uint8Array array = TypedArrays.createUint8Array(buffer);
            byte[] res = new byte[array.length()];
            for (int i = 0; i < res.length; i++) {
                res[i] = (byte) (array.get(i));
            }
            return res;
        }
    don't know if it is a great approach, but it has worked
    Rocco De Angelis
    @rdeangelis83
    If I remember it correctly transferring byte arrays via GWT-RPC is not so efficient. So that we have created a customFieldSerializer
    /**
     * Tranfer of byte arrays is very memory consuming
     * --> idea: create a string out of it and transfer it in one chuck.
     * But: creating strings with many bytes does not work either properly (in Chrome and FF at least)
     * So we create several smaller strings out of the byte array and transfer that one.
     *
     */
    
    @SuppressWarnings("UnusedDeclaration")
    public class AByteArray_CustomFieldSerializer extends CustomFieldSerializer<AByteArray> {
    
        private static final int CHUNK_SIZE = 50000;
    
        @Override
        public void deserializeInstance(SerializationStreamReader serializationStreamReader, AByteArray instance) throws SerializationException {
            deserialize(serializationStreamReader, instance);
        }
    
        @Override
        public void serializeInstance(SerializationStreamWriter serializationStreamWriter, AByteArray instance) throws SerializationException {
            serialize(serializationStreamWriter, instance);
        }
    
        @SuppressWarnings("unused")
        public static void deserialize(SerializationStreamReader reader, AByteArray instance) throws SerializationException {
            // nothing here
        }
    
        public static void serialize(SerializationStreamWriter writer, AByteArray instance) throws SerializationException {
            try {
                writeBytes(writer, instance.getBytes());
            } catch (UnsupportedEncodingException e) {
                ICommonLogger.Logger.error(e.getMessage(), e);
            }
        }
    
        private static void writeBytes(SerializationStreamWriter writer, byte[] bytes) throws UnsupportedEncodingException, SerializationException {
            int length = bytes.length;
            writer.writeInt(length);
    
            int pos = 0;
            while (pos < length) {
                String string = createString(bytes, pos, Math.min(CHUNK_SIZE, length-pos));
                writer.writeString(string);
                pos += CHUNK_SIZE;
            }
        }
    
        static String createString(byte[] bytes, int from, int len) throws UnsupportedEncodingException {
            byte subBytes[] = getSubArray(bytes, from, len);
            return ABase64.createString(ABase64.encode(subBytes));
        }
    
        private static byte[] getSubArray(byte[] source, int from, int len) {
            byte[] ret = new byte[len];
            // System.arraycopy() is slow in GWT
            //noinspection ManualArrayCopy
            for (int i = 0; i < ret.length; i++) {
                ret[i] = source[from+i];
            }
            return ret;
        }
    
        @Override
        public boolean hasCustomInstantiateInstance() {
            return true;
        }
    
        public static AByteArray instantiate(SerializationStreamReader reader) throws SerializationException {
            try {
                return AByteArray.create(readByteArray(reader));
            } catch (UnsupportedEncodingException e) {
                ICommonLogger.Logger.error(e.getMessage(), e);
                return null;
            }
        }
    
        private static byte[] readByteArray(SerializationStreamReader reader) throws SerializationException, UnsupportedEncodingException {
            int size = reader.readInt();
            byte[] bytes = new byte[size];
            int pos = 0;
            while (pos < size) {
                String string = reader.readString();
                byte[] subBytes = ABase64.decode(ABase64.getBytes(string));
                append(bytes, subBytes, pos);
                pos += subBytes.length;
            }
    
            return bytes;
        }
    
        private static void append(byte[] target, byte[] source, int pos) {
            for (int i = 0; i < source.length; i++) {
                target[pos + i] = source[i];
            }
        }
    
        @Override
        public AByteArray instantiateInstance(SerializationStreamReader streamReader) throws SerializationException {
            return instantiate(streamReader);
        }
    }
    Maybe helpful ...
    Colin Alworth
    @niloc132
    @jnehlmeier i reimplemented gwt-rpc to support typedarrays and binary payloads too - the initial impl didn't bother with sending binary over xhr, only websockets, but that was just my specific requirement
    i would definitely advise sending base64 over a plain byte[] if you're worried at all about payload size (byte[] will be on average something like 3-4x to send it though it will compress well at least, whereas base64 is always about 1.3x bigger than the original data)
    @rdeangelis83 i wonder if you recall why creating strings that big didn't work? i'm guessing it was because you were implementing base64 yourself with String.fromCharCode.apply and blowing the stack? or something in gwt-rpc itself that was breaking with gigantic strings?
    Colin Alworth
    @niloc132
    @JeffQuesado_twitter welcome to gitter, did you solve your java9 module issue?
    32 replies
    Rocco De Angelis
    @rdeangelis83

    @niloc132 the code is from 2013. I don't remember exactly anymore what was the reason. Yeah we have our own base64 implementation. But If I remember correctly the problem was in ABase64.createString(byte[] bytes) which only uses new String(bytes, IStandardEncoding.STANDARD_ENCODING)

        public static String createString(byte[] bytes) throws UnsupportedEncodingException {
            return new String(bytes, IStandardEncoding.STANDARD_ENCODING);
        }

    I also remember that System.arraycopy() was always slow in GWT. But this seems to be fixed in the trunk now.

    Colin Alworth
    @niloc132
    the String ctor did have the problem i described, but i think it is fixed by building up content in batches
    Rocco De Angelis
    @rdeangelis83
    Ahhh!
    Very similar the code :)
    Colin Alworth
    @niloc132
    yeah its a familiar pattern, other js certainly has that code too... i'm sure i've written it before too
    Jens Nehlmeier
    @jnehlmeier

    Is there any way to send an arraybuffer (provided through JS File API, wrapped into an Uint8Array) via GWT-RPC as byte array?

    I got a workaround for this

    @JeffQuesado_twitter Thanks, yes that would work although I am trying to avoid copying given that the file might be large.

    Colin Alworth
    @niloc132
    it will be copied anyway, to be put on the wire, so that might not be constructive?
    this is gwt 2.8.2 code, hence mixing and matching Any[]/JsArray<Any>, and exposes an api to JS, so i have to deal with arbitrary functions that they can pass in, and memoize large amounts of ticking data from the server
    Jens Nehlmeier
    @jnehlmeier
    yeah sure, but copying just to get an array that GWT knows about seems overkill. I mean Uint8Array is already what I want, it is just that GWT-RPC does not know it can be accessed and treated like a byte[]. But I think I decided against GWT-RPC and use plain XMLHttpRequest2 + FormData. That would also give access to progress events during upload.
    Colin Alworth
    @niloc132
    and let you send binary directly