You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by GitBox <gi...@apache.org> on 2021/09/29 17:43:06 UTC

[GitHub] [avro] RyanSkraba opened a new pull request #1347: AVRO-2863: Create an avro-android artifact

RyanSkraba opened a new pull request #1347:
URL: https://github.com/apache/avro/pull/1347


   Following the discussion on AVRO-2863, this PR shows how to create an `avro-android` artifact for experimental support of android for the next major release.
   
   * the `org.apache.avro.reflect package` is not supported.
   * `org.apache.avro.reflect.MapEntry` was deprecated in the `reflect` package and moved to `org.apache.avro.util`.  (Note, the important thing about this class is that it is reliably available and the internal data members are "key" and "value").
   *  All uses of `ClassValue`, which cache information extracted from a `java.lang.Class` were wrapped in a `org.apache.avro.util.ClassValueCache` so that the android implementation could override its behaviour.
   
   I haven't finished the `ThreadLocal.withInitial` wrapping -- I wanted to validate this approach first.
   
   This implementation currently works with the [android test project](https://github.com/david-gang/avro-android-compatibility) provided by @david-gang, which doesn't call any of the core code that touches `ThreadLocal.withInitial`.
   
   For now, Android compatibility needs to be checked manually with a sample application, either on an emulator or a real device.
   
   ### Jira
   
   - [X] My PR addresses the following [Avro Jira](https://issues.apache.org/jira/browse/AVRO/) issues and references them in the PR title. For example, "AVRO-1234: My Avro PR"
     - https://issues.apache.org/jira/browse/AVRO-2863
     - In case you are adding a dependency, check if the license complies with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   
   ### Tests
   
   - [X] My PR adds the following unit tests __OR__ does not need testing for this extremely good reason: Tests around the wrapper class `ClassValueCache`.
   
   ### Commits
   
   - [X] My commits all reference Jira issues in their subject lines. In addition, my commits follow the guidelines from "[How to write a good git commit message](https://chris.beams.io/posts/git-commit/)":
     1. Subject is separated from body by a blank line
     1. Subject is limited to 50 characters (not including Jira issue reference)
     1. Subject does not end with a period
     1. Subject uses the imperative mood ("add", not "adding")
     1. Body wraps at 72 characters
     1. Body explains "what" and "why", not "how"
   
   ### Documentation
   
   - [X] In case of new functionality, my PR adds documentation that describes how to use it.
     - All the public functions and the classes in the PR contain Javadoc that explain what it does
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [avro] RyanSkraba commented on pull request #1347: AVRO-2863: Create an avro-android artifact

Posted by GitBox <gi...@apache.org>.
RyanSkraba commented on pull request #1347:
URL: https://github.com/apache/avro/pull/1347#issuecomment-931444392


   I've created a second project to test this manually. https://github.com/RyanSkraba/avro-android-example/blob/main/app/src/androidTest/java/com/skraba/byexample/avroandroid/AvroTest.java
   
   I've checked binary, json and message serialization and deserialization on an emulator for API 24 and API 30.  I haven't checked Avro files or performance.
   
   The artifact name is currently `avro-android`.  Is there a better convention for this?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [avro] martin-g commented on pull request #1347: AVRO-2863: Create an avro-android artifact

Posted by GitBox <gi...@apache.org>.
martin-g commented on pull request #1347:
URL: https://github.com/apache/avro/pull/1347#issuecomment-931948231


   > The artifact name is currently `avro-android`. Is there a better convention for this?
   
   Guava uses `x.y.z-jre` and `x.y.z-android` (https://search.maven.org/artifact/com.google.guava/guava) but IMO `avro-android` looks better and it is consistent with the rest of the modules (https://search.maven.org/search?q=g:org.apache.avro). Only `trevni-avro` is inconsistent but I guess it is too late for it!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [avro] RyanSkraba merged pull request #1347: AVRO-2863: Create an avro-android artifact

Posted by GitBox <gi...@apache.org>.
RyanSkraba merged pull request #1347:
URL: https://github.com/apache/avro/pull/1347


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [avro] martin-g commented on a change in pull request #1347: AVRO-2863: Create an avro-android artifact

Posted by GitBox <gi...@apache.org>.
martin-g commented on a change in pull request #1347:
URL: https://github.com/apache/avro/pull/1347#discussion_r719134194



##########
File path: lang/java/avro/src/main/java/org/apache/avro/util/internal/ClassValueCache.java
##########
@@ -0,0 +1,47 @@
+/*
+ * 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
+ *
+ *     https://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.avro.util.internal;
+
+import java.util.function.Function;
+
+/**
+ * Wraps a {@link ClassValue} cache so it can be overridden in an android
+ * environment, where it isn't available.
+ *
+ * @param <R> Return type of the ClassValue
+ */
+public class ClassValueCache<R> implements Function<Class<?>, R> {
+
+  private final Function<Class<?>, R> ifAbsent;
+
+  public ClassValueCache(Function<Class<?>, R> ifAbsent) {
+    this.ifAbsent = ifAbsent;
+  }
+
+  private final ClassValue<R> cache = new ClassValue<R>() {

Review comment:
       nit: move the field before the constructor ?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org