Warning: this documentation is not yet completed. It will be completed gradually over time.
Note: attributes are to be assumed private and methods are to be assumed public, unless noted otherwise.
Note: attributes and methods noted as "private" are actually accessible, but the direct access of them is strongly discouraged and may results in random bugs after future refactoring.
Note: methods return
None
unless noted otherwise.
Note: for implementation details involving lock operations,
acquire ... release
is implemented usingwith
Tracking post scanning data.
add_stat(posts_scanned, scan_time)
: Addposts_scanned
to total numbers of posts scanned. Addscan_time
to total time spent on scanning.get_stat()
: Get total numbers of posts scanned, total time spent on scanning and posts scanned per second. If total time spent is zero, posts scanned per second is set toNone
. Returns a tuple(posts_scanned, scan_time, posts_per_second)
.reset_stat()
: Reset post scanning data, which includes total numbers of posts scanned and total time spent on scanning to0
.
Yes.
- None.
This class is implemented with 2 static variables and 1 lock.
num_posts_scanned
: Tracking total numbers of posts scanned.post_scan_time
: Tracking total time spent on scanning.rw_lock
: Lock. Controlling access tonum_posts_scanned
andpost_scan_time
.
add_stat(posts_scanned, scan_time)
: Obtainrw_lock
. Addposts_scanned
andscan_time
tonum_posts_scanned
andpost_scan_time
. Releaserw_lock
.get_stat()
: Obtainrw_lock
. Readnum_posts_scanned
intoposts_scanned
. Readpost_scan_time
intoscan_time
. Releaserw_lock
. Decide ifscan_time
is0
. If yes, setposts_per_second
toNone
. Otherwise calculateposts_per_second
asposts_scanned
divided byscan_time
. Return a tuple(posts_scanned, scan_time, posts_per_second)
.reset_stat()
: Obtainrw_lock
. Setnum_posts_scanned
andpost_scan_time
to0
. Releaserw_lock
.
- Both read and write operations are lock protected, as it is necessary to perform thread safe write and to prevent reading while another thread is writing.
- None
Tracking metasmoke status.
is_up()
: Query if metasmoke is up. ReturnsTrue
if metasmoke is up andFalse
otherwise.is_down()
: Query if metasmoke is down. ReturnsTrue
if metasmoke is down andFalse
otherwise.failed()
: Indicate a metasmoke connection failure.succeeded()
: Indicate a metasmoke connection success.get_failure_count()
: Get metasmoke connection failure counter value. The counter counts consecutive failures.reset_ms_status()
: Reset classGlobalVars.ms_status
to default values.
Yes.
- Metasmoke counter represents consecutive metasmoke failures.
This class is implemented with 2 static variables and 1 lock.
ms_is_up
: Whether or not metasmoke is up.counter
: Metasmoke connection failure counter.rw_lock
: Lock. Controlling access toms_is_up
,failure_count
andlast_ping_time
.
set_up()
: Private tometasmoke.py
. Obtainrw_lock
. Setms_is_up
toTrue
. Releaserw_lock
.set_down()
: Private tometasmoke.py
. Obtainrw_lock
. Setms_is_up
toFalse
. Releaserw_lock
.is_up()
: Obtainrw_lock
. Readms_is_up
intocurrent_ms_status
. Releaserw_lock
. Returncurrent_ms_status
.is_down()
: Callis_up()
and return the inverted returned value.failed()
: Obtainrw_lock
. Increasecounter
by1
. Releaserw_lock
.succeeded()
: Obtainrw_lock
. Setcounter
to0
. Releaserw_lock
.get_failure_count()
: Obtainrw_lock
. Readcounter
intocurrent_counter
. Releaserw_lock
. Returncurrent_failure_count
.reset_ms_status
: Obtainrw_lock
. Setms_is_up
toTrue
. Setcounter
to0
. Releaserw_lock
.
is_down()
is implemented to callis_up()
, so maintainance tasks only need to be performed onis_up()
.
- None.
Note: the documentation of this class is not yet completed.
AutoSwitch
set_ms_up()
: Switch metasmoke status to up.set_ms_down()
: Switch metasmoke status to down.
Not completed yet.
Unknown. The component currently documented in public interface is thread safe.
- Unless there are good reasons, always call
Metasmoke.ms_up()
andMetasmoke.ms_down()
instead ofGlobalVars.MSStatus.set_up()
andGlobalVars.MSStatus.set_down()
. The former is a wrapper of the latter which offers logging and chat messages.
Not completed yet.
- None.
Automatically switch metasmoke status.
ping_failed()
: Indicate a status ping failure.ping_succeeded()
: Indicate a status ping success.enable_autoswitch(to_enable)
: Turn on or off auto switch. Ifon
isTrue
, auto switch is turned on. Otherwise auto switch is turned off.get_ping_failure()
: Get the count of consecutive ping failures. Negative value indicates consecutive ping successes.reset_switch()
: Reset classMetasmoke.AutoSwitch
to default values.
Yes.
- Failures or successes contributing to auto switching of metasmoke status should be those of status ping. Other failures or successes should not trigger auto switch.
This class is implemented with 2 constants, 2 static variables and 1 lock.
MAX_FAILURES
: Maximum failures before metasmoke status is switched down.MAX_SUCCESSES
: Maximum successes before metasmoke status is switched up.ping_failure_counter
: Consecutive metasmoke status ping failure counter. A negative value represents successes while a positive value represents failures.autoswitch_is_on
: Whether or not to perform auto switch.rw_lock
: Lock. Controlling access toping_failure_counter
andautoswitch_is_on
.
ping_failed()
: Obtainrw_lock
. Decide ifping_failure_counter
is negative. If yes, setping_failure_counter
to0
. Increaseping_failure_counter
by1
. Readping_failure_counter
intocurrent_counter
. Readautoswitch_is_on
intocurrent_auto
. Releaserw_lock
. Decide ifcurrent_counter
is greater thanMAX_FAILURES
, metasmoke status is up, andcurrent_auto
isTrue
. If yes, issue a message to chat and callms_down()
.ping_succeeded()
: Obtainrw_lock
. Decide ifping_failure_counter
is positive. If yes, setping_failure_counter
to0
. Decreaseping_failure_counter
by1
. Read-ping_failure_counter
intocurrent_counter
. Readautoswitch_is_on
intocurrent_auto
. Releaserw_lock
. Decide ifcurrent_counter
is greater thanMAX_SUCCESSES
, metasmoke status is down, andcurrent_auto
isTrue
. If yes, issue a message to chat and callms_up()
.enable_autoswitch(to_enable)
: Obtainrw_lock
. Setautoswitch_is_on
toto_enable
. Releaserw_lock
.get_ping_failure()
: Obtainrw_lock
. Returnping_failure_counter
. Releaserw_lock
.reset_switch()
: Obtainrw_lock
. Setping_failure_counter
to0
. Setautoswitch_is_on
toTrue
. Releaserw_lock
.
- Only status ping failures and successes should count for turning metasmoke on and off, as otherwise it will be unbalanced since after metasmoke is declared down, only status pings are sent.
- None.
- On line 78 and 87,
GlobalVars.MSStatus.set_up()
andGlobalVars.MSStatus.set_down()
is called. This is to prevent circular import betweenMetasmoke
andSocketScience
. (20 May 2020)