unitPrice)
}
- def isOnOff: Boolean = isNamed(DSLCostPolicyNames.onoff)
-
- def isContinuous: Boolean = isNamed(DSLCostPolicyNames.continuous)
-
- def isDiscrete: Boolean = isNamed(DSLCostPolicyNames.discrete)
-
- def isOnce: Boolean = isNamed(DSLCostPolicyNames.once)
-
def isNamed(aName: String): Boolean = aName == name
def needsPreviousEventForCreditAndAmountCalculation: Boolean = {
*/
def computeNewAccumulatingAmount(oldAmount: Double, newEventValue: Double, details: Map[String, String]): Double
- def computeResourceInstanceAmountForNewBillingPeriod(oldAmount: Double): Double
-
/**
* The initial amount.
*/
@throws(classOf[Exception])
def constructImplicitEndEventFor(resourceEvent: ResourceEventModel, newOccurredMillis: Long): ResourceEventModel
-
- @throws(classOf[Exception])
- def constructImplicitStartEventFor(resourceEvent: ResourceEventModel): ResourceEventModel
}
object DSLCostPolicyNames {
oldAmount
}
- def computeResourceInstanceAmountForNewBillingPeriod(oldAmount: Double) = getResourceInstanceInitialAmount
-
def getResourceInstanceInitialAmount = 0.0
def supportsImplicitEvents = false
def constructImplicitEndEventFor(resourceEvent: ResourceEventModel, occurredMillis: Long) = {
throw new AquariumException("constructImplicitEndEventFor() Not compliant with %s".format(this))
}
-
- def constructImplicitStartEventFor(resourceEvent: ResourceEventModel) = {
- throw new AquariumException("constructImplicitStartEventFor() Not compliant with %s".format(this))
- }
}
/**
}
}
- def computeResourceInstanceAmountForNewBillingPeriod(oldAmount: Double): Double = {
- oldAmount
- }
-
def getResourceInstanceInitialAmount: Double = {
0.0
}
resourceEvent.withDetails(newDetails, newOccurredMillis)
}
-
- def constructImplicitStartEventFor(resourceEvent: ResourceEventModel) = {
- throw new AquariumException("constructImplicitStartEventFor() Not compliant with %s".format(this))
- }
}
/**
def computeNewAccumulatingAmount(oldAmount: Double, newEventValue: Double, details: Map[String, String]): Double = {
newEventValue
}
-
- def computeResourceInstanceAmountForNewBillingPeriod(oldAmount: Double): Double = {
- import OnOffCostPolicyValues.{ON, OFF}
- oldAmount match {
- case ON ⇒ /* implicit off at the end of the billing period */ OFF
- case OFF ⇒ OFF
- }
- }
def getResourceInstanceInitialAmount: Double = {
0.0
}
+ private[this]
+ def getValueForCreditCalculation(oldAmount: Double, newEventValue: Double): Double = {
+ import OnOffCostPolicyValues.{ON, OFF}
+
+ def exception(rs: OnOffPolicyResourceState) =
+ new AquariumException("Resource state transition error (%s -> %s)".format(rs, rs))
+
+ (oldAmount, newEventValue) match {
+ case (ON, ON) ⇒
+ throw exception(OnResourceState)
+ case (ON, OFF) ⇒
+ OFF
+ case (OFF, ON) ⇒
+ ON
+ case (OFF, OFF) ⇒
+ throw exception(OffResourceState)
+ }
+ }
+
override def isBillableEventBasedOnValue(eventValue: Double) = {
// ON events do not contribute, only OFF ones.
OnOffCostPolicyValues.isOFFValue(eventValue)
oldAmount + newEventValue
}
- def computeResourceInstanceAmountForNewBillingPeriod(oldAmount: Double): Double = {
- 0.0 // ?? def getResourceInstanceInitialAmount
- }
-
def getResourceInstanceInitialAmount: Double = {
0.0
}
def constructImplicitEndEventFor(resourceEvent: ResourceEventModel, occurredMillis: Long) = {
throw new AquariumInternalError("constructImplicitEndEventFor() Not compliant with %s".format(this))
}
-
- def constructImplicitStartEventFor(resourceEvent: ResourceEventModel) = {
- throw new AquariumInternalError("constructImplicitStartEventFor() Not compliant with %s".format(this))
- }
}
/**