All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tacitknowledge.slowlight.proxyserver.config.BehaviorFunctionConfig Maven / Gradle / Ivy

The newest version!
package com.tacitknowledge.slowlight.proxyserver.config;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * This class represents a behavior function configuration model. In order to
 * configure a behavior function specify the name of the handler parameter (ex.
 * writeLimit) as paramName property value, what will cause behavior function to
 * be attached and applied for that particular parameter, also specify the fully
 * qualified name of the class which will provide function implementation.
 * Please note that function class should implement the
 * {@link com.tacitknowledge.slowlight.proxyserver.handler.behavior.BehaviorFunction}
 * interface.
* *
* An example of behavior function configuration (JSON), please note that * this function is attached to the handler delay param by its name * *
 * {@code
 * ...
 * "handlers" : [
 *      {
 *          "name" : "delayHandler",
 *          "type" : "com.tacitknowledge.slowlight.proxyserver.handler.DelayChannelHandler",
 *          "params" : {"maxDataSize" : "0", "delay" : "500"},
 *          "behaviorFunctions" : [
 *              {
 *                  "paramName" : "delay",
 *                  "type" : "com.tacitknowledge.slowlight.proxyserver.handler.behavior.SinusoidalBehavior",
 *                  "ranges" : {"5" : "10", "10" : "15"}
 *              }
 *          ]
 *      },
 *      ...
 * ]
 * ...
 * }
 * 
* * @author Alexandr Donciu ([email protected]) */ public class BehaviorFunctionConfig extends ParameterizedConfig { /** * name of the parameter to be set by the behavior function */ private String paramName; /** * type of the behavior funtion */ private String type; /** * Time intervals in milliseconds for behavior functions to be used for * parameter setting. */ private Map ranges = new HashMap(); public String getParamName() { return paramName; } public void setParamName(final String paramName) { this.paramName = paramName; } public String getType() { return type; } public void setType(final String type) { this.type = type; } public Map getRanges() { return ranges; } public void setRanges(Map ranges) { this.ranges = ranges; } public String getId() { StringBuilder id = new StringBuilder(paramName); id.append("_").append(type); if (ranges == null) { return id.toString(); } Iterator keys = ranges.keySet().iterator(); while (keys.hasNext()) { String key = keys.next(); id.append("[").append(key).append(" - ").append(ranges.get(key)) .append("]"); } return id.toString(); } }