goldengate.common.cpu
Class GgConstraintLimitHandler

java.lang.Object
  extended by goldengate.common.cpu.GgConstraintLimitHandler
All Implemented Interfaces:
Runnable

public abstract class GgConstraintLimitHandler
extends Object
implements Runnable

Abstract class for Constraint Limit Handler for GoldenGate project

Author:
Frederic Bregier

Field Summary
 String lastAlert
           
 
Constructor Summary
GgConstraintLimitHandler()
          Empty constructor
GgConstraintLimitHandler(long WAITFORNETOP2, long TIMEOUTCON2, boolean useCpuLimit, boolean useJdKCpuLimit, double cpulimit, int channellimit)
          This constructor enables only Connection check ability
GgConstraintLimitHandler(long WAITFORNETOP2, long TIMEOUTCON2, boolean useCpuLimit, boolean useJdKCpuLimit, double cpulimit, int channellimit, double lowcpuLimit, double highcpuLimit, double percentageDecrease, org.jboss.netty.handler.traffic.GlobalTrafficShapingHandler handler, long delay, long limitLowBandwidth)
          This constructor enables both Connection check ability and throttling bandwidth with cpu usage
GgConstraintLimitHandler(long WAITFORNETOP2, long TIMEOUTCON2, boolean useJdkCpuLimit, double lowcpuLimit, double highcpuLimit, double percentageDecrease, org.jboss.netty.handler.traffic.GlobalTrafficShapingHandler handler, long delay, long limitLowBandwidth)
          This constructor enables only throttling bandwidth with cpu usage
 
Method Summary
 boolean checkConstraints()
           
 boolean checkConstraintsSleep(int step)
          Same as checkConstraints except that the thread will sleep some time proportionally to the current Load (if CPU related)
 int getChannelLimit()
           
 double getCpuLimit()
           
protected abstract  int getNumberLocalChannel()
           
protected abstract  long getReadLimit()
          Get the current setting on Read Limit (supposed to be not the value in the handler but in the configuration)
 long getSleepTime()
           
protected abstract  long getWriteLimit()
          Get the current setting on Write Limit (supposed to be not the value in the handler but in the configuration)
 void release()
          Release the resources
 void run()
          Check every delay if the current cpu usage needs to relax or to constraint the bandwidth
 void setChannelLimit(int channelLimit)
           
 void setCpuLimit(double cpuLimit)
           
 void setHandler(org.jboss.netty.handler.traffic.GlobalTrafficShapingHandler handler)
          Set the handler
 void setServer(boolean isServer)
          To explicitly set this handler as server mode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lastAlert

public String lastAlert
Constructor Detail

GgConstraintLimitHandler

public GgConstraintLimitHandler()
Empty constructor


GgConstraintLimitHandler

public GgConstraintLimitHandler(long WAITFORNETOP2,
                                long TIMEOUTCON2,
                                boolean useJdkCpuLimit,
                                double lowcpuLimit,
                                double highcpuLimit,
                                double percentageDecrease,
                                org.jboss.netty.handler.traffic.GlobalTrafficShapingHandler handler,
                                long delay,
                                long limitLowBandwidth)
This constructor enables only throttling bandwidth with cpu usage

Parameters:
WAITFORNETOP2 - 1000 ms as wait for a network operation
TIMEOUTCON2 - 10000 ms as timeout limit
useJdkCpuLimit - True to use JDK Cpu native or False for JavaSysMon
lowcpuLimit - for proactive cpu limitation (throttling bandwidth) (0<= x < 1 & highcpulimit)
highcpuLimit - for proactive cpu limitation (throttling bandwidth) (0<= x <= 1) 0 meaning no throttle activated
percentageDecrease - for proactive cpu limitation, throttling bandwidth reduction (0 < x < 1) as 0.25 for 25% of reduction
handler - the GlobalTrafficShapingHandler associated (null to have no proactive cpu limitation)
delay - the delay between 2 tests for proactive cpu limitation
limitLowBandwidth - the minimal bandwidth (read or write) to apply when decreasing bandwidth (low limit = 4096)

GgConstraintLimitHandler

public GgConstraintLimitHandler(long WAITFORNETOP2,
                                long TIMEOUTCON2,
                                boolean useCpuLimit,
                                boolean useJdKCpuLimit,
                                double cpulimit,
                                int channellimit)
This constructor enables only Connection check ability

Parameters:
useCpuLimit - True to enable cpuLimit on connection check
useJdKCpuLimit - True to use JDK Cpu native or False for JavaSysMon
cpulimit - high cpu limit (0<= x < 1) to refuse new connections
channellimit - number of connection limit (0<= x)

GgConstraintLimitHandler

public GgConstraintLimitHandler(long WAITFORNETOP2,
                                long TIMEOUTCON2,
                                boolean useCpuLimit,
                                boolean useJdKCpuLimit,
                                double cpulimit,
                                int channellimit,
                                double lowcpuLimit,
                                double highcpuLimit,
                                double percentageDecrease,
                                org.jboss.netty.handler.traffic.GlobalTrafficShapingHandler handler,
                                long delay,
                                long limitLowBandwidth)
This constructor enables both Connection check ability and throttling bandwidth with cpu usage

Parameters:
WAITFORNETOP2 - 1000 ms as wait for a network operation
TIMEOUTCON2 - 10000 ms as timeout limit
useCpuLimit - True to enable cpuLimit on connection check
useJdKCpuLimit - True to use JDK Cpu native or False for JavaSysMon
cpulimit - high cpu limit (0<= x < 1) to refuse new connections
channellimit - number of connection limit (0<= x)
lowcpuLimit - for proactive cpu limitation (throttling bandwidth) (0<= x < 1 & highcpulimit)
highcpuLimit - for proactive cpu limitation (throttling bandwidth) (0<= x <= 1) 0 meaning no throttle activated
percentageDecrease - for proactive cpu limitation, throttling bandwidth reduction (0 < x < 1) as 0.25 for 25% of reduction
handler - the GlobalTrafficShapingHandler associated (null to have no proactive cpu limitation)
delay - the delay between 2 tests for proactive cpu limitation
limitLowBandwidth - the minimal bandwidth (read or write) to apply when decreasing bandwidth (low limit = 4096)
Method Detail

release

public void release()
Release the resources


setServer

public void setServer(boolean isServer)
To explicitly set this handler as server mode

Parameters:
isServer -

checkConstraints

public boolean checkConstraints()
Returns:
True if one of the limit is exceeded. Always False if not a server mode

getNumberLocalChannel

protected abstract int getNumberLocalChannel()
Returns:
the current number of active Local Channel

checkConstraintsSleep

public boolean checkConstraintsSleep(int step)
Same as checkConstraints except that the thread will sleep some time proportionally to the current Load (if CPU related)

Parameters:
step - the current step in retry
Returns:
True if one of the limit is exceeded. Always False if not a server mode

getSleepTime

public long getSleepTime()
Returns:
a time below TIMEOUTCON with a random

getCpuLimit

public double getCpuLimit()
Returns:
the cpuLimit

setCpuLimit

public void setCpuLimit(double cpuLimit)
Parameters:
cpuLimit - the cpuLimit to set

getChannelLimit

public int getChannelLimit()
Returns:
the channelLimit

setChannelLimit

public void setChannelLimit(int channelLimit)
Parameters:
channelLimit - the channelLimit to set

getReadLimit

protected abstract long getReadLimit()
Get the current setting on Read Limit (supposed to be not the value in the handler but in the configuration)

Returns:
the current setting on Read Limit

getWriteLimit

protected abstract long getWriteLimit()
Get the current setting on Write Limit (supposed to be not the value in the handler but in the configuration)

Returns:
the current setting on Write Limit

setHandler

public void setHandler(org.jboss.netty.handler.traffic.GlobalTrafficShapingHandler handler)
Set the handler

Parameters:
handler -

run

public void run()
Check every delay if the current cpu usage needs to relax or to constraint the bandwidth

Specified by:
run in interface Runnable


Copyright © 2009-2012 Frederic Bregier. All Rights Reserved.