Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into jakarta-wip
Browse files Browse the repository at this point in the history
  • Loading branch information
petergeneric committed Jul 12, 2024
2 parents 14b09a1 + 2783625 commit a04d7cf
Show file tree
Hide file tree
Showing 31 changed files with 306 additions and 100 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven-test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: JDK17 Build and Test
name: JDK21 Build and Test

on: [ push, pull_request ]

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ compile:

dependencies:
$(MVN) install -DskipTests
$(MVN) dependency:tree
mvn dependency:tree

package:
$(MVN) clean package
Expand Down
2 changes: 1 addition & 1 deletion guice/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<parent>
<groupId>com.peterphi.std.guice</groupId>
<artifactId>stdlib-guice-parent</artifactId>
<version>14.7.8-SNAPSHOT</version>
<version>14.7.13-SNAPSHOT</version>
</parent>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.peterphi.std.guice.common;

import com.codahale.metrics.health.HealthCheckRegistry;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.peterphi.std.guice.common.serviceprops.composite.GuiceConfig;
Expand Down Expand Up @@ -51,7 +52,8 @@ protected <T> JAXBResourceProvider<T> bindConfigFile(final Class<T> type, final
*/
protected <T> JAXBResourceProvider<T> bindConfigFile(final Class<T> type, final String propertyName, Consumer<T> onLoad)
{
final JAXBResourceProvider<T> provider = new JAXBResourceProvider<T>(super.getProvider(JAXBResourceFactory.class),
final JAXBResourceProvider<T> provider = new JAXBResourceProvider<T>(getProvider(JAXBResourceFactory.class),
getProvider(HealthCheckRegistry.class),
propertyName,
type,
onLoad);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,17 @@ public void setSleepTime(final Timeout sleepTime)
/**
* Enable Verbose Tracing for the next run of this daemon
*/
public void makeNextRunVerbose()
public final void makeNextRunVerbose()
{
this.nextRunVerbose = true;
}


protected boolean shouldVerboseTrace()
{
return this.nextRunVerbose;
}

@Override
public void run()
{
Expand All @@ -160,10 +166,10 @@ public void run()
try
{
// Assign a trace id for operations performed by this run of this thread
Tracing.start(traceId, nextRunVerbose);
Tracing.start(traceId, shouldVerboseTrace());

if (nextRunVerbose)
nextRunVerbose = false;
nextRunVerbose = false; // Reset the temporary-verbose flag

userCodeRunning = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public JAXBResourceFactory(GuiceConfig config, JAXBSerialiserFactory factory)
* @param name
* the name of the property
* @param <T>
* @throws RuntimeException if a value cannot be retrieved
*
* @return
*/
Expand All @@ -42,7 +43,7 @@ public synchronized <T> T get(Class<T> clazz, final String name)

if (cached == null)
{
cached = new JAXBNamedResourceFactory<T>(this.config, this.factory, name, clazz);
cached = makeFactory(clazz, name);
cachedReferences.put(name, cached);
}

Expand All @@ -69,7 +70,7 @@ public synchronized <T> T get(Class<T> clazz, final String name, T defaultValue)

if (cached == null)
{
cached = new JAXBNamedResourceFactory<T>(this.config, this.factory, name, clazz);
cached = makeFactory(clazz, name);
cachedReferences.put(name, cached);
}

Expand All @@ -83,11 +84,16 @@ public synchronized <T> T get(Class<T> clazz, final String name, T defaultValue)
* @param clazz
* @param name
* @param <T>
*
* @return
*/
public <T> T getOnce(final Class<T> clazz, final String name)
{
return new JAXBNamedResourceFactory<T>(this.config, this.factory, name, clazz).get();
return makeFactory(clazz, name).get();
}


private <T> JAXBNamedResourceFactory<T> makeFactory(final Class<T> clazz, final String name)
{
return new JAXBNamedResourceFactory<T>(this.config, this.factory, name, clazz);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.peterphi.std.guice.common.serviceprops.jaxbref;

import com.codahale.metrics.health.HealthCheck;
import com.codahale.metrics.health.HealthCheckRegistry;
import com.google.inject.Provider;
import com.peterphi.std.threading.Timeout;

Expand All @@ -8,6 +10,7 @@
public class JAXBResourceProvider<T> implements Provider<T>
{
private final Provider<JAXBResourceFactory> resourceFactoryProvider;
private final Provider<HealthCheckRegistry> healthCheckRegistryProvider;
private final String propertyName;
private final Class<T> clazz;
private final Consumer<T> onLoadMethod;
Expand All @@ -17,13 +20,17 @@ public class JAXBResourceProvider<T> implements Provider<T>
private volatile T value;
private volatile long cacheExpires = Integer.MIN_VALUE;

private boolean hasRegisteredHealthCheck = false;


public JAXBResourceProvider(final Provider<JAXBResourceFactory> resourceFactoryProvider,
final Provider<HealthCheckRegistry> healthCheckRegistryProvider,
final String propertyName,
final Class<T> clazz,
final Consumer<T> onLoadMethod)
{
this.resourceFactoryProvider = resourceFactoryProvider;
this.healthCheckRegistryProvider = healthCheckRegistryProvider;
this.propertyName = propertyName;
this.clazz = clazz;
this.onLoadMethod = onLoadMethod;
Expand Down Expand Up @@ -55,6 +62,14 @@ public synchronized T get()
return obj;
}

final T obj = load(now);

return obj;
}


private synchronized T load(final long now)
{
// Cannot use cache, must recompute
final T obj = deserialise();

Expand All @@ -64,13 +79,43 @@ public synchronized T get()
this.value = obj;
this.cacheExpires = now + cacheValidity.getMilliseconds();
}

return obj;
}

private T deserialise()

private synchronized T deserialise()
{
final T obj = resourceFactoryProvider.get().getOnce(clazz, propertyName);
final JAXBResourceFactory provider = resourceFactoryProvider.get();

if (!hasRegisteredHealthCheck)
{
// Make sure we only register (or try to register) once
hasRegisteredHealthCheck = true;

// N.B. manually constructing a name of the form used by AbstractHealthCheck (which is not available in this module) so errors appear with the appropriate severity
healthCheckRegistryProvider.get().register("COMPROMISED:ConfigFile." + propertyName, new HealthCheck()
{
@Override
protected Result check() throws Exception
{
try
{
// Try to reload the live value on disk
// We call this because we want the actual value, not the last successfully loaded value
// N.B. this will also populate the cache on successful load
load(System.currentTimeMillis());

return Result.healthy();
}
catch (Throwable t)
{
return Result.unhealthy(t);
}
}
});
}

final T obj = provider.getOnce(clazz, propertyName);

if (onLoadMethod != null)
onLoadMethod.accept(obj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlType;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
Expand Down Expand Up @@ -91,28 +92,32 @@ public WQConstraintLine not()
}
}

@Override
public WQConstraint clone()
{
final WQConstraint that = new WQConstraint();

that.field = this.field;
that.function = this.function;
that.value = this.value;
that.value2 = this.value2;

if (this.valuelist != null)
that.valuelist = new ArrayList<>(this.valuelist);

return that;
}


@Override
public String toString()
{
if (function.hasBinaryParam())
return "QConstraint{" +
"'" +
field +
'\'' +
" " +
function +
" value='" +
value +
'\'' +
" value2='" +
value2 +
'\'' +
"}";
else if (function.hasParam())
return "QConstraint{" + "'" + field + '\'' + " " + function + " '" + value + "'}";
else
return "QConstraint{" + "'" + field + '\'' + " " + function + '}';
StringBuilder sb = new StringBuilder(64);

sb.append("QConstraint{");
toQueryFragment(sb);
sb.append('}');
return sb.toString();
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ public WQConstraintLine not()
g.add(this);
return g;
}

public abstract WQConstraintLine clone();
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ public String toString()
}


@Override
public WQConstraints clone()
{
final WQConstraints that = new WQConstraints();

that.offset = offset;
that.limit = limit;
that.computeSize = computeSize;
that.subclass = subclass;
that.constraints = new ArrayList<>(constraints.size());

for (WQConstraintLine constraint : this.constraints)
that.constraints.add(constraint.clone());

return that;
}

public String toQueryFragment()
{
StringBuilder sb = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ public WQGroup(final WQGroupType operator, final List<WQConstraintLine> constrai
this.constraints.addAll(constraints);
}

@Override
public WQGroup clone() {
WQGroup that = new WQGroup();

that.operator = operator;

for (WQConstraintLine constraint : constraints)
that.constraints.add(constraint.clone());

return that;
}

@Override
public String toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ public String toLegacyForm()
}


@Override
public WQOrder clone()
{
return new WQOrder(field, direction);
}

@Override
public String toString()
{
Expand Down
Loading

0 comments on commit a04d7cf

Please sign in to comment.