Skip to content

Commit

Permalink
Resumable VT metrics
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Kec <[email protected]>
  • Loading branch information
danielkec committed Jan 25, 2025
1 parent 58ea364 commit 5077028
Show file tree
Hide file tree
Showing 13 changed files with 139 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,21 @@
* limitations under the License.
*/

package io.helidon.webserver.crac.spi;
package io.helidon.common.crac;

import java.lang.management.ManagementFactory;
import java.util.ServiceLoader;

import io.helidon.common.LazyValue;

/**
* Helidon abstraction over CRaC API, no-op when integration module is not on classpath.
*/
public interface Crac {

/**
* Lazy singleton instance, either abstraction over actual CRaC API or no-op if integration module
* is missing on classpath.
*/
LazyValue<Crac> INSTANCE = LazyValue.create(() -> ServiceLoader.load(Crac.class)
.findFirst()
.orElseGet(CracNoop::new));

/**
* Gets CRaC singleton.
* @return singleton
*/
static Crac get() {
return INSTANCE.get();
return CracLookup.get();
}

/**
Expand Down
39 changes: 39 additions & 0 deletions common/common/src/main/java/io/helidon/common/crac/CracLookup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2025 Oracle and/or its affiliates.
*
* Licensed 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
*
* http://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 io.helidon.common.crac;

import java.util.ServiceLoader;

import io.helidon.common.LazyValue;

final class CracLookup {

private CracLookup() {
}

/**
* Lazy singleton instance, either abstraction over actual CRaC API or no-op if integration module
* is missing on classpath.
*/
private static final LazyValue<Crac> SINGLETON = LazyValue.create(() -> ServiceLoader.load(Crac.class)
.findFirst()
.orElseGet(CracNoop::new));

static Crac get() {
return SINGLETON.get();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, 2025 Oracle and/or its affiliates.
* Copyright (c) 2025 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,9 +14,10 @@
* limitations under the License.
*/

package io.helidon.webserver.crac.spi;
package io.helidon.common.crac;

class CracNoop implements Crac {

@Override
public void checkpointRestore() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
/**
* Helidon abstraction over CRaC API, no-op when integration module is not on classpath.
*/
package io.helidon.webserver.crac.spi;
package io.helidon.common.crac;
10 changes: 9 additions & 1 deletion common/common/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2024 Oracle and/or its affiliates.
* Copyright (c) 2017, 2025 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,7 +18,15 @@
* Helidon Common library.
*/
module io.helidon.common {
requires java.management;

uses io.helidon.common.crac.Crac;

exports io.helidon.common;
exports io.helidon.common.crac to
io.helidon.integrations.crac,
io.helidon.microprofile.server,
io.helidon.webserver,
io.helidon.metrics.systemmeters;

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.HashSet;
import java.util.Set;

import io.helidon.webserver.crac.spi.Crac;
import io.helidon.common.crac.Crac;

import org.crac.management.CRaCMXBean;

Expand All @@ -32,7 +32,7 @@ public class CracImpl implements Crac {
private static final Set<Object> STRONG_REFERENCES = new HashSet<>();

@Override
public io.helidon.webserver.crac.spi.Crac.Context<Resource> getGlobalContext() {
public io.helidon.common.crac.Crac.Context<Resource> getGlobalContext() {
return new HelidonContext(org.crac.Core.getGlobalContext());
}

Expand Down Expand Up @@ -72,7 +72,7 @@ public void checkpointRestoreOnStartup() {
}
}

private static class HelidonContext extends io.helidon.webserver.crac.spi.Crac.Context<Resource> {
private static class HelidonContext extends io.helidon.common.crac.Crac.Context<Resource> {

private final org.crac.Context<org.crac.Resource> delegate;

Expand All @@ -83,8 +83,8 @@ private static class HelidonContext extends io.helidon.webserver.crac.spi.Crac.C
@SuppressWarnings("unchecked")
@Override
public void beforeCheckpoint(
io.helidon.webserver.crac.spi.Crac.Context<? extends io.helidon.webserver.crac.spi.Crac.Resource> context)
throws io.helidon.webserver.crac.spi.Crac.CheckpointException {
io.helidon.common.crac.Crac.Context<? extends io.helidon.common.crac.Crac.Resource> context)
throws io.helidon.common.crac.Crac.CheckpointException {
try {
delegate.beforeCheckpoint(new CracContext((Context<Resource>) context));
} catch (org.crac.CheckpointException e) {
Expand All @@ -94,7 +94,7 @@ public void beforeCheckpoint(

@SuppressWarnings("unchecked")
@Override
public void afterRestore(Context<? extends Resource> context) throws io.helidon.webserver.crac.spi.Crac.RestoreException {
public void afterRestore(Context<? extends Resource> context) throws io.helidon.common.crac.Crac.RestoreException {
try {
delegate.afterRestore(new CracContext((Context<Resource>) context));
} catch (org.crac.RestoreException e) {
Expand All @@ -112,7 +112,7 @@ public void register(Resource resource) {

}

private static class HelidonCheckpointException extends io.helidon.webserver.crac.spi.Crac.CheckpointException {
private static class HelidonCheckpointException extends io.helidon.common.crac.Crac.CheckpointException {
private final org.crac.CheckpointException delegate;

HelidonCheckpointException(org.crac.CheckpointException delegate) {
Expand All @@ -128,9 +128,9 @@ public String getMessage() {
}

private static class CracCheckpointException extends org.crac.CheckpointException {
private final io.helidon.webserver.crac.spi.Crac.CheckpointException delegate;
private final io.helidon.common.crac.Crac.CheckpointException delegate;

CracCheckpointException(io.helidon.webserver.crac.spi.Crac.CheckpointException delegate) {
CracCheckpointException(io.helidon.common.crac.Crac.CheckpointException delegate) {
this.delegate = delegate;
this.setStackTrace(delegate.getStackTrace());
}
Expand All @@ -142,7 +142,7 @@ public String getMessage() {

}

private static class HelidonRestoreException extends io.helidon.webserver.crac.spi.Crac.RestoreException {
private static class HelidonRestoreException extends io.helidon.common.crac.Crac.RestoreException {
private final org.crac.RestoreException delegate;

HelidonRestoreException(org.crac.RestoreException delegate) {
Expand All @@ -157,9 +157,9 @@ public String getMessage() {
}

private static class CracRestoreException extends org.crac.RestoreException {
private final io.helidon.webserver.crac.spi.Crac.RestoreException delegate;
private final io.helidon.common.crac.Crac.RestoreException delegate;

CracRestoreException(io.helidon.webserver.crac.spi.Crac.RestoreException delegate) {
CracRestoreException(io.helidon.common.crac.Crac.RestoreException delegate) {
this.delegate = delegate;
this.setStackTrace(delegate.getStackTrace());
}
Expand All @@ -172,9 +172,9 @@ public String getMessage() {

private static class CracContext extends org.crac.Context<org.crac.Resource> {

private final io.helidon.webserver.crac.spi.Crac.Context<io.helidon.webserver.crac.spi.Crac.Resource> delegate;
private final io.helidon.common.crac.Crac.Context<io.helidon.common.crac.Crac.Resource> delegate;

CracContext(io.helidon.webserver.crac.spi.Crac.Context<io.helidon.webserver.crac.spi.Crac.Resource> delegate) {
CracContext(io.helidon.common.crac.Crac.Context<io.helidon.common.crac.Crac.Resource> delegate) {
this.delegate = delegate;
}

Expand Down Expand Up @@ -227,7 +227,7 @@ public void afterRestore(org.crac.Context<? extends org.crac.Resource> context)

}

private static class HelidonResource implements io.helidon.webserver.crac.spi.Crac.Resource {
private static class HelidonResource implements io.helidon.common.crac.Crac.Resource {

private final org.crac.Resource delegate;

Expand All @@ -238,15 +238,15 @@ private static class HelidonResource implements io.helidon.webserver.crac.spi.Cr
@SuppressWarnings("unchecked")
@Override
public void beforeCheckpoint(
io.helidon.webserver.crac.spi.Crac.Context<? extends io.helidon.webserver.crac.spi.Crac.Resource> context)
io.helidon.common.crac.Crac.Context<? extends io.helidon.common.crac.Crac.Resource> context)
throws Exception {
delegate.beforeCheckpoint(new CracContext((Context<Resource>) context));
}

@SuppressWarnings("unchecked")
@Override
public void afterRestore(
io.helidon.webserver.crac.spi.Crac.Context<? extends io.helidon.webserver.crac.spi.Crac.Resource> context)
io.helidon.common.crac.Crac.Context<? extends io.helidon.common.crac.Crac.Resource> context)
throws Exception {
delegate.afterRestore(new CracContext((Context<Resource>) context));
}
Expand Down
5 changes: 2 additions & 3 deletions integrations/crac/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

module io.helidon.integrations.crac {
requires crac;
requires io.helidon.webserver;
exports io.helidon.integrations.crac to io.helidon.webserver;
provides io.helidon.webserver.crac.spi.Crac with io.helidon.integrations.crac.CracImpl;
requires io.helidon.common;
provides io.helidon.common.crac.Crac with io.helidon.integrations.crac.CracImpl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ static List<Tag> createTags(String pairs) {
* @return true to include meters related to virtual threads
*/
@Option.Configured("virtual-threads.enabled")
@Option.DefaultBoolean(false)
@Option.DefaultBoolean(true)
boolean virtualThreadsEnabled();

/**
Expand Down
Loading

0 comments on commit 5077028

Please sign in to comment.