
org.integratedmodelling.engine.modelling.runtime.Process Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (C) 2007, 2015:
*
* - Ferdinando Villa
* - integratedmodelling.org
* - any other authors listed in @author annotations
*
* All rights reserved. This file is part of the k.LAB software suite,
* meant to enable modular, collaborative, integrated
* development of interoperable data and model components. For
* details, see http://integratedmodelling.org.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the Affero General Public License
* Version 3 or any later version.
*
* This program is distributed in the hope that it will be useful,
* but without any warranty; without even the implied warranty of
* merchantability or fitness for a particular purpose. See the
* Affero General Public License for more details.
*
* You should have received a copy of the Affero General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* The license is also available at: https://www.gnu.org/licenses/agpl.html
*******************************************************************************/
package org.integratedmodelling.engine.modelling.runtime;
import java.util.HashMap;
import java.util.Map;
import org.integratedmodelling.api.knowledge.IProperty;
import org.integratedmodelling.api.metadata.IMetadata;
import org.integratedmodelling.api.modelling.IActiveProcess;
import org.integratedmodelling.api.modelling.IDirectObservation;
import org.integratedmodelling.api.modelling.IModel;
import org.integratedmodelling.api.modelling.IModelBean;
import org.integratedmodelling.api.modelling.IObservable;
import org.integratedmodelling.api.modelling.IState;
import org.integratedmodelling.api.modelling.ISubject;
import org.integratedmodelling.api.modelling.scheduling.ITransition;
import org.integratedmodelling.api.monitoring.IMonitor;
import org.integratedmodelling.common.interfaces.NetworkSerializable;
import org.integratedmodelling.common.interfaces.actuators.IProcessActuator;
import org.integratedmodelling.common.model.runtime.Observation;
import org.integratedmodelling.common.model.runtime.Transition;
import org.integratedmodelling.common.utils.CamelCase;
import org.integratedmodelling.exceptions.KlabException;
import org.integratedmodelling.exceptions.KlabRuntimeException;
public class Process extends DirectObservation implements IActiveProcess, NetworkSerializable {
IProcessActuator actuator;
IModel model;
IDirectObservation subject;
String name;
public Process(IModel model, IDirectObservation subject, IProcessActuator accessor, IMonitor monitor) {
/*
* TODO processes may have their own scale eventually.
*/
super(model.getObservable(), subject.getScale(), model.getNamespace(),
model.getObservable().getLocalName() + "_" + subject.getName(), monitor);
this.model = model;
this.actuator = accessor;
this.subject = subject;
this.name = CamelCase.toLowerCase(getObservable().getLocalName(), '-');
this.parentId = ((Observation) subject).getInternalId();
}
@Override
public ISubject getContextObservation() {
return (ISubject) this.subject;
}
@Override
public IModel getModel() {
return this.model;
}
@Override
public Map getObjectStateCopy() {
return new HashMap();
}
@Override
public ITransition performTemporalTransitionFromCurrentState() throws KlabException {
ITransition result;
// set the clock forward
if (moveToNextTimePeriod() == null) {
// process has terminated
result = new Transition(scale, null, false);
} else {
result = reEvaluateStates(getCurrentTimePeriod());
if (result.agentSurvives() && this.actuator != null) {
/*
* ensure the subject that contains the states we see has been
* updated to receive a new transition. This may be called
* multiple times for the same transition (by all direct
* observations inherent to this subject).
*/
((Subject) this.subject).prepareForTransition(result);
this.actuator.processTransition(result, monitor);
}
}
return result;
}
@Override
public String toString() {
return "";
}
@Override
public IMetadata getMetadata() {
return metadata;
}
/**
* use with great caution. Only for reinterpretation.
*
* @param observable
*/
public void setObservable(IObservable observable) {
this.observable = observable;
}
@SuppressWarnings("unchecked")
@Override
public T serialize(Class extends IModelBean> desiredClass) {
if (!desiredClass.isAssignableFrom(org.integratedmodelling.common.beans.Process.class)) {
throw new KlabRuntimeException("cannot serialize a Context to a " + desiredClass.getCanonicalName());
}
org.integratedmodelling.common.beans.Process ret = new org.integratedmodelling.common.beans.Process();
super.serialize(ret);
return (T) ret;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy