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
Noneunless noted otherwise.
Note: for implementation details involving lock operations,
acquire ... releaseis implemented usingwith
Tracking post scanning data.
add_stat(posts_scanned, scan_time): Addposts_scannedto total numbers of posts scanned. Addscan_timeto 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_scannedandpost_scan_time.
add_stat(posts_scanned, scan_time): Obtainrw_lock. Addposts_scannedandscan_timetonum_posts_scannedandpost_scan_time. Releaserw_lock.get_stat(): Obtainrw_lock. Readnum_posts_scannedintoposts_scanned. Readpost_scan_timeintoscan_time. Releaserw_lock. Decide ifscan_timeis0. If yes, setposts_per_secondtoNone. Otherwise calculateposts_per_secondasposts_scanneddivided byscan_time. Return a tuple(posts_scanned, scan_time, posts_per_second).reset_stat(): Obtainrw_lock. Setnum_posts_scannedandpost_scan_timeto0. 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. ReturnsTrueif metasmoke is up andFalseotherwise.is_down(): Query if metasmoke is down. ReturnsTrueif metasmoke is down andFalseotherwise.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_statusto 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_countandlast_ping_time.
set_up(): Private tometasmoke.py. Obtainrw_lock. Setms_is_uptoTrue. Releaserw_lock.set_down(): Private tometasmoke.py. Obtainrw_lock. Setms_is_uptoFalse. Releaserw_lock.is_up(): Obtainrw_lock. Readms_is_upintocurrent_ms_status. Releaserw_lock. Returncurrent_ms_status.is_down(): Callis_up()and return the inverted returned value.failed(): Obtainrw_lock. Increasecounterby1. Releaserw_lock.succeeded(): Obtainrw_lock. Setcounterto0. Releaserw_lock.get_failure_count(): Obtainrw_lock. Readcounterintocurrent_counter. Releaserw_lock. Returncurrent_failure_count.reset_ms_status: Obtainrw_lock. Setms_is_uptoTrue. Setcounterto0. 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. IfonisTrue, 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.AutoSwitchto 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_counterandautoswitch_is_on.
ping_failed(): Obtainrw_lock. Decide ifping_failure_counteris negative. If yes, setping_failure_counterto0. Increaseping_failure_counterby1. Readping_failure_counterintocurrent_counter. Readautoswitch_is_onintocurrent_auto. Releaserw_lock. Decide ifcurrent_counteris greater thanMAX_FAILURES, metasmoke status is up, andcurrent_autoisTrue. If yes, issue a message to chat and callms_down().ping_succeeded(): Obtainrw_lock. Decide ifping_failure_counteris positive. If yes, setping_failure_counterto0. Decreaseping_failure_counterby1. Read-ping_failure_counterintocurrent_counter. Readautoswitch_is_onintocurrent_auto. Releaserw_lock. Decide ifcurrent_counteris greater thanMAX_SUCCESSES, metasmoke status is down, andcurrent_autoisTrue. If yes, issue a message to chat and callms_up().enable_autoswitch(to_enable): Obtainrw_lock. Setautoswitch_is_ontoto_enable. Releaserw_lock.get_ping_failure(): Obtainrw_lock. Returnping_failure_counter. Releaserw_lock.reset_switch(): Obtainrw_lock. Setping_failure_counterto0. Setautoswitch_is_ontoTrue. 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 betweenMetasmokeandSocketScience. (20 May 2020)