From 6bf3c4143f4a967e11ad43474d266fe23cfc0aa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Galland?= Date: Sun, 2 Jun 2019 10:57:53 +0200 Subject: [PATCH] [lang] Add getKernelLogger function into the Bootstrap. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Galland --- .../src/io/sarl/bootstrap/SRE.java | 1 + .../src/io/sarl/bootstrap/SREBootstrap.java | 19 +++++++++++++++++++ .../src/io/janusproject/Bootstrap.java | 13 +++++++++++++ 3 files changed, 33 insertions(+) diff --git a/main/coreplugins/io.sarl.lang.core/src/io/sarl/bootstrap/SRE.java b/main/coreplugins/io.sarl.lang.core/src/io/sarl/bootstrap/SRE.java index fb29420d5b..896b7d6e28 100644 --- a/main/coreplugins/io.sarl.lang.core/src/io/sarl/bootstrap/SRE.java +++ b/main/coreplugins/io.sarl.lang.core/src/io/sarl/bootstrap/SRE.java @@ -113,6 +113,7 @@ public static ServiceLoader getServiceLoader(boolean onlyInstalled * @return the set of libraries. * @since 0.7 */ + @Pure public static Set getBootstrappedLibraries() { final String name = PREFIX + SREBootstrap.class.getName(); final Set result = new TreeSet<>(); diff --git a/main/coreplugins/io.sarl.lang.core/src/io/sarl/bootstrap/SREBootstrap.java b/main/coreplugins/io.sarl.lang.core/src/io/sarl/bootstrap/SREBootstrap.java index 5c0838f12f..eacfc76efc 100644 --- a/main/coreplugins/io.sarl.lang.core/src/io/sarl/bootstrap/SREBootstrap.java +++ b/main/coreplugins/io.sarl.lang.core/src/io/sarl/bootstrap/SREBootstrap.java @@ -22,6 +22,9 @@ package io.sarl.bootstrap; import java.util.UUID; +import java.util.logging.Logger; + +import org.eclipse.xtext.xbase.lib.Pure; import io.sarl.lang.core.Agent; import io.sarl.lang.core.AgentContext; @@ -83,6 +86,7 @@ public interface SREBootstrap { * @return the identifier of the boot agent, or null if it is unknown. * @see #startAgent(int, Class, Object...) */ + @Pure UUID getBootAgentIdentifier(); /** Replies if the bootstrap could be used. @@ -91,6 +95,7 @@ public interface SREBootstrap { * * @return {@code true} if the bootstrap could be used. {@code false} if it cannot be used. */ + @Pure default boolean isActive() { return true; } @@ -183,6 +188,7 @@ default void setUniverseContextUUID(UUID id) { * @return the identifier, or {@code null} if no identifier is provided by the user and the default identifier should be used. * @since 0.9 */ + @Pure default UUID getUniverseContextUUID() { throw new UnsupportedOperationException(); } @@ -208,6 +214,7 @@ default void setUniverseSpaceUUID(UUID id) { * @return the identifier, or {@code null} if no identifier is provided by the user and the default identifier should be used. * @since 0.9 */ + @Pure default UUID getUniverseSpaceUUID() { throw new UnsupportedOperationException(); } @@ -224,4 +231,16 @@ default void setVerboseLevel(int level) { throw new UnsupportedOperationException(); } + /** Replies the logger used by the SRE. + * + *

This function replies a not {@code null} value only if the kernel was launched. + * + * @return the logger, or {@code null} if the kernel was not launched or has no logger. + * @since 0.10 + */ + @Pure + default Logger getKernelLogger() { + return null; + } + } diff --git a/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/Bootstrap.java b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/Bootstrap.java index 119ee3d539..981f6f4b33 100644 --- a/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/Bootstrap.java +++ b/sre/io.janusproject/io.janusproject.plugin/src/io/janusproject/Bootstrap.java @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; +import java.util.logging.Logger; import io.janusproject.kernel.Kernel; @@ -105,6 +106,18 @@ public AgentContext startWithoutAgent() { return kern.getJanusContext(); } + @Override + public Logger getKernelLogger() { + final Kernel kern; + synchronized (this) { + kern = this.kernel; + } + if (kern != null) { + return kern.getLogger(); + } + return null; + } + @Override public void setOffline(boolean isOffline) { Boot.setOffline(isOffline);