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, Serializable, Cloneable

public class ServiceRule
extends ArrayElement
implements Serializable, 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 addTimeFrameRule(TimeFrame frame)
          Announcing the ability to configure specific regulations for the TimeFrame.
 Object clone()
           
 void fromStream(BufferedReader in, Formatter f)
          Method fromStream
 Rule getDefaultRule()
          Gets the default time based regulations.
 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.
 String getServiceName()
          Gets the Service name of the Service the ServiceRule's regulations relate to.
 boolean isDefaultServiceRule()
           
 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.
 Iterator iterateRules()
          iterate all rules including the default rule which is returned first.
 Iterator iterateTBRules()
           
 void removeTimeFrameRule(TimeFrame frame)
          Eliminating the ability to configure specific regulations for the TimeFrame.
 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(String newServiceName)
          Sets the Service name the ServiceRule's Rules are related to .
 void toStream(PrintStream out, Formatter f)
          Method toStream
 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

clone

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

fromStream

public void fromStream(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

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

getServiceName

public 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

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

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

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

setQuotaManagmentMode

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

Parameters:
mode -

setServiceName

public void setServiceName(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(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 String toString()
The ServiceRule's String representation.

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

iterateTBRules

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

iterateRules

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

Returns:

Cisco Systems, Inc.

Copyright © 2011 Cisco Systems, Inc. Confidential.