Class MicroserviceInstance
java.lang.Object
desmoj.core.simulator.NamedObject
desmoj.core.simulator.ModelComponent
desmoj.core.simulator.Schedulable
desmoj.core.simulator.Entity
cambio.simulator.entities.NamedEntity
cambio.simulator.entities.networking.RequestSender
cambio.simulator.entities.microservice.MicroserviceInstance
- All Implemented Interfaces:
IRequestUpdateListener
,Comparable<IRequestUpdateListener>
A
MicroserviceInstance
(in the following just called instance) represents an actual, running instance of a
Microservice
.
An instance has responsibility to handle incoming requests. This is done by either:
1. Sending an answer back to
the requester, if the request is completed
2. Creating child requests for satisfying the dependencies of a
request
3. Submitting the request to its CPU
for handling of its computational demand.
During its lifetime an instances is aware of all requests it currently handles and of all dependencies it is currently waiting for.
An instance can have different states, which are defined and described by the enum InstanceState
.
- Author:
- Lion Wagner
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final List<ServiceDependencyInstance>
protected final List<ServiceDependencyInstance>
protected final CPU
protected final Set<RequestAnswer>
protected final Set<InternalRequest>
protected final Set<ServiceDependencyInstance>
protected final int
protected long
protected final Microservice
protected Set<InstanceOwnedPattern>
protected final MultiDataPointReporter
protected InstanceState
protected long
Fields inherited from class cambio.simulator.entities.networking.RequestSender
updateListenerProxy
Fields inherited from class desmoj.core.simulator.Schedulable
_schedule
-
Constructor Summary
ConstructorsConstructorDescriptionMicroserviceInstance
(desmoj.core.simulator.Model model, String name, boolean showInTrace, Microservice microservice, int instanceID) Creates a newMicroserviceInstance
for the givenMicroservice
parent. -
Method Summary
Modifier and TypeMethodDescriptionvoid
activatePatterns
(InstanceOwnedPatternConfiguration[] patterns) Activates the patterns that are owned by this instance.boolean
checkIfCanHandle
(Request request) Checks whether this Instance can handle the Request.final void
die()
Immediately kills this instance.final void
Completes the shutdown and transitions the instance into theInstanceState.SHUTDOWN
state.getCpu()
final int
final Microservice
getOwner()
double
Gets the relative work demand.getState()
Gets the state of the instance.double
getUsage()
Gets the current usage of the instance.void
Submits aRequest
at this instance for handling.protected void
handleIncomingRequest
(Request request) protected void
handleRequestAnswer
(RequestAnswer answer) boolean
onRequestArrivalAtTarget
(Request request, desmoj.core.simulator.TimeInstant when) Listener for the successful completion of the sending process.boolean
onRequestFailed
(Request request, desmoj.core.simulator.TimeInstant when, RequestFailedReason reason) Listener for the failure of the sending process.boolean
onRequestResultArrivedAtRequester
(Request request, desmoj.core.simulator.TimeInstant when) Listener for the successful receiving of the answer of a request.boolean
onRequestSend
(Request request, desmoj.core.simulator.TimeInstant when) Listener for the send-off of a request.void
setState
(InstanceState state) void
start()
Starts this instance, reading it to receive requests.final void
Starts the shutdown sequence of this instance.protected void
submitProcessToCPU
(CPUProcess newProcess) Methods inherited from class cambio.simulator.entities.networking.RequestSender
addUpdateListener, addUpdateListeners, sendRequest, sendRequest, sendRequest, sendRequest
Methods inherited from class cambio.simulator.entities.NamedEntity
getPlainName, getQuotedName, getQuotedPlainName, rename
Methods inherited from class desmoj.core.simulator.Entity
clone, generateTraceForScheduling, getIdentNumber, getQueueingPriority, getQueues, getScheduledEvents, isEqual, isLarger, isLargerOrEqual, isNotEqual, isQueued, isSimProcess, isSmaller, isSmallerOrEqual, schedule, schedule, schedule, schedule, schedule, schedule, schedule, schedule, schedule, scheduleAfter, scheduleAfter, scheduleAfter, scheduleBefore, scheduleBefore, scheduleBefore, schedulePreempt, schedulePreempt, schedulePreempt, setQueueingPriority
Methods inherited from class desmoj.core.simulator.Schedulable
assignReporter, cancel, getCorrespondingReportable, isCurrent, isScheduled, reSchedule, reSchedule, reSchedulePreempt, scheduledNext, setCorrespondingReportable
Methods inherited from class desmoj.core.simulator.ModelComponent
current, currentEntity, currentEntityAll, currentEvent, currentlySendDebugNotes, currentlySendTraceNotes, currentModel, currentSimProcess, debugIsOn, debugOff, debugOn, getModel, isExperimentCompatible, isModelCompatible, presentTime, sendDebugNote, sendMessage, sendTraceNote, sendWarning, skipTraceNote, skipTraceNote, traceIsOn, traceOff, traceOn
Methods inherited from class desmoj.core.simulator.NamedObject
getName, toString
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface cambio.simulator.entities.networking.IRequestUpdateListener
compareTo, getListeningPriority
-
Field Details
-
owner
-
cpu
-
instanceID
protected final int instanceID -
currentRequestsToHandle
-
currentlyOpenDependencies
-
currentAnswers
-
currentInternalSends
-
reporter
-
closedDependencies
-
abortedDependencies
-
state
-
patterns
-
notComputed
protected long notComputed -
waiting
protected long waiting
-
-
Constructor Details
-
MicroserviceInstance
public MicroserviceInstance(desmoj.core.simulator.Model model, String name, boolean showInTrace, Microservice microservice, int instanceID) Creates a newMicroserviceInstance
for the givenMicroservice
parent.- Parameters:
model
- Base model of the simulation.name
- Name of the instance.showInTrace
- Whether the instance outputs should be shown in the trace.microservice
- Parent microservice of the instance.instanceID
- ID of the instance.
-
-
Method Details
-
activatePatterns
Activates the patterns that are owned by this instance. This will call registersIRequestUpdateListener
s on this instance and call theIPatternLifeCycleHooks.start()
method on each pattern instance. -
getUsage
public double getUsage()Gets the current usage of the instance.- See Also:
-
getRelativeWorkDemand
public double getRelativeWorkDemand()Gets the relative work demand.- Returns:
- the relative work demand.
- See Also:
-
getState
Gets the state of the instance. -
handle
Submits aRequest
at this instance for handling.- Parameters:
request
-Request
that should be handled by this instance.
-
checkIfCanHandle
Checks whether this Instance can handle the Request.- Parameters:
request
- request that may should be handled by this instance.- Returns:
- true if this request will be handled, false otherwise
-
handleRequestAnswer
-
handleIncomingRequest
-
submitProcessToCPU
-
start
public void start()Starts this instance, reading it to receive requests.Currently, the startup process completes immediately.
-
startShutdown
public final void startShutdown()Starts the shutdown sequence of this instance. The service will not accept new requests, but will complete open requests. -
endShutdown
public final void endShutdown()Completes the shutdown and transitions the instance into theInstanceState.SHUTDOWN
state. The instance will not handle any requests in this state. -
die
public final void die()Immediately kills this instance. All currently active requests (computed and cascading) will be canceled. -
getOwner
-
getInstanceID
public final int getInstanceID() -
onRequestFailed
public boolean onRequestFailed(Request request, desmoj.core.simulator.TimeInstant when, RequestFailedReason reason) Description copied from interface:IRequestUpdateListener
Listener for the failure of the sending process. This could for example be due to the receiving service not being available, the request being canceled or timed out. Provides a reference to the failed request.- Specified by:
onRequestFailed
in interfaceIRequestUpdateListener
- Parameters:
request
- request that triggered this eventwhen
- time of this eventreason
- reason why the request failed- Returns:
- true if the request was terminally handled (consumed) by this instance
-
onRequestArrivalAtTarget
Description copied from interface:IRequestUpdateListener
Listener for the successful completion of the sending process. Provides a reference to the successfully arrived request.- Specified by:
onRequestArrivalAtTarget
in interfaceIRequestUpdateListener
- Parameters:
request
- request that triggered this eventwhen
- time of this event- Returns:
- true if the request was terminally handled (consumed) by this instance
-
onRequestSend
Description copied from interface:IRequestUpdateListener
Listener for the send-off of a request. Provides the send request.- Specified by:
onRequestSend
in interfaceIRequestUpdateListener
- Parameters:
request
- request that triggered this eventwhen
- time of this event- Returns:
- true if the request was terminally handled (consumed) by this instance
-
onRequestResultArrivedAtRequester
public boolean onRequestResultArrivedAtRequester(Request request, desmoj.core.simulator.TimeInstant when) Description copied from interface:IRequestUpdateListener
Listener for the successful receiving of the answer of a request.- Specified by:
onRequestResultArrivedAtRequester
in interfaceIRequestUpdateListener
- Parameters:
request
- request that triggered this eventwhen
- time of this event- Returns:
- true if the request was terminally handled (consumed) by this instance
-
getCpu
-
getPatterns
-
setState
-