-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cache JsonProvider result in JsonBindingBuilder #363
base: master
Are you sure you want to change the base?
Changes from all commits
2f91e4b
e85434e
e13dd73
8776082
8e25cf5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash -x | ||
# | ||
# Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. | ||
# | ||
# This program and the accompanying materials are made available under the | ||
# terms of the Eclipse Public License v. 2.0 which is available at | ||
# http://www.eclipse.org/legal/epl-2.0, | ||
# or the Eclipse Distribution License v. 1.0 which is available at | ||
# http://www.eclipse.org/org/documents/edl-v10.php. | ||
# | ||
# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
# | ||
|
||
die(){ echo "${1}" ; exit 1 ;} | ||
|
||
readonly RESULT_FILE="copyright-check.txt" | ||
|
||
mvn -q org.glassfish.copyright:glassfish-copyright-maven-plugin:copyright \ | ||
> ${RESULT_FILE} || (cat ${RESULT_FILE}; die "Error running the Maven command") | ||
|
||
grep -i "copyright" ${RESULT_FILE} \ | ||
&& die "COPYRIGHT ERROR" || echo "COPYRIGHT OK" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ | |
|
||
package org.eclipse.yasson.internal; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import javax.json.bind.Jsonb; | ||
|
@@ -25,17 +27,24 @@ | |
public class JsonBindingBuilder implements JsonbBuilder { | ||
private JsonbConfig config = new JsonbConfig(); | ||
private JsonProvider provider = null; | ||
private JsonBinding bindingCache = null; | ||
private Map<String, Object> configCache = null; | ||
private JsonProvider providerCache = null; | ||
|
||
@Override | ||
public JsonbBuilder withConfig(JsonbConfig config) { | ||
this.config = config; | ||
return this; | ||
synchronized (this) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. synchronization shouldn't be necessary here or in |
||
this.config = config; | ||
return this; | ||
} | ||
} | ||
|
||
@Override | ||
public JsonbBuilder withProvider(JsonProvider jsonpProvider) { | ||
this.provider = jsonpProvider; | ||
return this; | ||
synchronized (this) { | ||
this.provider = jsonpProvider; | ||
return this; | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -58,6 +67,33 @@ public Optional<JsonProvider> getProvider() { | |
|
||
@Override | ||
public Jsonb build() { | ||
return new JsonBinding(this); | ||
synchronized (this) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of synchronizing here, we could take advantage of some concurrent map operations. For example: JsonbKey currentKey = new JsonbKey(config, provider);
return jsonbCache.computeIfAbsent(currentKey, key -> new JsonBinding(this)); |
||
if (bindingCache != null | ||
&& configEqualsCachedConfig() | ||
&& providerEqualsCachedProvider()) { | ||
return bindingCache; | ||
} | ||
JsonBinding jsonBinding = new JsonBinding(this); | ||
cacheCurrentConfiguration(jsonBinding); | ||
return jsonBinding; | ||
} | ||
} | ||
|
||
private boolean configEqualsCachedConfig() { | ||
return (configCache != null && config != null && configCache.equals(config.getAsMap())) | ||
|| (config == null && configCache == null); | ||
} | ||
|
||
private boolean providerEqualsCachedProvider() { | ||
return (providerCache != null && providerCache.equals(provider)) | ||
|| (provider == null && providerCache == null); | ||
} | ||
|
||
private void cacheCurrentConfiguration(JsonBinding jsonBinding) { | ||
bindingCache = jsonBinding; | ||
if (config != null) { | ||
configCache = new HashMap<>(config.getAsMap()); | ||
} | ||
providerCache = provider; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
################################################################################ | ||
# | ||
# Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. | ||
# | ||
# This program and the accompanying materials are made available under the | ||
# terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 | ||
# which accompanies this distribution. | ||
# The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
# and the Eclipse Distribution License is available at | ||
# terms of the Eclipse Public License v. 2.0 which is available at | ||
# http://www.eclipse.org/legal/epl-2.0, | ||
# or the Eclipse Distribution License v. 1.0 which is available at | ||
# http://www.eclipse.org/org/documents/edl-v10.php. | ||
# | ||
# Contributors: | ||
# Tomas Langer | ||
################################################################################ | ||
# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
# | ||
|
||
# This adds command line options to native image tool | ||
Args=-H:IncludeResourceBundles=yasson-messages |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, | ||
* or the Eclipse Distribution License v. 1.0 which is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
*/ | ||
|
||
package org.eclipse.yasson.adapters.model; | ||
|
||
public class Chain { | ||
|
||
private String name; | ||
private Chain linksTo; | ||
private Foo has; | ||
|
||
public Chain(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Chain() { | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
public Chain getLinksTo() { | ||
return linksTo; | ||
} | ||
public void setLinksTo(Chain linksTo) { | ||
this.linksTo = linksTo; | ||
} | ||
public Foo getHas() { | ||
return has; | ||
} | ||
public void setHas(Foo has) { | ||
this.has = has; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few things on the binding cache here:
static
so that it is global (i.e. across multiple different instances ofJsonBindingBuilder
).JsonbBinding
to be cached. Consider creating a composite key class (that combines provider and config) so we can store cached instances in aMap<JsonbKey,Jsonbinding>
. This would also allow us to eagerly initialize the map and make itfinal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the
JsonbKey
class could look like this:In order for this to work, we will need to properly compare equality for
Jsonb
instances which can be done by doingconfigA.getAsMap().equals(configB.getAsMap())