Changeset 309
- Timestamp:
- 02/26/08 03:47:04 (9 months ago)
- Location:
- trunk/thrucommon
- Files:
-
- 1 added
- 3 modified
-
src/CircuitBreaker.cpp (modified) (8 diffs)
-
tests (modified) (1 prop)
-
tests/CircuitBreakerTest.cpp (added)
-
tests/Makefile.am (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/thrucommon/src/CircuitBreaker.cpp
r281 r309 15 15 uint16_t timeout_in_seconds) 16 16 { 17 char buf[64]; 18 sprintf (buf, "CircuitBreaker: threshold=%d, timeout_in_seconds=%d", 19 threshold, timeout_in_seconds); 20 LOG4CXX_INFO (logger, buf); 21 17 22 this->threshold = threshold; 18 23 this->timeout_in_seconds = timeout_in_seconds; … … 23 28 bool CircuitBreaker::allow () 24 29 { 30 LOG4CXX_DEBUG (logger, "allow: "); 25 31 // if timeout has elapsed give half open a try 26 if (this-> next_check >time (0))32 if (this->state == OPEN && this->next_check < time (0)) 27 33 { 34 LOG4CXX_INFO (logger, "allow: going half-open"); 28 35 this->state = HALF_OPEN; 29 36 } … … 33 40 void CircuitBreaker::success () 34 41 { 42 LOG4CXX_DEBUG (logger, "success: "); 35 43 // if we're half-open and got a success close things up, note that 36 44 // we should never be called if we're in the fully open state, that'd be a … … 38 46 if (this->state == HALF_OPEN) 39 47 { 48 LOG4CXX_INFO (logger, "success: in half-open, reset"); 40 49 this->reset (); 41 50 } … … 44 53 void CircuitBreaker::failure () 45 54 { 55 LOG4CXX_DEBUG (logger, "failure: "); 46 56 if (this->state == HALF_OPEN) 47 57 { 58 LOG4CXX_INFO (logger, "failure: in half-open, trip"); 48 59 this->trip (); 49 60 } … … 54 65 if (failure_count > this->threshold) 55 66 { 56 this->reset (); 67 LOG4CXX_INFO (logger, "failure: threashold breached, trip"); 68 this->trip (); 57 69 } 58 70 } … … 61 73 void CircuitBreaker::reset () 62 74 { 75 LOG4CXX_INFO (logger, "reset:"); 63 76 this->state = CLOSED; 64 77 this->failure_count = 0; … … 67 80 void CircuitBreaker::trip () 68 81 { 82 LOG4CXX_INFO (logger, "trip:"); 69 83 if (this->state != OPEN) 70 84 { 85 LOG4CXX_INFO (logger, "trip: tripped"); 71 86 this->state = OPEN; 72 this->next_check = time (0) + timeout_in_seconds;87 this->next_check = time (0) + (time_t)timeout_in_seconds; 73 88 } 74 89 } -
trunk/thrucommon/tests
- Property svn:ignore
-
old new 1 CircuitBreakerTest 1 2 .deps 2 3 .libs
-
- Property svn:ignore
-
trunk/thrucommon/tests/Makefile.am
r306 r309 4 4 LDADDS = ../src/libthrucommon.la 5 5 6 TESTS = SpreadTest 6 TESTS = SpreadTest CircuitBreakerTest 7 7 8 8 check_PROGRAMS=$(TESTS) … … 11 11 SpreadTest_LDADD = $(LDADDS) 12 12 SpreadTest_CXXFLAGS = $(CPPUNIT_CFLAGS) -I../src 13 SpreadTest_LDFLAGS = $(CPPUNIT_LIBS) $(SPEAD_LIBS) $(SSL_LIBS) $(THRIFT_LIBS) $(UUID_LIBS) $(MEMCACHED_LIBS) 13 SpreadTest_LDFLAGS = $(CPPUNIT_LIBS) $(SPEAD_LIBS) $(THRIFT_LIBS) 14 15 CircuitBreakerTest_SOURCES = CircuitBreakerTest.cpp 16 CircuitBreakerTest_LDADD = $(LDADDS) 17 CircuitBreakerTest_CXXFLAGS = $(CPPUNIT_CFLAGS) -I../src 18 CircuitBreakerTest_LDFLAGS = $(CPPUNIT_LIBS)
