Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package gov.nist.javax.sip.stack;
This is just a simple reusable congestion control valve JSIP apps can use to stop traffic when the number of server transactions reaches the limit specified in gov.nist.javax.sip.MAX_SERVER_TRANSACTIONS without breaking existing dialogs. The drop policy is specified in DROP_RESPONSE_STATUS where "0" means silent drop and any positive number will be interpreted as the status code of the error response that will be generated. To enable this in your application you must specify this property: gov.nist.javax.sip.SIP_MESSAGE_VALVE=gov.nist.javax.sip.stack.CongestionControlMessageValve It is advised to extend this class to add your application-specific control conditions

	private static StackLogger logger = CommonLogger.getLogger(CongestionControlMessageValve.class);
	protected SipStackImpl sipStack;
    // High water mark for ServerTransaction Table
    // after which requests are dropped.
    protected int serverTransactionTableHighwaterMark;
    protected int dropResponseStatus;
	public boolean processRequest(SIPRequest request,
			MessageChannel messageChannel) {
		String requestMethod = request.getMethod();
		// We should not attempt to drop these requests because they actually free resources
		// which is our goal in congested mode
		boolean undropableMethod = requestMethod.equals(.
		|| requestMethod.equals(.
		|| requestMethod.equals(.
		|| requestMethod.equals(.);
		if(!undropableMethod) {
				// Allow directly any subsequent requests
				if(request.getToTag() != null) {
					return true;
					try {
catch (IOException e) {
						.logError("Failed to send congestion control error response" + responsee);
				return false// Do not pass this request to the pipeline
		return true// OK, the processing of the request can continue
	public boolean processResponse(Response response,
			MessageChannel messageChannel) {
		return true;
	public void destroy() {
		.logInfo("Destorying the congestion control valve " + this);
	public void init(SipStack stack) {
		 = (SipStackImplstack;
		.logInfo("Initializing congestion control valve");
		String serverTransactionsString = .getConfigurationProperties().getProperty("gov.nist.javax.sip.MAX_SERVER_TRANSACTIONS""10000");
		 = new Integer(serverTransactionsString);
		String dropResponseStatusString = .getConfigurationProperties().getProperty("DROP_RESPONSE_STATUS""503");
		 = new Integer(dropResponseStatusString);
New to GrepCode? Check out our FAQ X