From 6ba5509d3cb657a0fe8041822cc2ba0dbb4775cf Mon Sep 17 00:00:00 2001 From: Ferdinando Villa Date: Mon, 2 Dec 2024 21:07:21 +0100 Subject: [PATCH] Stubs for class registry --- .../integratedmodelling/klab/api/Klab.java | 144 +++++---- .../impl/AbstractDistributionImpl.java | 128 ++++---- .../engine/distribution/impl/BuildImpl.java | 274 +++++++++--------- .../distribution/impl/LocalBuildImpl.java | 86 +++--- .../distribution/impl/LocalProductImpl.java | 126 ++++---- .../distribution/impl/LocalReleaseImpl.java | 60 ++-- .../engine/distribution/impl/ProductImpl.java | 212 +++++++------- .../engine/distribution/impl/ReleaseImpl.java | 130 ++++----- .../services/runtime/MessagingChannel.java | 5 +- .../api/services/runtime/Notification.java | 125 ++++---- .../scope/AbstractReactiveScopeImpl.java | 9 +- .../scope/MessagingChannelImpl.java | 1 - 12 files changed, 663 insertions(+), 637 deletions(-) diff --git a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/Klab.java b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/Klab.java index 709d3adb3..72c91c677 100644 --- a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/Klab.java +++ b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/Klab.java @@ -1,5 +1,6 @@ package org.integratedmodelling.klab.api; +import org.integratedmodelling.klab.api.collections.Pair; import org.integratedmodelling.klab.api.geometry.Geometry; import org.integratedmodelling.klab.api.knowledge.*; import org.integratedmodelling.klab.api.knowledge.observation.scale.Extent; @@ -13,14 +14,13 @@ import org.integratedmodelling.klab.api.services.runtime.extension.KlabFunction; import org.integratedmodelling.klab.api.services.runtime.extension.Library; +import java.lang.reflect.Constructor; import java.util.Collection; +import java.util.HashMap; import java.util.Map; /** - * Holds global configurations and functions that allow generic interfaces to expose constructor methods that - * produce implementation classes that depend on complex dependencies. Implements a poor-man injection pattern - * that needs to be configured in a static block, as done in klab.services.core. This permits - * complex classes like Scale or Projection to have generic builders declared in the API package. + * Global constants, enums and a registry for implementation of the basic interfaces. * * @author Ferd */ @@ -28,6 +28,7 @@ public enum Klab { INSTANCE; + /** * Error codes for all situations. These can (should) be passed, along with an ErrorContext, to * {@link org.integratedmodelling.klab.api.services.runtime.Channel#error(Object...)} to qualify the @@ -83,73 +84,96 @@ public interface Extents { public static final String TIME = "time"; } - } /** - * This is implemented and configured by services so that static constructors of classes that need complex - * dependencies can be provided with the correspondent interfaces in the klab.core.api - * package. Implements a poor-man injection pattern without the pain of actual injection. + * Register a class as an implementation of a given interface. Constructor parameters will be recorded to + * speed up lookup when newInstance() is called. Registering an interface more than once will log a + * warning. * - * @author Ferd + * @param implementationClass + * @param interfaceClass */ - public interface Configuration { - - Observable promoteConceptToObservable(Concept concept); - - Observable.Builder getObservableBuilder(Concept observable, Scope scope); - - Observable.Builder getObservableBuilder(Observable observable, Scope scope); - - Scale promoteGeometryToScale(Geometry geometry, Scope scope); - - Projection getDefaultSpatialProjection(); - - Projection getLatLonSpatialProjection(); - - Scale createScaleFromExtents(Collection> extents); - - Shape createShapeFromTextSpecification(String shapeText, Projection projection); - - Projection getSpatialProjection(String string); + public void register(Class implementationClass, Class interfaceClass) { - Coverage promoteScaleToCoverage(Scale geometry, double coverage); - - Model.Builder getModelBuilder(Observable observable); - - Model.Builder getModelBuilder(Artifact.Type nonSemanticType); - - Model.Builder getModelBuilder(Resource resource); - - Model.Builder getModelBuilder(Object value); - - Model.Builder getModelLearner(String outputResourceUrn); - - Quantity parseQuantity(String quantityDescription); - - /** - * Deep copy of an extent - anything not immutable must be a new object. - * - * @param extent - * @return - */ - Extent createExtentCopy(Extent extent); } - private Configuration configuration; - /** - * Call this in the static block of the core package configuration to ensure that the constructors know - * how to do their job. - * - * @param configuration + * @param interfaceClass + * @param arguments + * @param + * @return */ - public void setConfiguration(Configuration configuration) { - this.configuration = configuration; - } + public T newInstance(Class interfaceClass, Object... arguments) { - public Configuration getConfiguration() { - return this.configuration; } + +// /** +// * This is implemented and configured by services so that static constructors of classes that need complex +// * dependencies can be provided with the correspondent interfaces in the klab.core.api +// * package. Implements a poor-man injection pattern without the pain of actual injection. +// * +// * @author Ferd +// * @deprecated use the registry functions +// */ +// public interface Configuration { +// +// Observable promoteConceptToObservable(Concept concept); +// +// Observable.Builder getObservableBuilder(Concept observable, Scope scope); +// +// Observable.Builder getObservableBuilder(Observable observable, Scope scope); +// +// Scale promoteGeometryToScale(Geometry geometry, Scope scope); +// +// Projection getDefaultSpatialProjection(); +// +// Projection getLatLonSpatialProjection(); +// +// Scale createScaleFromExtents(Collection> extents); +// +// Shape createShapeFromTextSpecification(String shapeText, Projection projection); +// +// Projection getSpatialProjection(String string); +// +// Coverage promoteScaleToCoverage(Scale geometry, double coverage); +// +// Model.Builder getModelBuilder(Observable observable); +// +// Model.Builder getModelBuilder(Artifact.Type nonSemanticType); +// +// Model.Builder getModelBuilder(Resource resource); +// +// Model.Builder getModelBuilder(Object value); +// +// Model.Builder getModelLearner(String outputResourceUrn); +// +// Quantity parseQuantity(String quantityDescription); +// +// /** +// * Deep copy of an extent - anything not immutable must be a new object. +// * +// * @param extent +// * @return +// */ +// Extent createExtentCopy(Extent extent); +// } +// +// private Configuration configuration; +// +// /** +// * Call this in the static block of the core package configuration to ensure that the constructors know +// * how to do their job. +// * +// * @param configuration +// */ +// public void setConfiguration(Configuration configuration) { +// this.configuration = configuration; +// } +// +// public Configuration getConfiguration() { +// return this.configuration; +// } + } diff --git a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/AbstractDistributionImpl.java b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/AbstractDistributionImpl.java index 1bf4aaa74..cf7f1e658 100644 --- a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/AbstractDistributionImpl.java +++ b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/AbstractDistributionImpl.java @@ -1,64 +1,64 @@ -package org.integratedmodelling.klab.api.engine.distribution.impl; - -import org.integratedmodelling.klab.api.engine.distribution.Build; -import org.integratedmodelling.klab.api.engine.distribution.Distribution; -import org.integratedmodelling.klab.api.engine.distribution.Product; -import org.integratedmodelling.klab.api.engine.distribution.RunningInstance; -import org.integratedmodelling.klab.api.scope.Scope; -import org.integratedmodelling.klab.api.utils.PropertyBean; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collection; - -/** - * {@link Distribution} bean which implements all the properties and can be initialized from and saved to a - * {@link java.util.Properties} object. Subclasses will need to define any further properties. - */ -public abstract class AbstractDistributionImpl extends PropertyBean implements Distribution { - - private Collection products = new ArrayList<>(); - - @Override - public Collection getProducts() { - return products; - } - - - public AbstractDistributionImpl() { - super(null); - } - - public AbstractDistributionImpl(File file) { - super(file); - } - - @Override - public Product findProduct(Product.ProductType productType) { - for (var product : products) { - if (product.getProductType() == productType) { - return product; - } - } - return null; - } - - /** - * This is used by {@link LocalBuildImpl} so that we can run the build in more capable implementations by - * just overriding this. - * - * @param build - * @param scope - * @return - */ - public RunningInstance runBuild(Build build, Scope scope) { - return null; - } - - public RunningInstance getInstance(Build build, Scope scope) { - return null; - } - - - -} +//package org.integratedmodelling.klab.api.engine.distribution.impl; +// +//import org.integratedmodelling.klab.api.engine.distribution.Build; +//import org.integratedmodelling.klab.api.engine.distribution.Distribution; +//import org.integratedmodelling.klab.api.engine.distribution.Product; +//import org.integratedmodelling.klab.api.engine.distribution.RunningInstance; +//import org.integratedmodelling.klab.api.scope.Scope; +//import org.integratedmodelling.klab.api.utils.PropertyBean; +// +//import java.io.File; +//import java.util.ArrayList; +//import java.util.Collection; +// +///** +// * {@link Distribution} bean which implements all the properties and can be initialized from and saved to a +// * {@link java.util.Properties} object. Subclasses will need to define any further properties. +// */ +//public abstract class AbstractDistributionImpl extends PropertyBean implements Distribution { +// +// private Collection products = new ArrayList<>(); +// +// @Override +// public Collection getProducts() { +// return products; +// } +// +// +// public AbstractDistributionImpl() { +// super(null); +// } +// +// public AbstractDistributionImpl(File file) { +// super(file); +// } +// +// @Override +// public Product findProduct(Product.ProductType productType) { +// for (var product : products) { +// if (product.getProductType() == productType) { +// return product; +// } +// } +// return null; +// } +// +// /** +// * This is used by {@link LocalBuildImpl} so that we can run the build in more capable implementations by +// * just overriding this. +// * +// * @param build +// * @param scope +// * @return +// */ +// public RunningInstance runBuild(Build build, Scope scope) { +// return null; +// } +// +// public RunningInstance getInstance(Build build, Scope scope) { +// return null; +// } +// +// +// +//} diff --git a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/BuildImpl.java b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/BuildImpl.java index d4e8453db..e410914c4 100644 --- a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/BuildImpl.java +++ b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/BuildImpl.java @@ -1,137 +1,137 @@ -package org.integratedmodelling.klab.api.engine.distribution.impl; - -import org.integratedmodelling.klab.api.data.Version; -import org.integratedmodelling.klab.api.engine.distribution.Product; -import org.integratedmodelling.klab.api.engine.distribution.Build; -import org.integratedmodelling.klab.api.engine.distribution.RunningInstance; -import org.integratedmodelling.klab.api.scope.Scope; -import org.integratedmodelling.klab.api.utils.PropertyBean; - -import java.io.File; -import java.time.Instant; - -/** - * {@link Build} bean which implements all the properties and can be initialized from a - * {@link java.util.Properties} object. Subclasses will need to define any further properties. - */ -public abstract class BuildImpl extends PropertyBean implements Build { - - private ProductImpl product; - - private ReleaseImpl release; - private File localWorkspace; - private Instant buildDate; - private Version version; - private boolean osSpecific; - private String executable; - - public BuildImpl() { - super(null); - } - - public BuildImpl(File propertiesFile) { - super(propertiesFile); - // TODO read the properties. This creates a stub so we create the product as well. - readProperties(); - this.product = new ProductImpl() { - @Override - public Status getStatus() { - return null; - } - - @Override - public RunningInstance getInstance(Scope scope) { - return null; - } - - @Override - public RunningInstance launch(Scope scope) { - return null; - } - }; - this.product.setName(getProperty(Product.PRODUCT_NAME_PROPERTY)); - } - - private void readProperties() { - var localWs = getProperty(BUILD_WORKSPACE_PROPERTY); - if (localWs != null) { - setLocalWorkspace(new File(localWs)); - } - setVersion(Version.create(getProperty(BUILD_VERSION_PROPERTY))); - setOsSpecific(Boolean.valueOf(getProperty(PRODUCT_OSSPECIFIC_PROPERTY))); - setExecutable(getProperty(BUILD_MAINCLASS_PROPERTY)); - setBuildDate(Instant.ofEpochMilli(Long.valueOf(getProperty(BUILD_TIME_PROPERTY, - "" + System.currentTimeMillis())))); - } - - public BuildImpl(File propertiesFile, ProductImpl product, ReleaseImpl release) { - super(propertiesFile); - // TODO read the properties. This creates a stub so we create the product as well. - readProperties(); - this.product = product; - this.release = release; - } - - @Override - public ProductImpl getProduct() { - return product; - } - - @Override - public File getLocalWorkspace() { - return localWorkspace; - } - - @Override - public Instant getBuildDate() { - return buildDate; - } - - @Override - public Version getVersion() { - return version; - } - - @Override - public boolean isOsSpecific() { - return osSpecific; - } - - public void setProduct(ProductImpl product) { - this.product = product; - } - - public void setLocalWorkspace(File localWorkspace) { - this.localWorkspace = localWorkspace; - } - - public void setBuildDate(Instant buildDate) { - this.buildDate = buildDate; - } - - public void setVersion(Version version) { - this.version = version; - } - - public void setOsSpecific(boolean osSpecific) { - this.osSpecific = osSpecific; - } - - @Override - public ReleaseImpl getRelease() { - return release; - } - - public void setRelease(ReleaseImpl release) { - this.release = release; - } - - @Override - public String getExecutable() { - return executable; - } - - public void setExecutable(String executable) { - this.executable = executable; - } -} +//package org.integratedmodelling.klab.api.engine.distribution.impl; +// +//import org.integratedmodelling.klab.api.data.Version; +//import org.integratedmodelling.klab.api.engine.distribution.Product; +//import org.integratedmodelling.klab.api.engine.distribution.Build; +//import org.integratedmodelling.klab.api.engine.distribution.RunningInstance; +//import org.integratedmodelling.klab.api.scope.Scope; +//import org.integratedmodelling.klab.api.utils.PropertyBean; +// +//import java.io.File; +//import java.time.Instant; +// +///** +// * {@link Build} bean which implements all the properties and can be initialized from a +// * {@link java.util.Properties} object. Subclasses will need to define any further properties. +// */ +//public abstract class BuildImpl extends PropertyBean implements Build { +// +// private ProductImpl product; +// +// private ReleaseImpl release; +// private File localWorkspace; +// private Instant buildDate; +// private Version version; +// private boolean osSpecific; +// private String executable; +// +// public BuildImpl() { +// super(null); +// } +// +// public BuildImpl(File propertiesFile) { +// super(propertiesFile); +// // TODO read the properties. This creates a stub so we create the product as well. +// readProperties(); +// this.product = new ProductImpl() { +// @Override +// public Status getStatus() { +// return null; +// } +// +// @Override +// public RunningInstance getInstance(Scope scope) { +// return null; +// } +// +// @Override +// public RunningInstance launch(Scope scope) { +// return null; +// } +// }; +// this.product.setName(getProperty(Product.PRODUCT_NAME_PROPERTY)); +// } +// +// private void readProperties() { +// var localWs = getProperty(BUILD_WORKSPACE_PROPERTY); +// if (localWs != null) { +// setLocalWorkspace(new File(localWs)); +// } +// setVersion(Version.create(getProperty(BUILD_VERSION_PROPERTY))); +// setOsSpecific(Boolean.valueOf(getProperty(PRODUCT_OSSPECIFIC_PROPERTY))); +// setExecutable(getProperty(BUILD_MAINCLASS_PROPERTY)); +// setBuildDate(Instant.ofEpochMilli(Long.valueOf(getProperty(BUILD_TIME_PROPERTY, +// "" + System.currentTimeMillis())))); +// } +// +// public BuildImpl(File propertiesFile, ProductImpl product, ReleaseImpl release) { +// super(propertiesFile); +// // TODO read the properties. This creates a stub so we create the product as well. +// readProperties(); +// this.product = product; +// this.release = release; +// } +// +// @Override +// public ProductImpl getProduct() { +// return product; +// } +// +// @Override +// public File getLocalWorkspace() { +// return localWorkspace; +// } +// +// @Override +// public Instant getBuildDate() { +// return buildDate; +// } +// +// @Override +// public Version getVersion() { +// return version; +// } +// +// @Override +// public boolean isOsSpecific() { +// return osSpecific; +// } +// +// public void setProduct(ProductImpl product) { +// this.product = product; +// } +// +// public void setLocalWorkspace(File localWorkspace) { +// this.localWorkspace = localWorkspace; +// } +// +// public void setBuildDate(Instant buildDate) { +// this.buildDate = buildDate; +// } +// +// public void setVersion(Version version) { +// this.version = version; +// } +// +// public void setOsSpecific(boolean osSpecific) { +// this.osSpecific = osSpecific; +// } +// +// @Override +// public ReleaseImpl getRelease() { +// return release; +// } +// +// public void setRelease(ReleaseImpl release) { +// this.release = release; +// } +// +// @Override +// public String getExecutable() { +// return executable; +// } +// +// public void setExecutable(String executable) { +// this.executable = executable; +// } +//} diff --git a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/LocalBuildImpl.java b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/LocalBuildImpl.java index eb7330b17..fe6893aae 100644 --- a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/LocalBuildImpl.java +++ b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/LocalBuildImpl.java @@ -1,43 +1,43 @@ -package org.integratedmodelling.klab.api.engine.distribution.impl; - -import org.integratedmodelling.klab.api.engine.distribution.Product; -import org.integratedmodelling.klab.api.engine.distribution.RunningInstance; -import org.integratedmodelling.klab.api.scope.Scope; - -import java.io.File; - -public class LocalBuildImpl extends BuildImpl { - - AbstractDistributionImpl distribution; - - public LocalBuildImpl(File buildPropertyFile, AbstractDistributionImpl distribution, ProductImpl product, ReleaseImpl release) { - super(buildPropertyFile, product, release); - this.distribution = distribution; - } - - @Override - public Product.Status getStatus() { - return Product.Status.UP_TO_DATE; - } - - @Override - public boolean synchronize(Scope scope) { - return true; - } - - @Override - public RunningInstance getInstance(Scope scope) { - return distribution.getInstance(this, scope); - } - - - @Override - public RunningInstance launch(Scope scope) { - return distribution.runBuild(this, scope); - } - - @Override - public String getRemotePath() { - return null; - } -} +//package org.integratedmodelling.klab.api.engine.distribution.impl; +// +//import org.integratedmodelling.klab.api.engine.distribution.Product; +//import org.integratedmodelling.klab.api.engine.distribution.RunningInstance; +//import org.integratedmodelling.klab.api.scope.Scope; +// +//import java.io.File; +// +//public class LocalBuildImpl extends BuildImpl { +// +// AbstractDistributionImpl distribution; +// +// public LocalBuildImpl(File buildPropertyFile, AbstractDistributionImpl distribution, ProductImpl product, ReleaseImpl release) { +// super(buildPropertyFile, product, release); +// this.distribution = distribution; +// } +// +// @Override +// public Product.Status getStatus() { +// return Product.Status.UP_TO_DATE; +// } +// +// @Override +// public boolean synchronize(Scope scope) { +// return true; +// } +// +// @Override +// public RunningInstance getInstance(Scope scope) { +// return distribution.getInstance(this, scope); +// } +// +// +// @Override +// public RunningInstance launch(Scope scope) { +// return distribution.runBuild(this, scope); +// } +// +// @Override +// public String getRemotePath() { +// return null; +// } +//} diff --git a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/LocalProductImpl.java b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/LocalProductImpl.java index d2ee0f303..dc396900a 100644 --- a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/LocalProductImpl.java +++ b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/LocalProductImpl.java @@ -1,63 +1,63 @@ -package org.integratedmodelling.klab.api.engine.distribution.impl; - -import org.integratedmodelling.klab.api.engine.distribution.Build; -import org.integratedmodelling.klab.api.engine.distribution.RunningInstance; -import org.integratedmodelling.klab.api.scope.Scope; - -import java.io.File; - -public class LocalProductImpl extends ProductImpl { - - public LocalProductImpl(File file, AbstractDistributionImpl distribution) { - super(file, distribution); - } - - @Override - public Status getStatus() { - return null; - } - - @Override - public RunningInstance launch(Scope scope) { - - var lastLaunched = getProperty(LAST_BUILD_LAUNCHED); - var build = locateBuild(lastLaunched); - if (build != null) { - return build.launch(scope); - } - return null; - } - - @Override - public RunningInstance getInstance(Scope scope) { - - var lastLaunched = getProperty(LAST_BUILD_LAUNCHED); - var build = locateBuild(lastLaunched); - if (build != null) { - return build.getInstance(scope); - } - return null; - } - - - private Build locateBuild(String lastLaunched) { - if (lastLaunched != null) { - String[] launched = lastLaunched.split("\\/"); - var release = getReleases().stream().filter(r -> r.getName().equals(launched[0])).findAny(); - if (release.isPresent()) { - var ret = - release.get().getBuilds().stream().filter(b -> b.getVersion().getBuild() == Long.valueOf(launched[1])).findAny(); - if (ret.isPresent()) { - return ret.get(); - } - } - } - if (!getReleases().isEmpty()) { - var release = getReleases().get(0); - if (!release.getBuilds().isEmpty()) { - return release.getBuilds().get(0); - } - } - return null; - } -} +//package org.integratedmodelling.klab.api.engine.distribution.impl; +// +//import org.integratedmodelling.klab.api.engine.distribution.Build; +//import org.integratedmodelling.klab.api.engine.distribution.RunningInstance; +//import org.integratedmodelling.klab.api.scope.Scope; +// +//import java.io.File; +// +//public class LocalProductImpl extends ProductImpl { +// +// public LocalProductImpl(File file, AbstractDistributionImpl distribution) { +// super(file, distribution); +// } +// +// @Override +// public Status getStatus() { +// return null; +// } +// +// @Override +// public RunningInstance launch(Scope scope) { +// +// var lastLaunched = getProperty(LAST_BUILD_LAUNCHED); +// var build = locateBuild(lastLaunched); +// if (build != null) { +// return build.launch(scope); +// } +// return null; +// } +// +// @Override +// public RunningInstance getInstance(Scope scope) { +// +// var lastLaunched = getProperty(LAST_BUILD_LAUNCHED); +// var build = locateBuild(lastLaunched); +// if (build != null) { +// return build.getInstance(scope); +// } +// return null; +// } +// +// +// private Build locateBuild(String lastLaunched) { +// if (lastLaunched != null) { +// String[] launched = lastLaunched.split("\\/"); +// var release = getReleases().stream().filter(r -> r.getName().equals(launched[0])).findAny(); +// if (release.isPresent()) { +// var ret = +// release.get().getBuilds().stream().filter(b -> b.getVersion().getBuild() == Long.valueOf(launched[1])).findAny(); +// if (ret.isPresent()) { +// return ret.get(); +// } +// } +// } +// if (!getReleases().isEmpty()) { +// var release = getReleases().get(0); +// if (!release.getBuilds().isEmpty()) { +// return release.getBuilds().get(0); +// } +// } +// return null; +// } +//} diff --git a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/LocalReleaseImpl.java b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/LocalReleaseImpl.java index 3963e1cc0..49e99b42a 100644 --- a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/LocalReleaseImpl.java +++ b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/LocalReleaseImpl.java @@ -1,30 +1,30 @@ -package org.integratedmodelling.klab.api.engine.distribution.impl; - -import org.integratedmodelling.klab.api.engine.distribution.Build; - -import java.io.File; -import java.util.Collections; -import java.util.Comparator; - -public class LocalReleaseImpl extends ReleaseImpl { - public LocalReleaseImpl(File releasePropertyFile, AbstractDistributionImpl distribution, ProductImpl product) { - super(releasePropertyFile); - this.setProduct(product); - this.setName(getProperty(RELEASE_NAME_PROPERTY)); - for (String buildName : getProperty(BUILD_VERSIONS_PROPERTY, "").split(",")) { - File buildPropertyFile = - new File(releasePropertyFile.getParent() + File.separator + buildName + File.separator + Build.BUILD_PROPERTIES_FILE); - if (buildPropertyFile.isFile()) { - getBuilds().add(new LocalBuildImpl(buildPropertyFile, distribution, product, this)); - } - } - - // sort last build first - Collections.sort(this.getBuilds(), new Comparator() { - @Override - public int compare(Build o1, Build o2) { - return o2.getVersion().compareTo(o1.getVersion()); - } - }); - } -} +//package org.integratedmodelling.klab.api.engine.distribution.impl; +// +//import org.integratedmodelling.klab.api.engine.distribution.Build; +// +//import java.io.File; +//import java.util.Collections; +//import java.util.Comparator; +// +//public class LocalReleaseImpl extends ReleaseImpl { +// public LocalReleaseImpl(File releasePropertyFile, AbstractDistributionImpl distribution, ProductImpl product) { +// super(releasePropertyFile); +// this.setProduct(product); +// this.setName(getProperty(RELEASE_NAME_PROPERTY)); +// for (String buildName : getProperty(BUILD_VERSIONS_PROPERTY, "").split(",")) { +// File buildPropertyFile = +// new File(releasePropertyFile.getParent() + File.separator + buildName + File.separator + Build.BUILD_PROPERTIES_FILE); +// if (buildPropertyFile.isFile()) { +// getBuilds().add(new LocalBuildImpl(buildPropertyFile, distribution, product, this)); +// } +// } +// +// // sort last build first +// Collections.sort(this.getBuilds(), new Comparator() { +// @Override +// public int compare(Build o1, Build o2) { +// return o2.getVersion().compareTo(o1.getVersion()); +// } +// }); +// } +//} diff --git a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/ProductImpl.java b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/ProductImpl.java index 5b2b3c73c..ef2df7096 100644 --- a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/ProductImpl.java +++ b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/ProductImpl.java @@ -1,106 +1,106 @@ -package org.integratedmodelling.klab.api.engine.distribution.impl; - -import org.integratedmodelling.klab.api.data.Version; -import org.integratedmodelling.klab.api.engine.distribution.Product; -import org.integratedmodelling.klab.api.engine.distribution.Release; -import org.integratedmodelling.klab.api.utils.PropertyBean; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -/** - * {@link Product} bean which implements all the properties and can be initialized from a - * {@link java.util.Properties} object. Subclasses will need to define any further properties. - */ -public abstract class ProductImpl extends PropertyBean implements Product { - private String id; - private ProductType productType; - private Type type; - private String name; - private String description; - private Version version; - private List releases = new ArrayList<>(); - - public ProductImpl() { - super(null); - } - - public ProductImpl(File propertiesFile, AbstractDistributionImpl distribution){ - super(propertiesFile); - this.setName(getProperty(Product.PRODUCT_NAME_PROPERTY)); - this.setProductType(ProductType.valueOf(getProperty(PRODUCT_CLASS_PROPERTY))); - this.setType(Type.forOption(getProperty(PRODUCT_TYPE_PROPERTY))); - this.setDescription(getProperty(PRODUCT_DESCRIPTION_PROPERTY)); - - for (String releaseName : getProperty(RELEASE_NAMES_PROPERTY, "").split(",")) { - File releasePropertyFile = new File(propertiesFile.getParent() + File.separator + releaseName + File.separator + ReleaseImpl.RELEASE_PROPERTIES_FILE); - if (releasePropertyFile.isFile()) { - getReleases().add(new LocalReleaseImpl(releasePropertyFile, distribution, this)); - } - } - } - - @Override - public String getId() { - return id; - } - - @Override - public ProductType getProductType() { - return productType; - } - - @Override - public Type getType() { - return this.type; - } - - @Override - public String getName() { - return name; - } - - @Override - public String getDescription() { - return description; - } - - @Override - public Version getVersion() { - return version; - } - - @Override - public List getReleases() { - return releases; - } - - public void setId(String id) { - this.id = id; - } - - public void setProductType(ProductType productType) { - this.productType = productType; - } - - public void setType(Type type) { - this.type = type; - } - - public void setName(String name) { - this.name = name; - } - - public void setDescription(String description) { - this.description = description; - } - - public void setVersion(Version version) { - this.version = version; - } - - public void setReleases(List releases) { - this.releases = releases; - } -} +//package org.integratedmodelling.klab.api.engine.distribution.impl; +// +//import org.integratedmodelling.klab.api.data.Version; +//import org.integratedmodelling.klab.api.engine.distribution.Product; +//import org.integratedmodelling.klab.api.engine.distribution.Release; +//import org.integratedmodelling.klab.api.utils.PropertyBean; +// +//import java.io.File; +//import java.util.ArrayList; +//import java.util.List; +// +///** +// * {@link Product} bean which implements all the properties and can be initialized from a +// * {@link java.util.Properties} object. Subclasses will need to define any further properties. +// */ +//public abstract class ProductImpl extends PropertyBean implements Product { +// private String id; +// private ProductType productType; +// private Type type; +// private String name; +// private String description; +// private Version version; +// private List releases = new ArrayList<>(); +// +// public ProductImpl() { +// super(null); +// } +// +// public ProductImpl(File propertiesFile, AbstractDistributionImpl distribution){ +// super(propertiesFile); +// this.setName(getProperty(Product.PRODUCT_NAME_PROPERTY)); +// this.setProductType(ProductType.valueOf(getProperty(PRODUCT_CLASS_PROPERTY))); +// this.setType(Type.forOption(getProperty(PRODUCT_TYPE_PROPERTY))); +// this.setDescription(getProperty(PRODUCT_DESCRIPTION_PROPERTY)); +// +// for (String releaseName : getProperty(RELEASE_NAMES_PROPERTY, "").split(",")) { +// File releasePropertyFile = new File(propertiesFile.getParent() + File.separator + releaseName + File.separator + ReleaseImpl.RELEASE_PROPERTIES_FILE); +// if (releasePropertyFile.isFile()) { +// getReleases().add(new LocalReleaseImpl(releasePropertyFile, distribution, this)); +// } +// } +// } +// +// @Override +// public String getId() { +// return id; +// } +// +// @Override +// public ProductType getProductType() { +// return productType; +// } +// +// @Override +// public Type getType() { +// return this.type; +// } +// +// @Override +// public String getName() { +// return name; +// } +// +// @Override +// public String getDescription() { +// return description; +// } +// +// @Override +// public Version getVersion() { +// return version; +// } +// +// @Override +// public List getReleases() { +// return releases; +// } +// +// public void setId(String id) { +// this.id = id; +// } +// +// public void setProductType(ProductType productType) { +// this.productType = productType; +// } +// +// public void setType(Type type) { +// this.type = type; +// } +// +// public void setName(String name) { +// this.name = name; +// } +// +// public void setDescription(String description) { +// this.description = description; +// } +// +// public void setVersion(Version version) { +// this.version = version; +// } +// +// public void setReleases(List releases) { +// this.releases = releases; +// } +//} diff --git a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/ReleaseImpl.java b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/ReleaseImpl.java index 2301ac14d..a05e429ef 100644 --- a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/ReleaseImpl.java +++ b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/engine/distribution/impl/ReleaseImpl.java @@ -1,65 +1,65 @@ -package org.integratedmodelling.klab.api.engine.distribution.impl; - -import org.integratedmodelling.klab.api.data.Version; -import org.integratedmodelling.klab.api.engine.distribution.Build; -import org.integratedmodelling.klab.api.engine.distribution.Release; -import org.integratedmodelling.klab.api.utils.PropertyBean; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -public class ReleaseImpl extends PropertyBean implements Release { - - private String name; - private Version version; - private List builds = new ArrayList<>(); - - private ProductImpl product; - - public ReleaseImpl() { - super(null); - } - - public ReleaseImpl(File file) { - super(file); - // TODO read properties - } - - @Override - public String getName() { - return name; - } - - @Override - public Version getVersion() { - return version; - } - - @Override - public List getBuilds() { - return builds; - } - - public void setName(String name) { - this.name = name; - } - - public void setVersion(Version version) { - this.version = version; - } - - public void setBuilds(List builds) { - this.builds = builds; - } - - @Override - public ProductImpl getProduct() { - return product; - } - - public void setProduct(ProductImpl product) { - this.product = product; - } - -} +//package org.integratedmodelling.klab.api.engine.distribution.impl; +// +//import org.integratedmodelling.klab.api.data.Version; +//import org.integratedmodelling.klab.api.engine.distribution.Build; +//import org.integratedmodelling.klab.api.engine.distribution.Release; +//import org.integratedmodelling.klab.api.utils.PropertyBean; +// +//import java.io.File; +//import java.util.ArrayList; +//import java.util.List; +// +//public class ReleaseImpl extends PropertyBean implements Release { +// +// private String name; +// private Version version; +// private List builds = new ArrayList<>(); +// +// private ProductImpl product; +// +// public ReleaseImpl() { +// super(null); +// } +// +// public ReleaseImpl(File file) { +// super(file); +// // TODO read properties +// } +// +// @Override +// public String getName() { +// return name; +// } +// +// @Override +// public Version getVersion() { +// return version; +// } +// +// @Override +// public List getBuilds() { +// return builds; +// } +// +// public void setName(String name) { +// this.name = name; +// } +// +// public void setVersion(Version version) { +// this.version = version; +// } +// +// public void setBuilds(List builds) { +// this.builds = builds; +// } +// +// @Override +// public ProductImpl getProduct() { +// return product; +// } +// +// public void setProduct(ProductImpl product) { +// this.product = product; +// } +// +//} diff --git a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/services/runtime/MessagingChannel.java b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/services/runtime/MessagingChannel.java index a7a9b7981..8553e07fe 100644 --- a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/services/runtime/MessagingChannel.java +++ b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/services/runtime/MessagingChannel.java @@ -41,7 +41,7 @@ void connectToService(KlabService.ServiceCapabilities capabilities, UserIdentity /** * Install one or more message matchers to react to messages received and sent through the managed * queues. - * + * @deprecated * @param matchers * @return */ @@ -55,6 +55,9 @@ void connectToService(KlabService.ServiceCapabilities capabilities, UserIdentity * @param supplier * @param * @return + * @deprecated the {@link Channel#onEvent(Message.MessageClass, Message.MessageType, Consumer, Object...)} + * mechanism does the same thing, unify to provide a future and use messaging in the client, add the + * service ID in the matcher and remove Message.Match */ Future trackMessages(Message.Match match, Function supplier); diff --git a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/services/runtime/Notification.java b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/services/runtime/Notification.java index 45bdb2024..a69c63bab 100644 --- a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/services/runtime/Notification.java +++ b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/services/runtime/Notification.java @@ -1,15 +1,12 @@ package org.integratedmodelling.klab.api.services.runtime; +import org.integratedmodelling.klab.api.Klab; import org.integratedmodelling.klab.api.exceptions.KlabIllegalArgumentException; import org.integratedmodelling.klab.api.knowledge.KlabAsset; -import org.integratedmodelling.klab.api.lang.kim.KlabStatement; -import org.integratedmodelling.klab.api.services.runtime.impl.NotificationImpl; import org.integratedmodelling.klab.api.utils.Utils; import org.integratedmodelling.klab.api.view.UI; import java.io.Serializable; -import java.time.Instant; -import java.time.OffsetDateTime; public interface Notification extends Serializable { @@ -98,23 +95,23 @@ interface LexicalContext { */ LexicalContext getLexicalContext(); - public static NotificationImpl of(String message, Level level) { - return new NotificationImpl(message, level); + public static Notification of(String message, Level level) { + return create(message, level); } - public static NotificationImpl error(Object... objects) { + public static Notification error(Object... objects) { return create(Utils.Collections.flatCollection(Level.Error, objects).toArray()); } - public static NotificationImpl info(Object... objects) { + public static Notification info(Object... objects) { return create(Utils.Collections.flatCollection(Level.Info, objects).toArray()); } - public static NotificationImpl warning(Object... objects) { + public static Notification warning(Object... objects) { return create(Utils.Collections.flatCollection(Level.Warning, objects).toArray()); } - public static NotificationImpl debug(Object... objects) { + public static Notification debug(Object... objects) { return create(Utils.Collections.flatCollection(Level.Debug, objects).toArray()); } @@ -124,58 +121,60 @@ public static NotificationImpl debug(Object... objects) { * @param objects * @return */ - public static NotificationImpl create(Object... objects) { - - Level level = Level.Info; - String message = "No message"; - LexicalContext lexicalContext = null; - long timestamp = System.currentTimeMillis(); - Mode mode = Mode.Normal; - UI.Interactivity interactivity = UI.Interactivity.BATCH; -// Message.ForwardingPolicy forwardingPolicy = Message.ForwardingPolicy.DoNotForward; - - if (objects != null) { - for (Object o : objects) { - if (o instanceof Throwable throwable) { - message = Utils.Exceptions.stackTrace(throwable); - level = Level.Error; - } else if (o instanceof String string) { - message = string; - } else if (o instanceof UI.Interactivity inter) { - interactivity = inter; - } else if (o instanceof Instant instant) { - timestamp = instant.toEpochMilli(); - } else if (o instanceof OffsetDateTime date) { - timestamp = date.toInstant().toEpochMilli(); - } else if (o instanceof Level l) { - level = l; - } else if (o instanceof LexicalContext lc) { - lexicalContext = lc; - } else if (o instanceof Mode mod) { - mode = mod; - } /*else if (o instanceof Message.ForwardingPolicy fwp) { - forwardingPolicy = fwp; - } */else if (o instanceof KlabStatement statement) { - var lc = new NotificationImpl.LexicalContextImpl(); - lc.setLength(statement.getLength()); - lc.setOffsetInDocument(statement.getOffsetInDocument()); - lc.setDocumentUrn(statement.getNamespace()); - lc.setProjectUrn(statement.getProjectName()); - lc.setDocumentType(statement.getDocumentClass()); - lc.setType(KlabAsset.classify(statement)); - lexicalContext = lc; - } - } - } - - var ret = new NotificationImpl(message, level); - ret.setLexicalContext(lexicalContext); - ret.setTimestamp(timestamp); - ret.setMode(mode); - ret.setInteractivity(interactivity); -// ret.setType(type); -// ret.setForwardingPolicy(forwardingPolicy); - - return ret; + public static Notification create(Object... objects) { + + return Klab.INSTANCE.newInstance(Notification.class, objects); + +// Level level = Level.Info; +// String message = "No message"; +// LexicalContext lexicalContext = null; +// long timestamp = System.currentTimeMillis(); +// Mode mode = Mode.Normal; +// UI.Interactivity interactivity = UI.Interactivity.BATCH; +//// Message.ForwardingPolicy forwardingPolicy = Message.ForwardingPolicy.DoNotForward; +// +// if (objects != null) { +// for (Object o : objects) { +// if (o instanceof Throwable throwable) { +// message = Utils.Exceptions.stackTrace(throwable); +// level = Level.Error; +// } else if (o instanceof String string) { +// message = string; +// } else if (o instanceof UI.Interactivity inter) { +// interactivity = inter; +// } else if (o instanceof Instant instant) { +// timestamp = instant.toEpochMilli(); +// } else if (o instanceof OffsetDateTime date) { +// timestamp = date.toInstant().toEpochMilli(); +// } else if (o instanceof Level l) { +// level = l; +// } else if (o instanceof LexicalContext lc) { +// lexicalContext = lc; +// } else if (o instanceof Mode mod) { +// mode = mod; +// } /*else if (o instanceof Message.ForwardingPolicy fwp) { +// forwardingPolicy = fwp; +// } */else if (o instanceof KlabStatement statement) { +// var lc = new NotificationImpl.LexicalContextImpl(); +// lc.setLength(statement.getLength()); +// lc.setOffsetInDocument(statement.getOffsetInDocument()); +// lc.setDocumentUrn(statement.getNamespace()); +// lc.setProjectUrn(statement.getProjectName()); +// lc.setDocumentType(statement.getDocumentClass()); +// lc.setType(KlabAsset.classify(statement)); +// lexicalContext = lc; +// } +// } +// } +// +// var ret = new NotificationImpl(message, level); +// ret.setLexicalContext(lexicalContext); +// ret.setTimestamp(timestamp); +// ret.setMode(mode); +// ret.setInteractivity(interactivity); +//// ret.setType(type); +//// ret.setForwardingPolicy(forwardingPolicy); +// +// return ret; } } \ No newline at end of file diff --git a/klab.core.common/src/main/java/org/integratedmodelling/common/authentication/scope/AbstractReactiveScopeImpl.java b/klab.core.common/src/main/java/org/integratedmodelling/common/authentication/scope/AbstractReactiveScopeImpl.java index 1d7761e1c..2a4bb22ee 100644 --- a/klab.core.common/src/main/java/org/integratedmodelling/common/authentication/scope/AbstractReactiveScopeImpl.java +++ b/klab.core.common/src/main/java/org/integratedmodelling/common/authentication/scope/AbstractReactiveScopeImpl.java @@ -1,5 +1,6 @@ package org.integratedmodelling.common.authentication.scope; +import org.integratedmodelling.common.runtime.MessageImpl; import org.integratedmodelling.klab.api.exceptions.KlabInternalErrorException; import org.integratedmodelling.klab.api.exceptions.KlabResourceAccessException; import org.integratedmodelling.klab.api.identities.Identity; @@ -29,10 +30,10 @@ public AbstractReactiveScopeImpl(Identity identity, boolean isSender, boolean is super(identity, isSender, isReceiver); } - protected AbstractReactiveScopeImpl(AbstractReactiveScopeImpl other) { - super(other); - this.agent = other.agent; - } +// protected AbstractReactiveScopeImpl(AbstractReactiveScopeImpl other) { +// super(other); +// this.agent = other.agent; +// } @Override public KActorsBehavior.Ref getAgent() { diff --git a/klab.core.common/src/main/java/org/integratedmodelling/common/authentication/scope/MessagingChannelImpl.java b/klab.core.common/src/main/java/org/integratedmodelling/common/authentication/scope/MessagingChannelImpl.java index 9743540b2..dd76ff51e 100644 --- a/klab.core.common/src/main/java/org/integratedmodelling/common/authentication/scope/MessagingChannelImpl.java +++ b/klab.core.common/src/main/java/org/integratedmodelling/common/authentication/scope/MessagingChannelImpl.java @@ -14,7 +14,6 @@ import org.integratedmodelling.klab.api.services.runtime.Message; import org.integratedmodelling.klab.api.services.runtime.MessagingChannel; -import java.io.Closeable; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.*;