01 /*
02 * Created on Aug 29, 2007
03 */
04 package com.x8ing.mc.bp.operation;
05
06 import java.util.List;
07
08 import com.x8ing.lsm4j.Condition;
09 import com.x8ing.lsm4j.state.ProcessableState;
10 import com.x8ing.mc.bp.AbstractBusinessAction;
11 import com.x8ing.mc.bp.BalanceAccount;
12 import com.x8ing.mc.bp.Bug;
13 import com.x8ing.mc.bp.BusinessContext;
14 import com.x8ing.mc.distribution.RandomDistribution;
15 import com.x8ing.mc.distribution.RandomDistributionConstant;
16
17 /**
18 * @author Patrick Heusser
19 */
20 public class OperationRunsAction extends AbstractBusinessAction {
21
22 private RandomDistribution outageChance = new RandomDistributionConstant(0, 100);
23
24 private RandomDistribution findNewBugChance = new RandomDistributionConstant(0, 100);
25
26 /**
27 * @see com.x8ing.mc.bp.AbstractBusinessAction#execute(com.x8ing.lsm4j.state.ProcessableState,
28 * com.x8ing.mc.bp.BusinessContext, com.x8ing.lsm4j.Condition, java.util.List)
29 */
30 public void execute(ProcessableState currentState, BusinessContext businessContext, Condition previousCondition,
31 List lastVisitedStatesHistory) {
32
33 // check if we found a new bug
34 if (findNewBugChance.getNextRandomNumber() > businessContext.getConfiguration().getChanceForFindingANewBugInProduction()
35 && !businessContext.isNoMoreDiscoveringOfBugs()) {
36
37 // add a new bug to the queue (create the bug with value 0 first)
38 Bug bug = new Bug(businessContext.getCurrentDate(), 0, 0, businessContext.getBugs().getNextBugID());
39 businessContext.getQueuedBugs().add(bug);
40 addLogBookEntry("production discovered a new bug. bugID=" + bug.getBugID());
41
42 }
43
44 // check if an outtage happens
45 if (outageChance.getNextRandomNumber() < businessContext.getConfiguration().getChanceOperationHasOutage()) {
46
47 // we have a problem
48 businessContext.setProductionSystemRunning(false);
49
50 addLogBookEntry("production failure occured.");
51
52 } else {
53
54 // business runs smoothly
55 addBalanceSheetTransaction("current process gain", businessContext.getCurrentProcessGain(), BalanceAccount.PRODUCTION);
56
57 }
58
59 }
60
61 protected void lazyInit() {
62 // empty
63 }
64
65 }
|