Cisco Systems, Inc.

com.pcube.apps.engage.policy
Class ServiceRule

java.lang.Object
  extended by com.pcube.apps.engage.common.ArrayElement
      extended by com.pcube.apps.engage.policy.ServiceRule
All Implemented Interfaces:
Formattable, java.io.Serializable, java.lang.Cloneable

public class ServiceRule
extends ArrayElement
implements java.io.Serializable, java.lang.Cloneable, Formattable

A set of time based Rules for a specific Package and Service. ServiceRule holds a different Rule per each time frame, and a default Rule. By default, all of the time based Rules nherit all of the default Rule's parameters. To configure a Rule for a specific time frame, it must be explicitly announced by using the addTimeFrameRule function.

Code Sample:

*
 // creates a new Package Package myPackage = new Package(myPolicy); * // creates new service rule ServiceRule serviceRule = new ServiceRule(policy); * // adds service to rule try{ serviceRule.setServiceName(serviceName); }catch(ItemNotFoundException e) { // handle exception } * // gets the default rule - it will apply for all the time based rules since no time based // rules are created Rule defaultRule = serviceRule.getDefaultRule(); // set default rule state to be disable defaultRule.setState(Rule.RULE_STATE_DISABLED); * // announce the need for configuring specific behavior for the T1 Rule peak = null; try{ peak = serviceRule.addTimeFrameRule(TimeFrame.T1); }catch(ItemNotFoundException e) { // handle exception } }catch(DuplicateItemException e) { // handle exception } * // set T1 rule state to be enable peak.setState(Rule.RULE_STATE_ENABLED); * // adds service rule to the package's serviceRuleArray try{ myPackage.setServiceRule(serviceRule); }catch(ItemNotFoundException e) { // handle exception }
 
 
The code is an example of setting a Rule which will apply for only T1 timeframe, and a defautl Rule that will apply for the rest of the time frames, and will be disabled.

See Also:
Serialized Form

Constructor Summary
ServiceRule(com.pcube.apps.engage.policy.Rule.RuleResourceProvider resourceProvider)
          ServiceRule Constructor
 
Method Summary
 Rule addRuleFrameRule(RuleFrame frame)
           
 Rule addTimeFrameRule(TimeFrame frame)
          Announcing the ability to configure specific regulations for the TimeFrame.
 java.lang.Object clone()
           
 void fromStream(java.io.BufferedReader in, Formatter f)
          Method fromStream
 Rule getDefaultRule()
          Gets the default time based regulations.
 int getPackageIndex()
           
 Rule getRuleForRuleFrame(int ruleFrameIndex)
           
 Rule getRuleForRuleFrame(RuleFrame frame)
           
 Rule getRuleForTimeFrame(int timeFrameIndex)
          Gets the set of regulations for the specific TimeFrame by the TimeFrame index
 Rule getRuleForTimeFrame(TimeFrame frame)
          Gets the set of regulations for the specific TimeFrame.
 java.lang.String getServiceName()
          Gets the Service name of the Service the ServiceRule's regulations relate to.
 boolean getTurState()
           
 boolean isDefaultServiceRule()
           
 boolean isRuleFrameRuleDefined(int ruleFrameIndex)
           
 boolean isRuleFrameRuleDefined(RuleFrame frame)
           
 boolean isTimeFrameRuleDefined(int timeFrameIndex)
          Checks if a certain TimeFrame has specific regulations ,by the TimeFrame index.
 boolean isTimeFrameRuleDefined(TimeFrame frame)
          Checks if a certain TimeFrame has specific regulations.
 java.util.Iterator iterateRFRules()
           
 java.util.Iterator iterateRules()
          iterate all rules including the default rule which is returned first.
 java.util.Iterator iterateTBRules()
           
 void removeRuleFrameRule(RuleFrame frame)
           
 void removeTimeFrameRule(TimeFrame frame)
          Eliminating the ability to configure specific regulations for the TimeFrame.
 void setDefaultRuleOverride(boolean isDefaultRuleOverride)
           
 void setPackageIndex(int index)
          Sets the Package index the ServiceRule's Rules are related to .
 void setQuotaManagmentMode(int mode)
          sets quota managment mode: sets in default anf TB rules.
 void setServiceName(java.lang.String newServiceName)
          Sets the Service name the ServiceRule's Rules are related to .
 void setTurState(boolean isTurEnabled)
           
 void toStream(java.io.PrintStream out, Formatter f)
          Method toStream
 java.lang.String toString()
          The ServiceRule's String representation.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ServiceRule

public ServiceRule(com.pcube.apps.engage.policy.Rule.RuleResourceProvider resourceProvider)
ServiceRule Constructor

Parameters:
policy - the Policy the ServiceRule belongs to
Method Detail

addTimeFrameRule

public Rule addTimeFrameRule(TimeFrame frame)
                      throws DuplicateItemException
Announcing the ability to configure specific regulations for the TimeFrame. This will create a copy of the current default regulations, which can be configured.

Parameters:
frame - the desired TimeFrame
Returns:
the TimeFrame regulations. The Rule is initialized with this ServiceRule's default Rule's values
Throws:
DuplicateItemException - if the TimeFrame already has a specific Rule
ItemNotFoundException

addRuleFrameRule

public Rule addRuleFrameRule(RuleFrame frame)
                      throws DuplicateItemException
Throws:
DuplicateItemException

clone

public java.lang.Object clone()
Specified by:
clone in class ArrayElement
See Also:
ArrayElement.clone()

fromStream

public void fromStream(java.io.BufferedReader in,
                       Formatter f)
                throws ImportExportException
Description copied from interface: Formattable
Method fromStream

Specified by:
fromStream in interface Formattable
Throws:
ImportExportException
See Also:
Formattable.fromStream(java.io.BufferedReader, com.pcube.apps.engage.common.Formatter)

getDefaultRule

public Rule getDefaultRule()
Gets the default time based regulations. These regulations apply for all of the time frames which were not announced as configurable using the function addTimeFrameRule

Returns:
the default Rule

getRuleForTimeFrame

public Rule getRuleForTimeFrame(int timeFrameIndex)
Gets the set of regulations for the specific TimeFrame by the TimeFrame index

Parameters:
timeFrameIndex -
Returns:
@throws ItemNotFoundException

getRuleForRuleFrame

public Rule getRuleForRuleFrame(int ruleFrameIndex)

getRuleForTimeFrame

public Rule getRuleForTimeFrame(TimeFrame frame)
Gets the set of regulations for the specific TimeFrame. The time frame's regulations must be announced as configurable using the addTimeFrameRule function, otherwise an ItemNotFoundException will be thrown

Parameters:
frame - the desired TimeFrame
Returns:
the TimeFrame's specific Rule
Throws:
ItemNotFoundException - if a specific Rule for this TimeFrame was not created

getRuleForRuleFrame

public Rule getRuleForRuleFrame(RuleFrame frame)

getServiceName

public java.lang.String getServiceName()
Gets the Service name of the Service the ServiceRule's regulations relate to.

Returns:
the Service name

isDefaultServiceRule

public boolean isDefaultServiceRule()
Returns:
true if this the rule of the default service

isTimeFrameRuleDefined

public boolean isTimeFrameRuleDefined(int timeFrameIndex)
Checks if a certain TimeFrame has specific regulations ,by the TimeFrame index. If there is no specific regulation the ServiceRule's default regulations are set.

Parameters:
timeFrameIndex - the queried TimeFrame's index
Returns:
true if specific regulations were configured for the TimeFrame, false otherwise

isRuleFrameRuleDefined

public boolean isRuleFrameRuleDefined(int ruleFrameIndex)

isTimeFrameRuleDefined

public boolean isTimeFrameRuleDefined(TimeFrame frame)
Checks if a certain TimeFrame has specific regulations. If there is no specific regulation the ServiceRule's default regulations are set.

Parameters:
frame - the queried TimeFrame
Returns:
true if specific regulations were configured for the TimeFrame, false otherwise

isRuleFrameRuleDefined

public boolean isRuleFrameRuleDefined(RuleFrame frame)

removeTimeFrameRule

public void removeTimeFrameRule(TimeFrame frame)
Eliminating the ability to configure specific regulations for the TimeFrame.

Parameters:
frame - the TimeFrame
Throws:
ItemNotFoundException - if no configuration ability was given to the TimeFrame in the first place

removeRuleFrameRule

public void removeRuleFrameRule(RuleFrame frame)

setPackageIndex

public void setPackageIndex(int index)
Sets the Package index the ServiceRule's Rules are related to . The Rules are Package-Service-TimeFrame oriented.

Parameters:
index - the new Package index

getPackageIndex

public int getPackageIndex()

setQuotaManagmentMode

public void setQuotaManagmentMode(int mode)
sets quota managment mode: sets in default anf TB rules.

Parameters:
mode -

setServiceName

public void setServiceName(java.lang.String newServiceName)
Sets the Service name the ServiceRule's Rules are related to . The Rules are Package-Service-TimeFrame oriented.

Parameters:
newServiceName - the new Service's name
Throws:
ItemNotFoundException - if no such Service exists in the Policy's ServiceArray

toStream

public void toStream(java.io.PrintStream out,
                     Formatter f)
Description copied from interface: Formattable
Method toStream

Specified by:
toStream in interface Formattable
See Also:
Formattable.toStream(java.io.PrintStream, com.pcube.apps.engage.common.Formatter)

toString

public java.lang.String toString()
The ServiceRule's String representation.

Overrides:
toString in class java.lang.Object
Returns:
the ServiceRule's String representation

setTurState

public void setTurState(boolean isTurEnabled)

getTurState

public boolean getTurState()

setDefaultRuleOverride

public void setDefaultRuleOverride(boolean isDefaultRuleOverride)

iterateTBRules

public java.util.Iterator iterateTBRules()
Returns:
an iterator for the time-based rules only (the default rule is excluded).

iterateRFRules

public java.util.Iterator iterateRFRules()

iterateRules

public java.util.Iterator iterateRules()
iterate all rules including the default rule which is returned first.

Returns:

Cisco Systems, Inc.

Copyright © 2013 Cisco Systems, Inc. Confidential.