release version 1.10.0
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.core</groupId>
|
||||
<artifactId>object-runtime</artifactId>
|
||||
<version>1.9.0</version>
|
||||
<version>1.10.0</version>
|
||||
</parent>
|
||||
<artifactId>object-runtime-core</artifactId>
|
||||
<packaging>bundle</packaging>
|
||||
@ -17,6 +17,10 @@
|
||||
ru.entaxy.platform.objects.runtime.impl,
|
||||
ru.entaxy.platform.objects.runtime.impl.manager
|
||||
</bundle.osgi.export.pkg>
|
||||
<bundle.osgi.pricate.pkg>
|
||||
ru.entaxy.platform.objects.runtime.internal
|
||||
</bundle.osgi.pricate.pkg>
|
||||
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@ -40,6 +44,16 @@
|
||||
<artifactId>org.apache.felix.healthcheck.annotation</artifactId>
|
||||
<version>2.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.core</groupId>
|
||||
<artifactId>core-support-runtime</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ru.entaxy.platform</groupId>
|
||||
<artifactId>search-service</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -25,36 +25,84 @@
|
||||
*/
|
||||
package ru.entaxy.platform.objects.runtime;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
|
||||
import ru.entaxy.platform.base.objects.EntaxyObject;
|
||||
|
||||
public interface EntaxyRuntimeObject extends EntaxyObject {
|
||||
|
||||
public enum ENTAXY_RUNTIME_OBJECT_STATE {
|
||||
ACTIVE,
|
||||
INACTIVE,
|
||||
UNKNOWN
|
||||
}
|
||||
|
||||
public interface CAPABILITIES_RUNTIME extends CAPABILITIES {
|
||||
String ATTR_RESOURCES = "resources";
|
||||
}
|
||||
|
||||
boolean isColocatedWith(EntaxyRuntimeObject object);
|
||||
|
||||
List<EntaxyRuntimeRelation> getRelations(EntaxyObject.OBJECT_RELATION relationType);
|
||||
List<EntaxyRuntimeRelation> getSubordRelations();
|
||||
List<EntaxyRuntimeRelation> getIncomiingRelations(EntaxyObject.OBJECT_RELATION relationType);
|
||||
List<EntaxyRuntimeRelation> getIncomiingSubordRelations();
|
||||
|
||||
List<EntaxyRuntimeRelation> getDependsOn();
|
||||
List<EntaxyRuntimeRelation> getDependents();
|
||||
|
||||
EntaxyRuntimeObjectContainer getContainer();
|
||||
|
||||
List<EntaxyRuntimeObject> getColocatedObjects();
|
||||
|
||||
List<EntaxyRuntimeObjectResource> getResources();
|
||||
|
||||
public enum ENTAXY_RUNTIME_OBJECT_STATE {
|
||||
ACTIVE,
|
||||
INACTIVE,
|
||||
UNKNOWN
|
||||
}
|
||||
|
||||
public interface CAPABILITIES_RUNTIME extends CAPABILITIES {
|
||||
String ATTR_RESOURCES = "resources";
|
||||
}
|
||||
|
||||
public interface SEARCH {
|
||||
|
||||
String ATTR_ID = "id";
|
||||
String ATTR_TYPE = "type";
|
||||
String ATTR_DISPLAY_NAME = "displayName";
|
||||
String ATTR_LABEL = "label";
|
||||
String ATTR_SCOPE = "scope";
|
||||
String ATTR_RESOURCES = "resources";
|
||||
String ATTR_FACTORY = "factory";
|
||||
String ATTR_RELATIONS_IN = "relationsIn";
|
||||
String ATTR_RELATIONS_OUT = "relationsOut";
|
||||
|
||||
List<String> STANDARD_ATTRIBUTES_LIST = Arrays.asList(new String[] {
|
||||
ATTR_ID, ATTR_TYPE, ATTR_DISPLAY_NAME, ATTR_LABEL, ATTR_SCOPE, ATTR_RESOURCES, ATTR_FACTORY,
|
||||
ATTR_RELATIONS_IN, ATTR_RELATIONS_OUT
|
||||
});
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> STANDARD_ATTRIBUTES = MapUtils.putAll(new LinkedHashMap<String, String>(), new String[][] {
|
||||
{ATTR_ID, "Object id"},
|
||||
{ATTR_TYPE, "Object type"},
|
||||
{ATTR_DISPLAY_NAME, "Display name"},
|
||||
{ATTR_LABEL, "Label"},
|
||||
{ATTR_SCOPE, "Scope"},
|
||||
{ATTR_RESOURCES, "Resources"},
|
||||
{ATTR_FACTORY, "Factory Id"},
|
||||
{ATTR_RELATIONS_IN, "Incoming relations"},
|
||||
{ATTR_RELATIONS_OUT, "Outgoing relations"}
|
||||
});
|
||||
}
|
||||
|
||||
boolean isColocatedWith(EntaxyRuntimeObject object);
|
||||
|
||||
List<EntaxyRuntimeRelation> getRelations(EntaxyObject.OBJECT_RELATION relationType);
|
||||
|
||||
List<EntaxyRuntimeRelation> getSubordRelations();
|
||||
|
||||
List<EntaxyRuntimeRelation> getIncomiingRelations(EntaxyObject.OBJECT_RELATION relationType);
|
||||
|
||||
List<EntaxyRuntimeRelation> getIncomiingSubordRelations();
|
||||
|
||||
List<EntaxyRuntimeRelation> getDependsOn();
|
||||
|
||||
List<EntaxyRuntimeRelation> getDependents();
|
||||
|
||||
EntaxyRuntimeObjectContainer getContainer();
|
||||
|
||||
List<EntaxyRuntimeObject> getColocatedObjects();
|
||||
|
||||
List<EntaxyRuntimeObjectResource> getResources();
|
||||
|
||||
Map<String, Object> getAllAttributes();
|
||||
|
||||
boolean hasAttribute(String name);
|
||||
|
||||
Object getAttribute(String name);
|
||||
|
||||
Object getAttributeOrDefault(String name, Object defaultValue);
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -25,40 +25,69 @@
|
||||
*/
|
||||
package ru.entaxy.platform.objects.runtime;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
|
||||
public interface EntaxyRuntimeObjectContainer {
|
||||
|
||||
public enum ENTAXY_RUNTIME_OBJECT_CONTAINER_STATE {
|
||||
Installed,
|
||||
Resolved,
|
||||
Unknown,
|
||||
GracePeriod,
|
||||
Waiting,
|
||||
Starting,
|
||||
Active,
|
||||
Stopping,
|
||||
Failure,
|
||||
}
|
||||
|
||||
String getId();
|
||||
String getName();
|
||||
|
||||
default String getType() {
|
||||
return "bundle";
|
||||
}
|
||||
|
||||
ENTAXY_RUNTIME_OBJECT_CONTAINER_STATE getState();
|
||||
|
||||
List<EntaxyRuntimeObject> getObjects();
|
||||
|
||||
List<EntaxyRuntimeObjectContainer> getParentContainers();
|
||||
List<EntaxyRuntimeObjectContainer> getChildContainers();
|
||||
|
||||
List<EntaxyRuntimeObjectContainer> getDependencies();
|
||||
List<EntaxyRuntimeObjectContainer> getDependent();
|
||||
|
||||
List<EntaxyRuntimeObjectContainer> getRelatedContainers();
|
||||
List<EntaxyRuntimeObjectContainer> getIncomingRelatedContainers();
|
||||
|
||||
public enum ENTAXY_RUNTIME_OBJECT_CONTAINER_STATE {
|
||||
Installed,
|
||||
Resolved,
|
||||
Unknown,
|
||||
GracePeriod,
|
||||
Waiting,
|
||||
Starting,
|
||||
Active,
|
||||
Stopping,
|
||||
Failure,
|
||||
}
|
||||
|
||||
public interface SEARCH {
|
||||
|
||||
String ATTR_ID = "id";
|
||||
String ATTR_TYPE = "type";
|
||||
String ATTR_NAME = "name";
|
||||
String ATTR_STATE = "state";
|
||||
|
||||
List<String> STANDARD_ATTRIBUTES_LIST = Arrays.asList(new String[] {
|
||||
ATTR_ID, ATTR_TYPE, ATTR_NAME, ATTR_STATE
|
||||
});
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> STANDARD_ATTRIBUTES = MapUtils.putAll(new LinkedHashMap<String, String>(), new String[][] {
|
||||
{ATTR_ID, "Container id"},
|
||||
{ATTR_TYPE, "Container type"},
|
||||
{ATTR_NAME, "Container name"},
|
||||
{ATTR_STATE, "Container state"}
|
||||
});
|
||||
}
|
||||
|
||||
String getId();
|
||||
|
||||
String getName();
|
||||
|
||||
default String getType() {
|
||||
return "bundle";
|
||||
}
|
||||
|
||||
ENTAXY_RUNTIME_OBJECT_CONTAINER_STATE getState();
|
||||
|
||||
List<EntaxyRuntimeObject> getObjects();
|
||||
|
||||
List<EntaxyRuntimeObjectContainer> getParentContainers();
|
||||
|
||||
List<EntaxyRuntimeObjectContainer> getChildContainers();
|
||||
|
||||
List<EntaxyRuntimeObjectContainer> getDependencies();
|
||||
|
||||
List<EntaxyRuntimeObjectContainer> getDependent();
|
||||
|
||||
List<EntaxyRuntimeObjectContainer> getRelatedContainers();
|
||||
|
||||
List<EntaxyRuntimeObjectContainer> getIncomingRelatedContainers();
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -25,27 +25,69 @@
|
||||
*/
|
||||
package ru.entaxy.platform.objects.runtime;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.osgi.framework.Filter;
|
||||
import org.osgi.framework.FrameworkUtil;
|
||||
import org.osgi.framework.InvalidSyntaxException;
|
||||
|
||||
import ru.entaxy.platform.base.objects.EntaxyObject;
|
||||
import ru.entaxy.platform.objects.runtime.EntaxyRuntimeObject.ENTAXY_RUNTIME_OBJECT_STATE;
|
||||
|
||||
public interface EntaxyRuntimeObjectService {
|
||||
|
||||
EntaxyRuntimeObject getRuntimeObject(EntaxyObject origin);
|
||||
EntaxyRuntimeObject getRuntimeObject(String runtimeObjectId);
|
||||
|
||||
EntaxyRuntimeObjectContainer getContainer(String containerName);
|
||||
|
||||
List<EntaxyRuntimeObject> getObjects();
|
||||
List<EntaxyRuntimeObject> getObjectsForContainer(EntaxyRuntimeObjectContainer container);
|
||||
public interface Listener {
|
||||
|
||||
void objectAdded(EntaxyRuntimeObject object);
|
||||
|
||||
void objectModified(EntaxyRuntimeObject object);
|
||||
|
||||
void objectRemoved(EntaxyRuntimeObject object);
|
||||
|
||||
}
|
||||
|
||||
void addListener(Listener listener);
|
||||
|
||||
void removeListener(Listener listener);
|
||||
|
||||
EntaxyRuntimeObject getRuntimeObject(EntaxyObject origin);
|
||||
|
||||
EntaxyRuntimeObject getRuntimeObject(String runtimeObjectId);
|
||||
|
||||
EntaxyRuntimeObjectContainer getContainer(String containerName);
|
||||
|
||||
List<EntaxyRuntimeObject> getObjects();
|
||||
|
||||
default List<EntaxyRuntimeObject> findObjects(String filter) throws InvalidSyntaxException {
|
||||
Filter osgiFilter = FrameworkUtil.createFilter(filter);
|
||||
return findObjects(osgiFilter);
|
||||
};
|
||||
|
||||
List<EntaxyRuntimeObject> findObjects(Filter filter);
|
||||
|
||||
Map<String, Object> getObjectEssense(EntaxyRuntimeObject object);
|
||||
|
||||
List<EntaxyRuntimeObject> getObjectsForContainer(EntaxyRuntimeObjectContainer container);
|
||||
|
||||
List<EntaxyRuntimeObjectContainer> getContainers();
|
||||
|
||||
EntaxyRuntimeObjectContainer getContainerForObject(EntaxyRuntimeObject runtimeObject);
|
||||
|
||||
EntaxyRuntimeObjectContainer getContainerForObject(String runtimeObjectId);
|
||||
|
||||
ENTAXY_RUNTIME_OBJECT_STATE getObjectState(String runtimeObjectId);
|
||||
|
||||
ENTAXY_RUNTIME_OBJECT_STATE getObjectState(EntaxyRuntimeObject runtimeObject);
|
||||
|
||||
default Map<String, Map<String, Object>> getExtendedObjectInfo(String runtimeObjectId) {
|
||||
EntaxyRuntimeObject entaxyRuntimeObject = getRuntimeObject(runtimeObjectId);
|
||||
if (entaxyRuntimeObject == null)
|
||||
return new HashMap<>();
|
||||
return getExtendedObjectInfo(entaxyRuntimeObject);
|
||||
};
|
||||
|
||||
Map<String, Map<String, Object>> getExtendedObjectInfo(EntaxyRuntimeObject runtimeObject);
|
||||
|
||||
List<EntaxyRuntimeObjectContainer> getContainers();
|
||||
|
||||
EntaxyRuntimeObjectContainer getContainerForObject(EntaxyRuntimeObject runtimeObject);
|
||||
EntaxyRuntimeObjectContainer getContainerForObject(String runtimeObjectId);
|
||||
|
||||
ENTAXY_RUNTIME_OBJECT_STATE getObjectState(String runtimeObjectId);
|
||||
ENTAXY_RUNTIME_OBJECT_STATE getObjectState(EntaxyRuntimeObject runtimeObject);
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -31,9 +31,13 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.FrameworkUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ru.entaxy.platform.base.objects.EntaxyObject;
|
||||
import ru.entaxy.platform.objects.runtime.EntaxyRuntimeObject;
|
||||
@ -41,149 +45,186 @@ import ru.entaxy.platform.objects.runtime.EntaxyRuntimeObjectContainer;
|
||||
|
||||
public abstract class EntaxyRuntimeObjectContainerImpl implements EntaxyRuntimeObjectContainer {
|
||||
|
||||
String id;
|
||||
String name;
|
||||
|
||||
Map<String, EntaxyRuntimeObjectImpl> objects = new HashMap<>();
|
||||
private static final Logger log = LoggerFactory.getLogger(EntaxyRuntimeObjectContainerImpl.class);
|
||||
|
||||
List<EntaxyRuntimeObject> objectsCache = new ArrayList<>();
|
||||
|
||||
public void bundle(Bundle bundle) {
|
||||
setId(bundle.getBundleId() + "");
|
||||
setName(bundle.getSymbolicName());
|
||||
}
|
||||
String id;
|
||||
String name;
|
||||
|
||||
public void bundle(long bundleId) {
|
||||
if (bundleId > 0) {
|
||||
Bundle b = FrameworkUtil.getBundle(this.getClass()).getBundleContext().getBundle(bundleId);
|
||||
if (b != null)
|
||||
bundle(b);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(EntaxyRuntimeObjectImpl object) {
|
||||
objects.put(object.getObjectFullId(), object);
|
||||
object.setContainerImpl(this);
|
||||
objectsCache.add((EntaxyRuntimeObject)object);
|
||||
}
|
||||
|
||||
public void remove(EntaxyRuntimeObjectImpl object) {
|
||||
objects.remove(object.getObjectFullId());
|
||||
object.setContainerImpl(null);
|
||||
objectsCache.remove((EntaxyRuntimeObject)object);
|
||||
}
|
||||
Map<String, EntaxyRuntimeObjectImpl> objects = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
List<EntaxyRuntimeObject> objectsCache = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
Object objectsLock = new Object();
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public void bundle(Bundle bundle) {
|
||||
setId(bundle.getBundleId() + "");
|
||||
setName(bundle.getSymbolicName());
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public void bundle(long bundleId) {
|
||||
bundle(bundleId, FrameworkUtil.getBundle(this.getClass()).getBundleContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeObject> getObjects() {
|
||||
return objectsCache;
|
||||
}
|
||||
public void bundle(long bundleId, BundleContext bundleContext) {
|
||||
if (bundleId > 0) {
|
||||
// try to find BundleContext that is not null
|
||||
// 'cause when first starting compact assembly
|
||||
// current context can be null due to refreshing
|
||||
BundleContext context = bundleContext;
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeObjectContainer> getParentContainers() {
|
||||
final Set<EntaxyRuntimeObjectContainer> containers = new HashSet<>();
|
||||
for (EntaxyRuntimeObjectImpl roi: this.objects.values()) {
|
||||
roi.getIncomingRelations().stream()
|
||||
.filter(r -> r.isSubordinating())
|
||||
.map(r -> r.getSource())
|
||||
.map(obj -> EntaxyRuntimeObjectServiceImpl.getInstance().getContainerForObject(obj.getObjectFullId()))
|
||||
.filter(cont -> (cont != null))
|
||||
.filter(cnt -> !this.id.equals(cnt.getId()))
|
||||
.forEach(cont -> containers.add(cont));
|
||||
}
|
||||
return new ArrayList<>(containers);
|
||||
}
|
||||
if (context == null)
|
||||
context = FrameworkUtil.getBundle(getClass()).getBundleContext();
|
||||
if (context == null)
|
||||
context = FrameworkUtil.getBundle(EntaxyObject.class).getBundleContext();
|
||||
if (context != null) {
|
||||
Bundle b = context.getBundle(bundleId);
|
||||
if (b != null)
|
||||
bundle(b);
|
||||
} else {
|
||||
log.error("NOT FOUND suitable BundleContext while creating container for [{}]", bundleId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeObjectContainer> getChildContainers() {
|
||||
final Set<EntaxyRuntimeObjectContainer> containers = new HashSet<>();
|
||||
for (EntaxyRuntimeObjectImpl roi: this.objects.values()) {
|
||||
roi.getRelations().stream()
|
||||
.filter(r -> r.isSubordinating())
|
||||
.map(r -> r.getTarget())
|
||||
.map(obj -> EntaxyRuntimeObjectServiceImpl.getInstance().getContainerForObject(obj.getObjectFullId()))
|
||||
.filter(cont -> (cont != null))
|
||||
.filter(cnt -> !this.id.equals(cnt.getId()))
|
||||
.forEach(cont -> containers.add(cont));
|
||||
}
|
||||
return new ArrayList<>(containers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeObjectContainer> getDependencies() {
|
||||
final Set<EntaxyRuntimeObjectContainer> containers = new HashSet<>();
|
||||
for (EntaxyRuntimeObjectImpl roi: this.objects.values()) {
|
||||
roi.getRelations().stream()
|
||||
.filter(r -> EntaxyObject.OBJECT_RELATION.DEPENDENCY.equals(r.getType()))
|
||||
.map(r -> r.getTarget())
|
||||
.map(obj -> EntaxyRuntimeObjectServiceImpl.getInstance().getContainerForObject(obj.getObjectFullId()))
|
||||
.filter(cont -> (cont != null))
|
||||
.filter(cnt -> !this.id.equals(cnt.getId()))
|
||||
.forEach(cont -> containers.add(cont));
|
||||
}
|
||||
return new ArrayList<>(containers);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeObjectContainer> getDependent() {
|
||||
final Set<EntaxyRuntimeObjectContainer> containers = new HashSet<>();
|
||||
for (EntaxyRuntimeObjectImpl roi: this.objects.values()) {
|
||||
roi.getIncomingRelations().stream()
|
||||
.filter(r -> EntaxyObject.OBJECT_RELATION.DEPENDENCY.equals(r.getType()))
|
||||
.map(r -> r.getSource())
|
||||
.map(obj -> EntaxyRuntimeObjectServiceImpl.getInstance().getContainerForObject(obj.getObjectFullId()))
|
||||
.filter(cont -> (cont != null))
|
||||
.filter(cnt -> !this.id.equals(cnt.getId()))
|
||||
.forEach(cont -> containers.add(cont));
|
||||
}
|
||||
return new ArrayList<>(containers);
|
||||
}
|
||||
public void add(EntaxyRuntimeObjectImpl object) {
|
||||
synchronized (objectsLock) {
|
||||
objects.put(object.getObjectFullId(), object);
|
||||
object.setContainerImpl(this);
|
||||
rebuildCache();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeObjectContainer> getRelatedContainers() {
|
||||
final Set<EntaxyRuntimeObjectContainer> containers = new HashSet<>();
|
||||
for (EntaxyRuntimeObjectImpl roi: this.objects.values()) {
|
||||
roi.getRelations().stream()
|
||||
.filter(r -> EntaxyObject.OBJECT_RELATION.DEPENDENCY.equals(r.getType()))
|
||||
.map(r -> r.getTarget())
|
||||
.map(obj -> EntaxyRuntimeObjectServiceImpl.getInstance().getContainerForObject(obj.getObjectFullId()))
|
||||
.filter(cont -> (cont != null))
|
||||
.filter(cnt -> !this.id.equals(cnt.getId()))
|
||||
.forEach(cont -> containers.add(cont));
|
||||
}
|
||||
return new ArrayList<>(containers);
|
||||
}
|
||||
public void remove(EntaxyRuntimeObjectImpl object) {
|
||||
synchronized (objectsLock) {
|
||||
objects.remove(object.getObjectFullId());
|
||||
object.setContainerImpl(null);
|
||||
rebuildCache();
|
||||
}
|
||||
}
|
||||
|
||||
protected void rebuildCache() {
|
||||
objectsCache.clear();
|
||||
objectsCache.addAll(objects.values().stream().map(v -> (EntaxyRuntimeObject) v).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeObject> getObjects() {
|
||||
return objectsCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeObjectContainer> getParentContainers() {
|
||||
final Set<EntaxyRuntimeObjectContainer> containers = new HashSet<>();
|
||||
for (EntaxyRuntimeObjectImpl roi : this.objects.values()) {
|
||||
roi.getIncomingRelations().stream()
|
||||
.filter(r -> r.isSubordinating())
|
||||
.map(r -> r.getSource())
|
||||
.map(obj -> EntaxyRuntimeObjectServiceImpl.getInstance()
|
||||
.getContainerForObject(obj.getObjectFullId()))
|
||||
.filter(cont -> (cont != null))
|
||||
.filter(cnt -> !this.id.equals(cnt.getId()))
|
||||
.forEach(cont -> containers.add(cont));
|
||||
}
|
||||
return new ArrayList<>(containers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeObjectContainer> getChildContainers() {
|
||||
final Set<EntaxyRuntimeObjectContainer> containers = new HashSet<>();
|
||||
for (EntaxyRuntimeObjectImpl roi : this.objects.values()) {
|
||||
roi.getRelations().stream()
|
||||
.filter(r -> r.isSubordinating())
|
||||
.map(r -> r.getTarget())
|
||||
.map(obj -> EntaxyRuntimeObjectServiceImpl.getInstance()
|
||||
.getContainerForObject(obj.getObjectFullId()))
|
||||
.filter(cont -> (cont != null))
|
||||
.filter(cnt -> !this.id.equals(cnt.getId()))
|
||||
.forEach(cont -> containers.add(cont));
|
||||
}
|
||||
return new ArrayList<>(containers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeObjectContainer> getDependencies() {
|
||||
final Set<EntaxyRuntimeObjectContainer> containers = new HashSet<>();
|
||||
for (EntaxyRuntimeObjectImpl roi : this.objects.values()) {
|
||||
roi.getRelations().stream()
|
||||
.filter(r -> EntaxyObject.OBJECT_RELATION.DEPENDENCY.equals(r.getType()))
|
||||
.map(r -> r.getTarget())
|
||||
.map(obj -> EntaxyRuntimeObjectServiceImpl.getInstance()
|
||||
.getContainerForObject(obj.getObjectFullId()))
|
||||
.filter(cont -> (cont != null))
|
||||
.filter(cnt -> !this.id.equals(cnt.getId()))
|
||||
.forEach(cont -> containers.add(cont));
|
||||
}
|
||||
return new ArrayList<>(containers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeObjectContainer> getDependent() {
|
||||
final Set<EntaxyRuntimeObjectContainer> containers = new HashSet<>();
|
||||
for (EntaxyRuntimeObjectImpl roi : this.objects.values()) {
|
||||
roi.getIncomingRelations().stream()
|
||||
.filter(r -> EntaxyObject.OBJECT_RELATION.DEPENDENCY.equals(r.getType()))
|
||||
.map(r -> r.getSource())
|
||||
.map(obj -> EntaxyRuntimeObjectServiceImpl.getInstance()
|
||||
.getContainerForObject(obj.getObjectFullId()))
|
||||
.filter(cont -> (cont != null))
|
||||
.filter(cnt -> !this.id.equals(cnt.getId()))
|
||||
.forEach(cont -> containers.add(cont));
|
||||
}
|
||||
return new ArrayList<>(containers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeObjectContainer> getRelatedContainers() {
|
||||
final Set<EntaxyRuntimeObjectContainer> containers = new HashSet<>();
|
||||
for (EntaxyRuntimeObjectImpl roi : this.objects.values()) {
|
||||
roi.getRelations().stream()
|
||||
.filter(r -> EntaxyObject.OBJECT_RELATION.DEPENDENCY.equals(r.getType()))
|
||||
.map(r -> r.getTarget())
|
||||
.map(obj -> EntaxyRuntimeObjectServiceImpl.getInstance()
|
||||
.getContainerForObject(obj.getObjectFullId()))
|
||||
.filter(cont -> (cont != null))
|
||||
.filter(cnt -> !this.id.equals(cnt.getId()))
|
||||
.forEach(cont -> containers.add(cont));
|
||||
}
|
||||
return new ArrayList<>(containers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeObjectContainer> getIncomingRelatedContainers() {
|
||||
final Set<EntaxyRuntimeObjectContainer> containers = new HashSet<>();
|
||||
for (EntaxyRuntimeObjectImpl roi : this.objects.values()) {
|
||||
roi.getIncomingRelations().stream()
|
||||
.filter(r -> EntaxyObject.OBJECT_RELATION.DEPENDENCY.equals(r.getType()))
|
||||
.map(r -> r.getSource())
|
||||
.map(obj -> EntaxyRuntimeObjectServiceImpl.getInstance()
|
||||
.getContainerForObject(obj.getObjectFullId()))
|
||||
.filter(cont -> (cont != null))
|
||||
.filter(cnt -> !this.id.equals(cnt.getId()))
|
||||
.forEach(cont -> containers.add(cont));
|
||||
}
|
||||
return new ArrayList<>(containers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeObjectContainer> getIncomingRelatedContainers() {
|
||||
final Set<EntaxyRuntimeObjectContainer> containers = new HashSet<>();
|
||||
for (EntaxyRuntimeObjectImpl roi: this.objects.values()) {
|
||||
roi.getIncomingRelations().stream()
|
||||
.filter(r -> EntaxyObject.OBJECT_RELATION.DEPENDENCY.equals(r.getType()))
|
||||
.map(r -> r.getSource())
|
||||
.map(obj -> EntaxyRuntimeObjectServiceImpl.getInstance().getContainerForObject(obj.getObjectFullId()))
|
||||
.filter(cont -> (cont != null))
|
||||
.filter(cnt -> !this.id.equals(cnt.getId()))
|
||||
.forEach(cont -> containers.add(cont));
|
||||
}
|
||||
return new ArrayList<>(containers);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -27,7 +27,9 @@ package ru.entaxy.platform.objects.runtime.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.osgi.framework.Bundle;
|
||||
@ -36,6 +38,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ru.entaxy.platform.base.objects.EntaxyObject;
|
||||
import ru.entaxy.platform.base.support.CommonUtils;
|
||||
import ru.entaxy.platform.base.support.osgi.bundle.BundleCapabilityHelper;
|
||||
import ru.entaxy.platform.base.support.osgi.bundle.CapabilityDescriptor;
|
||||
import ru.entaxy.platform.objects.runtime.EntaxyRuntimeObject;
|
||||
@ -44,273 +47,380 @@ import ru.entaxy.platform.objects.runtime.EntaxyRuntimeObjectResource;
|
||||
import ru.entaxy.platform.objects.runtime.EntaxyRuntimeRelation;
|
||||
|
||||
public class EntaxyRuntimeObjectImpl implements EntaxyRuntimeObject {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(EntaxyRuntimeObjectImpl.class);
|
||||
|
||||
private static final BundleInfo nullBundleInfo = new BundleInfo() {
|
||||
public long getBundleId() {
|
||||
return -1;
|
||||
};
|
||||
};
|
||||
|
||||
protected static EntaxyObject nullWrappedObject = new EntaxyObject() {
|
||||
|
||||
@Override
|
||||
public BundleInfo getBundleInfo() {
|
||||
return nullBundleInfo;
|
||||
}
|
||||
protected static final String CAPABILITY_PLATFORM = "platform";
|
||||
|
||||
@Override
|
||||
public String getConfiguration() {
|
||||
return "";
|
||||
}
|
||||
private static final Logger log = LoggerFactory.getLogger(EntaxyRuntimeObjectImpl.class);
|
||||
|
||||
@Override
|
||||
public String getFactoryId() {
|
||||
return "";
|
||||
}
|
||||
private static final BundleInfo nullBundleInfo = new BundleInfo() {
|
||||
public long getBundleId() {
|
||||
return -1;
|
||||
};
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "NULL-object";
|
||||
}
|
||||
protected static EntaxyObject nullWrappedObject = new EntaxyObject() {
|
||||
|
||||
@Override
|
||||
public List<Relation> getRelations() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@Override
|
||||
public BundleInfo getBundleInfo() {
|
||||
return nullBundleInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Relation> getIncomingRelations() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getScope() {
|
||||
return "";
|
||||
}
|
||||
@Override
|
||||
public String getConfiguration() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "";
|
||||
}
|
||||
@Override
|
||||
public String getFactoryId() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComplete() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public String getId() {
|
||||
return "NULL-object";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProvided() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGhost() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
EntaxyRuntimeObjectContainerImpl containerImpl;
|
||||
|
||||
protected EntaxyObject wrappedObject = nullWrappedObject;
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return getId();
|
||||
}
|
||||
|
||||
List<EntaxyRuntimeObjectResourceImpl> resources = new ArrayList<>();
|
||||
|
||||
public EntaxyRuntimeObjectImpl() {
|
||||
super();
|
||||
}
|
||||
|
||||
public EntaxyRuntimeObjectImpl(EntaxyObject object) {
|
||||
super();
|
||||
setWrappedObject(object);
|
||||
}
|
||||
|
||||
protected void reload(EntaxyObject object) {
|
||||
this.resources.clear();
|
||||
try {
|
||||
|
||||
// we assume that the object can be a ghost with no bundle info yet
|
||||
if (object.getBundleInfo() == null)
|
||||
return;
|
||||
|
||||
Bundle bundle = FrameworkUtil.getBundle(getClass()).getBundleContext().getBundle(object.getBundleInfo().getBundleId());
|
||||
BundleCapabilityHelper helper = new BundleCapabilityHelper(bundle);
|
||||
CapabilityDescriptor capability = helper.findObjectDeclaration(object.getId(), object.getType());
|
||||
if (capability != null) {
|
||||
Object resources = capability.getAttributes().get(CAPABILITIES_RUNTIME.ATTR_RESOURCES);
|
||||
if (resources != null) {
|
||||
if (resources instanceof List) {
|
||||
List<?> resourceList = (List)resources;
|
||||
for (Object resourceDesc: resourceList)
|
||||
if (resourceDesc == null)
|
||||
continue;
|
||||
else
|
||||
try {
|
||||
this.resources.add(EntaxyRuntimeObjectResourceImpl.create(resourceDesc.toString()));
|
||||
} catch (IllegalArgumentException iae) {
|
||||
log.warn("Error wrapping reeource ", iae);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("Reloading object [" + object.getObjectFullId() + "] failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BundleInfo getBundleInfo() {
|
||||
return wrappedObject.getBundleInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConfiguration() {
|
||||
return wrappedObject.getConfiguration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFactoryId() {
|
||||
return wrappedObject.getFactoryId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return wrappedObject.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Relation> getRelations() {
|
||||
return wrappedObject.getRelations();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Relation> getIncomingRelations() {
|
||||
return wrappedObject.getIncomingRelations();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getScope() {
|
||||
return wrappedObject.getScope();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return wrappedObject.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComplete() {
|
||||
return wrappedObject.isComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProvided() {
|
||||
return wrappedObject.isProvided();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGhost() {
|
||||
return wrappedObject.isGhost();
|
||||
}
|
||||
|
||||
public boolean isLoaded() {
|
||||
return (this.wrappedObject != null)
|
||||
&& (this.wrappedObject != nullWrappedObject);
|
||||
}
|
||||
|
||||
public EntaxyObject getWrappedObject() {
|
||||
return wrappedObject;
|
||||
}
|
||||
@Override
|
||||
public List<Relation> getRelations() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public void setWrappedObject(EntaxyObject wrappedObject) {
|
||||
reload(wrappedObject);
|
||||
this.wrappedObject = wrappedObject;
|
||||
}
|
||||
@Override
|
||||
public List<Relation> getIncomingRelations() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
EntaxyRuntimeObjectContainerImpl getContainerImpl() {
|
||||
return containerImpl;
|
||||
}
|
||||
@Override
|
||||
public String getScope() {
|
||||
return "";
|
||||
}
|
||||
|
||||
void setContainerImpl(EntaxyRuntimeObjectContainerImpl containerImpl) {
|
||||
this.containerImpl = containerImpl;
|
||||
}
|
||||
@Override
|
||||
public String getOwner() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isColocatedWith(EntaxyRuntimeObject object) {
|
||||
EntaxyRuntimeObjectContainer objectContainer = object.getContainer();
|
||||
if ((containerImpl == null) || (objectContainer == null))
|
||||
return false;
|
||||
return containerImpl.getId().equals(objectContainer.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeRelation> getRelations(OBJECT_RELATION relationType) {
|
||||
return getRelations().stream()
|
||||
.filter(r -> relationType.equals(r.getType()))
|
||||
.map(r -> new EntaxyRuntimeRelationImpl(r))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
@Override
|
||||
public String getType() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeRelation> getSubordRelations() {
|
||||
return getRelations().stream()
|
||||
.filter(r -> r.isSubordinating())
|
||||
.map(r -> new EntaxyRuntimeRelationImpl(r))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
@Override
|
||||
public boolean isComplete() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeRelation> getIncomiingRelations(OBJECT_RELATION relationType) {
|
||||
return getIncomingRelations().stream()
|
||||
.filter(r -> relationType.equals(r.getType()))
|
||||
.map(r -> new EntaxyRuntimeRelationImpl(r))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
@Override
|
||||
public boolean isProvided() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeRelation> getIncomiingSubordRelations() {
|
||||
return getIncomingRelations().stream()
|
||||
.filter(r -> r.isSubordinating())
|
||||
.map(r -> new EntaxyRuntimeRelationImpl(r))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
@Override
|
||||
public boolean isGhost() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeRelation> getDependsOn() {
|
||||
List<EntaxyRuntimeRelation> result = getIncomiingSubordRelations();
|
||||
result.addAll(getRelations(OBJECT_RELATION.DEPENDENCY));
|
||||
result.addAll(getRelations(OBJECT_RELATION.USE));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeRelation> getDependents() {
|
||||
List<EntaxyRuntimeRelation> result = getSubordRelations();
|
||||
result.addAll(getIncomiingRelations(OBJECT_RELATION.DEPENDENCY));
|
||||
result.addAll(getIncomiingRelations(OBJECT_RELATION.USE));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntaxyRuntimeObjectContainer getContainer() {
|
||||
return (EntaxyRuntimeObjectContainer)containerImpl;
|
||||
}
|
||||
// TODO find out the cause and remove this workaround
|
||||
static {
|
||||
try {
|
||||
EntaxyRuntimeObjectImpl.class.getClassLoader().loadClass(EntaxyRuntimeObjectResourceImpl.class.getName());
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeObject> getColocatedObjects() {
|
||||
if (containerImpl == null)
|
||||
return Collections.emptyList();
|
||||
return containerImpl.getObjects().stream()
|
||||
.filter(obj -> (obj!=this))
|
||||
.map(obj -> (EntaxyRuntimeObject)obj)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
EntaxyRuntimeObjectContainerImpl containerImpl;
|
||||
|
||||
protected EntaxyObject wrappedObject = nullWrappedObject;
|
||||
|
||||
List<EntaxyRuntimeObjectResourceImpl> resources = new ArrayList<>();
|
||||
|
||||
Map<String, Object> allAttributes = new HashMap<>();
|
||||
|
||||
protected boolean loadedSuccessfully = false;
|
||||
|
||||
public EntaxyRuntimeObjectImpl() {
|
||||
super();
|
||||
}
|
||||
|
||||
public EntaxyRuntimeObjectImpl(EntaxyObject object) {
|
||||
super();
|
||||
setWrappedObject(object);
|
||||
}
|
||||
|
||||
protected void reload(EntaxyObject object) {
|
||||
this.resources.clear();
|
||||
this.allAttributes.clear();
|
||||
loadedSuccessfully = false;
|
||||
try {
|
||||
|
||||
// we assume that the object can be a ghost with no bundle info yet
|
||||
if (object.getBundleInfo() == null)
|
||||
return;
|
||||
|
||||
Bundle bundle = FrameworkUtil.getBundle(getClass()).getBundleContext()
|
||||
.getBundle(object.getBundleInfo().getBundleId());
|
||||
BundleCapabilityHelper helper = new BundleCapabilityHelper(bundle);
|
||||
if (!helper.isLoaded())
|
||||
return;
|
||||
CapabilityDescriptor capability = helper.findObjectDeclaration(object.getId(), object.getType());
|
||||
checkIsPlatform(helper);
|
||||
if (capability != null) {
|
||||
allAttributes.putAll(capability.getAttributes());
|
||||
|
||||
Object resources = capability.getAttributes().get(CAPABILITIES_RUNTIME.ATTR_RESOURCES);
|
||||
if (resources != null) {
|
||||
if (resources instanceof List) {
|
||||
List<?> resourceList = (List) resources;
|
||||
for (Object resourceDesc : resourceList)
|
||||
if (resourceDesc == null)
|
||||
continue;
|
||||
else
|
||||
try {
|
||||
this.resources.add(EntaxyRuntimeObjectResourceImpl.create(resourceDesc.toString()));
|
||||
} catch (IllegalArgumentException iae) {
|
||||
log.warn("Error wrapping reeource ", iae);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
loadedSuccessfully = true;
|
||||
} catch (Exception e) {
|
||||
log.warn("Reloading object [" + object.getObjectFullId() + "] failed", e);
|
||||
loadedSuccessfully = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkIsPlatform(BundleCapabilityHelper helper) {
|
||||
List<CapabilityDescriptor> capabilities = helper.getEntaxyObjectsProvidedCapabilities();
|
||||
if (capabilities != null && capabilities.size() > 0) {
|
||||
Map<String, Object> attributes;
|
||||
for (CapabilityDescriptor capability : capabilities) {
|
||||
attributes = capability.getAttributes();
|
||||
if (attributes.containsKey(CAPABILITY_PLATFORM)) {
|
||||
allAttributes.put(CAPABILITY_PLATFORM, attributes.get(CAPABILITY_PLATFORM));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BundleInfo getBundleInfo() {
|
||||
return wrappedObject.getBundleInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConfiguration() {
|
||||
return wrappedObject.getConfiguration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFactoryId() {
|
||||
return wrappedObject.getFactoryId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return wrappedObject.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return wrappedObject.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Relation> getRelations() {
|
||||
return wrappedObject.getRelations();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Relation> getIncomingRelations() {
|
||||
return wrappedObject.getIncomingRelations();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getScope() {
|
||||
return wrappedObject.getScope();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOwner() {
|
||||
String owner = wrappedObject.getOwner();
|
||||
if (!CommonUtils.isValid(owner) && EntaxyObject.OBJECT_SCOPE.PRIVATE.equals(getScope())) {
|
||||
// private objects can't exists without owner
|
||||
// so we'll suppose owner as first composite
|
||||
// and if no, then first aggregate
|
||||
|
||||
List<EntaxyRuntimeRelation> relations = getIncomiingRelations(OBJECT_RELATION.COMPOSITION);
|
||||
if (!relations.isEmpty())
|
||||
return relations.get(0).getMain().getObjectFullId();
|
||||
|
||||
relations = getIncomiingRelations(OBJECT_RELATION.AGGREGATION);
|
||||
if (!relations.isEmpty())
|
||||
return relations.get(0).getMain().getObjectFullId();
|
||||
|
||||
}
|
||||
return owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return wrappedObject.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComplete() {
|
||||
return wrappedObject.isComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProvided() {
|
||||
return wrappedObject.isProvided();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGhost() {
|
||||
return wrappedObject.isGhost();
|
||||
}
|
||||
|
||||
public boolean isLoaded() {
|
||||
return (this.wrappedObject != null)
|
||||
&& (this.wrappedObject != nullWrappedObject);
|
||||
}
|
||||
|
||||
public EntaxyObject getWrappedObject() {
|
||||
return wrappedObject;
|
||||
}
|
||||
|
||||
public void setWrappedObject(EntaxyObject wrappedObject) {
|
||||
reload(wrappedObject);
|
||||
this.wrappedObject = wrappedObject;
|
||||
}
|
||||
|
||||
EntaxyRuntimeObjectContainerImpl getContainerImpl() {
|
||||
return containerImpl;
|
||||
}
|
||||
|
||||
void setContainerImpl(EntaxyRuntimeObjectContainerImpl containerImpl) {
|
||||
this.containerImpl = containerImpl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isColocatedWith(EntaxyRuntimeObject object) {
|
||||
EntaxyRuntimeObjectContainer objectContainer = object.getContainer();
|
||||
if ((containerImpl == null) || (objectContainer == null))
|
||||
return false;
|
||||
return containerImpl.getId().equals(objectContainer.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeRelation> getRelations(OBJECT_RELATION relationType) {
|
||||
return getRelations().stream()
|
||||
.filter(r -> relationType.equals(r.getType()))
|
||||
.map(r -> new EntaxyRuntimeRelationImpl(r))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeRelation> getSubordRelations() {
|
||||
return getRelations().stream()
|
||||
.filter(r -> r.isSubordinating())
|
||||
.map(r -> new EntaxyRuntimeRelationImpl(r))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeRelation> getIncomiingRelations(OBJECT_RELATION relationType) {
|
||||
return getIncomingRelations().stream()
|
||||
.filter(r -> relationType.equals(r.getType()))
|
||||
.map(r -> new EntaxyRuntimeRelationImpl(r))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeRelation> getIncomiingSubordRelations() {
|
||||
return getIncomingRelations().stream()
|
||||
.filter(r -> r.isSubordinating())
|
||||
.map(r -> new EntaxyRuntimeRelationImpl(r))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeRelation> getDependsOn() {
|
||||
List<EntaxyRuntimeRelation> result = getIncomiingSubordRelations();
|
||||
result.addAll(getRelations(OBJECT_RELATION.DEPENDENCY));
|
||||
result.addAll(getRelations(OBJECT_RELATION.USE));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeRelation> getDependents() {
|
||||
List<EntaxyRuntimeRelation> result = getSubordRelations();
|
||||
result.addAll(getIncomiingRelations(OBJECT_RELATION.DEPENDENCY));
|
||||
result.addAll(getIncomiingRelations(OBJECT_RELATION.USE));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntaxyRuntimeObjectContainer getContainer() {
|
||||
return (EntaxyRuntimeObjectContainer) containerImpl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeObject> getColocatedObjects() {
|
||||
if (containerImpl == null)
|
||||
return Collections.emptyList();
|
||||
return containerImpl.getObjects().stream()
|
||||
.filter(obj -> (obj != this))
|
||||
.map(obj -> (EntaxyRuntimeObject) obj)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeObjectResource> getResources() {
|
||||
return internalGetResources().stream().map(res -> (EntaxyRuntimeObjectResource) res)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getAllAttributes() {
|
||||
return internalGetAllAttributes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAttribute(String name) {
|
||||
return internalGetAllAttributes().containsKey(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getAttribute(String name) {
|
||||
return internalGetAllAttributes().get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getAttributeOrDefault(String name, Object defaultValue) {
|
||||
return internalGetAllAttributes().getOrDefault(name, defaultValue);
|
||||
}
|
||||
|
||||
protected Map<String, Object> internalGetAllAttributes() {
|
||||
if (!loadedSuccessfully)
|
||||
reload(wrappedObject);
|
||||
return allAttributes;
|
||||
}
|
||||
|
||||
protected List<EntaxyRuntimeObjectResourceImpl> internalGetResources() {
|
||||
if (!loadedSuccessfully)
|
||||
reload(wrappedObject);
|
||||
return this.resources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeObjectResource> getResources() {
|
||||
return this.resources.stream().map(res -> (EntaxyRuntimeObjectResource)res).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -26,173 +26,329 @@
|
||||
package ru.entaxy.platform.objects.runtime.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.karaf.bundle.core.BundleService;
|
||||
import org.osgi.framework.Filter;
|
||||
import org.osgi.service.component.ComponentContext;
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Deactivate;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
import org.osgi.service.component.annotations.ReferenceCardinality;
|
||||
import org.osgi.service.component.annotations.ReferencePolicy;
|
||||
import org.osgi.service.component.annotations.ReferencePolicyOption;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ru.entaxy.esb.resources.EntaxyResourceService;
|
||||
import ru.entaxy.platform.base.objects.EntaxyObject;
|
||||
import ru.entaxy.platform.base.objects.EntaxyObjectService;
|
||||
import ru.entaxy.platform.base.objects.EntaxyObjectServiceListener;
|
||||
import ru.entaxy.platform.core.artifact.service.ArtifactService;
|
||||
import ru.entaxy.platform.objects.runtime.EntaxyObjectCustomizer;
|
||||
import ru.entaxy.platform.objects.runtime.EntaxyRuntimeObject;
|
||||
import ru.entaxy.platform.objects.runtime.EntaxyRuntimeObject.ENTAXY_RUNTIME_OBJECT_STATE;
|
||||
import ru.entaxy.platform.objects.runtime.EntaxyRuntimeObjectContainer;
|
||||
import ru.entaxy.platform.objects.runtime.EntaxyRuntimeObjectContainer.ENTAXY_RUNTIME_OBJECT_CONTAINER_STATE;
|
||||
import ru.entaxy.platform.objects.runtime.EntaxyRuntimeObjectExtendedDataProvider;
|
||||
import ru.entaxy.platform.objects.runtime.EntaxyRuntimeObjectService;
|
||||
import ru.entaxy.platform.objects.runtime.EntaxyRuntimeObject.ENTAXY_RUNTIME_OBJECT_STATE;
|
||||
|
||||
@Component (service = EntaxyRuntimeObjectService.class, immediate = true)
|
||||
@Component(service = EntaxyRuntimeObjectService.class, immediate = true)
|
||||
public class EntaxyRuntimeObjectServiceImpl implements EntaxyRuntimeObjectService, EntaxyObjectServiceListener {
|
||||
|
||||
private static EntaxyRuntimeObjectServiceImpl INSTANCE = null;
|
||||
|
||||
public static EntaxyRuntimeObjectServiceImpl getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Reference (cardinality = ReferenceCardinality.MANDATORY, policyOption = ReferencePolicyOption.GREEDY)
|
||||
protected EntaxyObjectService objectService;
|
||||
|
||||
@Reference (cardinality = ReferenceCardinality.MANDATORY, policyOption = ReferencePolicyOption.GREEDY)
|
||||
protected EntaxyResourceService resourceService;
|
||||
|
||||
@Reference (cardinality = ReferenceCardinality.MANDATORY, policyOption = ReferencePolicyOption.GREEDY)
|
||||
protected BundleService bundleService;
|
||||
private static final Logger log = LoggerFactory.getLogger(EntaxyRuntimeObjectServiceImpl.class);
|
||||
|
||||
@Reference(cardinality = ReferenceCardinality.MANDATORY, policyOption = ReferencePolicyOption.GREEDY)
|
||||
ArtifactService artifactService;
|
||||
|
||||
protected Object storageLock = new Object();
|
||||
|
||||
protected ObjectRuntimeStorage storage = new ObjectRuntimeStorage();
|
||||
|
||||
@Activate
|
||||
public void activate(ComponentContext componentContext) {
|
||||
INSTANCE = this;
|
||||
objectService.addListener(this);
|
||||
synchronized (storageLock) {
|
||||
fillCurrentObjects();
|
||||
}
|
||||
}
|
||||
|
||||
protected void fillCurrentObjects() {
|
||||
// make a copy
|
||||
List<EntaxyObject> objectsList = new ArrayList<>(objectService.getObjects());
|
||||
for (EntaxyObject obj: objectsList)
|
||||
storage.add(obj);
|
||||
}
|
||||
|
||||
// EntaxyObjectServiceListener
|
||||
|
||||
@Override
|
||||
public void objectAdded(EntaxyObject entaxyObject) {
|
||||
synchronized (storageLock) {
|
||||
storage.add(entaxyObject);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void objectModified(EntaxyObject entaxyObject) {
|
||||
synchronized (storageLock) {
|
||||
storage.update(entaxyObject);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void objectRemoved(EntaxyObject entaxyObject) {
|
||||
synchronized (storageLock) {
|
||||
storage.remove(entaxyObject);
|
||||
}
|
||||
}
|
||||
private static EntaxyRuntimeObjectServiceImpl INSTANCE = null;
|
||||
|
||||
// EntaxyRuntimeObjectService
|
||||
|
||||
@Override
|
||||
public EntaxyRuntimeObject getRuntimeObject(EntaxyObject origin) {
|
||||
return this.storage.objects.get(origin.getObjectFullId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntaxyRuntimeObject getRuntimeObject(String runtimeObjectId) {
|
||||
return this.storage.objects.get(runtimeObjectId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntaxyRuntimeObjectContainer getContainer(String containerName) {
|
||||
Optional<EntaxyRuntimeObjectContainer> container = storage.containers.values().stream()
|
||||
.filter(c -> containerName.equalsIgnoreCase(c.getName()))
|
||||
.map(c -> (EntaxyRuntimeObjectContainer)c)
|
||||
.findFirst();
|
||||
return container.isPresent()?container.get():null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeObject> getObjects() {
|
||||
return this.storage.objectsCache;
|
||||
}
|
||||
public static EntaxyRuntimeObjectServiceImpl getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeObject> getObjectsForContainer(EntaxyRuntimeObjectContainer container) {
|
||||
return container.getObjects();
|
||||
}
|
||||
@Reference(cardinality = ReferenceCardinality.MANDATORY, policyOption = ReferencePolicyOption.GREEDY,
|
||||
policy = ReferencePolicy.DYNAMIC)
|
||||
volatile protected EntaxyObjectService objectService;
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeObjectContainer> getContainers() {
|
||||
return storage.containers.values().stream().map(c -> (EntaxyRuntimeObjectContainer)c).collect(Collectors.toList());
|
||||
}
|
||||
@Reference(cardinality = ReferenceCardinality.MANDATORY, policyOption = ReferencePolicyOption.GREEDY,
|
||||
policy = ReferencePolicy.DYNAMIC)
|
||||
volatile protected EntaxyResourceService resourceService;
|
||||
|
||||
@Override
|
||||
public EntaxyRuntimeObjectContainer getContainerForObject(EntaxyRuntimeObject runtimeObject) {
|
||||
return runtimeObject.getContainer();
|
||||
}
|
||||
@Reference(cardinality = ReferenceCardinality.MANDATORY, policyOption = ReferencePolicyOption.GREEDY,
|
||||
policy = ReferencePolicy.DYNAMIC)
|
||||
volatile protected BundleService bundleService;
|
||||
|
||||
@Override
|
||||
public EntaxyRuntimeObjectContainer getContainerForObject(String runtimeObjectId) {
|
||||
EntaxyRuntimeObjectImpl impl = storage.objects.get(runtimeObjectId);
|
||||
if (impl == null)
|
||||
return null;
|
||||
return impl.getContainer();
|
||||
}
|
||||
@Reference(cardinality = ReferenceCardinality.MANDATORY, policyOption = ReferencePolicyOption.GREEDY,
|
||||
policy = ReferencePolicy.DYNAMIC)
|
||||
volatile ArtifactService artifactService;
|
||||
|
||||
@Override
|
||||
public ENTAXY_RUNTIME_OBJECT_STATE getObjectState(String runtimeObjectId) {
|
||||
return getObjectState(getRuntimeObject(runtimeObjectId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ENTAXY_RUNTIME_OBJECT_STATE getObjectState(EntaxyRuntimeObject runtimeObject) {
|
||||
if (runtimeObject == null)
|
||||
return ENTAXY_RUNTIME_OBJECT_STATE.UNKNOWN;
|
||||
EntaxyRuntimeObjectContainer container = runtimeObject.getContainer();
|
||||
try {
|
||||
ENTAXY_RUNTIME_OBJECT_CONTAINER_STATE containerState = container.getState();
|
||||
if (ENTAXY_RUNTIME_OBJECT_CONTAINER_STATE.Active.equals(containerState))
|
||||
return ENTAXY_RUNTIME_OBJECT_STATE.ACTIVE;
|
||||
return ENTAXY_RUNTIME_OBJECT_STATE.INACTIVE;
|
||||
} catch (Exception e) {
|
||||
return ENTAXY_RUNTIME_OBJECT_STATE.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
// others
|
||||
|
||||
public EntaxyResourceService getResourceService() {
|
||||
return resourceService;
|
||||
}
|
||||
|
||||
public BundleService getBundleService() {
|
||||
return bundleService;
|
||||
}
|
||||
|
||||
public ArtifactService getArtifactService() {
|
||||
return artifactService;
|
||||
}
|
||||
protected List<Listener> listeners = new ArrayList<>();
|
||||
|
||||
protected Object storageLock = new Object();
|
||||
|
||||
protected ObjectRuntimeStorage storage = new ObjectRuntimeStorage();
|
||||
|
||||
protected List<EntaxyObjectCustomizer> customizers = new ArrayList<>();
|
||||
|
||||
protected Object customizersLock = new Object();
|
||||
|
||||
protected Map<String, EntaxyRuntimeObjectExtendedDataProvider> extendedDataProviders = new HashMap<>();
|
||||
|
||||
protected Object extendedDataProvidersLock = new Object();
|
||||
|
||||
@Activate
|
||||
public void activate(ComponentContext componentContext) {
|
||||
INSTANCE = this;
|
||||
storage.setBundleContext(componentContext.getBundleContext());
|
||||
objectService.addListener(this);
|
||||
synchronized (storageLock) {
|
||||
fillCurrentObjects();
|
||||
}
|
||||
}
|
||||
|
||||
@Deactivate
|
||||
public void deactivate() {
|
||||
storage.setBundleContext(null);
|
||||
try {
|
||||
objectService.removeListener(this);
|
||||
} catch (Exception ex) {
|
||||
log.trace(ex.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC,
|
||||
policyOption = ReferencePolicyOption.GREEDY, unbind = "removeCustomizer")
|
||||
public void addCustomizer(EntaxyObjectCustomizer customizer) {
|
||||
synchronized (customizersLock) {
|
||||
customizers.add(customizer);
|
||||
synchronized (storageLock) {
|
||||
for (EntaxyRuntimeObjectImpl object : storage.objects.values()) {
|
||||
if (customizer.isAccepted(object.getWrappedObject())) {
|
||||
storage.update(customizer.applyCustomization(object.getWrappedObject()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeCustomizer(EntaxyObjectCustomizer customizer) {
|
||||
customizers.add(customizer);
|
||||
synchronized (storageLock) {
|
||||
for (EntaxyRuntimeObjectImpl object : storage.objects.values()) {
|
||||
if (customizer.isAccepted(object.getWrappedObject())) {
|
||||
storage.update(customizer.unapplyCustomization(object.getWrappedObject()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC,
|
||||
policyOption = ReferencePolicyOption.GREEDY, unbind = "removeExtendedDataProvider")
|
||||
public void addExtendedDataProvider(EntaxyRuntimeObjectExtendedDataProvider dataProvider) {
|
||||
synchronized (extendedDataProvidersLock) {
|
||||
this.extendedDataProviders.put(dataProvider.getProviderId(), dataProvider);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeExtendedDataProvider(EntaxyRuntimeObjectExtendedDataProvider dataProvider) {
|
||||
synchronized (extendedDataProvidersLock) {
|
||||
this.extendedDataProviders.remove(dataProvider.getProviderId());
|
||||
}
|
||||
}
|
||||
|
||||
protected void fillCurrentObjects() {
|
||||
// make a copy
|
||||
List<EntaxyObject> objectsList = new ArrayList<>(objectService.getObjects());
|
||||
for (EntaxyObject obj : objectsList)
|
||||
storage.add(customize(obj));
|
||||
}
|
||||
|
||||
protected EntaxyObject customize(EntaxyObject object) {
|
||||
synchronized (customizersLock) {
|
||||
for (EntaxyObjectCustomizer customizer : customizers) {
|
||||
if (customizer.isAccepted(object))
|
||||
return customizer.applyCustomization(object);
|
||||
}
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
// EntaxyObjectServiceListener
|
||||
|
||||
@Override
|
||||
public void objectAdded(EntaxyObject entaxyObject) {
|
||||
synchronized (storageLock) {
|
||||
storage.add(customize(entaxyObject));
|
||||
}
|
||||
EntaxyRuntimeObject runtimeObject = getRuntimeObject(entaxyObject);
|
||||
if (runtimeObject == null)
|
||||
return;
|
||||
for (Listener l : listeners) {
|
||||
l.objectAdded(runtimeObject);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void objectModified(EntaxyObject entaxyObject) {
|
||||
synchronized (storageLock) {
|
||||
storage.update(customize(entaxyObject));
|
||||
}
|
||||
EntaxyRuntimeObject runtimeObject = getRuntimeObject(entaxyObject);
|
||||
if (runtimeObject == null)
|
||||
return;
|
||||
for (Listener l : listeners) {
|
||||
l.objectModified(runtimeObject);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void objectRemoved(EntaxyObject entaxyObject) {
|
||||
EntaxyRuntimeObject runtimeObject = getRuntimeObject(entaxyObject);
|
||||
synchronized (storageLock) {
|
||||
storage.remove(entaxyObject);
|
||||
}
|
||||
if (runtimeObject == null)
|
||||
return;
|
||||
for (Listener l : listeners) {
|
||||
l.objectRemoved(runtimeObject);
|
||||
}
|
||||
}
|
||||
|
||||
// EntaxyRuntimeObjectService
|
||||
|
||||
@Override
|
||||
public void addListener(Listener listener) {
|
||||
removeListener(listener);
|
||||
this.listeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(Listener listener) {
|
||||
this.listeners.remove(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntaxyRuntimeObject getRuntimeObject(EntaxyObject origin) {
|
||||
return this.storage.objects.get(origin.getObjectFullId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntaxyRuntimeObject getRuntimeObject(String runtimeObjectId) {
|
||||
return this.storage.objects.get(runtimeObjectId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntaxyRuntimeObjectContainer getContainer(String containerName) {
|
||||
Optional<EntaxyRuntimeObjectContainer> container = storage.containers.values().stream()
|
||||
.filter(c -> containerName.equalsIgnoreCase(c.getName()))
|
||||
.map(c -> (EntaxyRuntimeObjectContainer) c)
|
||||
.findFirst();
|
||||
return container.isPresent() ? container.get() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeObject> getObjects() {
|
||||
return this.storage.objectsCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeObject> findObjects(final Filter filter) {
|
||||
|
||||
return getObjects().stream()
|
||||
.filter(obj -> filter.matches(getObjectEssense(obj)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getObjectEssense(EntaxyRuntimeObject object) {
|
||||
Map<String, Object> result = new HashMap<>(object.getAllAttributes());
|
||||
result.put("type", object.getType());
|
||||
|
||||
EntaxyRuntimeObjectContainer container = object.getContainer();
|
||||
if (container != null) {
|
||||
result.put("container.id", container.getId());
|
||||
result.put("container.name", container.getName());
|
||||
result.put("container.type", container.getType());
|
||||
result.put("container.state", container.getState().name());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeObject> getObjectsForContainer(EntaxyRuntimeObjectContainer container) {
|
||||
return container.getObjects();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EntaxyRuntimeObjectContainer> getContainers() {
|
||||
return storage.containers.values().stream().map(c -> (EntaxyRuntimeObjectContainer) c)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntaxyRuntimeObjectContainer getContainerForObject(EntaxyRuntimeObject runtimeObject) {
|
||||
return runtimeObject.getContainer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntaxyRuntimeObjectContainer getContainerForObject(String runtimeObjectId) {
|
||||
EntaxyRuntimeObjectImpl impl = storage.objects.get(runtimeObjectId);
|
||||
if (impl == null)
|
||||
return null;
|
||||
return impl.getContainer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Map<String, Object>> getExtendedObjectInfo(EntaxyRuntimeObject runtimeObject) {
|
||||
Map<String, Map<String, Object>> result = new HashMap<>();
|
||||
synchronized (extendedDataProvidersLock) {
|
||||
for (Map.Entry<String, EntaxyRuntimeObjectExtendedDataProvider> entry : extendedDataProviders.entrySet()) {
|
||||
Map<String, Object> providerResult = entry.getValue().getExtendedData(runtimeObject);
|
||||
if (providerResult != null)
|
||||
result.put(entry.getKey(), providerResult);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ENTAXY_RUNTIME_OBJECT_STATE getObjectState(String runtimeObjectId) {
|
||||
return getObjectState(getRuntimeObject(runtimeObjectId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ENTAXY_RUNTIME_OBJECT_STATE getObjectState(EntaxyRuntimeObject runtimeObject) {
|
||||
if (runtimeObject == null)
|
||||
return ENTAXY_RUNTIME_OBJECT_STATE.UNKNOWN;
|
||||
EntaxyRuntimeObjectContainer container = runtimeObject.getContainer();
|
||||
try {
|
||||
ENTAXY_RUNTIME_OBJECT_CONTAINER_STATE containerState = container.getState();
|
||||
if (ENTAXY_RUNTIME_OBJECT_CONTAINER_STATE.Active.equals(containerState))
|
||||
return ENTAXY_RUNTIME_OBJECT_STATE.ACTIVE;
|
||||
return ENTAXY_RUNTIME_OBJECT_STATE.INACTIVE;
|
||||
} catch (Exception e) {
|
||||
return ENTAXY_RUNTIME_OBJECT_STATE.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
// others
|
||||
|
||||
public EntaxyResourceService getResourceService() {
|
||||
return resourceService;
|
||||
}
|
||||
|
||||
public BundleService getBundleService() {
|
||||
return bundleService;
|
||||
}
|
||||
|
||||
public ArtifactService getArtifactService() {
|
||||
return artifactService;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -30,85 +30,98 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.hazelcast.map.impl.mapstore.writethrough.WriteThroughStore;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
import ru.entaxy.platform.base.objects.EntaxyObject;
|
||||
import ru.entaxy.platform.objects.runtime.EntaxyRuntimeObject;
|
||||
|
||||
public class ObjectRuntimeStorage {
|
||||
|
||||
EntaxyRuntimeObjectContainerImpl ghostsContainer;
|
||||
|
||||
Map<String, EntaxyRuntimeObjectContainerImpl> containers = new HashMap<>();
|
||||
|
||||
Map<String, EntaxyRuntimeObjectImpl> objects = new HashMap<>();
|
||||
|
||||
List<EntaxyRuntimeObject> objectsCache = new ArrayList<>();
|
||||
|
||||
protected Object containersLock = new Object();
|
||||
|
||||
public ObjectRuntimeStorage() {
|
||||
super();
|
||||
ghostsContainer = new EntaxyRuntimeObjectContainerBundle();
|
||||
}
|
||||
|
||||
public void add(EntaxyObject object) {
|
||||
|
||||
if (!object.isGhost()) {
|
||||
|
||||
long bundleId = object.getBundleInfo().getBundleId();
|
||||
EntaxyRuntimeObjectContainerImpl container = getCreateBundleContainer(bundleId);
|
||||
EntaxyRuntimeObjectImpl wrapped = wrap(object);
|
||||
container.add(wrapped);
|
||||
|
||||
} else {
|
||||
|
||||
EntaxyRuntimeObjectContainerImpl container = ghostsContainer;
|
||||
EntaxyRuntimeObjectImpl wrapped = wrap(object);
|
||||
container.add(wrapped);
|
||||
|
||||
}
|
||||
EntaxyRuntimeObjectContainerImpl ghostsContainer;
|
||||
|
||||
rebuildCache();
|
||||
}
|
||||
|
||||
public void update(EntaxyObject object) {
|
||||
add(object);
|
||||
rebuildCache();
|
||||
}
|
||||
Map<String, EntaxyRuntimeObjectContainerImpl> containers = new HashMap<>();
|
||||
|
||||
public void remove(EntaxyObject object) {
|
||||
EntaxyRuntimeObjectImpl impl = objects.get(object.getObjectFullId());
|
||||
if (impl == null)
|
||||
return;
|
||||
|
||||
objects.remove(object.getObjectFullId());
|
||||
|
||||
rebuildCache();
|
||||
}
|
||||
Map<String, EntaxyRuntimeObjectImpl> objects = new HashMap<>();
|
||||
|
||||
List<EntaxyRuntimeObject> objectsCache = new ArrayList<>();
|
||||
|
||||
protected Object containersLock = new Object();
|
||||
|
||||
protected BundleContext bundleContext;
|
||||
|
||||
public ObjectRuntimeStorage() {
|
||||
super();
|
||||
ghostsContainer = new EntaxyRuntimeObjectContainerBundle();
|
||||
}
|
||||
|
||||
public void add(EntaxyObject object) {
|
||||
|
||||
if (!object.isGhost()) {
|
||||
|
||||
long bundleId = object.getBundleInfo().getBundleId();
|
||||
EntaxyRuntimeObjectContainerImpl container = getCreateBundleContainer(bundleId);
|
||||
EntaxyRuntimeObjectImpl wrapped = wrap(object);
|
||||
container.add(wrapped);
|
||||
|
||||
} else {
|
||||
|
||||
EntaxyRuntimeObjectContainerImpl container = ghostsContainer;
|
||||
EntaxyRuntimeObjectImpl wrapped = wrap(object);
|
||||
container.add(wrapped);
|
||||
|
||||
}
|
||||
|
||||
rebuildCache();
|
||||
}
|
||||
|
||||
public void update(EntaxyObject object) {
|
||||
add(object);
|
||||
rebuildCache();
|
||||
}
|
||||
|
||||
public void remove(EntaxyObject object) {
|
||||
EntaxyRuntimeObjectImpl impl = objects.get(object.getObjectFullId());
|
||||
if (impl == null)
|
||||
return;
|
||||
|
||||
impl.getContainerImpl().remove(impl);
|
||||
|
||||
objects.remove(object.getObjectFullId());
|
||||
|
||||
rebuildCache();
|
||||
}
|
||||
|
||||
protected synchronized void rebuildCache() {
|
||||
this.objectsCache.clear();
|
||||
this.objects.values().stream().map(obj -> (EntaxyRuntimeObject) obj).forEach(obj -> this.objectsCache.add(obj));
|
||||
}
|
||||
|
||||
protected EntaxyRuntimeObjectImpl wrap(EntaxyObject object) {
|
||||
if (objects.containsKey(object.getObjectFullId()))
|
||||
objects.get(object.getObjectFullId()).setWrappedObject(object);
|
||||
else
|
||||
objects.put(object.getObjectFullId(), new EntaxyRuntimeObjectImpl(object));
|
||||
return objects.get(object.getObjectFullId());
|
||||
}
|
||||
|
||||
protected EntaxyRuntimeObjectContainerImpl getCreateBundleContainer(long bundleId) {
|
||||
String containerId = bundleId + "";
|
||||
synchronized (containersLock) {
|
||||
if (!containers.containsKey(containerId)) {
|
||||
EntaxyRuntimeObjectContainerImpl containerImpl = new EntaxyRuntimeObjectContainerBundle();
|
||||
containerImpl.bundle(bundleId, bundleContext);
|
||||
containers.put(containerImpl.getId(), containerImpl);
|
||||
}
|
||||
}
|
||||
return containers.get(containerId);
|
||||
}
|
||||
|
||||
public BundleContext getBundleContext() {
|
||||
return bundleContext;
|
||||
}
|
||||
|
||||
public void setBundleContext(BundleContext bundleContext) {
|
||||
this.bundleContext = bundleContext;
|
||||
}
|
||||
|
||||
protected synchronized void rebuildCache() {
|
||||
this.objectsCache.clear();
|
||||
this.objects.values().stream().map(obj -> (EntaxyRuntimeObject)obj).forEach(obj -> this.objectsCache.add(obj));
|
||||
}
|
||||
|
||||
protected EntaxyRuntimeObjectImpl wrap(EntaxyObject object) {
|
||||
if (objects.containsKey(object.getObjectFullId()))
|
||||
objects.get(object.getObjectFullId()).setWrappedObject(object);
|
||||
else
|
||||
objects.put(object.getObjectFullId(), new EntaxyRuntimeObjectImpl(object));
|
||||
return objects.get(object.getObjectFullId());
|
||||
}
|
||||
|
||||
protected EntaxyRuntimeObjectContainerImpl getCreateBundleContainer(long bundleId) {
|
||||
String containerId = bundleId + "";
|
||||
synchronized (containersLock) {
|
||||
if (!containers.containsKey(containerId)) {
|
||||
EntaxyRuntimeObjectContainerImpl containerImpl = new EntaxyRuntimeObjectContainerBundle();
|
||||
containerImpl.bundle(bundleId);
|
||||
containers.put(containerImpl.getId(), containerImpl);
|
||||
}
|
||||
}
|
||||
return containers.get(containerId);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -33,6 +33,7 @@ import java.util.stream.Collectors;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ru.entaxy.platform.base.objects.EntaxyObject;
|
||||
import ru.entaxy.platform.base.objects.EntaxyObject.OBJECT_RELATION;
|
||||
import ru.entaxy.platform.core.artifact.legacy.BundleController;
|
||||
import ru.entaxy.platform.objects.runtime.EntaxyRuntimeObject;
|
||||
@ -59,6 +60,9 @@ public class OperationExecutorStop extends OperationExecutor<OperationExecutorSt
|
||||
|
||||
List<EntaxyRuntimeObject> objects = relations.stream()
|
||||
.map(rel -> rel.getDependent())
|
||||
.filter(obj ->
|
||||
!runtimeObject.isColocatedWith(obj) ||
|
||||
!EntaxyObject.OBJECT_SCOPE.PRIVATE.equals(obj.getScope()))
|
||||
.filter(obj -> ENTAXY_RUNTIME_OBJECT_STATE.ACTIVE.equals(getObjectState(obj)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -34,6 +34,7 @@ import java.util.stream.Collectors;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ru.entaxy.platform.base.objects.EntaxyObject;
|
||||
import ru.entaxy.platform.base.objects.EntaxyObject.OBJECT_RELATION;
|
||||
import ru.entaxy.platform.objects.runtime.EntaxyRuntimeObject;
|
||||
import ru.entaxy.platform.objects.runtime.EntaxyRuntimeRelation;
|
||||
@ -56,6 +57,9 @@ public class OperationExecutorUninstall extends OperationExecutor<OperationExecu
|
||||
|
||||
List<EntaxyRuntimeObject> objects = relations.stream()
|
||||
.map(rel -> rel.getDependent())
|
||||
.filter(obj ->
|
||||
!runtimeObject.isColocatedWith(obj) ||
|
||||
!EntaxyObject.OBJECT_SCOPE.PRIVATE.equals(obj.getScope()))
|
||||
.filter(obj -> ENTAXY_RUNTIME_OBJECT_STATE.ACTIVE.equals(getObjectState(obj)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-core
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.core</groupId>
|
||||
<artifactId>object-runtime</artifactId>
|
||||
<version>1.9.0</version>
|
||||
<version>1.10.0</version>
|
||||
</parent>
|
||||
<artifactId>object-runtime-shell</artifactId>
|
||||
<packaging>bundle</packaging>
|
||||
@ -19,6 +19,11 @@
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.core</groupId>
|
||||
<artifactId>artifact-management</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.karaf.shell</groupId>
|
||||
<artifactId>org.apache.karaf.shell.core</artifactId>
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-shell
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-shell
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-shell
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-shell
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-shell
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -27,12 +27,16 @@ package ru.entaxy.platform.objects.runtime.shell;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.karaf.shell.api.action.Command;
|
||||
import org.apache.karaf.shell.api.action.lifecycle.Service;
|
||||
import org.apache.karaf.shell.support.table.ShellTable;
|
||||
|
||||
import ru.entaxy.platform.base.support.JSONUtils;
|
||||
import ru.entaxy.platform.base.support.karaf.shell.ShellTableExt;
|
||||
import ru.entaxy.platform.objects.runtime.EntaxyRuntimeObject;
|
||||
import ru.entaxy.platform.objects.runtime.EntaxyRuntimeObjectContainer;
|
||||
import ru.entaxy.platform.objects.runtime.EntaxyRuntimeObjectResource;
|
||||
@ -41,74 +45,98 @@ import ru.entaxy.platform.objects.runtime.EntaxyRuntimeObjectResource;
|
||||
@Command(name = "object-info", scope = EntaxyRuntimeObjectServiceSupport.OBJECTS_SCOPE, description = "Get object info")
|
||||
public class ObjectInfo extends RuntimeObjectAwareCommand {
|
||||
|
||||
@Override
|
||||
public Object doExecute(EntaxyRuntimeObject entaxyObject) throws Exception {
|
||||
|
||||
EntaxyRuntimeObjectContainer container = entaxyObject.getContainer();
|
||||
|
||||
String message = "Object Info for ".concat(entaxyObject.getObjectFullId())
|
||||
.concat("\n----------------------------------------")
|
||||
.concat("\nID: ".concat(entaxyObject.getId()))
|
||||
.concat("\nTYPE: ".concat(entaxyObject.getType()))
|
||||
.concat("\nFULL ID: ".concat(entaxyObject.getObjectFullId()))
|
||||
.concat("\nFACTORY ID: ".concat(entaxyObject.getFactoryId()))
|
||||
.concat("\nCONTAINER: ".concat(RuntimeObjectShellUtils.getContainerPrintString(container)))
|
||||
.concat("\nBUNDLE ID: ".concat(entaxyObject.getBundleInfo().getBundleId()+""))
|
||||
.concat("\nCOLOCATED WITH OBJECTS: ")
|
||||
.concat(
|
||||
container.getObjects().stream()
|
||||
.filter(obj-> !obj.getObjectFullId().equals(entaxyObject.getObjectFullId()))
|
||||
.map(obj -> ("\n\t" + obj.getObjectFullId()))
|
||||
.collect(Collectors.joining())
|
||||
.concat("\nPARENT OBJECTS: ")
|
||||
.concat(
|
||||
RuntimeObjectShellUtils.getRelationListMainPrintString(
|
||||
entaxyObject.getIncomiingSubordRelations()
|
||||
, "\n\t")
|
||||
)
|
||||
.concat("\nDEPENDENCIES: ")
|
||||
.concat(
|
||||
RuntimeObjectShellUtils.getRelationListMainPrintString(
|
||||
RuntimeObjectShellUtils.getObjectDependenciesAndUses(entaxyObject)
|
||||
, "\n\t")
|
||||
)
|
||||
)
|
||||
.concat("\nCHILD OBJECTS: ")
|
||||
.concat(
|
||||
RuntimeObjectShellUtils.getRelationListDependentPrintString(
|
||||
entaxyObject.getSubordRelations()
|
||||
, "\n\t")
|
||||
)
|
||||
.concat("\nDEPENDENTS: ")
|
||||
.concat(
|
||||
RuntimeObjectShellUtils.getRelationListDependentPrintString(
|
||||
RuntimeObjectShellUtils.getObjectIncomingDependenciesAndUses(entaxyObject)
|
||||
, "\n\t")
|
||||
);
|
||||
|
||||
// object resources
|
||||
ShellTable table = new ShellTable();
|
||||
table.column("Scope");
|
||||
table.column("Exists");
|
||||
table.column("Url");
|
||||
|
||||
for (EntaxyRuntimeObjectResource res: entaxyObject.getResources())
|
||||
table.addRow().addContent(
|
||||
res.getScope().name(),
|
||||
(res.getResource().exists()?"*":""),
|
||||
res.getResourceUrl()
|
||||
);
|
||||
|
||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PrintStream printStream = new PrintStream(outputStream)) {
|
||||
@Override
|
||||
public Object doExecute(EntaxyRuntimeObject entaxyObject) throws Exception {
|
||||
|
||||
table.print(printStream);
|
||||
message = message.concat("\nRESOURCES: \n").concat(outputStream.toString());
|
||||
}
|
||||
|
||||
// output to console
|
||||
System.out.println(message);
|
||||
|
||||
return null;
|
||||
}
|
||||
EntaxyRuntimeObjectContainer container = entaxyObject.getContainer();
|
||||
|
||||
String message = "Object Info for ".concat(entaxyObject.getObjectFullId())
|
||||
.concat("\n----------------------------------------")
|
||||
.concat("\nID: ".concat(entaxyObject.getId()))
|
||||
.concat("\nTYPE: ".concat(entaxyObject.getType()))
|
||||
.concat("\nFULL ID: ".concat(entaxyObject.getObjectFullId()))
|
||||
.concat("\nFACTORY ID: ".concat(entaxyObject.getFactoryId()))
|
||||
.concat("\nCONTAINER: ".concat(RuntimeObjectShellUtils.getContainerPrintString(container)))
|
||||
.concat("\nBUNDLE ID: ".concat(entaxyObject.getBundleInfo().getBundleId() + ""))
|
||||
.concat("\nCOLOCATED WITH OBJECTS: ")
|
||||
.concat(
|
||||
container.getObjects().stream()
|
||||
.filter(obj -> !obj.getObjectFullId().equals(entaxyObject.getObjectFullId()))
|
||||
.map(obj -> ("\n\t" + obj.getObjectFullId()))
|
||||
.collect(Collectors.joining())
|
||||
.concat("\nPARENT OBJECTS: ")
|
||||
.concat(
|
||||
RuntimeObjectShellUtils.getRelationListMainPrintString(
|
||||
entaxyObject.getIncomiingSubordRelations(), "\n\t"))
|
||||
.concat("\nDEPENDENCIES: ")
|
||||
.concat(
|
||||
RuntimeObjectShellUtils.getRelationListMainPrintString(
|
||||
RuntimeObjectShellUtils.getObjectDependenciesAndUses(entaxyObject),
|
||||
"\n\t")))
|
||||
.concat("\nCHILD OBJECTS: ")
|
||||
.concat(
|
||||
RuntimeObjectShellUtils.getRelationListDependentPrintString(
|
||||
entaxyObject.getSubordRelations(), "\n\t"))
|
||||
.concat("\nDEPENDENTS: ")
|
||||
.concat(
|
||||
RuntimeObjectShellUtils.getRelationListDependentPrintString(
|
||||
RuntimeObjectShellUtils.getObjectIncomingDependenciesAndUses(entaxyObject), "\n\t"));
|
||||
|
||||
// object resources
|
||||
ShellTable table = new ShellTable();
|
||||
table.column("Scope");
|
||||
table.column("Exists");
|
||||
table.column("Url");
|
||||
|
||||
for (EntaxyRuntimeObjectResource res : entaxyObject.getResources())
|
||||
table.addRow().addContent(
|
||||
res.getScope().name(),
|
||||
(res.getResource() == null ? "" : (res.getResource().exists() ? "*" : "")),
|
||||
res.getResourceUrl());
|
||||
|
||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
PrintStream printStream = new PrintStream(outputStream)) {
|
||||
|
||||
table.print(printStream);
|
||||
message = message.concat("\nRESOURCES: \n").concat(outputStream.toString());
|
||||
}
|
||||
|
||||
ShellTableExt tableExt = new ShellTableExt();
|
||||
tableExt.column("Attribute");
|
||||
tableExt.column("Value").maxSize(70);
|
||||
|
||||
for (Map.Entry<String, Object> entry : entaxyObject.getAllAttributes().entrySet()) {
|
||||
|
||||
String toOutput = "";
|
||||
|
||||
if (entry.getValue() != null) {
|
||||
if (entry.getValue() instanceof List)
|
||||
toOutput = ((List) entry.getValue())
|
||||
.stream().map(v -> v == null ? "" : v.toString())
|
||||
.collect(Collectors.joining("\n")).toString();
|
||||
else if (entry.getValue() instanceof Map) {
|
||||
toOutput = JSONUtils.GSON.toJsonTree((Map) entry.getValue()).toString();
|
||||
} else {
|
||||
toOutput = entry.getValue().toString();
|
||||
}
|
||||
}
|
||||
|
||||
tableExt.addRow().addContent(entry.getKey(), toOutput);
|
||||
|
||||
}
|
||||
|
||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
PrintStream printStream = new PrintStream(outputStream)) {
|
||||
|
||||
tableExt.print(printStream);
|
||||
message = message.concat("\nATTRIBUTES: \n").concat(outputStream.toString());
|
||||
}
|
||||
|
||||
|
||||
// output to console
|
||||
System.out.println(message);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-shell
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
@ -81,7 +81,7 @@ public abstract class ObjectOperationCommand extends RuntimeObjectAwareCommand {
|
||||
table.addRow().addContent(key, result.getAffected().get(key).name());
|
||||
|
||||
// output
|
||||
System.out.println("\nOperaton should be applied to the following affected objects:");
|
||||
System.out.println("\nOperation should be applied to the following affected objects:");
|
||||
table.print(System.out);
|
||||
|
||||
String message = "\n"
|
||||
@ -102,7 +102,7 @@ public abstract class ObjectOperationCommand extends RuntimeObjectAwareCommand {
|
||||
table.addRow().addContent(key, result.getAffected().get(key).name());
|
||||
|
||||
// output
|
||||
System.out.println("\nThe following operatons must be applied before invoking the current one:");
|
||||
System.out.println("\nThe following operations must be applied before invoking the current one:");
|
||||
table.print(System.out);
|
||||
|
||||
}
|
||||
@ -129,7 +129,7 @@ public abstract class ObjectOperationCommand extends RuntimeObjectAwareCommand {
|
||||
table.addRow().addContent(key, result.getAffected().get(key).name());
|
||||
|
||||
// output
|
||||
System.out.println("\nThe following suboperatons failed:");
|
||||
System.out.println("\nThe following suboperations failed:");
|
||||
table.print(System.out);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-shell
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-shell
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-shell
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-shell
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* test-producers
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-shell
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-shell
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* object-runtime-shell
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2023 EmDev LLC
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
|
@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>1.9.0</version>
|
||||
<version>1.10.0</version>
|
||||
</parent>
|
||||
<groupId>ru.entaxy.esb.platform.runtime.core</groupId>
|
||||
<artifactId>object-runtime</artifactId>
|
||||
|
Reference in New Issue
Block a user