Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferdinando Villa committed Dec 1, 2024
1 parent 6be8109 commit ddc012f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.integratedmodelling.klab.api.data;

import java.lang.annotation.*;

/**
* Used to tag arguments that will be changed by the call that annotates them when passed as parameters.
*/
@Documented
@Target(ElementType.PARAMETER)
public @interface Mutable {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.integratedmodelling.klab.api.scope;

import org.integratedmodelling.klab.api.data.Mutable;
import org.integratedmodelling.klab.api.data.RuntimeAsset;
import org.integratedmodelling.klab.api.exceptions.KlabIllegalStateException;
import org.integratedmodelling.klab.api.geometry.Geometry;
Expand Down Expand Up @@ -171,14 +172,15 @@ default Type getType() {
* derived from it so that what is happening can be reconstructed at the client side.
*
* @param observation an unresolved observation to be resolved by the runtime and added to the digital
* twin. The
* twin. After the call exits, the resolution will be ongoing but the observation will
* have gained a valid ID and URN. The
* {@link
* org.integratedmodelling.klab.api.digitaltwin.DigitalTwin#createObservation(Scope,
* Object...)} method can be used to construct it from existing knowledge.
* @return a {@link Future} producing the resolved observation when resolution is finished. If resolution
* has failed, the observation in the future will be unresolved.
*/
Future<Observation> observe(Observation observation);
Future<Observation> observe(@Mutable Observation observation);

/**
* Return all observations affected by the passed one in this scope, either through model dependencies or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,19 @@ static class EventMatcher {
private final AtomicBoolean errors = new AtomicBoolean(false);
private final List<BiConsumer<Channel, Message>> listeners =
Collections.synchronizedList(new ArrayList<>());
private final Multimap<Pair<Message.MessageClass, Message.MessageType>, EventMatcher> eventMatchers =
ArrayListMultimap.create();
private final Multimap<Pair<Message.MessageClass, Message.MessageType>, EventMatcher> eventMatchers;

public ChannelImpl(Identity identity) {
this.identity = identity;
this.eventMatchers = ArrayListMultimap.create();
}

protected ChannelImpl(ChannelImpl other) {
this.identity = other.identity;
this.interrupted = other.interrupted;
this.errors.set(other.errors.get());
this.listeners.addAll(other.listeners);
this.eventMatchers = other.eventMatchers;
}

@Override
Expand Down Expand Up @@ -98,8 +99,6 @@ public void event(Message message) {
private void handleMatch(Pair<Message.MessageClass, Message.MessageType> key, EventMatcher matcher,
Message message) {

System.out.println("PORCO DIO UN POSSIBILE MATCH: " + message);

// Quickly check if match is real
boolean match = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ public Collection<Message.Queue> setupMessagingQueues(String scopeId,
DeliverCallback deliverCallback = (consumerTag, delivery) -> {
var message = Utils.Json.parseObject(new String(delivery.getBody(),
StandardCharsets.UTF_8), Message.class);

System.out.println("DIO PESCHIERE " + MessagingChannelImpl.this.getClass().getCanonicalName() + " <- " + message);
//
// System.out.println("DIO PESCHIERE " + MessagingChannelImpl.this.getClass().getCanonicalName() + " <- " + message);

// if there is a consumer installed fo this queue, run it. Then if it returns
// continue, continue, else stop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.integratedmodelling.klab.api.knowledge.Observable;
import org.integratedmodelling.klab.api.knowledge.SemanticType;
import org.integratedmodelling.klab.api.knowledge.observation.Observation;
import org.integratedmodelling.klab.api.knowledge.observation.impl.ObservationImpl;
import org.integratedmodelling.klab.api.provenance.Agent;
import org.integratedmodelling.klab.api.provenance.Provenance;
import org.integratedmodelling.klab.api.scope.ContextScope;
Expand Down Expand Up @@ -91,6 +92,10 @@ public Future<Observation> observe(Observation observation) {
long taskId = runtime.submit(observation, this);

if (taskId != Observation.UNASSIGNED_ID) {
if (observation instanceof ObservationImpl observation1) {
observation1.setId(taskId);
observation1.setUrn(this.getId() + "." + taskId);
}
return runtime.resolve(taskId, this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public void observe(Object asset, boolean adding) {
final boolean observering = isObserver;

/* one-time event handlers */
scope()
currentContext
.onEvent(Message.MessageClass.ObservationLifecycle,
Message.MessageType.ResolutionSuccessful, (message) -> {
var obs = message.getPayload(Observation.class);
Expand Down

0 comments on commit ddc012f

Please sign in to comment.