├── .gitignore ├── README.md ├── asimov.properties ├── dist ├── .gitignore ├── runAsimovOSX.sh └── usecase.xml ├── examples └── simple │ ├── ASIMOV_Simple_MD_Office_Example.png │ ├── README.md │ └── usecase.xml ├── pom.xml ├── publishMaven.sh └── src ├── main ├── java │ └── io │ │ ├── asimov │ │ ├── agent │ │ │ ├── gui │ │ │ │ ├── ScenarioAgentGui.java │ │ │ │ └── SemanticAgentGui.java │ │ │ ├── negotiator │ │ │ │ ├── DemandingNegotiatorAgent.java │ │ │ │ └── ProvidingNegotiatorAgent.java │ │ │ ├── process │ │ │ │ ├── ManageProcessActionService.java │ │ │ │ ├── NonSkeletonActivityCapability.java │ │ │ │ ├── NotYetInitializedException.java │ │ │ │ ├── ProcessCompletion.java │ │ │ │ ├── ProcessManagementWorld.java │ │ │ │ └── ResourceAllocation.java │ │ │ ├── resource │ │ │ │ ├── GenericResourceManagementWorld.java │ │ │ │ ├── ResourceManagementWorld.java │ │ │ │ └── impl │ │ │ │ │ ├── GenericResourceManagementOrganizationImpl.java │ │ │ │ │ └── GenericResourceManagementWorldImpl.java │ │ │ └── scenario │ │ │ │ ├── Context.java │ │ │ │ ├── ContextUtil.java │ │ │ │ ├── Replication.java │ │ │ │ ├── ScenarioManagementOrganization.java │ │ │ │ ├── ScenarioManagementWorld.java │ │ │ │ ├── ScenarioReplication.java │ │ │ │ ├── SimStatus.java │ │ │ │ └── impl │ │ │ │ └── ScenarioReplicatorImpl.java │ │ ├── bootstrap │ │ │ └── Booter.java │ │ ├── db │ │ │ ├── Datasource.java │ │ │ └── mongo │ │ │ │ ├── MongoDatasource.java │ │ │ │ └── MongoUtil.java │ │ ├── graph │ │ │ └── GraphUtil.java │ │ ├── messaging │ │ │ ├── ASIMOVAllResourcesReadyMessage.java │ │ │ ├── ASIMOVBasicAgent.java │ │ │ ├── ASIMOVMessage.java │ │ │ ├── ASIMOVMessageID.java │ │ │ └── ASIMOVNewResourceMessage.java │ │ ├── microservice │ │ │ └── negotiation │ │ │ │ ├── AgentServiceProxy.java │ │ │ │ ├── ClaimSortByProposal.java │ │ │ │ ├── ConversionCallback.java │ │ │ │ ├── ResourceAllocationNegotiator.java │ │ │ │ ├── ResourceAllocationRequestor.java │ │ │ │ ├── ResourceAllocationResponder.java │ │ │ │ ├── ResourceReadyListeningResource.java │ │ │ │ ├── ResourceReadyNotification.java │ │ │ │ ├── impl │ │ │ │ ├── ClaimSortByProposalImpl.java │ │ │ │ ├── NegotiatingCapability.java │ │ │ │ ├── ResourceAllocationNegotiatorImpl.java │ │ │ │ ├── ResourceAllocationRequestorImpl.java │ │ │ │ └── ResourceAllocationResponderImpl.java │ │ │ │ └── messages │ │ │ │ ├── AvailabilityCheck.java │ │ │ │ ├── AvailabilityReply.java │ │ │ │ ├── Claim.java │ │ │ │ ├── Claimed.java │ │ │ │ ├── Proposal.java │ │ │ │ └── ProposalRequest.java │ │ ├── model │ │ │ ├── ASIMOVContext.java │ │ │ ├── ASIMOVOrganization.java │ │ │ ├── ASIMOVOrganizationWorld.java │ │ │ ├── ASIMOVResourceDescriptor.java │ │ │ ├── AbstractASIMOVOrganizationtWorld.java │ │ │ ├── AbstractEmbodied.java │ │ │ ├── AbstractEntity.java │ │ │ ├── AbstractNamed.java │ │ │ ├── AbstractPersonTraceEventProducer.java │ │ │ ├── AbstractPersonTraceModelComponent.java │ │ │ ├── ActivityParticipation.java │ │ │ ├── ActivityParticipationResourceInformation.java │ │ │ ├── Body.java │ │ │ ├── Connection.java │ │ │ ├── ConnectionFrom.java │ │ │ ├── ConnectionTo.java │ │ │ ├── CoordinationUtil.java │ │ │ ├── DirectlyContains.java │ │ │ ├── DirectlyIn.java │ │ │ ├── Named.java │ │ │ ├── PersonTraceModelComponent.java │ │ │ ├── Resource.java │ │ │ ├── ResourceAllocation.java │ │ │ ├── ResourceRequirement.java │ │ │ ├── ResourceTraceEventListener.java │ │ │ ├── ResourceTraceEventProducer.java │ │ │ ├── ResourceTraceEventType.java │ │ │ ├── ResourceTraceEventWrapper.java │ │ │ ├── ResourceTraceEventWrapperListener.java │ │ │ ├── ResourceTraceModel.java │ │ │ ├── ResourceType.java │ │ │ ├── Time.java │ │ │ ├── TraceService.java │ │ │ ├── XMLConvertible.java │ │ │ ├── events │ │ │ │ ├── ActivityEvent.java │ │ │ │ ├── Event.java │ │ │ │ ├── EventStatus.java │ │ │ │ ├── EventStatusChangeEntry.java │ │ │ │ └── EventType.java │ │ │ ├── process │ │ │ │ ├── Activity.java │ │ │ │ ├── DistanceMatrixService.java │ │ │ │ ├── DistanceMatrixServiceImpl.java │ │ │ │ ├── IDistanceMatrix.java │ │ │ │ ├── Next.java │ │ │ │ ├── Process.java │ │ │ │ ├── ProcessManagementOrganization.java │ │ │ │ ├── ProcessType.java │ │ │ │ ├── Task.java │ │ │ │ ├── Transition.java │ │ │ │ └── impl │ │ │ │ │ ├── ManageProcessActionImpl.java │ │ │ │ │ ├── ProcessCompleterImpl.java │ │ │ │ │ ├── ProcessCompletionInitiator.java │ │ │ │ │ └── ProcessManagementWorldImpl.java │ │ │ ├── resource │ │ │ │ ├── AbstractResourceManagementWorld.java │ │ │ │ ├── ActivityParticipantImpl.java │ │ │ │ ├── DirectoryLookup.java │ │ │ │ ├── NonSkeletonActivityCapabilityImpl.java │ │ │ │ ├── ResouceReadyInitiatorImpl.java │ │ │ │ ├── ResourceDescriptor.java │ │ │ │ ├── ResourceManagementOrganization.java │ │ │ │ ├── ResourceReadyListenerImpl.java │ │ │ │ ├── ResourceSubtype.java │ │ │ │ ├── RouteInitiatorImpl.java │ │ │ │ └── RouteLookup.java │ │ │ ├── sl │ │ │ │ ├── ASIMOVAgents.java │ │ │ │ ├── ASIMOVAndNode.java │ │ │ │ ├── ASIMOVFormula.java │ │ │ │ ├── ASIMOVFunctionNode.java │ │ │ │ ├── ASIMOVIntegerTerm.java │ │ │ │ ├── ASIMOVNode.java │ │ │ │ ├── ASIMOVNotNode.java │ │ │ │ ├── ASIMOVSLUtil.java │ │ │ │ ├── ASIMOVStringTerm.java │ │ │ │ ├── ASIMOVTerm.java │ │ │ │ ├── ASIMOVTermSequenceNode.java │ │ │ │ ├── LegacySLUtil.java │ │ │ │ ├── SL.java │ │ │ │ └── SLConvertible.java │ │ │ ├── usecase │ │ │ │ ├── RouteProviderImpl.java │ │ │ │ ├── ScenarioManagementWorldImpl.java │ │ │ │ └── UseCaseScenario.java │ │ │ └── xml │ │ │ │ ├── Resource.java │ │ │ │ ├── ResourceType.java │ │ │ │ ├── XMLStreamEventTypeEnum.java │ │ │ │ ├── XMLStreamObserver.java │ │ │ │ ├── XmlNamespaceMapper.java │ │ │ │ ├── XmlUtil.java │ │ │ │ └── moxy │ │ │ │ ├── MOXyXmlContextCacheEntry.java │ │ │ │ └── MOXyXmlContextID.java │ │ ├── reasoning │ │ │ └── sl │ │ │ │ ├── ASIMOVSLBelief.java │ │ │ │ ├── ASIMOVSLQuery.java │ │ │ │ ├── ASIMOVSLReasoningCapability.java │ │ │ │ ├── KBase.java │ │ │ │ ├── SLConvertible.java │ │ │ │ ├── SLParsable.java │ │ │ │ └── SLParsableSerializable.java │ │ ├── run │ │ │ └── RunUseCase.java │ │ ├── unavailability │ │ │ ├── MonkeyAgent.java │ │ │ ├── MonkeyAgentWorld.java │ │ │ ├── UnAvailabilityRequest.java │ │ │ └── UnavailabilityDistribution.java │ │ ├── util │ │ │ └── extrapolator │ │ │ │ └── EventExtrapolator.java │ │ └── vis │ │ │ └── timeline │ │ │ ├── VisJSTimeline.java │ │ │ ├── VisJSTimelineGroup.java │ │ │ ├── VisJSTimelineItem.java │ │ │ └── VisJSTimelineUtil.java │ │ └── coala │ │ ├── agent │ │ └── AbstractAgentManager.java │ │ ├── dsol │ │ └── DsolSimulatorService.java │ │ ├── enterprise │ │ └── role │ │ │ └── AbstractActorRole.java │ │ └── random │ │ └── impl │ │ └── RandomizingCapabilityImpl.java ├── resources │ ├── asimov.properties │ ├── eve.yaml │ ├── gui │ │ ├── .gitignore │ │ ├── README.md │ │ ├── html │ │ │ ├── css │ │ │ │ ├── global.css │ │ │ │ └── vis.css │ │ │ ├── data │ │ │ │ ├── style.css │ │ │ │ ├── typeusage.json │ │ │ │ └── usage.json │ │ │ ├── images │ │ │ │ ├── asimov_logo.png │ │ │ │ ├── asimov_logo_large.png │ │ │ │ ├── toggleOff.png │ │ │ │ └── toggleOn.png │ │ │ ├── index.html │ │ │ └── js │ │ │ │ ├── init.js │ │ │ │ └── vis.js │ │ └── package.json │ └── log4j.properties └── xsd │ └── asim │ ├── asimovBPM.xsd │ ├── asimovCIM.xsd │ ├── asimovEvent.xsd │ ├── asimovUnits.xsd │ └── main.xsd └── test ├── java └── io │ └── asimov │ └── test │ └── sim │ ├── ASIMOVMessageSenderAgent.java │ ├── ASIMOVReasoningMessageReceiverAgent.java │ ├── EventTraceWriter.java │ ├── ModelTest.java │ ├── NegotiationTest.java │ ├── NegotiationTestAgent.java │ ├── Platform.java │ ├── ScenarioTest.java │ └── TimeLineWriter.java └── resources ├── eve.yaml ├── gui ├── .gitignore ├── README.md ├── html │ ├── css │ │ ├── global.css │ │ └── vis.css │ ├── data │ │ ├── style.css │ │ ├── typeusage.json │ │ └── usage.json │ ├── images │ │ ├── asimov_logo.png │ │ ├── asimov_logo_large.png │ │ ├── toggleOff.png │ │ └── toggleOn.png │ ├── index.html │ └── js │ │ ├── init.js │ │ └── vis.js └── package.json ├── log4j.properties ├── log4j2-test.json ├── resource-usage-vis ├── style.css ├── timeline-vis-compact_experimental.html ├── timeline-vis.html ├── typeusage.json └── usage.json └── usecase.xml /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.jar 8 | *.war 9 | *.ear 10 | 11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 12 | hs_err_pid* 13 | /target/ 14 | /target/ 15 | /target/ 16 | -------------------------------------------------------------------------------- /dist/.gitignore: -------------------------------------------------------------------------------- 1 | /example_output/ 2 | /sniffer.json 3 | /mongodb-osx-x86_64-2.6.7/ 4 | /mongodb/ 5 | /mongodb-osx-x86_64-2.6.7.tgz 6 | /data/ 7 | -------------------------------------------------------------------------------- /dist/runAsimovOSX.sh: -------------------------------------------------------------------------------- 1 | #bin/bash 2 | 3 | SOURCE="${BASH_SOURCE[0]}" 4 | while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink 5 | DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" 6 | SOURCE="$(readlink "$SOURCE")" 7 | [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located 8 | done 9 | DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" 10 | 11 | 12 | ps -ef | grep mongod | grep -v grep 13 | if ([ $? -eq "0" ]); then 14 | echo "Detected running mongoDB instance will use this for persitence" 15 | else 16 | echo "Did not detect mongoDB instance will download and install it before run of ASIMOV" 17 | if [ ! -f $DIR/mongodb/bin/mongod ]; then 18 | if [ ! -f mongodb-osx-x86_64-2.6.7.tgz ]; then 19 | curl -O http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.6.7.tgz 20 | fi 21 | if [ ! -f mongodb-osx-x86_64-2.6.7.tgz ]; then 22 | echo "Failed to download mongo please install and start manualy" 23 | exit 1; 24 | else 25 | tar -zxvf mongodb-osx-x86_64-2.6.7.tgz 26 | mkdir -p mongodb 27 | cp -R -n mongodb-osx-x86_64-2.6.7/ mongodb 28 | rm mongodb-osx-x86_64-2.6.7.tgz 29 | rm -Rf mongodb-osx-x86_64-2.6.7 30 | mkdir -p $DIR/data/db 31 | echo "Installed mongodb starting it now" 32 | fi 33 | else 34 | echo "Detected mongodb installation starting it now" 35 | fi 36 | $DIR/mongodb/bin/mongod --dbpath $DIR/data/db & 37 | fi 38 | echo "Starting ASIMOV, when finished the results will be displayed in your web browser." 39 | if (java -XX:PermSize=512m -XX:MaxPermSize=2048m -Xms256m -Xmx2048m -jar ASIMOV.jar usecase.xml 2 example_output); then 40 | open -n "$DIR/example_output/gui/html/index.html" 41 | else 42 | echo "An error occured while running ASIMOV." 43 | exit 1; 44 | fi 45 | -------------------------------------------------------------------------------- /examples/simple/ASIMOV_Simple_MD_Office_Example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/almende/asimov/154a9c698ffe9de6c46dba869dde8b27a1fe2af3/examples/simple/ASIMOV_Simple_MD_Office_Example.png -------------------------------------------------------------------------------- /publishMaven.sh: -------------------------------------------------------------------------------- 1 | #bin/bash 2 | git commit -a -m "New deployment" 3 | git push 4 | mvn clean deploy -Dmaven.test.skip=true -------------------------------------------------------------------------------- /src/main/java/io/asimov/agent/negotiator/DemandingNegotiatorAgent.java: -------------------------------------------------------------------------------- 1 | package io.asimov.agent.negotiator; 2 | 3 | /** 4 | * {@link DemandingNegotiatorAgent} 5 | * 6 | * @date $Date$ 7 | * @version $Revision$ 8 | * @author suki 9 | * 10 | */ 11 | public class DemandingNegotiatorAgent 12 | { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/agent/negotiator/ProvidingNegotiatorAgent.java: -------------------------------------------------------------------------------- 1 | package io.asimov.agent.negotiator; 2 | 3 | /** 4 | * {@link ProvidingNegotiatorAgent} 5 | * 6 | * @date $Date$ 7 | * @version $Revision$ 8 | * @author suki 9 | * 10 | */ 11 | public class ProvidingNegotiatorAgent 12 | { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/agent/process/ManageProcessActionService.java: -------------------------------------------------------------------------------- 1 | package io.asimov.agent.process; 2 | 3 | import io.asimov.model.ActivityParticipation; 4 | import io.coala.capability.CapabilityFactory; 5 | import io.coala.enterprise.role.Executor; 6 | 7 | /** 8 | * {@link ManageProcessActionService} 9 | * 10 | * @date $Date: 2014-09-01 11:53:05 +0200 (ma, 01 sep 2014) $ 11 | * @version $Revision: 1048 $ 12 | * @author suki 13 | * 14 | */ 15 | public interface ManageProcessActionService extends Executor 16 | { 17 | 18 | /** 19 | * {@link Factory} 20 | * 21 | * @version $Revision: 1048 $ 22 | * @author Rick 23 | */ 24 | interface Factory extends CapabilityFactory 25 | { 26 | // empty 27 | } 28 | 29 | /** 30 | * @param cause the {@link ProcessCompletion.Request} that triggered this process management call/request 31 | */ 32 | void manageProcessInstanceForType(ProcessCompletion.Request cause); 33 | 34 | /** 35 | * @param result 36 | */ 37 | void notifyActivityParticipationResult(ActivityParticipation.Result result); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/agent/process/NotYetInitializedException.java: -------------------------------------------------------------------------------- 1 | package io.asimov.agent.process; 2 | 3 | /** 4 | * This exception is thrown when a role is not yet initialized and a request for data has been made. 5 | * The way to handle this exception is to wait until it is initialized. 6 | * 7 | * {@link NotYetInitializedException} 8 | * 9 | * @date $Date: 2014-09-01 11:53:05 +0200 (ma, 01 sep 2014) $ 10 | * @version $Revision: 1048 $ 11 | * @author suki 12 | * 13 | */ 14 | public class NotYetInitializedException extends Exception 15 | { 16 | 17 | /** */ 18 | private static final long serialVersionUID = 1L; 19 | 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/agent/process/ProcessManagementWorld.java: -------------------------------------------------------------------------------- 1 | package io.asimov.agent.process; 2 | 3 | import io.asimov.model.ASIMOVOrganizationWorld; 4 | import io.asimov.model.events.EventType; 5 | import io.asimov.model.process.Process; 6 | import io.coala.capability.CapabilityFactory; 7 | import io.coala.capability.embody.Percept; 8 | import rx.Observable; 9 | 10 | /** 11 | * {@link ProcessManagementWorld} 12 | * 13 | * @version $Revision: 1048 $ 14 | * @author Rick 15 | * 16 | */ 17 | public interface ProcessManagementWorld extends ASIMOVOrganizationWorld 18 | { 19 | 20 | /** 21 | * {@link Factory} 22 | * 23 | * @version $Revision: 1048 $ 24 | * @author Rick 25 | * 26 | */ 27 | interface Factory extends CapabilityFactory 28 | { 29 | // empty 30 | } 31 | 32 | Process getProcess(String processTypeID); 33 | 34 | Observable makeObservation(String processTypeID); 35 | 36 | /** 37 | * @param activityName 38 | * @param resourceName 39 | * @param eventType 40 | * @return activityInstanceID 41 | */ 42 | void performProcessChange(String processID, String processInstanceID, EventType eventType) throws Exception; 43 | 44 | 45 | /** 46 | * @see PersonResourceManagementWorld#performActivityChange(String, String, 47 | * EventType) 48 | */ 49 | public void performAvailabilityChange(final String resourceName, 50 | final EventType eventType) throws Exception; 51 | 52 | // 53 | // /** 54 | // * @param agent 55 | // * @return 56 | // */ 57 | // List getAssemblyLineTypesForAgentID(AgentID agent); 58 | // 59 | // /** 60 | // * @param resourceAgent 61 | // * @param resourceName 62 | // * @return 63 | // */ 64 | // List getMaterialsForSupplyType(AgentID resourceAgent, 65 | // SupplyType resourceName); 66 | // 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/agent/resource/GenericResourceManagementWorld.java: -------------------------------------------------------------------------------- 1 | package io.asimov.agent.resource; 2 | 3 | import io.asimov.model.ASIMOVResourceDescriptor; 4 | import io.asimov.model.events.ActivityEvent; 5 | import io.asimov.model.events.EventType; 6 | import io.coala.capability.CapabilityFactory; 7 | import io.coala.time.SimTime; 8 | 9 | import java.util.List; 10 | 11 | import rx.Observable; 12 | 13 | public interface GenericResourceManagementWorld extends ResourceManagementWorld { 14 | 15 | interface Factory extends CapabilityFactory 16 | { 17 | // empty 18 | } 19 | 20 | public Observable onActivityEvent(); 21 | 22 | /** 23 | * @param activityName 24 | * @param resourceName 25 | * @param eventType 26 | * @return activityInstanceID 27 | */ 28 | void performActivityChange(String processID, String processInstanceID, String activityName, String activityInstanceId, List resourceNames, EventType eventType) throws Exception; 29 | 30 | /** 31 | * To determine the start of a active simulation period for this resource 32 | * @param time the time the resource entered the building/campus/etc. 33 | */ 34 | void enteredSite(SimTime time); 35 | 36 | /** 37 | * To determine the end of a active simulation period for this resource 38 | * @param time the time the resource left the building/campus/etc. 39 | */ 40 | void leftSite(SimTime time); 41 | 42 | public boolean isMoveable(); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/agent/resource/ResourceManagementWorld.java: -------------------------------------------------------------------------------- 1 | package io.asimov.agent.resource; 2 | 3 | import io.asimov.model.ASIMOVOrganizationWorld; 4 | import io.asimov.model.AbstractEmbodied; 5 | import io.coala.agent.AgentID; 6 | import io.coala.capability.CapabilityFactory; 7 | import io.coala.capability.embody.GroundingCapability; 8 | import io.coala.capability.embody.PerceivingCapability; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * {@link ResourceManagementWorld} 14 | * 15 | * TODO Move to even more generic worldView in sim-common 16 | * 17 | * @version $Revision: 1048 $ 18 | * @author Rick 19 | */ 20 | public interface ResourceManagementWorld> extends 21 | ASIMOVOrganizationWorld, GroundingCapability, PerceivingCapability 22 | { 23 | 24 | /** 25 | * {@link Factory} 26 | * 27 | * @version $Revision: 1048 $ 28 | * @author Rick 29 | * 30 | */ 31 | @SuppressWarnings("rawtypes") 32 | interface Factory extends CapabilityFactory 33 | { 34 | // empty 35 | } 36 | 37 | E getEntity(); 38 | 39 | /** 40 | * @return 41 | */ 42 | String getResourceType(); 43 | 44 | /** 45 | * Gets the current location for the service owner. 46 | * @return the agentID of the agent representing the current location of the service owner 47 | */ 48 | AgentID getCurrentLocation(); 49 | 50 | /** 51 | * Gets the current location (as coordinates) for the service owner. 52 | * @return the coordinates of the current location of the service owner. 53 | */ 54 | List getCurrentCoordinates(); 55 | 56 | 57 | boolean isAvailable(); 58 | 59 | void setAvailable(); 60 | 61 | void setUnavailable(); 62 | 63 | /** 64 | * Print debug statement for resource that have debugging enabled in config with stacktrace 65 | * @param line 66 | */ 67 | void debug(final String... line); 68 | 69 | /** 70 | * Print debug statement for resource that have debugging enabled in config 71 | * @param includeStackTrace 72 | * @param line 73 | */ 74 | void debug(final boolean includeStackTrace, final String... line); 75 | 76 | /** 77 | * Sets the current location for the service owner. 78 | * @param locationAgentID the agentID of the agent representing the current location of the service owner 79 | */ 80 | //void setCurrentLocation(final AgentID locationAgentID); 81 | 82 | /** 83 | * Sets the current location for the service owner. 84 | * @param locationAgentID the agentID of the agent representing the current location of the service owner 85 | * @param coordinates of the current location of the service owner. 86 | */ 87 | //void setCurrentLocation(final AgentID locationAgentID, final List coordinates); 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/agent/resource/impl/GenericResourceManagementOrganizationImpl.java: -------------------------------------------------------------------------------- 1 | package io.asimov.agent.resource.impl; 2 | 3 | import io.asimov.agent.resource.GenericResourceManagementWorld; 4 | import io.asimov.model.resource.ResourceManagementOrganization; 5 | import io.coala.bind.Binder; 6 | import io.coala.log.InjectLogger; 7 | 8 | import javax.inject.Inject; 9 | 10 | import org.apache.log4j.Logger; 11 | 12 | /** 13 | * 14 | * @author suki 15 | * 16 | */ 17 | public class GenericResourceManagementOrganizationImpl extends 18 | ResourceManagementOrganization 19 | { 20 | 21 | /** */ 22 | private static final long serialVersionUID = 1L; 23 | 24 | /** */ 25 | @InjectLogger 26 | private Logger LOG; 27 | 28 | /** 29 | * {@link GenericResourceManagementOrganizationImpl} constructor 30 | * 31 | * @param binder 32 | * @throws Exception 33 | */ 34 | @Inject 35 | public GenericResourceManagementOrganizationImpl(final Binder binder) 36 | throws Exception 37 | { 38 | super(binder); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/agent/scenario/Context.java: -------------------------------------------------------------------------------- 1 | package io.asimov.agent.scenario; 2 | 3 | import io.asimov.model.ASIMOVContext; 4 | import io.asimov.model.AbstractEmbodied; 5 | import io.asimov.model.XMLConvertible; 6 | import io.asimov.xml.TContext; 7 | 8 | import java.util.Set; 9 | 10 | public interface Context extends XMLConvertible { 11 | 12 | Set getResourceTypes(); 13 | > Iterable getResources(String resourceType); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/agent/scenario/ContextUtil.java: -------------------------------------------------------------------------------- 1 | package io.asimov.agent.scenario; 2 | 3 | import org.eclipse.persistence.oxm.XMLUnmarshaller; 4 | 5 | public class ContextUtil { 6 | 7 | public static XMLUnmarshaller getContextUnmarshaller() { 8 | throw new IllegalStateException("No context unmarhaller for resources was build yet"); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/agent/scenario/ScenarioManagementOrganization.java: -------------------------------------------------------------------------------- 1 | package io.asimov.agent.scenario; 2 | 3 | import io.asimov.agent.gui.ScenarioAgentGui; 4 | import io.asimov.agent.scenario.ScenarioReplication.ScenarioReplicator; 5 | import io.asimov.model.ASIMOVOrganization; 6 | import io.coala.bind.Binder; 7 | import io.coala.capability.admin.DestroyingCapability; 8 | import io.coala.capability.plan.ClockStatusUpdate; 9 | import io.coala.log.InjectLogger; 10 | 11 | import java.awt.GraphicsEnvironment; 12 | import java.awt.HeadlessException; 13 | 14 | import javax.inject.Inject; 15 | 16 | import org.apache.log4j.Logger; 17 | 18 | import rx.Observer; 19 | 20 | /** 21 | * {@link ScenarioManagementOrganization} 22 | * 23 | * @version $Revision: 1083 $ 24 | * @author Rick 25 | * 26 | */ 27 | public class ScenarioManagementOrganization extends 28 | ASIMOVOrganization 29 | { 30 | 31 | /** */ 32 | private static final long serialVersionUID = 1L; 33 | 34 | /** */ 35 | @InjectLogger 36 | private Logger LOG; 37 | 38 | /** */ 39 | private ScenarioAgentGui myGui; 40 | 41 | /** 42 | * {@link ScenarioManagementOrganization} constructor 43 | * 44 | * @param binder 45 | * @throws Exception 46 | */ 47 | @Inject 48 | private ScenarioManagementOrganization(final Binder binder) 49 | throws Exception 50 | { 51 | super(binder); 52 | } 53 | 54 | @Override 55 | public void initialize() throws Exception 56 | { 57 | super.initialize(); 58 | 59 | if (getProperty("gui").getBoolean(false) 60 | || getProperty("scenario.gui").getBoolean(false) 61 | || getProperty(getID().getValue() + ".gui").getBoolean(false)) 62 | try 63 | { 64 | if (!GraphicsEnvironment.isHeadless()) 65 | this.myGui = new ScenarioAgentGui(getBinder(), null, true, 66 | true); 67 | } catch (final HeadlessException e) 68 | { 69 | LOG.warn("No screen/keyboard/mouse available", e); 70 | } 71 | 72 | getSimulator().getStatusUpdates().subscribe( 73 | new Observer() 74 | { 75 | @Override 76 | public void onNext(final ClockStatusUpdate update) 77 | { 78 | LOG.trace("Simulator " + update.getClockID() 79 | + " status is now " + update.getStatus()); 80 | if (update.getStatus().isFinished()) 81 | try 82 | { 83 | getBinder().inject(DestroyingCapability.class) 84 | .destroy(); 85 | } catch (final Exception e) 86 | { 87 | LOG.error("Problem destroying self", e); 88 | } 89 | } 90 | 91 | @Override 92 | public void onCompleted() 93 | { 94 | // 95 | } 96 | 97 | @Override 98 | public void onError(final Throwable t) 99 | { 100 | LOG.warn("Problem with simulator status", t); 101 | } 102 | }); 103 | 104 | // initialize all roles 105 | // getDirectoryProvider(); 106 | 107 | LOG.info("Requesting replication..."); 108 | final ScenarioReplication fact = getScenarioReplicator().initiate(); 109 | LOG.info("Scheduled request: " + fact); 110 | 111 | // getSimulator().getStatusUpdates().doOnNext( 112 | // new Action1() 113 | // { 114 | // @Override 115 | // public void call(final ClockStatusUpdate update) 116 | // { 117 | // if (update.getStatus().isFinished()) 118 | // try 119 | // { 120 | // LOG.info("Simulator done"); 121 | // getFinalizer().kill(); // FIXME kill? 122 | // } catch (final Exception e) 123 | // { 124 | // LOG.error("Problem killing self", e); 125 | // } 126 | // } 127 | // }); 128 | } 129 | 130 | @Override 131 | public void finish() 132 | { 133 | if (this.myGui != null && this.myGui.isVisible()) 134 | this.myGui.dispose(); 135 | } 136 | 137 | 138 | /** 139 | * @return the {@link ScenarioReplicator} 140 | */ 141 | protected ScenarioReplicator getScenarioReplicator() 142 | { 143 | return getBinder().inject(ScenarioReplicator.class); 144 | } 145 | 146 | } 147 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/agent/scenario/SimStatus.java: -------------------------------------------------------------------------------- 1 | package io.asimov.agent.scenario; 2 | 3 | import javax.persistence.Embeddable; 4 | 5 | /** 6 | * 7 | * {@link SimStatus} 8 | * 9 | * @date $Date: 2013-08-01 11:03:17 +0200 (do, 01 aug 2013) $ 10 | * @version $Revision: 328 $ 11 | * @author Jos 12 | * @author Rick 13 | * 14 | */ 15 | @Embeddable 16 | public enum SimStatus 17 | { 18 | /** simulation has been created */ 19 | CREATED, 20 | 21 | /** world is being build for simulation before simulation start time */ 22 | PREPARING, 23 | 24 | /** simulation is running */ 25 | RUNNING, 26 | 27 | /** simulation has finished */ 28 | FINISHED, 29 | 30 | /** simulation has been cancelled */ 31 | CANCELLED, 32 | 33 | ; 34 | } -------------------------------------------------------------------------------- /src/main/java/io/asimov/messaging/ASIMOVAllResourcesReadyMessage.java: -------------------------------------------------------------------------------- 1 | package io.asimov.messaging; 2 | 3 | import io.coala.agent.AgentID; 4 | import io.coala.message.AbstractMessage; 5 | import io.coala.time.SimTime; 6 | 7 | 8 | public class ASIMOVAllResourcesReadyMessage extends AbstractMessage 9 | { 10 | /** */ 11 | private static final long serialVersionUID = 2L; 12 | 13 | public String token = null; 14 | 15 | protected ASIMOVAllResourcesReadyMessage() 16 | { 17 | 18 | } 19 | 20 | /** 21 | * {@link ASIMOVAllResourcesReadyMessage} constructor 22 | * 23 | * @param time 24 | * @param senderID 25 | * @param receiverID 26 | * @param content 27 | */ 28 | public ASIMOVAllResourcesReadyMessage(final SimTime time, final AgentID senderID, 29 | final AgentID receiverID, final String token) 30 | { 31 | super(new ASIMOVMessageID(senderID.getModelID(), time), senderID 32 | .getModelID(), senderID, receiverID); 33 | this.token = token; 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /src/main/java/io/asimov/messaging/ASIMOVBasicAgent.java: -------------------------------------------------------------------------------- 1 | package io.asimov.messaging; 2 | 3 | import io.coala.agent.AgentID; 4 | import io.coala.agent.BasicAgent; 5 | import io.coala.bind.Binder; 6 | import io.coala.capability.interact.ReceivingCapability; 7 | import io.coala.lifecycle.ActivationType; 8 | import io.coala.log.InjectLogger; 9 | import io.coala.log.LogUtil; 10 | import io.coala.message.Message; 11 | import io.coala.model.ModelComponent; 12 | import io.coala.time.SimTime; 13 | 14 | import javax.inject.Inject; 15 | 16 | import org.apache.log4j.Logger; 17 | 18 | import rx.functions.Action1; 19 | 20 | /** 21 | * {@link ASIMOVBasicAgent} 22 | * 23 | * @date $Date: 2014-09-01 11:53:05 +0200 (ma, 01 sep 2014) $ 24 | * @version $Revision: 1048 $ 25 | * @author suki 26 | * 27 | * @param 28 | */ 29 | public abstract class ASIMOVBasicAgent extends BasicAgent implements ModelComponent 30 | { 31 | 32 | // sub-types: resource (equipment, room, occupant, etc.) 33 | 34 | /** */ 35 | private static final long serialVersionUID = -8697203058486189448L; 36 | 37 | @InjectLogger 38 | private Logger LOG; 39 | 40 | @Inject 41 | protected ASIMOVBasicAgent(final Binder binder) 42 | { 43 | super(binder); 44 | } 45 | 46 | @Override 47 | public void initialize() 48 | { 49 | if (LOG == null) 50 | { 51 | LOG = LogUtil.getLogger(ASIMOVBasicAgent.class, this); 52 | 53 | new NullPointerException("LOG was not injected??") 54 | .printStackTrace(); 55 | } 56 | LOG.info("ASIMOVAgent is initializing."); 57 | 58 | getBinder().inject(ReceivingCapability.class).getIncoming() 59 | .subscribe(new Action1>() 60 | { 61 | @Override 62 | public void call(Message m) 63 | { 64 | processMessage(m); 65 | } 66 | }); 67 | // initialize roles here 68 | } 69 | 70 | protected void processMessage(Message m) 71 | { 72 | throw new IllegalStateException( 73 | "processMessage not yet implemented! Failed to process message:" 74 | + m); 75 | } 76 | 77 | /** @see BasicAgent#getActivationType() */ 78 | @Override 79 | public ActivationType getActivationType() 80 | { 81 | return ActivationType.ACTIVATE_ONCE; 82 | } 83 | 84 | @Override 85 | public void finish() 86 | { 87 | if (LOG != null) 88 | LOG.info("ASIMOVAgent is finalizing."); 89 | } 90 | 91 | /** @see ModelComponent#getOwnerID() */ 92 | @Override 93 | public AgentID getOwnerID() 94 | { 95 | return getID(); 96 | } 97 | 98 | /** @see ModelComponent#getTime() */ 99 | @Override 100 | public SimTime getTime() 101 | { 102 | return getSimulator().getTime(); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/messaging/ASIMOVMessage.java: -------------------------------------------------------------------------------- 1 | package io.asimov.messaging; 2 | 3 | import io.coala.agent.AgentID; 4 | import io.coala.message.AbstractMessage; 5 | import io.coala.time.SimTime; 6 | 7 | import java.io.Serializable; 8 | 9 | /** 10 | * {@link ASIMOVMessage} 11 | * 12 | * @version $Revision: 1048 $ 13 | * @author Rick 14 | * 15 | */ 16 | public class ASIMOVMessage extends AbstractMessage 17 | { 18 | /** */ 19 | private static final long serialVersionUID = 1L; 20 | 21 | public Serializable content = null; 22 | 23 | protected ASIMOVMessage() 24 | { 25 | 26 | } 27 | 28 | /** 29 | * {@link ASIMOVMessage} constructor 30 | * 31 | * @param time 32 | * @param senderID 33 | * @param receiverID 34 | * @param content 35 | */ 36 | public ASIMOVMessage(final SimTime time, final AgentID senderID, 37 | final AgentID receiverID, final Serializable content) 38 | { 39 | super(new ASIMOVMessageID(senderID.getModelID(), time), senderID 40 | .getModelID(), senderID, receiverID); 41 | this.content = content; 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /src/main/java/io/asimov/messaging/ASIMOVMessageID.java: -------------------------------------------------------------------------------- 1 | package io.asimov.messaging; 2 | 3 | import io.coala.message.MessageID; 4 | import io.coala.model.ModelID; 5 | import io.coala.time.SimTime; 6 | 7 | /** 8 | * {@link ASIMOVMessageID} 9 | * 10 | * @version $Revision: 1048 $ 11 | * @author Rick 12 | * 13 | */ 14 | public class ASIMOVMessageID extends MessageID 15 | { 16 | 17 | /** */ 18 | private static final long serialVersionUID = 1L; 19 | 20 | private static long msgID = 0; 21 | 22 | private static synchronized long getNextCounterValue() { 23 | msgID++; 24 | return msgID; 25 | } 26 | 27 | protected ASIMOVMessageID() 28 | { 29 | 30 | } 31 | 32 | /** 33 | * {@link ASIMOVMessageID} constructor 34 | * 35 | * @param modelID 36 | * @param instant 37 | */ 38 | public ASIMOVMessageID(final ModelID modelID, final SimTime instant) 39 | { 40 | super(modelID, getNextCounterValue(), instant); 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /src/main/java/io/asimov/messaging/ASIMOVNewResourceMessage.java: -------------------------------------------------------------------------------- 1 | package io.asimov.messaging; 2 | 3 | import io.asimov.model.ASIMOVResourceDescriptor; 4 | import io.coala.agent.AgentID; 5 | import io.coala.message.AbstractMessage; 6 | import io.coala.time.SimTime; 7 | 8 | 9 | public class ASIMOVNewResourceMessage extends AbstractMessage 10 | { 11 | /** */ 12 | private static final long serialVersionUID = 4L; 13 | 14 | public ASIMOVResourceDescriptor resource = null; 15 | 16 | protected ASIMOVNewResourceMessage() 17 | { 18 | 19 | } 20 | 21 | /** 22 | * {@link ASIMOVNewResourceMessage} constructor 23 | * 24 | * @param time 25 | * @param senderID 26 | * @param receiverID 27 | * @param content 28 | */ 29 | public ASIMOVNewResourceMessage(final SimTime time, final AgentID senderID, 30 | final AgentID receiverID, final ASIMOVResourceDescriptor resource) 31 | { 32 | super(new ASIMOVMessageID(senderID.getModelID(), time), senderID 33 | .getModelID(), senderID, receiverID); 34 | this.resource = resource; 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /src/main/java/io/asimov/microservice/negotiation/AgentServiceProxy.java: -------------------------------------------------------------------------------- 1 | package io.asimov.microservice.negotiation; 2 | 3 | import io.coala.agent.AgentID; 4 | import io.coala.bind.Binder; 5 | 6 | /** 7 | * {@link AgentServiceProxy} 8 | * 9 | * @version $Revision: 1048 $ 10 | * @author Rick 11 | * 12 | */ 13 | public class AgentServiceProxy 14 | { 15 | private final Binder binder; 16 | 17 | /** 18 | * @return the binder 19 | */ 20 | public Binder getBinder() 21 | { 22 | return this.binder; 23 | } 24 | 25 | public AgentServiceProxy(final Binder b) 26 | { 27 | this.binder = b; 28 | } 29 | 30 | public AgentID getID() 31 | { 32 | return getBinder().getID(); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /src/main/java/io/asimov/microservice/negotiation/ClaimSortByProposal.java: -------------------------------------------------------------------------------- 1 | package io.asimov.microservice.negotiation; 2 | 3 | import io.asimov.microservice.negotiation.messages.Claim; 4 | import io.asimov.microservice.negotiation.messages.Proposal; 5 | import io.coala.capability.BasicCapabilityStatus; 6 | import io.coala.capability.Capability; 7 | import io.coala.capability.CapabilityFactory; 8 | 9 | import java.util.Comparator; 10 | 11 | import rx.Observable; 12 | 13 | /** 14 | * {@link ClaimSortByProposal} 15 | * 16 | * @date $Date: 2014-09-01 11:53:05 +0200 (ma, 01 sep 2014) $ 17 | * @version $Revision: 1048 $ 18 | * @author suki 19 | * 20 | */ 21 | public interface ClaimSortByProposal extends Capability 22 | { 23 | interface Factory extends CapabilityFactory 24 | { 25 | // empty 26 | } 27 | 28 | /** 29 | * Returns the claim's ordered based on the proposals generated by the 30 | * response to the query from the scoreQueryAdapter. 31 | * 32 | * @param claims the candidate claims 33 | * @param scoreQueryAdapter 34 | * @param proposalComparator the comparator to base the 35 | * @return 36 | * @throws Exception If an error was encountered during the request (message sending) of proposalsRequests. 37 | */ 38 | Observable sort(Iterable claims, 39 | ConversionCallback scoreQueryAdapter, 40 | Comparator proposalComparator) throws Exception; 41 | 42 | /** 43 | * The method that handles the incoming messages needed for the sort. 44 | * @param p the incoming proposal. 45 | */ 46 | void handle(Proposal p); 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/microservice/negotiation/ConversionCallback.java: -------------------------------------------------------------------------------- 1 | package io.asimov.microservice.negotiation; 2 | 3 | import java.io.Serializable; 4 | 5 | public interface ConversionCallback 6 | { 7 | /** 8 | * Method that converts the formula to determine requirement match and 9 | * availability to the formula for allocation confirmation. 10 | * 11 | * @param f Formula to determine requirement match and availability. 12 | * @return Converted formula for allocation confirmation. 13 | */ 14 | public Serializable convert(Serializable f); 15 | } -------------------------------------------------------------------------------- /src/main/java/io/asimov/microservice/negotiation/ResourceAllocationNegotiator.java: -------------------------------------------------------------------------------- 1 | package io.asimov.microservice.negotiation; 2 | 3 | import io.asimov.microservice.negotiation.ResourceAllocationRequestor.AllocationCallback; 4 | import io.coala.agent.AgentID; 5 | import io.coala.capability.BasicCapabilityStatus; 6 | import io.coala.capability.Capability; 7 | import io.coala.capability.CapabilityFactory; 8 | import io.coala.message.Message; 9 | 10 | import java.io.Serializable; 11 | import java.util.Map; 12 | import java.util.Set; 13 | 14 | import rx.Observable; 15 | 16 | /** 17 | * {@link ResourceAllocationNegotiator} 18 | * 19 | * @date $Date: 2014-09-23 16:13:57 +0200 (di, 23 sep 2014) $ 20 | * @version $Revision: 1074 $ 21 | * @author suki 22 | * 23 | */ 24 | public interface ResourceAllocationNegotiator extends Capability 25 | { 26 | interface Factory extends CapabilityFactory 27 | { 28 | // empty 29 | } 30 | 31 | public interface ConversionCallback 32 | { 33 | /** 34 | * Method that converts the formula to determine requirement match and 35 | * availability to the formula for allocation confirmation. 36 | * 37 | * @param f Formula to determine requirement match and availability. 38 | * @return Converted formula for allocation confirmation. 39 | */ 40 | public Serializable convert(Serializable f); 41 | } 42 | 43 | void processMessage(Message m); 44 | 45 | void deAllocate(final String scenarioAgentID); 46 | 47 | /** 48 | * @param callback 49 | * @param candidateMap 50 | * @param conversion 51 | */ 52 | Observable negotiate(AllocationCallback callback, 53 | Map> candidateMap, 54 | ConversionCallback conversion); 55 | 56 | } -------------------------------------------------------------------------------- /src/main/java/io/asimov/microservice/negotiation/ResourceAllocationRequestor.java: -------------------------------------------------------------------------------- 1 | package io.asimov.microservice.negotiation; 2 | 3 | import io.asimov.microservice.negotiation.messages.Claimed; 4 | import io.coala.agent.AgentID; 5 | import io.coala.capability.BasicCapabilityStatus; 6 | import io.coala.capability.Capability; 7 | import io.coala.capability.CapabilityFactory; 8 | 9 | import java.io.Serializable; 10 | import java.util.Map; 11 | import java.util.Set; 12 | 13 | /** 14 | * {@link ResourceAllocationRequestor} 15 | * 16 | * @date $Date: 2014-09-23 16:13:57 +0200 (di, 23 sep 2014) $ 17 | * @version $Revision: 1074 $ 18 | * @author suki 19 | * 20 | */ 21 | public interface ResourceAllocationRequestor extends Capability 22 | { 23 | 24 | interface Factory extends CapabilityFactory 25 | { 26 | // empty 27 | } 28 | 29 | public interface AllocationCallback 30 | { 31 | /** Gets the map of AIDs allocated for the required resources */ 32 | public Map getAllocatedResources(); 33 | 34 | /** Gets the AIDs of the unavailable resources. */ 35 | public Set getUnavailabeResourceIDs(); 36 | 37 | /** Check if allocation succeeded */ 38 | public boolean wasSucces(); 39 | 40 | /** 41 | * The callback method that will be called if all resource are 42 | * allocated. This method must be implemented to finalize the allocation 43 | * from the callers perspective. 44 | * 45 | * @param resources A map of AIDs allocated for the required resources. 46 | */ 47 | public void done(Map resources); 48 | 49 | /** 50 | * The callback method that will be called if a resource is unavailable. 51 | * 52 | * @param aids The AIDs of the unavailable resources. 53 | */ 54 | public void failure(Set aids); 55 | 56 | /** 57 | * The scenario agent ID 58 | * @return 59 | */ 60 | public AgentID getScenarioAgentID(); 61 | 62 | /** 63 | * This method is called if an error occurred during the execution of 64 | * the allocation protocol that was not caused by unavailability of the 65 | * resource. 66 | * @param error The cause of the error 67 | */ 68 | public void error(Exception error); 69 | } 70 | 71 | void resetFailedClaims(); 72 | 73 | /** 74 | * @param candidateMap the candidateMap to set 75 | */ 76 | void setCandidateMap(Map> candidateMap); 77 | 78 | void handleIncommingClaimed(Claimed claimed); 79 | 80 | void doAllocation(AllocationCallback callback); 81 | 82 | void deAllocate(final String scenarioAgentID) throws Exception; 83 | 84 | /** 85 | * @return the queryToAssertionMap 86 | */ 87 | Map getQueryToAssertionMap(); 88 | 89 | /** 90 | * @param queryToAssertionMap the queryToAssertionMap to set 91 | */ 92 | void setQueryToAssertionMap( 93 | Map queryToAssertionMap); 94 | 95 | } -------------------------------------------------------------------------------- /src/main/java/io/asimov/microservice/negotiation/ResourceAllocationResponder.java: -------------------------------------------------------------------------------- 1 | package io.asimov.microservice.negotiation; 2 | 3 | import io.asimov.microservice.negotiation.messages.AvailabilityCheck; 4 | import io.asimov.microservice.negotiation.messages.AvailabilityReply; 5 | import io.asimov.microservice.negotiation.messages.Claim; 6 | import io.asimov.microservice.negotiation.messages.Claimed; 7 | import io.asimov.microservice.negotiation.messages.Proposal; 8 | import io.asimov.microservice.negotiation.messages.ProposalRequest; 9 | import io.coala.capability.BasicCapabilityStatus; 10 | import io.coala.capability.Capability; 11 | import io.coala.capability.CapabilityFactory; 12 | import io.coala.message.Message; 13 | 14 | /** 15 | * {@link ResourceAllocationResponder} 16 | * 17 | * @date $Date: 2014-09-01 11:53:05 +0200 (ma, 01 sep 2014) $ 18 | * @version $Revision: 1048 $ 19 | * @author suki 20 | * 21 | */ 22 | public interface ResourceAllocationResponder extends Capability 23 | { 24 | 25 | interface Factory extends CapabilityFactory 26 | { 27 | // empty 28 | } 29 | 30 | void processMessage(Message m); 31 | 32 | Claimed processClaim(Claim claim); 33 | 34 | AvailabilityReply processAvailabilityCheck( 35 | AvailabilityCheck availabilityCheck); 36 | 37 | void reset(); 38 | 39 | /** 40 | * @param proposalRequest 41 | * @return the proposal with the score 42 | */ 43 | Proposal processProposalRequest(ProposalRequest proposalRequest); 44 | 45 | } -------------------------------------------------------------------------------- /src/main/java/io/asimov/microservice/negotiation/ResourceReadyListeningResource.java: -------------------------------------------------------------------------------- 1 | package io.asimov.microservice.negotiation; 2 | 3 | import io.asimov.microservice.negotiation.ResourceReadyNotification.ResourceReadyListener; 4 | 5 | 6 | /** 7 | * {@link ResourceReadyListeningResource} 8 | * 9 | * @date $Date: 2014-07-10 08:44:48 +0200 (do, 10 jul 2014) $ 10 | * @version $Revision: 977 $ 11 | * @author suki 12 | * 13 | */ 14 | public interface ResourceReadyListeningResource 15 | { 16 | ResourceReadyListener getResourceReadyListener(); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/microservice/negotiation/impl/NegotiatingCapability.java: -------------------------------------------------------------------------------- 1 | package io.asimov.microservice.negotiation.impl; 2 | 3 | import io.asimov.db.Datasource; 4 | import io.asimov.microservice.negotiation.AgentServiceProxy; 5 | import io.asimov.model.TraceService; 6 | import io.asimov.model.events.ActivityEvent; 7 | import io.asimov.model.events.Event; 8 | import io.asimov.model.events.EventType; 9 | import io.coala.bind.Binder; 10 | import io.coala.capability.BasicCapability; 11 | import io.coala.capability.replicate.ReplicatingCapability; 12 | import io.coala.log.LogUtil; 13 | import io.coala.time.SimTime; 14 | 15 | import java.util.Collections; 16 | import java.util.List; 17 | 18 | import org.apache.log4j.Logger; 19 | 20 | import rx.Observer; 21 | import rx.subjects.PublishSubject; 22 | import rx.subjects.Subject; 23 | 24 | public class NegotiatingCapability extends BasicCapability { 25 | 26 | /** 27 | * 28 | */ 29 | private static final long serialVersionUID = -2911404735178698550L; 30 | 31 | private static Logger LOG = LogUtil.getLogger(NegotiatingCapability.class); 32 | 33 | protected final AgentServiceProxy agentServiceProxy; 34 | 35 | private Subject allocation = PublishSubject 36 | .create(); 37 | 38 | 39 | protected NegotiatingCapability(Binder binder) { 40 | this(new AgentServiceProxy(binder)); 41 | } 42 | 43 | 44 | public NegotiatingCapability(AgentServiceProxy agent) 45 | { 46 | super(agent.getBinder()); 47 | this.agentServiceProxy = agent; 48 | } 49 | 50 | protected AgentServiceProxy getAgentServiceProxy() 51 | { 52 | return agentServiceProxy; 53 | } 54 | 55 | public static class AlreadyAllocatedException extends Exception { 56 | 57 | /** 58 | * 59 | */ 60 | private static final long serialVersionUID = 2796747050881798664L; 61 | 62 | } 63 | 64 | public static class NotAllocatedException extends Exception { 65 | 66 | /** 67 | * 68 | */ 69 | private static final long serialVersionUID = 2786747050881798664L; 70 | 71 | } 72 | 73 | public void performAllocationChange(final String resourceName, 74 | final EventType eventType) throws Exception { 75 | // LOG.info("fire ASIMOV resource unavailability event!"); 76 | // if (eventType.equals(EventType.ALLOCATED) && allocated.contains(resourceName)) 77 | // throw new AlreadyAllocatedException(); 78 | // else if (eventType.equals(EventType.ALLOCATED)) { 79 | // allocated.add(resourceName); 80 | // System.out.println(getID().getOwnerID()+" allocated "+resourceName); 81 | // } 82 | // if (eventType.equals(EventType.DEALLOCATED) && !allocated.contains(resourceName)) 83 | // throw new AlreadyAllocatedException(); 84 | // else if (eventType.equals(EventType.DEALLOCATED)) { 85 | // allocated.remove(resourceName); 86 | // System.out.println(getID().getOwnerID()+" de-allocated "+resourceName); 87 | // } 88 | if (eventType.equals(EventType.ALLOCATED) || eventType.equals(EventType.DEALLOCATED)) 89 | fireAndForget(eventType, Collections.singletonList(resourceName), 90 | this.allocation); 91 | else 92 | LOG.error("Unsupported event type for (de-)allocation"); 93 | } 94 | 95 | @SuppressWarnings("unchecked") 96 | protected > void fireAndForget( 97 | final EventType eventType, final List involvedResources, 98 | final Observer publisher) { 99 | final SimTime now = getBinder().inject(ReplicatingCapability.class) 100 | .getTime(); 101 | publisher.onNext((T) TraceService.getInstance( 102 | getAgentServiceProxy().getID().getModelID().getValue()).saveEvent( 103 | getBinder().inject(Datasource.class), null, null, null, null, 104 | involvedResources, eventType, now)); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/microservice/negotiation/messages/AvailabilityCheck.java: -------------------------------------------------------------------------------- 1 | package io.asimov.microservice.negotiation.messages; 2 | 3 | import io.asimov.messaging.ASIMOVMessageID; 4 | import io.coala.agent.AgentID; 5 | import io.coala.json.JSONConvertible; 6 | import io.coala.json.JsonUtil; 7 | import io.coala.log.LogUtil; 8 | import io.coala.message.AbstractMessage; 9 | import io.coala.name.Identifier; 10 | import io.coala.time.SimTime; 11 | 12 | import java.io.Serializable; 13 | 14 | import org.apache.log4j.Logger; 15 | 16 | import com.fasterxml.jackson.annotation.JsonIgnore; 17 | import com.fasterxml.jackson.core.JsonProcessingException; 18 | 19 | public class AvailabilityCheck extends AbstractMessage implements 20 | Serializable, JSONConvertible 21 | { 22 | /** */ 23 | private static final long serialVersionUID = 1L; 24 | 25 | @JsonIgnore 26 | private static final Logger LOG = LogUtil 27 | .getLogger(AvailabilityCheck.class); 28 | 29 | public Serializable requirements; 30 | 31 | protected AvailabilityCheck() 32 | { 33 | // Zero arguments constructor 34 | } 35 | 36 | public AvailabilityCheck(final SimTime time, final AgentID senderID, 37 | final AgentID receiverID) 38 | { 39 | 40 | super(new ASIMOVMessageID(senderID.getModelID(), time), senderID 41 | .getModelID(), senderID, receiverID); 42 | } 43 | 44 | /** 45 | * @return the requirements 46 | */ 47 | public Serializable getRequirements() 48 | { 49 | return requirements; 50 | } 51 | 52 | /** 53 | * @param requirements the requirements to set 54 | */ 55 | public void setRequirements(Serializable requirements) 56 | { 57 | this.requirements = requirements; 58 | } 59 | 60 | /** @see Identifier#toString() */ 61 | @Override 62 | public String toString() 63 | { 64 | return String.format("%s%s", getClass().getSimpleName(), toJSON()); 65 | } 66 | 67 | /** @see JSONConvertible#toJSON() */ 68 | @Override 69 | public String toJSON() 70 | { 71 | try 72 | { 73 | // final JsonNode node = JsonUtil.getJOM().valueToTree(this); 74 | return JsonUtil.getJOM().writeValueAsString(this); 75 | } catch (final JsonProcessingException e) 76 | { 77 | LOG.warn( 78 | "Problem marshalling " + getClass().getName() + " to JSON", 79 | e); 80 | return String.format("id=\"%s\"", getID()); 81 | } 82 | } 83 | 84 | @Override 85 | public AvailabilityCheck fromJSON(final String jsonValue) 86 | { 87 | return JsonUtil.fromJSONString(jsonValue, AvailabilityCheck.class); 88 | } 89 | 90 | } -------------------------------------------------------------------------------- /src/main/java/io/asimov/microservice/negotiation/messages/AvailabilityReply.java: -------------------------------------------------------------------------------- 1 | package io.asimov.microservice.negotiation.messages; 2 | 3 | import io.asimov.messaging.ASIMOVMessageID; 4 | import io.coala.agent.AgentID; 5 | import io.coala.json.JSONConvertible; 6 | import io.coala.json.JsonUtil; 7 | import io.coala.log.LogUtil; 8 | import io.coala.message.AbstractMessage; 9 | import io.coala.name.Identifier; 10 | import io.coala.time.SimTime; 11 | 12 | import java.io.Serializable; 13 | 14 | import org.apache.log4j.Logger; 15 | 16 | import com.fasterxml.jackson.annotation.JsonIgnore; 17 | import com.fasterxml.jackson.core.JsonProcessingException; 18 | 19 | /** 20 | * {@link AvailabilityReply} 21 | * 22 | * @version $Revision: 1049 $ 23 | * @author Rick 24 | */ 25 | public class AvailabilityReply extends AbstractMessage implements 26 | Serializable, JSONConvertible 27 | { 28 | /** */ 29 | private static final long serialVersionUID = 1L; 30 | 31 | @JsonIgnore 32 | private static final Logger LOG = LogUtil 33 | .getLogger(AvailabilityReply.class); 34 | 35 | public boolean available; 36 | public Serializable requirements; 37 | public ASIMOVMessageID replyToId; 38 | 39 | protected AvailabilityReply() 40 | { 41 | // Zero arguments constructor 42 | } 43 | 44 | public AvailabilityReply(final AvailabilityCheck source, 45 | final SimTime time, final AgentID senderID, final AgentID receiverID) 46 | { 47 | super(source.getID(), senderID.getModelID(), senderID, receiverID); 48 | requirements = source.getRequirements(); 49 | replyToId = source.getID(); 50 | } 51 | 52 | /** 53 | * @return the available 54 | */ 55 | public boolean isAvailable() 56 | { 57 | return available; 58 | } 59 | 60 | /** 61 | * @param available the available to set 62 | */ 63 | public void setAvailable(boolean available) 64 | { 65 | this.available = available; 66 | } 67 | 68 | /** 69 | * @return the requirements 70 | */ 71 | public Serializable getRequirements() 72 | { 73 | return requirements; 74 | } 75 | 76 | /** 77 | * @param requirements the requirements to set 78 | */ 79 | public void setRequirements(Serializable requirements) 80 | { 81 | this.requirements = requirements; 82 | } 83 | 84 | /** @see Identifier#toString() */ 85 | @Override 86 | public String toString() 87 | { 88 | return String.format("%s%s", getClass().getSimpleName(), toJSON()); 89 | } 90 | 91 | /** @see JSONConvertible#toJSON() */ 92 | @Override 93 | public String toJSON() 94 | { 95 | try 96 | { 97 | // final JsonNode node = JsonUtil.getJOM().valueToTree(this); 98 | return JsonUtil.getJOM().writeValueAsString(this); 99 | } catch (final JsonProcessingException e) 100 | { 101 | LOG.warn( 102 | "Problem marshalling " + getClass().getName() + " to JSON", 103 | e); 104 | return String.format("id=\"%s\"", getReplyToId()); 105 | } 106 | } 107 | 108 | @Override 109 | public AvailabilityReply fromJSON(final String jsonValue) 110 | { 111 | return JsonUtil.fromJSONString(jsonValue, AvailabilityReply.class); 112 | } 113 | 114 | public ASIMOVMessageID getReplyToId() 115 | { 116 | return this.replyToId; 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/microservice/negotiation/messages/Claim.java: -------------------------------------------------------------------------------- 1 | package io.asimov.microservice.negotiation.messages; 2 | 3 | import io.asimov.messaging.ASIMOVMessageID; 4 | import io.coala.agent.AgentID; 5 | import io.coala.json.JSONConvertible; 6 | import io.coala.json.JsonUtil; 7 | import io.coala.log.LogUtil; 8 | import io.coala.message.AbstractMessage; 9 | import io.coala.name.Identifier; 10 | import io.coala.time.SimTime; 11 | 12 | import java.io.Serializable; 13 | 14 | import org.apache.log4j.Logger; 15 | 16 | import com.fasterxml.jackson.core.JsonProcessingException; 17 | 18 | public class Claim extends AbstractMessage implements 19 | Serializable, JSONConvertible 20 | { 21 | /** */ 22 | private static final long serialVersionUID = 1L; 23 | 24 | private static final Logger LOG = LogUtil.getLogger(Claim.class); 25 | 26 | private boolean deClaim = false; 27 | 28 | private Serializable query; 29 | 30 | private Serializable assertion; 31 | 32 | protected Claim() 33 | { 34 | // zero argument constructor 35 | } 36 | 37 | public Claim(final SimTime time, final AgentID senderID, 38 | final AgentID receiverID) 39 | { 40 | 41 | super(new ASIMOVMessageID(senderID.getModelID(), time), senderID 42 | .getModelID(), senderID, receiverID); 43 | } 44 | 45 | /** 46 | * @return the deClaim 47 | */ 48 | public boolean isDeClaim() 49 | { 50 | return deClaim; 51 | } 52 | 53 | /** 54 | * @param deClaim the deClaim to set 55 | */ 56 | public void setDeClaim(boolean deClaim) 57 | { 58 | this.deClaim = deClaim; 59 | } 60 | 61 | /** @see Identifier#toString() */ 62 | @Override 63 | public String toString() 64 | { 65 | return String.format("%s%s", getClass().getSimpleName(), toJSON()); 66 | } 67 | 68 | /** @see JSONConvertible#toJSON() */ 69 | @Override 70 | public String toJSON() 71 | { 72 | try 73 | { 74 | // final JsonNode node = JsonUtil.getJOM().valueToTree(this); 75 | return JsonUtil.getJOM().writeValueAsString(this); 76 | } catch (final JsonProcessingException e) 77 | { 78 | LOG.warn( 79 | "Problem marshalling " + getClass().getName() + " to JSON", 80 | e); 81 | return String.format("id=\"%s\"", getID()); 82 | } 83 | } 84 | 85 | @Override 86 | public Claim fromJSON(final String jsonValue) 87 | { 88 | return JsonUtil.fromJSONString(jsonValue, Claim.class); 89 | } 90 | 91 | /** 92 | * @return the query 93 | */ 94 | public Serializable getQuery() 95 | { 96 | return query; 97 | } 98 | 99 | /** 100 | * @param query the query to set 101 | */ 102 | public void setQuery(Serializable query) 103 | { 104 | this.query = query; 105 | } 106 | 107 | /** 108 | * @return the assertion 109 | */ 110 | public Serializable getAssertion() 111 | { 112 | return assertion; 113 | } 114 | 115 | /** 116 | * @param assertion the assertion to set 117 | */ 118 | public void setAssertion(Serializable assertion) 119 | { 120 | this.assertion = assertion; 121 | } 122 | } -------------------------------------------------------------------------------- /src/main/java/io/asimov/microservice/negotiation/messages/Claimed.java: -------------------------------------------------------------------------------- 1 | package io.asimov.microservice.negotiation.messages; 2 | 3 | import io.asimov.messaging.ASIMOVMessageID; 4 | import io.coala.agent.AgentID; 5 | import io.coala.json.JSONConvertible; 6 | import io.coala.json.JsonUtil; 7 | import io.coala.log.LogUtil; 8 | import io.coala.message.AbstractMessage; 9 | import io.coala.name.Identifier; 10 | import io.coala.time.SimTime; 11 | 12 | import java.io.Serializable; 13 | 14 | import org.apache.log4j.Logger; 15 | 16 | import com.fasterxml.jackson.core.JsonProcessingException; 17 | 18 | public class Claimed extends AbstractMessage implements 19 | Serializable, JSONConvertible 20 | { 21 | /** */ 22 | private static final long serialVersionUID = 1L; 23 | 24 | private static final Logger LOG = LogUtil.getLogger(Claimed.class); 25 | 26 | public boolean available; 27 | 28 | private ASIMOVMessageID replyToId; 29 | 30 | protected Claimed() 31 | { 32 | // zero argument constructor 33 | } 34 | 35 | public Claimed(final Claim source, final SimTime time, 36 | final AgentID senderID, final AgentID receiverID) 37 | { 38 | super(source.getID(), senderID.getModelID(), senderID, receiverID); 39 | replyToId = source.getID(); 40 | } 41 | 42 | /** 43 | * @return the available 44 | */ 45 | public boolean isAvailable() 46 | { 47 | return available; 48 | } 49 | 50 | /** 51 | * @param available the available to set 52 | */ 53 | public void setAvailable(boolean available) 54 | { 55 | this.available = available; 56 | } 57 | 58 | /** 59 | * @return the id 60 | */ 61 | public ASIMOVMessageID getReplyToId() 62 | { 63 | return replyToId; 64 | } 65 | 66 | /** @see Identifier#toString() */ 67 | @Override 68 | public String toString() 69 | { 70 | return String.format("%s%s", getClass().getSimpleName(), toJSON()); 71 | } 72 | 73 | /** @see JSONConvertible#toJSON() */ 74 | @Override 75 | public String toJSON() 76 | { 77 | try 78 | { 79 | // final JsonNode node = JsonUtil.getJOM().valueToTree(this); 80 | return JsonUtil.getJOM().writeValueAsString(this); 81 | } catch (final JsonProcessingException e) 82 | { 83 | LOG.warn( 84 | "Problem marshalling " + getClass().getName() + " to JSON", 85 | e); 86 | return String.format("id=\"%s\"", getID()); 87 | } 88 | } 89 | 90 | @Override 91 | public Claimed fromJSON(final String jsonValue) 92 | { 93 | return JsonUtil.fromJSONString(jsonValue, Claimed.class); 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/microservice/negotiation/messages/Proposal.java: -------------------------------------------------------------------------------- 1 | package io.asimov.microservice.negotiation.messages; 2 | 3 | import io.asimov.messaging.ASIMOVMessageID; 4 | import io.coala.agent.AgentID; 5 | import io.coala.json.JSONConvertible; 6 | import io.coala.json.JsonUtil; 7 | import io.coala.log.LogUtil; 8 | import io.coala.message.AbstractMessage; 9 | import io.coala.name.Identifier; 10 | import io.coala.time.SimTime; 11 | 12 | import java.io.Serializable; 13 | 14 | import org.apache.log4j.Logger; 15 | 16 | import com.fasterxml.jackson.core.JsonProcessingException; 17 | 18 | /** 19 | * {@link Proposal} 20 | * 21 | * @version $Revision: 1049 $ 22 | * @author Rick 23 | * 24 | */ 25 | public class Proposal extends AbstractMessage implements 26 | Serializable, JSONConvertible 27 | { 28 | /** */ 29 | private static final long serialVersionUID = 1L; 30 | 31 | private static final Logger LOG = LogUtil.getLogger(Proposal.class); 32 | 33 | private ASIMOVMessageID replyToId; 34 | 35 | private double score; 36 | 37 | protected Proposal() 38 | { 39 | // zero argument constructor 40 | } 41 | 42 | public Proposal(final ProposalRequest source, final SimTime time, 43 | final AgentID senderID, final AgentID receiverID) 44 | { 45 | super(source.getID(), senderID.getModelID(), senderID, receiverID); 46 | replyToId = source.getID(); 47 | } 48 | 49 | /** 50 | * @return the score 51 | */ 52 | public double getScore() 53 | { 54 | return this.score; 55 | } 56 | 57 | /** 58 | * @param score the score to set 59 | */ 60 | public void setScore(double score) 61 | { 62 | this.score = score; 63 | } 64 | 65 | /** 66 | * @return the id 67 | */ 68 | public ASIMOVMessageID getReplyToId() 69 | { 70 | return replyToId; 71 | } 72 | 73 | /** @see Identifier#toString() */ 74 | @Override 75 | public String toString() 76 | { 77 | return String.format("%s%s", getClass().getSimpleName(), toJSON()); 78 | } 79 | 80 | /** @see JSONConvertible#toJSON() */ 81 | @Override 82 | public String toJSON() 83 | { 84 | try 85 | { 86 | // final JsonNode node = JsonUtil.getJOM().valueToTree(this); 87 | return JsonUtil.getJOM().writeValueAsString(this); 88 | } catch (final JsonProcessingException e) 89 | { 90 | LOG.warn( 91 | "Problem marshalling " + getClass().getName() + " to JSON", 92 | e); 93 | return String.format("id=\"%s\"", getID()); 94 | } 95 | } 96 | 97 | @Override 98 | public Proposal fromJSON(final String jsonValue) 99 | { 100 | return JsonUtil.fromJSONString(jsonValue, Proposal.class); 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/microservice/negotiation/messages/ProposalRequest.java: -------------------------------------------------------------------------------- 1 | package io.asimov.microservice.negotiation.messages; 2 | 3 | import io.asimov.messaging.ASIMOVMessageID; 4 | import io.coala.agent.AgentID; 5 | import io.coala.json.JSONConvertible; 6 | import io.coala.json.JsonUtil; 7 | import io.coala.log.LogUtil; 8 | import io.coala.message.AbstractMessage; 9 | import io.coala.name.Identifier; 10 | import io.coala.time.SimTime; 11 | 12 | import java.io.Serializable; 13 | 14 | import org.apache.log4j.Logger; 15 | 16 | import com.fasterxml.jackson.core.JsonProcessingException; 17 | 18 | /** 19 | * {@link ProposalRequest} 20 | * 21 | * @version $Revision: 1049 $ 22 | * @author Rick 23 | * 24 | */ 25 | public class ProposalRequest extends AbstractMessage implements 26 | Serializable, JSONConvertible 27 | { 28 | /** */ 29 | private static final long serialVersionUID = 1L; 30 | 31 | private static final Logger LOG = LogUtil.getLogger(ProposalRequest.class); 32 | 33 | private Serializable query; 34 | 35 | private Claim claim; 36 | 37 | protected ProposalRequest() 38 | { 39 | // zero argument constructor 40 | } 41 | 42 | public ProposalRequest(final SimTime time, final AgentID senderID, 43 | final AgentID receiverID) 44 | { 45 | super(new ASIMOVMessageID(senderID.getModelID(), time), senderID 46 | .getModelID(), senderID, receiverID); 47 | } 48 | 49 | /** @see Identifier#toString() */ 50 | @Override 51 | public String toString() 52 | { 53 | return String.format("%s%s", getClass().getSimpleName(), toJSON()); 54 | } 55 | 56 | /** @see JSONConvertible#toJSON() */ 57 | @Override 58 | public String toJSON() 59 | { 60 | try 61 | { 62 | // final JsonNode node = JsonUtil.getJOM().valueToTree(this); 63 | return JsonUtil.getJOM().writeValueAsString(this); 64 | } catch (final JsonProcessingException e) 65 | { 66 | LOG.warn( 67 | "Problem marshalling " + getClass().getName() + " to JSON", 68 | e); 69 | return String.format("id=\"%s\"", getID()); 70 | } 71 | } 72 | 73 | @Override 74 | public ProposalRequest fromJSON(final String jsonValue) 75 | { 76 | return JsonUtil.fromJSONString(jsonValue, ProposalRequest.class); 77 | } 78 | 79 | /** 80 | * @return the query 81 | */ 82 | public Serializable getQuery() 83 | { 84 | return query; 85 | } 86 | 87 | /** 88 | * @param query the query to set 89 | */ 90 | public void setQuery(Serializable query) 91 | { 92 | this.query = query; 93 | } 94 | 95 | /** 96 | * @return the claim 97 | */ 98 | public Serializable getClaim() 99 | { 100 | return claim; 101 | } 102 | 103 | /** 104 | * @param claim the claim to set 105 | */ 106 | public void setClaim(Claim claim) 107 | { 108 | this.claim = claim; 109 | } 110 | } -------------------------------------------------------------------------------- /src/main/java/io/asimov/model/ASIMOVContext.java: -------------------------------------------------------------------------------- 1 | package io.asimov.model; 2 | 3 | import io.asimov.agent.scenario.Context; 4 | import io.asimov.xml.TContext; 5 | import io.asimov.xml.TResource; 6 | 7 | import java.util.ArrayList; 8 | import java.util.HashMap; 9 | import java.util.List; 10 | import java.util.Map; 11 | import java.util.Set; 12 | 13 | public class ASIMOVContext implements Context { 14 | 15 | 16 | final private static Map>> resources = 17 | new HashMap>>(); 18 | 19 | 20 | 21 | @Override 22 | public Set getResourceTypes() { 23 | return resources.keySet(); 24 | } 25 | 26 | @Override 27 | public > Iterable getResources( 28 | final String resourceType) { 29 | return resources.get(resourceType); 30 | } 31 | 32 | @Override 33 | public ASIMOVContext fromXML(TContext xmlBean) { 34 | for (io.asimov.xml.TResource resource : xmlBean.getResource()) { 35 | if (resources.containsKey(resource.getResourceType())) 36 | resources.put(resource.getResourceType(), new ArrayList>()); 37 | List> resourceContainer = resources.get(resource.getResourceType()); 38 | ASIMOVResourceDescriptor resourceDescriptor = new ASIMOVResourceDescriptor().fromXML(resource); 39 | resourceContainer.add((AbstractEmbodied)resourceDescriptor); 40 | } 41 | return this; 42 | } 43 | 44 | @Override 45 | public TContext toXML() { 46 | TContext context = new TContext(); 47 | for (String type : getResourceTypes()) { 48 | for (Object r : getResources(type)) { 49 | context.getResource().add((TResource)((ASIMOVResourceDescriptor) r).toXML()); 50 | } 51 | } 52 | return context; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/model/ASIMOVOrganizationWorld.java: -------------------------------------------------------------------------------- 1 | package io.asimov.model; 2 | 3 | import io.coala.capability.CapabilityID; 4 | import io.coala.capability.embody.GroundingCapability; 5 | import io.coala.model.ModelComponent; 6 | 7 | /** 8 | * {@link ASIMOVOrganizationWorld} 9 | * 10 | * @version $Revision: 1048 $ 11 | * @author Rick 12 | * 13 | */ 14 | public interface ASIMOVOrganizationWorld extends GroundingCapability, 15 | ModelComponent 16 | { 17 | 18 | /** */ 19 | String WORLD_NAME = "world"; 20 | 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/model/AbstractASIMOVOrganizationtWorld.java: -------------------------------------------------------------------------------- 1 | package io.asimov.model; 2 | 3 | import io.coala.agent.AgentID; 4 | import io.coala.bind.Binder; 5 | import io.coala.capability.BasicCapability; 6 | import io.coala.capability.CapabilityID; 7 | import io.coala.capability.embody.GroundingCapability; 8 | import io.coala.capability.replicate.ReplicatingCapability; 9 | import io.coala.model.ModelComponent; 10 | import io.coala.time.Instant; 11 | 12 | import javax.inject.Inject; 13 | 14 | /** 15 | * {@link AbstractASIMOVOrganizationtWorld} 16 | * 17 | * @version $Revision: 1048 $ 18 | * @author Rick 19 | * 20 | */ 21 | public abstract class AbstractASIMOVOrganizationtWorld extends BasicCapability implements 22 | GroundingCapability, ModelComponent 23 | { 24 | 25 | /** */ 26 | private static final long serialVersionUID = 1L; 27 | 28 | /** 29 | * {@link AbstractASIMOVOrganizationtWorld} constructor 30 | * @param binder 31 | */ 32 | @Inject 33 | protected AbstractASIMOVOrganizationtWorld(final Binder binder) 34 | { 35 | super(binder); 36 | } 37 | 38 | 39 | /** @see ModelComponent#getOwnerID() */ 40 | @Override 41 | public AgentID getOwnerID() 42 | { 43 | return getBinder().getID(); 44 | } 45 | 46 | /** @see ModelComponent#getTime() */ 47 | @Override 48 | public Instant getTime() 49 | { 50 | return getBinder().inject(ReplicatingCapability.class).getTime(); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/model/AbstractEntity.java: -------------------------------------------------------------------------------- 1 | package io.asimov.model; 2 | 3 | import java.util.UUID; 4 | 5 | import javax.persistence.Entity; 6 | import javax.persistence.GeneratedValue; 7 | import javax.persistence.Id; 8 | import javax.persistence.Inheritance; 9 | import javax.persistence.InheritanceType; 10 | 11 | import org.eclipse.persistence.annotations.UuidGenerator; 12 | import org.eclipse.persistence.nosql.annotations.DataFormatType; 13 | import org.eclipse.persistence.nosql.annotations.Field; 14 | import org.eclipse.persistence.nosql.annotations.NoSql; 15 | 16 | /** 17 | * {@link AbstractEntity} 18 | * 19 | * @date $Date: 2014-03-26 20:36:21 +0100 (Wed, 26 Mar 2014) $ 20 | * @version $Revision: 796 $ 21 | * @author Rick 22 | * 23 | */ 24 | @Entity 25 | @UuidGenerator(name = "EMP_ID_GEN") 26 | @Inheritance(strategy= InheritanceType.TABLE_PER_CLASS) 27 | @NoSql(dataFormat = DataFormatType.MAPPED) 28 | public abstract class AbstractEntity> extends 29 | AbstractNamed 30 | { 31 | 32 | /** */ 33 | // private static final Logger LOG = Logger.getLogger(AbstractEntity.class); 34 | 35 | /** */ 36 | private static final long serialVersionUID = 1L; 37 | 38 | /** */ 39 | @Id 40 | @GeneratedValue(generator = "EMP_ID_GEN") 41 | @Field(name = "_id") 42 | private String id; 43 | 44 | /** @return the object identifier, managed by the database */ 45 | public UUID getUUID() 46 | { 47 | return this.id == null ? null : UUID.fromString(this.id); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/model/AbstractNamed.java: -------------------------------------------------------------------------------- 1 | package io.asimov.model; 2 | 3 | import io.asimov.model.Named; 4 | import io.coala.json.JSONConvertible; 5 | import io.coala.json.JsonUtil; 6 | import io.coala.log.LogUtil; 7 | import io.coala.name.AbstractIdentifier; 8 | import io.coala.name.Identifier; 9 | 10 | import org.apache.log4j.Logger; 11 | import org.eclipse.persistence.nosql.annotations.DataFormatType; 12 | import org.eclipse.persistence.nosql.annotations.NoSql; 13 | 14 | import com.fasterxml.jackson.annotation.JsonIgnore; 15 | import com.fasterxml.jackson.annotation.JsonInclude; 16 | import com.fasterxml.jackson.annotation.JsonInclude.Include; 17 | import com.fasterxml.jackson.core.JsonProcessingException; 18 | 19 | /** 20 | * {@link AbstractNamed} 21 | * 22 | * @date $Date: 2014-09-11 15:17:30 +0200 (do, 11 sep 2014) $ 23 | * @version $Revision: 1049 $ 24 | * @author Rick 25 | * 26 | */ 27 | @JsonInclude(Include.NON_NULL) 28 | @NoSql(dataFormat = DataFormatType.MAPPED) 29 | public abstract class AbstractNamed> extends 30 | AbstractIdentifier implements Named //, JSONConvertible// 31 | { 32 | 33 | /** */ 34 | private static final Logger LOG = LogUtil.getLogger(AbstractNamed.class); 35 | 36 | /** */ 37 | private static final long serialVersionUID = 1L; 38 | 39 | /** */ 40 | private String name = null; 41 | 42 | /** @param name the name to set for this {@link THIS} */ 43 | protected void setName(final String name) 44 | { 45 | this.name = name; 46 | super.setValue(name); 47 | } 48 | 49 | /** @return the name of this {@link THIS} */ 50 | @Override 51 | public String getName() 52 | { 53 | return this.name; 54 | } 55 | 56 | /** 57 | * @param value the (unique) value of this {@link AbstractNamed} object 58 | * @return this {@link AbstractNamed} object 59 | */ 60 | @SuppressWarnings("unchecked") 61 | protected THIS withValue(final String value) 62 | { 63 | setValue(value); 64 | return (THIS) this; 65 | } 66 | 67 | /** @param name the name to set for this {@link THIS} */ 68 | @SuppressWarnings("unchecked") 69 | public THIS withName(final String name) 70 | { 71 | setName(name); 72 | return (THIS) this; 73 | } 74 | 75 | /** @see Identifier#setValue(Comparable) */ 76 | @Override 77 | protected void setValue(final String value) 78 | { 79 | setName(value); 80 | } 81 | 82 | /** @see Identifier#getValue() */ 83 | @Override 84 | @JsonIgnore 85 | public String getValue() 86 | { 87 | return getName(); 88 | } 89 | 90 | /** @see Identifier#toString() */ 91 | @Override 92 | public String toString() 93 | { 94 | return String.format("%s%s", getClass().getSimpleName(), toJSON()); 95 | } 96 | 97 | /** @see JSONConvertible#toJSON() */ 98 | @Override 99 | public String toJSON() 100 | { 101 | try 102 | { 103 | // final JsonNode node = JsonUtil.getJOM().valueToTree(this); 104 | return JsonUtil.getJOM().writeValueAsString(this); 105 | } catch (final JsonProcessingException e) 106 | { 107 | LOG.warn( 108 | "Problem marshalling " + getClass().getName() + " to JSON", 109 | e); 110 | return String.format("name=\"%s\"", getValue()); 111 | } 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/model/AbstractPersonTraceEventProducer.java: -------------------------------------------------------------------------------- 1 | package io.asimov.model; 2 | 3 | import io.asimov.model.events.Event; 4 | import io.coala.log.LogUtil; 5 | 6 | import java.rmi.RemoteException; 7 | 8 | import nl.tudelft.simulation.dsol.SimRuntimeException; 9 | import nl.tudelft.simulation.dsol.formalisms.eventscheduling.SimEvent; 10 | 11 | import org.apache.log4j.Logger; 12 | 13 | /** 14 | * {@link AbstractPersonTraceEventProducer} 15 | * 16 | * @date $Date: 2014-11-24 12:10:07 +0100 (ma, 24 nov 2014) $ 17 | * @version $Revision: 1122 $ 18 | * @author Rick 19 | */ 20 | public abstract class AbstractPersonTraceEventProducer extends 21 | AbstractPersonTraceModelComponent implements 22 | ResourceTraceEventProducer 23 | { 24 | 25 | /** */ 26 | private static final long serialVersionUID = 1L; 27 | 28 | /** */ 29 | private static final Logger LOG = LogUtil 30 | .getLogger(AbstractPersonTraceEventProducer.class); 31 | 32 | /** 33 | * {@link AbstractPersonTraceEventProducer} constructor 34 | * 35 | * @param model 36 | * @param name 37 | */ 38 | protected AbstractPersonTraceEventProducer( 39 | final ResourceTraceModel model, final String name) 40 | { 41 | super(model, name); 42 | } 43 | 44 | /** 45 | * @param startActivity 46 | * @throws SimRuntimeException 47 | * @throws RemoteException 48 | */ 49 | protected void scheduleTraceEvent(final Event event) 50 | throws RemoteException, SimRuntimeException 51 | { 52 | scheduleTraceEvent(event, event.getExecutionTime().doubleValue()); 53 | } 54 | 55 | /** 56 | * @param startActivity 57 | * @throws SimRuntimeException 58 | * @throws RemoteException 59 | */ 60 | protected void scheduleTraceEvent(final Event event, 61 | final Number absExecTime) throws RemoteException, 62 | SimRuntimeException 63 | { 64 | final double interval = simTime(extrapolatePeriod); 65 | if (extrapolateRepeat > 0 && absExecTime.doubleValue() > interval) 66 | { 67 | LOG.warn("Ignoring event at t=" + absExecTime 68 | + " beyond exrapolate interval: " + extrapolatePeriod); 69 | return; 70 | } 71 | 72 | final int n = 1 + Math.max(0, extrapolateRepeat); 73 | for (int i = 0; i < n; i++) 74 | { 75 | final double t = i * interval + absExecTime.doubleValue(); 76 | final ResourceTraceEventWrapper wrappedEvent = new ResourceTraceEventWrapper( 77 | this, t, event); 78 | getSimulator().scheduleEvent( 79 | new SimEvent(t, this, this, FIRE_TRACE_EVENT_METHOD_ID, 80 | new Object[] { wrappedEvent })); 81 | } 82 | } 83 | 84 | /** */ 85 | private static final String FIRE_TRACE_EVENT_METHOD_ID = "fireTraceEvent"; 86 | 87 | /** */ 88 | protected void fireTraceEvent(final ResourceTraceEventWrapper event) 89 | { 90 | try 91 | { 92 | fireEvent(event); 93 | } catch (final Throwable t) 94 | { 95 | LOG.warn("Problem while handling event: " + event); 96 | } 97 | } 98 | 99 | /** @see ResourceTraceEventProducer#addListener(ResourceTraceEventListener) */ 100 | @Override 101 | public void addListener(final ResourceTraceEventListener listener) 102 | { 103 | addListener(new ResourceTraceEventWrapperListener(listener), 104 | ResourceTraceEventWrapper.OCCUPANT_EVENT_TYPE); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/model/AbstractPersonTraceModelComponent.java: -------------------------------------------------------------------------------- 1 | package io.asimov.model; 2 | 3 | import io.coala.dsol.util.AbstractDsolModelComponent; 4 | import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface; 5 | 6 | /** 7 | * {@link AbstractPersonTraceModelComponent} 8 | * 9 | * @date $Date: 2014-05-07 11:59:38 +0200 (Wed, 07 May 2014) $ 10 | * @version $Revision: 880 $ 11 | * @author Rick 12 | * 13 | */ 14 | public abstract class AbstractPersonTraceModelComponent extends 15 | AbstractDsolModelComponent 16 | implements PersonTraceModelComponent 17 | { 18 | 19 | /** */ 20 | private static final long serialVersionUID = 1L; 21 | 22 | /** 23 | * {@link AbstractPersonTraceModelComponent} constructor 24 | * 25 | * @param model 26 | * @param name 27 | */ 28 | public AbstractPersonTraceModelComponent(final ResourceTraceModel model, 29 | final String name) 30 | { 31 | super(model, name); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/model/Connection.java: -------------------------------------------------------------------------------- 1 | package io.asimov.model; 2 | 3 | 4 | 5 | /** 6 | * 7 | * @author suki 8 | */ 9 | public abstract class Connection extends AbstractEntity implements XMLConvertible 10 | { 11 | 12 | /** */ 13 | private static final long serialVersionUID = 1L; 14 | 15 | public static final String DELAY = "DELAY"; 16 | 17 | private Time delay; 18 | 19 | public Time getDelay() 20 | { 21 | if (delay == null) 22 | delay = new Time(); 23 | return delay; 24 | } 25 | 26 | public void setDelay(Time delay) 27 | { 28 | this.delay = delay; 29 | } 30 | 31 | @Override 32 | public boolean equals(Object obj) 33 | { 34 | if (obj == null) 35 | { 36 | return false; 37 | } 38 | if (getClass() != obj.getClass()) 39 | { 40 | return false; 41 | } 42 | final Connection other = (Connection) obj; 43 | if (this.delay != other.delay 44 | && (this.delay == null || !this.delay.equals(other.delay))) 45 | { 46 | return false; 47 | } 48 | return true; 49 | } 50 | 51 | @Override 52 | public int hashCode() 53 | { 54 | int hash = 7; 55 | hash = 37 * hash + (this.delay != null ? this.delay.hashCode() : 0); 56 | return hash; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/model/ConnectionFrom.java: -------------------------------------------------------------------------------- 1 | package io.asimov.model; 2 | 3 | import io.asimov.model.sl.ASIMOVTerm; 4 | 5 | import javax.persistence.Entity; 6 | 7 | import org.eclipse.persistence.nosql.annotations.NoSql; 8 | 9 | /** 10 | * 11 | * @author suki 12 | */ 13 | @Entity 14 | @NoSql(dataType = "connections") 15 | public class ConnectionFrom extends Connection 16 | { 17 | 18 | /** */ 19 | private static final long serialVersionUID = 1L; 20 | 21 | public static String TERM_NAME = "CONNECTION_FROM"; 22 | 23 | public static final String SOURCE_BODY = "SOURCE_BODY"; 24 | 25 | /** Pattern for a {@link ConnectionFrom} {@link Term} representation */ 26 | public static ASIMOVTerm PATTERN = new ASIMOVTerm().withName(TERM_NAME) 27 | .instantiate().add(DELAY, null) 28 | .add(SOURCE_BODY, null); 29 | 30 | protected ASIMOVTerm getPattern(){ 31 | return PATTERN; 32 | } 33 | 34 | 35 | private Body sourceBody; 36 | 37 | /** 38 | * 39 | * @return 40 | */ 41 | public Body getSourceBody() 42 | { 43 | return sourceBody; 44 | } 45 | 46 | /** 47 | * 48 | * @param source 49 | */ 50 | public void setSourceBody(Body sourceBody) 51 | { 52 | this.sourceBody = sourceBody; 53 | } 54 | 55 | @Override 56 | public boolean equals(Object obj) 57 | { 58 | if (obj == null) 59 | { 60 | return false; 61 | } 62 | if (getClass() != obj.getClass()) 63 | { 64 | return false; 65 | } 66 | final ConnectionFrom other = (ConnectionFrom) obj; 67 | if (this.getSourceBody() != other.getSourceBody() 68 | && (this.getSourceBody() == null || !this.getSourceBody() 69 | .equals(other.getSourceBody()))) 70 | { 71 | return false; 72 | } 73 | if (this.getDelay() != other.getDelay() 74 | && (this.getDelay() == null || !this.getDelay().equals( 75 | other.getDelay()))) 76 | { 77 | if (this.getDelay() == null || other.getDelay() == null) 78 | return true; 79 | else 80 | return false; 81 | } 82 | return true; 83 | } 84 | 85 | @Override 86 | public int hashCode() 87 | { 88 | int hash = 7; 89 | hash = 89 90 | * hash 91 | + (this.getSourceBody() != null ? this.getSourceBody() 92 | .hashCode() : 0); 93 | hash = 89 * hash 94 | + (this.getDelay() != null ? this.getDelay().hashCode() : 0); 95 | return hash; 96 | } 97 | 98 | @Override 99 | public Connection fromXML(Object xmlBean) 100 | { 101 | // TODO Auto-generated method stub 102 | return null; 103 | } 104 | 105 | @Override 106 | public Object toXML() 107 | { 108 | // TODO Auto-generated method stub 109 | return null; 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/model/ConnectionTo.java: -------------------------------------------------------------------------------- 1 | package io.asimov.model; 2 | 3 | import io.asimov.model.sl.ASIMOVTerm; 4 | 5 | import javax.persistence.Entity; 6 | 7 | import org.eclipse.persistence.nosql.annotations.NoSql; 8 | 9 | /** 10 | * 11 | * @author suki 12 | */ 13 | @Entity 14 | @NoSql(dataType = "connections") 15 | public class ConnectionTo extends Connection 16 | { 17 | 18 | /** */ 19 | private static final long serialVersionUID = 1L; 20 | 21 | public static String TERM_NAME = "CONNECTION_TO"; 22 | 23 | public static final String TARGET_BODY = "TARGET_BODY"; 24 | 25 | /** Pattern for a {@link ConnectionTo} {@link Term} representation */ 26 | public static ASIMOVTerm PATTERN = new ASIMOVTerm().withName(TERM_NAME) 27 | .instantiate().add(DELAY, null) 28 | .add(TARGET_BODY, null); 29 | 30 | protected ASIMOVTerm getPattern(){ 31 | return PATTERN; 32 | } 33 | 34 | private Body targetBody; 35 | 36 | /** 37 | * 38 | * @return 39 | */ 40 | public Body getTargetBody() 41 | { 42 | return targetBody; 43 | } 44 | 45 | /** 46 | * 47 | * @param source 48 | */ 49 | public void setTargetBody(Body targetBody) 50 | { 51 | this.targetBody = targetBody; 52 | } 53 | 54 | @Override 55 | public boolean equals(Object obj) 56 | { 57 | if (obj == null) 58 | { 59 | return false; 60 | } 61 | if (getClass() != obj.getClass()) 62 | { 63 | return false; 64 | } 65 | final ConnectionTo other = (ConnectionTo) obj; 66 | if (this.getTargetBody() != other.getTargetBody() 67 | && (this.getTargetBody() == null || !this.getTargetBody() 68 | .equals(other.getTargetBody()))) 69 | { 70 | return false; 71 | } 72 | if (this.getDelay() != other.getDelay() 73 | && (this.getDelay() == null || !this.getDelay().equals( 74 | other.getDelay()))) 75 | { 76 | if (this.getDelay() == null || other.getDelay() == null) 77 | return true; 78 | else 79 | return false; 80 | } 81 | return true; 82 | } 83 | 84 | @Override 85 | public int hashCode() 86 | { 87 | int hash = 3; 88 | hash = 97 * hash 89 | + (this.targetBody != null ? this.targetBody.hashCode() : 0); 90 | hash = 97 * hash 91 | + (this.getDelay() != null ? this.getDelay().hashCode() : 0); 92 | return hash; 93 | } 94 | 95 | @Override 96 | public Connection fromXML(Object xmlBean) 97 | { 98 | // TODO Auto-generated method stub 99 | return null; 100 | } 101 | 102 | @Override 103 | public Object toXML() 104 | { 105 | // TODO Auto-generated method stub 106 | return null; 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/model/DirectlyContains.java: -------------------------------------------------------------------------------- 1 | package io.asimov.model; 2 | 3 | import io.asimov.model.sl.ASIMOVTerm; 4 | 5 | import javax.persistence.Entity; 6 | 7 | import org.eclipse.persistence.nosql.annotations.NoSql; 8 | 9 | /** 10 | * 11 | * @author suki 12 | */ 13 | @Entity 14 | @NoSql(dataType = "containers") 15 | public class DirectlyContains extends ConnectionTo 16 | { 17 | 18 | /** */ 19 | private static final long serialVersionUID = 1L; 20 | 21 | public static String TERM_NAME = "DIRECTLY_CONTAINS"; 22 | 23 | /** Pattern for a {@link DirectlyContains} {@link Term} representation */ 24 | public static ASIMOVTerm PATTERN = new ASIMOVTerm().withName(TERM_NAME) 25 | .instantiate().add(DELAY, null) 26 | .add(TARGET_BODY, null); 27 | 28 | protected ASIMOVTerm getPattern(){ 29 | return PATTERN; 30 | } 31 | 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/model/DirectlyIn.java: -------------------------------------------------------------------------------- 1 | package io.asimov.model; 2 | 3 | import io.asimov.model.sl.ASIMOVTerm; 4 | 5 | import javax.persistence.Entity; 6 | 7 | import org.eclipse.persistence.nosql.annotations.NoSql; 8 | 9 | /** 10 | * 11 | * @author suki 12 | */ 13 | @Entity 14 | @NoSql(dataType = "containers") 15 | public class DirectlyIn extends ConnectionFrom 16 | { 17 | 18 | /** */ 19 | private static final long serialVersionUID = 1L; 20 | 21 | 22 | public static String TERM_NAME = "DIRECTLY_IN"; 23 | 24 | /** Pattern for a {@link DirectlyIn} {@link Term} representation */ 25 | public static ASIMOVTerm PATTERN = new ASIMOVTerm().withName(TERM_NAME) 26 | .instantiate().add(DELAY, null) 27 | .add(SOURCE_BODY, null); 28 | 29 | protected ASIMOVTerm getPattern(){ 30 | return PATTERN; 31 | } 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/model/Named.java: -------------------------------------------------------------------------------- 1 | package io.asimov.model; 2 | 3 | /** 4 | * {@link Named} 5 | * 6 | * @date $Date: 2013-08-09 14:31:03 +0200 (vr, 09 aug 2013) $ 7 | * @version $Revision: 347 $ 8 | * @author Rick 9 | * 10 | */ 11 | public interface Named 12 | { 13 | /** @return the name of this {@link Named} object */ 14 | String getName(); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/model/PersonTraceModelComponent.java: -------------------------------------------------------------------------------- 1 | package io.asimov.model; 2 | 3 | import org.joda.time.Duration; 4 | import org.joda.time.Period; 5 | 6 | import io.coala.dsol.util.DsolModelComponent; 7 | import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface; 8 | 9 | /** 10 | * {@link PersonTraceModelComponent} 11 | * 12 | * @date $Date: 2014-09-28 14:42:17 +0200 (zo, 28 sep 2014) $ 13 | * @version $Revision: 1083 $ 14 | * @author Rick 15 | * 16 | */ 17 | public interface PersonTraceModelComponent extends 18 | DsolModelComponent 19 | { 20 | 21 | /** */ 22 | String ALL_ACTIVITIES = "ALL Activities"; 23 | 24 | /** */ 25 | String ANY_ACTIVITY = "Any Activity"; 26 | 27 | /** */ 28 | String ALL_EQUIPMENT = "ALL Equipment"; 29 | 30 | /** */ 31 | String ALL_LIGHTING = "ALL Lighting"; 32 | 33 | /** */ 34 | String ALL_ROOMS = "ALL Rooms"; 35 | 36 | /** */ 37 | String ALL_OCCUPANTS = "ALL Occupants"; 38 | 39 | /** */ 40 | String ANY_OCCUPANT = "ANY Occupant"; 41 | 42 | /** */ 43 | String EXTRAPOLATE_PERIOD_KEY = "extrapolate.period"; 44 | 45 | /** */ 46 | String EXTRAPOLATE_REPEAT_KEY = "extrapolate.repeat"; 47 | 48 | /** */ 49 | Duration extrapolatePeriod = Period.parse( 50 | System.getProperty(EXTRAPOLATE_PERIOD_KEY, "P7D")) 51 | .toStandardDuration(); 52 | 53 | /** */ 54 | Integer extrapolateRepeat = Integer.valueOf(System.getProperty( 55 | EXTRAPOLATE_REPEAT_KEY, "0")); 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/model/ResourceAllocation.java: -------------------------------------------------------------------------------- 1 | package io.asimov.model; 2 | 3 | import io.asimov.model.sl.ASIMOVNode; 4 | import io.asimov.model.sl.ASIMOVTerm; 5 | import io.asimov.model.sl.SL; 6 | import io.asimov.model.sl.SLConvertible; 7 | 8 | import javax.persistence.Embeddable; 9 | 10 | /** 11 | * 12 | * {@link ResourceAllocation} 13 | * 14 | * @date $Date: 2014-03-28 11:22:14 +0100 (Fri, 28 Mar 2014) $ 15 | * @version $Revision: 806 $ 16 | * @author Rick 17 | * 18 | */ 19 | @Embeddable 20 | public class ResourceAllocation extends AbstractNamed 21 | implements SLConvertible, 22 | XMLConvertible 23 | { 24 | 25 | /** */ 26 | private static final long serialVersionUID = 1L; 27 | 28 | /** */ 29 | private String resourceRequirementID; 30 | 31 | /** */ 32 | private String allocatedAgentID; 33 | 34 | /** */ 35 | public static final String RESOURCE_ALLOCATION_TERM = "RESOURCE_ALLOCATION"; 36 | 37 | /** */ 38 | public static final String ALLOCATED_AGENT_AID = "ALLOCATED_AGENT_AID"; 39 | 40 | /** */ 41 | public static final String RESOURCE_REQUIREMENT_ID = "RESOURCE_REQUIREMENT_ID"; 42 | 43 | /** */ 44 | public static final ASIMOVTerm PATTERN = new ASIMOVTerm() 45 | .withName(RESOURCE_ALLOCATION_TERM) 46 | .instantiate().add(ALLOCATED_AGENT_AID, null) 47 | .add(RESOURCE_REQUIREMENT_ID, null) 48 | .add(RESOURCE_ALLOCATION_TERM, SL.string(ResourceAllocation.class.getName())); 49 | 50 | /** */ 51 | private static long counter = 0L; 52 | 53 | /** */ 54 | public ResourceAllocation() 55 | { 56 | withName("alloc" + (++counter)); 57 | } 58 | 59 | /** @return the resourceRequirementID */ 60 | public String getResourceRequirementID() 61 | { 62 | return this.resourceRequirementID; 63 | } 64 | 65 | /** @param resourceRequirementID the resourceRequirementID to set */ 66 | protected void setResourceRequirementID(final String resourceRequirementID) 67 | { 68 | this.resourceRequirementID = resourceRequirementID; 69 | } 70 | 71 | /** @param resourceRequirementID the resourceRequirementID to set */ 72 | public ResourceAllocation withResourceRequirementID( 73 | final String resourceRequirementID) 74 | { 75 | setResourceRequirementID(resourceRequirementID); 76 | return this; 77 | } 78 | 79 | /** @return the allocatedAgentID */ 80 | public String getAllocatedAgentID() 81 | { 82 | return this.allocatedAgentID; 83 | } 84 | 85 | /** @param allocatedAgentID the allocatedAgentID to set */ 86 | protected void setAllocatedAgentID(final String allocatedAgentID) 87 | { 88 | this.allocatedAgentID = allocatedAgentID; 89 | } 90 | 91 | /** @param allocatedAgentID the allocatedAgentID to set */ 92 | public ResourceAllocation withAllocatedAgentID(final String allocatedAgentID) 93 | { 94 | setAllocatedAgentID(allocatedAgentID); 95 | return this; 96 | } 97 | 98 | /** @see SLConvertible#toSL() */ 99 | @Override 100 | @SuppressWarnings("unchecked") 101 | public ASIMOVTerm toSL() 102 | { 103 | return PATTERN.instantiate().add(ALLOCATED_AGENT_AID, 104 | new ASIMOVTerm().withName(getAllocatedAgentID())).add( 105 | RESOURCE_REQUIREMENT_ID, SL.string(getResourceRequirementID())); 106 | } 107 | 108 | /** @see XMLConvertible#toXML() */ 109 | @Override 110 | public Object toXML() 111 | { 112 | // FIXME implement 113 | throw new IllegalStateException("Not Implemented!"); 114 | } 115 | 116 | /** @see XMLConvertible#fromXML(Object) */ 117 | @Override 118 | public ResourceAllocation fromXML(final Object xmlBean) 119 | { 120 | // FIXME implement 121 | return this; 122 | } 123 | 124 | /** @see SLConvertible#fromSL(Term) */ 125 | @Override 126 | public > ResourceAllocation fromSL(final N term) 127 | { 128 | // FIXME implement 129 | return this; 130 | } 131 | 132 | } -------------------------------------------------------------------------------- /src/main/java/io/asimov/model/ResourceTraceEventListener.java: -------------------------------------------------------------------------------- 1 | package io.asimov.model; 2 | 3 | import io.asimov.model.events.ActivityEvent; 4 | 5 | /** 6 | * {@link ResourceTraceEventListener} 7 | * 8 | * @date $Date: 2014-09-11 15:17:30 +0200 (do, 11 sep 2014) $ 9 | * @version $Revision: 1049 $ 10 | * @author Rick 11 | */ 12 | public interface ResourceTraceEventListener extends PersonTraceModelComponent 13 | { 14 | 15 | /** @param event the newly triggered {@link ActivityEvent} */ 16 | void onActivity(ActivityEvent event); 17 | 18 | /** called when no more events occur */ 19 | void onTraceComplete(); 20 | } -------------------------------------------------------------------------------- /src/main/java/io/asimov/model/ResourceTraceEventProducer.java: -------------------------------------------------------------------------------- 1 | package io.asimov.model; 2 | 3 | 4 | /** 5 | * {@link ResourceTraceEventProducer} 6 | * 7 | * @date $Date: 2014-07-21 11:41:22 +0200 (ma, 21 jul 2014) $ 8 | * @version $Revision: 1004 $ 9 | * @author Rick 10 | */ 11 | public interface ResourceTraceEventProducer extends PersonTraceModelComponent 12 | { 13 | 14 | /** @param listener the listener */ 15 | void addListener(ResourceTraceEventListener listener); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/model/ResourceTraceEventType.java: -------------------------------------------------------------------------------- 1 | package io.asimov.model; 2 | 3 | /** */ 4 | enum ResourceTraceEventType 5 | { 6 | /** */ 7 | ACTIVITY, 8 | 9 | /** */ 10 | USAGE, 11 | 12 | /** */ 13 | MOVEMENT, 14 | 15 | /** */ 16 | DONE, 17 | 18 | ; 19 | } -------------------------------------------------------------------------------- /src/main/java/io/asimov/model/ResourceTraceEventWrapper.java: -------------------------------------------------------------------------------- 1 | package io.asimov.model; 2 | 3 | import io.asimov.model.events.ActivityEvent; 4 | import io.asimov.model.events.Event; 5 | import io.asimov.xml.TEventTrace.EventRecord; 6 | import nl.tudelft.simulation.event.EventType; 7 | import nl.tudelft.simulation.event.TimedEvent; 8 | 9 | /** 10 | * {@link ResourceTraceEventWrapper} wraps any {@link PersonEvent} bean inside 11 | * a DSOL {@link TimedEvent} 12 | * 13 | * @date $Date: 2014-09-11 15:17:30 +0200 (do, 11 sep 2014) $ 14 | * @version $Revision: 1049 $ 15 | * @author Rick 16 | */ 17 | public class ResourceTraceEventWrapper extends TimedEvent implements 18 | XMLConvertible 19 | { 20 | 21 | /** */ 22 | private static final long serialVersionUID = 1L; 23 | 24 | /** */ 25 | public static final EventType OCCUPANT_EVENT_TYPE = new EventType( 26 | "person"); 27 | 28 | /** */ 29 | private final ResourceTraceEventType type; 30 | 31 | /** 32 | * {@link DsolMovementEvent} constructor 33 | * 34 | * @param absSimTime 35 | * @param oldRate 36 | * @param newRate 37 | */ 38 | public ResourceTraceEventWrapper(final Event event) 39 | { 40 | this(null, event.getExecutionTime().getValue().doubleValue(), event); 41 | } 42 | 43 | /** 44 | * {@link DsolMovementEvent} constructor 45 | * 46 | * @param absSimTime 47 | * @param oldRate 48 | * @param newRate 49 | */ 50 | public ResourceTraceEventWrapper(final Number absSimTime, 51 | final Event event) 52 | { 53 | this(null, absSimTime, event); 54 | } 55 | 56 | /** 57 | * {@link DsolMovementEvent} constructor 58 | * 59 | * @param source 60 | * @param absSimTime 61 | * @param oldRate 62 | * @param newRate 63 | */ 64 | public ResourceTraceEventWrapper(final ResourceTraceEventProducer source, 65 | final Number absSimTime, final Event event) 66 | { 67 | super(OCCUPANT_EVENT_TYPE, source, event, absSimTime.doubleValue()); 68 | if (event == null) 69 | this.type = ResourceTraceEventType.DONE; 70 | else if (event instanceof ActivityEvent) 71 | this.type = ResourceTraceEventType.ACTIVITY; 72 | else 73 | throw new IllegalStateException("Event type unsupported: " 74 | + event.getClass().getName()); 75 | } 76 | 77 | public ResourceTraceEventType getPersonEventType() 78 | { 79 | return this.type; 80 | } 81 | 82 | 83 | /** 84 | * @return {@code true} if wrapped {@link PersonEvent} is a 85 | * {@link ActivityEvent}, {@code false} otherwise 86 | */ 87 | public boolean isActivityEvent() 88 | { 89 | return getPersonEventType() == ResourceTraceEventType.ACTIVITY; 90 | } 91 | 92 | /** 93 | * @return {@code true} if wrapped {@link PersonEvent} is a 94 | * {@link MaterialEvent}, {@code false} otherwise 95 | */ 96 | public boolean isUsageEvent() 97 | { 98 | return getPersonEventType() == ResourceTraceEventType.USAGE; 99 | } 100 | 101 | /** 102 | * @return {@code true} if wrapped {@link PersonEvent} is a 103 | * {@link MovementEvent}, {@code false} otherwise 104 | */ 105 | public boolean isMovementEvent() 106 | { 107 | return getPersonEventType() == ResourceTraceEventType.MOVEMENT; 108 | } 109 | 110 | 111 | public ActivityEvent getActivity() 112 | { 113 | return isActivityEvent() ? (ActivityEvent) getContent() : null; 114 | } 115 | 116 | 117 | /** @see XMLConvertible#fromXML(java.lang.Object) */ 118 | @Override 119 | public ResourceTraceEventWrapper fromXML(final EventRecord event) 120 | { 121 | return 122 | // isMovementEvent() ? getMovement().fromXML(event, null, null) 123 | // : isActivityEvent() ? getActivity().fromXML(event, null, null) 124 | // : isUsageEvent() ? getUsage().fromXML(event, null, null) : 125 | null; 126 | } 127 | 128 | /** @see XMLConvertible#toXML() */ 129 | @Override 130 | public EventRecord toXML() 131 | { 132 | return isActivityEvent() ? getActivity().toXML() : null; 133 | } 134 | 135 | } -------------------------------------------------------------------------------- /src/main/java/io/asimov/model/ResourceTraceEventWrapperListener.java: -------------------------------------------------------------------------------- 1 | package io.asimov.model; 2 | 3 | import nl.tudelft.simulation.event.EventInterface; 4 | import nl.tudelft.simulation.event.EventListenerInterface; 5 | 6 | /** 7 | * {@link ResourceTraceEventWrapperListener} wraps a 8 | * {@link ResourceTraceEventListener} on which it triggers respective methods 9 | * based on the content type of the {@link ResourceTraceEventWrapper} events it 10 | * listens to 11 | * 12 | * @date $Date: 2014-09-11 15:17:30 +0200 (do, 11 sep 2014) $ 13 | * @version $Revision: 1049 $ 14 | * @author Rick 15 | */ 16 | public class ResourceTraceEventWrapperListener implements 17 | EventListenerInterface 18 | { 19 | /** */ 20 | private final ResourceTraceEventListener listener; 21 | 22 | public ResourceTraceEventWrapperListener( 23 | final ResourceTraceEventListener listener) 24 | { 25 | this.listener = listener; 26 | } 27 | 28 | @Override 29 | public void notify(final EventInterface event) 30 | { 31 | if (event instanceof ResourceTraceEventWrapper == false) 32 | throw new IllegalStateException("Unexpected event type: " 33 | + event.getClass().getName()); 34 | 35 | final ResourceTraceEventWrapper ote = (ResourceTraceEventWrapper) event; 36 | switch (ote.getPersonEventType()) 37 | { 38 | case ACTIVITY: 39 | this.listener.onActivity(ote.getActivity()); 40 | break; 41 | default: 42 | throw new IllegalStateException("Unsupported event type: " 43 | + ote.getPersonEventType()); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /src/main/java/io/asimov/model/ResourceType.java: -------------------------------------------------------------------------------- 1 | package io.asimov.model; 2 | 3 | public class ResourceType extends AbstractNamed 4 | { 5 | 6 | /** 7 | * 8 | */ 9 | private static final long serialVersionUID = -2974456469547801645L; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/io/asimov/model/Time.java: -------------------------------------------------------------------------------- 1 | package io.asimov.model; 2 | 3 | import io.asimov.model.sl.ASIMOVNode; 4 | import io.asimov.model.sl.ASIMOVTerm; 5 | import io.asimov.model.sl.SL; 6 | import io.asimov.reasoning.sl.SLConvertible; 7 | 8 | import javax.persistence.Entity; 9 | 10 | import org.eclipse.persistence.nosql.annotations.NoSql; 11 | 12 | /** 13 | * 14 | * @author suki 15 | */ 16 | @Entity 17 | @NoSql(dataType = "time") 18 | public class Time extends AbstractEntity