brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjcorb...@apache.org
Subject [2/4] brooklyn-server git commit: BROOKLYN-304: avoid json err serializing ClassLoader
Date Wed, 16 Nov 2016 12:30:12 GMT
BROOKLYN-304: avoid json err serializing ClassLoader

Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/04711a5d
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/04711a5d
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/04711a5d

Branch: refs/heads/master
Commit: 04711a5d66906e496c0894769219fc35c408ed34
Parents: db16acb
Author: Aled Sage <aled.sage@gmail.com>
Authored: Thu Nov 10 14:14:32 2016 +0000
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Thu Nov 10 14:15:12 2016 +0000

----------------------------------------------------------------------
 .../util/core/json/BidiSerialization.java        | 19 +++++++++++++++++++
 .../core/json/BrooklynObjectsJsonMapper.java     |  1 +
 .../base/ShellEnvironmentSerializerTest.java     |  4 ++--
 3 files changed, 22 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/04711a5d/core/src/main/java/org/apache/brooklyn/util/core/json/BidiSerialization.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/json/BidiSerialization.java
b/core/src/main/java/org/apache/brooklyn/util/core/json/BidiSerialization.java
index 74a5cf4..8601904 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/json/BidiSerialization.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/json/BidiSerialization.java
@@ -273,4 +273,23 @@ public class BidiSerialization {
             return mgmt.getExecutionManager().getTask((String) values.get("id"));
         }
     }
+    
+    /**
+     * Serializes a classloader to just tell us about its type; cannot deserialize it again
though!
+     * 
+     * See https://issues.apache.org/jira/browse/BROOKLYN-304 - this new behaviour is better
than the
+     * {@link OutOfMemoryError} we used to get.
+     */
+    public static class ClassLoaderSerialization extends AbstractWithManagementContextSerialization<ClassLoader>
{
+        public ClassLoaderSerialization(ManagementContext mgmt) { 
+            super(ClassLoader.class, mgmt);
+        }
+        @Override
+        public void customWriteBody(ClassLoader value, JsonGenerator jgen, SerializerProvider
provider) throws IOException {
+        }
+        @Override
+        protected ClassLoader customReadBody(String type, Map<Object, Object> values,
JsonParser jp, DeserializationContext ctxt) throws IOException {
+            return null;
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/04711a5d/core/src/main/java/org/apache/brooklyn/util/core/json/BrooklynObjectsJsonMapper.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/json/BrooklynObjectsJsonMapper.java
b/core/src/main/java/org/apache/brooklyn/util/core/json/BrooklynObjectsJsonMapper.java
index f6c5bee..37601a5 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/json/BrooklynObjectsJsonMapper.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/json/BrooklynObjectsJsonMapper.java
@@ -40,6 +40,7 @@ public class BrooklynObjectsJsonMapper {
         new BidiSerialization.EnricherSerialization(mgmt).install(mapperModule);
         new BidiSerialization.FeedSerialization(mgmt).install(mapperModule);
         new BidiSerialization.TaskSerialization(mgmt).install(mapperModule);
+        new BidiSerialization.ClassLoaderSerialization(mgmt).install(mapperModule);
 
         mapper.registerModule(new GuavaModule()).registerModule(mapperModule);
         return mapper;

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/04711a5d/software/base/src/test/java/org/apache/brooklyn/entity/software/base/ShellEnvironmentSerializerTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/ShellEnvironmentSerializerTest.java
b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/ShellEnvironmentSerializerTest.java
index 5328ee5..4820b37 100644
--- a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/ShellEnvironmentSerializerTest.java
+++ b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/ShellEnvironmentSerializerTest.java
@@ -61,9 +61,9 @@ public class ShellEnvironmentSerializerTest extends BrooklynAppUnitTestSupport
{
         assertSerialize(ImmutableList.of(app), "[" + appExpected + "]");
         assertSerialize(ImmutableMap.of("app", app), "{\"app\":" + appExpected + "}");
         assertSerialize(mgmt, "{\"type\":\"org.apache.brooklyn.api.mgmt.ManagementContext\"}");
-        // TODO Fails with java.lang.OutOfMemoryError: GC overhead limit exceeded
         // https://issues.apache.org/jira/browse/BROOKLYN-304
-        // assertSerialize(getClass().getClassLoader(), "???");
+        assertSerialize(getClass().getClassLoader(), "{\"type\":\""+getClass().getClassLoader().getClass().getCanonicalName()+"\"}");
+        assertSerialize(getClass(), "class "+getClass().getName());
     }
 
     private void assertSerialize(Object actual, String expected) {


Mime
View raw message