Commit 8a34e439 authored by Sebastian Kummer's avatar Sebastian Kummer

ZP-698 fixed typo in memcached provider filename, when waiting for a

mutex only log up to 5 messages (spread over the configured total amount
of time), if memcache is down don't retry in other connections for up to
30 seconds (configurable), removed TCP_NODELAY and NO_BLOCK options,
memcache servers are setup in a single string, renamed ReInitSharedMem()
to ReInitIPC(), fixed comments and public/private/protected visibility,
fixed upper/lowercasing of method names, added some dots.

Released under the Affero GNU General Public License (AGPL) version 3.
parent 3f17ba03
......@@ -42,10 +42,15 @@
* Consult LICENSE file for details
************************************************/
// The list of available memcache servers
// More servers can be added as 'hostname:port'
// if no port is specified, the default port 11211 will be used
$zpush_ipc_memcached_servers = array('localhost');
// Comma separated list of available memcache servers.
// Servers can be added as 'hostname:port,otherhost:port'
define('MEMCACHED_SERVERS','localhost:11211');
// Memcached down indicator
// In case memcached is not available, a lock file will be written to disk
define('MEMCACHED_DOWN_LOCK_FILE', '/tmp/z-push-memcache-down');
// indicates how long the lock file will be maintained (in seconds)
define('MEMCACHED_DOWN_LOCK_EXPIRATION', 30);
// Prefix to used for keys
define('MEMCACHED_PREFIX', 'z-push-ipc');
......@@ -53,8 +58,8 @@ define('MEMCACHED_PREFIX', 'z-push-ipc');
// Connection timeout in ms
define('MEMCACHED_TIMEOUT', 100);
// Mutex timeout in s
// Mutex timeout (in seconds)
define('MEMCACHED_MUTEX_TIMEOUT', 5);
// Waiting time before re-trying to aquire mutext (in millionth of sec)
define('MEMCACHED_BLOCK_USLEEP', 10000);
// Waiting time before re-trying to aquire mutex (in ms), must be higher than 0
define('MEMCACHED_BLOCK_WAIT', 10);
<?php
/***********************************************
* File : ipcmemcachedorovider.php
* File : ipcmemcacheprovider.php
* Project : Z-Push
* Descr : IPC provider using Memcached PHP extension
* and memcached servers defined in
......@@ -46,6 +46,10 @@
class IpcMemcachedProvider implements IIpcProvider {
protected $type;
private $maxWaitCycles;
private $logWaitCycles;
private $isDownUntil;
private $wasDown;
private $reconnectCount;
/**
* Instance of memcached class
......@@ -63,9 +67,9 @@ class IpcMemcachedProvider implements IIpcProvider {
* @param string $class
*/
public function __construct($type, $allocate, $class) {
global $zpush_ipc_memcached_servers;
$this->type = $type;
$this->maxWaitCycles = round(MEMCACHED_MUTEX_TIMEOUT * 1000 * 1000 / MEMCACHED_BLOCK_USLEEP);
$this->maxWaitCycles = round(MEMCACHED_MUTEX_TIMEOUT * 1000 / MEMCACHED_BLOCK_WAIT)+1;
$this->logWaitCycles = round($this->maxWaitCycles/5);
// not used, but required by function signature
unset($allocate, $class);
......@@ -74,15 +78,27 @@ class IpcMemcachedProvider implements IIpcProvider {
throw new FatalMisconfigurationException("IpcMemcachedProvider failure: can not find class Memcached. Please make sure the php memcached extension is installed.");
}
$this->memcached = new Memcached(md5(serialize($zpush_ipc_memcached_servers)));
$this->reconnectCount = 0;
$this->init();
// check if memcached was down recently
$this->isDownUntil = $this->getIsDownTime();
$this->wasDown = ! $this->IsActive();
}
/**
* Initializes the Memcached object & connection.
*
* @access private
* @return void
*/
private function init() {
$this->memcached = new Memcached(md5(MEMCACHED_SERVERS) . $this->reconnectCount++);
$this->memcached->setOptions(array(
// setting a short timeout, to better kope with failed nodes
Memcached::OPT_CONNECT_TIMEOUT => 5,
Memcached::OPT_CONNECT_TIMEOUT => MEMCACHED_TIMEOUT,
Memcached::OPT_SEND_TIMEOUT => MEMCACHED_TIMEOUT * 1000,
Memcached::OPT_RECV_TIMEOUT => MEMCACHED_TIMEOUT * 1000,
Memcached::OPT_TCP_NODELAY => true,
Memcached::OPT_NO_BLOCK => false,
// use igbinary, if available
Memcached::OPT_SERIALIZER => Memcached::HAVE_IGBINARY ? Memcached::SERIALIZER_IGBINARY : (Memcached::HAVE_JSON ? Memcached::SERIALIZER_JSON : Memcached::SERIALIZER_PHP),
......@@ -99,28 +115,27 @@ class IpcMemcachedProvider implements IIpcProvider {
// with persistent connections, only add servers, if they not already added!
if (!count($this->memcached->getServerList())) {
foreach($zpush_ipc_memcached_servers as $host_port) {
$parts = explode(':', $host_port);
$host = array_shift($parts);
$port = $parts ? array_shift($parts) : 11211; // default port
foreach(explode(',', MEMCACHED_SERVERS) as $host_port) {
list($host,$port) = explode(':', trim($host_port));
$this->memcached->addServer($host, $port);
}
}
}
/**
* Reinitializes shared memory by removing, detaching and re-allocating it
* Reinitializes the IPC data. If the provider has no way of performing
* this action, it should return 'false'.
*
* @access public
* @return boolean
*/
public function ReInitSharedMem() {
return ($this->RemoveSharedMem() && $this->InitSharedMem());
public function ReInitIPC() {
// this is not supported in memcache
return false;
}
/**
* Cleans up the shared memory block
* Cleans up the IPC data block.
*
* @access public
* @return boolean
......@@ -130,17 +145,24 @@ class IpcMemcachedProvider implements IIpcProvider {
}
/**
* Indicates if the shared memory is active
* Indicates if the IPC is active.
*
* @access public
* @return boolean
*/
public function IsActive() {
return true;
$down = $this->isDownUntil > time();
// reconnect if we were down but should retry now
if (!$down && $this->wasDown) {
ZLog::Write(LOGLEVEL_DEBUG, "IpcMemcachedProvider->IsActive(): memcache was down, trying to reconnect");
$this->init();
$this->wasDown = false;
}
return !$down;
}
/**
* Blocks the class mutex
* Blocks the class mutex.
* Method blocks until mutex is available!
* ATTENTION: make sure that you *always* release a blocked mutex!
*
......@@ -148,85 +170,116 @@ class IpcMemcachedProvider implements IIpcProvider {
* It will fail as long other client has stored it or the
* MEMCACHED_MUTEX_TIMEOUT is reached.
*
* @access protected
* @access public
* @return boolean
*/
public function blockMutex() {
public function BlockMutex() {
if (!$this->IsActive()) {
return false;
}
$n = 0;
while(!$this->memcached->add($this->type+10, true, MEMCACHED_MUTEX_TIMEOUT)) {
if ($n++) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("IpcMemcachedProvider->BlockMutex() waiting to aquire mutex for type: %s", $this->type));
if (++$n % $this->logWaitCycles == 0) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("IpcMemcachedProvider->BlockMutex() waiting to aquire mutex for type: %s ", $this->type));
}
// wait before retrying
usleep(MEMCACHED_BLOCK_USLEEP);
usleep(MEMCACHED_BLOCK_WAIT * 1000);
if ($n > $this->maxWaitCycles) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("IpcMemcachedProvider->BlockMutex() could not aquire mutex for type: %s. Check memcache service!", $this->type));
$this->markAsDown();
return false;
}
}
if ($n) {
ZLog::Write(LOGLEVEL_WARN, sprintf("IpcMemcachedProvider->BlockMutex() mutex aquired after waiting for %sms for type: %s", ($n*MEMCACHED_BLOCK_USLEEP/1000), $this->type));
ZLog::Write(LOGLEVEL_WARN, sprintf("IpcMemcachedProvider->BlockMutex() mutex aquired after waiting for %sms for type: %s", ($n*MEMCACHED_BLOCK_WAIT), $this->type));
}
return true;
}
/**
* Releases the class mutex
* After the release other processes are able to block the mutex themselfs
* Releases the class mutex.
* After the release other processes are able to block the mutex themselves.
*
* @access protected
* @access public
* @return boolean
*/
public function releaseMutex() {
public function ReleaseMutex() {
return $this->memcached->delete($this->type+10);
}
/**
* Indicates if the requested variable is available in shared memory
* Indicates if the requested variable is available in IPC data.
*
* @param int $id int indicating the variable
*
* @access protected
* @access public
* @return boolean
*/
public function hasData($id = 2) {
public function HasData($id = 2) {
$this->memcached->get($this->type.':'.$id);
return $this->memcached->getResultCode() === Memcached::RES_SUCCESS;
}
/**
* Returns the requested variable from shared memory
* Returns the requested variable from IPC data.
*
* @param int $id int indicating the variable
*
* @access protected
* @access public
* @return mixed
*/
public function getData($id = 2) {
public function GetData($id = 2) {
return $this->memcached->get($this->type.':'.$id);
}
/**
* Writes the transmitted variable to shared memory
* Writes the transmitted variable to IPC data.
* Subclasses may never use an id < 2!
*
* @param mixed $data data which should be saved into shared memory
* @param mixed $data data which should be saved into IPC data
* @param int $id int indicating the variable (bigger than 2!)
*
* @access protected
* @access public
* @return boolean
*/
public function setData($data, $id = 2) {
public function SetData($data, $id = 2) {
return $this->memcached->set($this->type.':'.$id, $data);
}
/**
* Sets the time when the shared memory block was created
* Gets the epoch time until the memcache server should not be retried.
* If there is no data available, 0 is returned.
*
* @access private
* @return long
*/
private function getIsDownTime() {
if (file_exists(MEMCACHED_DOWN_LOCK_FILE)) {
$timestamp = file_get_contents(MEMCACHED_DOWN_LOCK_FILE);
// is the lock file expired?
if ($timestamp > time()) {
ZLog::Write(LOGLEVEL_WARN, sprintf("IpcMemcachedProvider(): Memcache service is marked as down until %s.", strftime("%d.%m.%Y %H:%M:%S", $timestamp)));
return $timestamp;
}
else {
unlink(MEMCACHED_DOWN_LOCK_FILE);
}
}
return 0;
}
/**
* Indicates that memcache is not available and that it should not be retried.
*
* @access private
* @return boolean
*/
private function setInitialCleanTime() {
return true;
private function markAsDown() {
ZLog::Write(LOGLEVEL_WARN, sprintf("IpcMemcachedProvider(): Marking memcache service as down for %d seconds.", MEMCACHED_DOWN_LOCK_EXPIRATION));
$downUntil = time() + MEMCACHED_DOWN_LOCK_EXPIRATION;
$this->isDownUntil = $downUntil;
$this->wasDown = true;
return !!file_put_contents(MEMCACHED_DOWN_LOCK_FILE, $downUntil);
}
}
\ No newline at end of file
......@@ -58,33 +58,33 @@ class IpcSharedMemoryProvider implements IIpcProvider {
$this->type = $type;
$this->allocate = $allocate;
if ($this->InitSharedMem())
if ($this->initSharedMem())
ZLog::Write(LOGLEVEL_DEBUG, sprintf("%s(): Initialized mutexid %s and memid %s.", $class, $this->mutexid, $this->memid));
}
/**
* Allocates shared memory
* Allocates shared memory.
*
* @access private
* @return boolean
*/
private function InitSharedMem() {
private function initSharedMem() {
if (!function_exists('sem_get') || !function_exists('shm_attach') || !function_exists('sem_acquire')|| !function_exists('shm_get_var')) {
ZLog::Write(LOGLEVEL_INFO, "IpcSharedMemoryProvider->InitSharedMem(): PHP libraries for the use shared memory are not available. Check the isntalled php packages or use e.g. the memcache IPC provider.");
ZLog::Write(LOGLEVEL_INFO, "IpcSharedMemoryProvider->initSharedMem(): PHP libraries for the use shared memory are not available. Check the isntalled php packages or use e.g. the memcache IPC provider.");
return false;
}
// Create mutex
$this->mutexid = @sem_get($this->type, 1);
if ($this->mutexid === false) {
ZLog::Write(LOGLEVEL_ERROR, "IpcSharedMemoryProvider->InitSharedMem(): could not aquire semaphore");
ZLog::Write(LOGLEVEL_ERROR, "IpcSharedMemoryProvider->initSharedMem(): could not aquire semaphore");
return false;
}
// Attach shared memory
$this->memid = shm_attach($this->type+10, $this->allocate);
if ($this->memid === false) {
ZLog::Write(LOGLEVEL_ERROR, "IpcSharedMemoryProvider->InitSharedMem(): could not attach shared memory");
ZLog::Write(LOGLEVEL_ERROR, "IpcSharedMemoryProvider->initSharedMem(): could not attach shared memory");
@sem_remove($this->mutexid);
$this->mutexid = false;
return false;
......@@ -97,12 +97,12 @@ class IpcSharedMemoryProvider implements IIpcProvider {
}
/**
* Removes and detaches shared memory
* Removes and detaches shared memory.
*
* @access private
* @return boolean
*/
private function RemoveSharedMem() {
private function removeSharedMem() {
if ((isset($this->mutexid) && $this->mutexid !== false) && (isset($this->memid) && $this->memid !== false)) {
@sem_acquire($this->mutexid);
$memid = $this->memid;
......@@ -121,17 +121,17 @@ class IpcSharedMemoryProvider implements IIpcProvider {
}
/**
* Reinitializes shared memory by removing, detaching and re-allocating it
* Reinitializes the IPC data by removing, detaching and re-allocating it.
*
* @access public
* @return boolean
*/
public function ReInitSharedMem() {
return ($this->RemoveSharedMem() && $this->InitSharedMem());
public function ReInitIPC() {
return ($this->removeSharedMem() && $this->initSharedMem());
}
/**
* Cleans up the shared memory block
* Cleans up the IPC data block.
*
* @access public
* @return boolean
......@@ -140,12 +140,12 @@ class IpcSharedMemoryProvider implements IIpcProvider {
$stat = false;
// exclusive block
if ($this->blockMutex()) {
$cleanuptime = ($this->hasData(1)) ? $this->getData(1) : false;
if ($this->BlockMutex()) {
$cleanuptime = ($this->HasData(1)) ? $this->GetData(1) : false;
// TODO implement Shared Memory cleanup
$this->releaseMutex();
$this->ReleaseMutex();
}
// end exclusive block
......@@ -153,7 +153,7 @@ class IpcSharedMemoryProvider implements IIpcProvider {
}
/**
* Indicates if the shared memory is active
* Indicates if the IPC is active.
*
* @access public
* @return boolean
......@@ -163,14 +163,14 @@ class IpcSharedMemoryProvider implements IIpcProvider {
}
/**
* Blocks the class mutex
* Blocks the class mutex.
* Method blocks until mutex is available!
* ATTENTION: make sure that you *always* release a blocked mutex!
*
* @access protected
* @access public
* @return boolean
*/
public function blockMutex() {
public function BlockMutex() {
if ((isset($this->mutexid) && $this->mutexid !== false) && (isset($this->memid) && $this->memid !== false))
return @sem_acquire($this->mutexid);
......@@ -178,13 +178,13 @@ class IpcSharedMemoryProvider implements IIpcProvider {
}
/**
* Releases the class mutex
* After the release other processes are able to block the mutex themselfs
* Releases the class mutex.
* After the release other processes are able to block the mutex themselves.
*
* @access protected
* @access public
* @return boolean
*/
public function releaseMutex() {
public function ReleaseMutex() {
if ((isset($this->mutexid) && $this->mutexid !== false) && (isset($this->memid) && $this->memid !== false))
return @sem_release($this->mutexid);
......@@ -192,19 +192,19 @@ class IpcSharedMemoryProvider implements IIpcProvider {
}
/**
* Indicates if the requested variable is available in shared memory
* Indicates if the requested variable is available in IPC data.
*
* @param int $id int indicating the variable
*
* @access protected
* @access public
* @return boolean
*/
public function hasData($id = 2) {
public function HasData($id = 2) {
if ((isset($this->mutexid) && $this->mutexid !== false) && (isset($this->memid) && $this->memid !== false)) {
if (function_exists("shm_has_var"))
return @shm_has_var($this->memid, $id);
else {
$some = $this->getData($id);
$some = $this->GetData($id);
return isset($some);
}
}
......@@ -212,14 +212,14 @@ class IpcSharedMemoryProvider implements IIpcProvider {
}
/**
* Returns the requested variable from shared memory
* Returns the requested variable from IPC data.
*
* @param int $id int indicating the variable
*
* @access protected
* @access public
* @return mixed
*/
public function getData($id = 2) {
public function GetData($id = 2) {
if ((isset($this->mutexid) && $this->mutexid !== false) && (isset($this->memid) && $this->memid !== false))
return @shm_get_var($this->memid, $id);
......@@ -227,16 +227,16 @@ class IpcSharedMemoryProvider implements IIpcProvider {
}
/**
* Writes the transmitted variable to shared memory
* Writes the transmitted variable to IPC data.
* Subclasses may never use an id < 2!
*
* @param mixed $data data which should be saved into shared memory
* @param mixed $data data which should be saved into IPC data
* @param int $id int indicating the variable (bigger than 2!)
*
* @access protected
* @access public
* @return boolean
*/
public function setData($data, $id = 2) {
public function SetData($data, $id = 2) {
if ((isset($this->mutexid) && $this->mutexid !== false) && (isset($this->memid) && $this->memid !== false))
return @shm_put_var($this->memid, $id, $data);
......@@ -253,12 +253,12 @@ class IpcSharedMemoryProvider implements IIpcProvider {
$stat = false;
// exclusive block
if ($this->blockMutex()) {
if ($this->BlockMutex()) {
if ($this->hasData(1) == false)
$stat = $this->setData(time(), 1);
if ($this->HasData(1) == false)
$stat = $this->SetData(time(), 1);
$this->releaseMutex();
$this->ReleaseMutex();
}
// end exclusive block
......
......@@ -47,7 +47,7 @@
include_once('backend/ipcsharedmemory/ipcsharedmemoryprovider.php');
abstract class InterProcessData {
// Defines which IPC provider to laod, first has preference
// Defines which IPC provider to load, first has preference
// if IPC_PROVIDER in the main config is set, that class will be loaded
const PROVIDER_LOAD_ORDER = array('IpcMemcachedProvider', 'IpcSharedMemoryProvider');
const CLEANUPTIME = 1;
......@@ -100,12 +100,12 @@ abstract class InterProcessData {
}
/**
* Initializes internal parameters
* Initializes internal parameters.
*
* @access public
* @access protected
* @return boolean
*/
public function InitializeParams() {
protected function initializeParams() {
if (!isset(self::$devid)) {
self::$devid = Request::GetDeviceID();
self::$pid = @getmypid();
......@@ -116,7 +116,17 @@ abstract class InterProcessData {
}
/**
* Cleans up the shared memory block
* Reinitializes the IPC data by removing, detaching and re-allocating it.
*
* @access public
* @return boolean
*/
public function ReInitIPC() {
return $this->ipcProvider ? $this->ipcProvider->ReInitIPC() : false;
}
/**
* Cleans up the IPC data block.
*
* @access public
* @return boolean
......@@ -126,7 +136,7 @@ abstract class InterProcessData {
}
/**
* Indicates if the shared memory is active
* Indicates if the IPC is active.
*
* @access public
* @return boolean
......@@ -136,7 +146,7 @@ abstract class InterProcessData {
}
/**
* Blocks the class mutex
* Blocks the class mutex.
* Method blocks until mutex is available!
* ATTENTION: make sure that you *always* release a blocked mutex!
*
......@@ -144,22 +154,22 @@ abstract class InterProcessData {
* @return boolean
*/
protected function blockMutex() {
return $this->ipcProvider ? $this->ipcProvider->blockMutex() : false;
return $this->ipcProvider ? $this->ipcProvider->BlockMutex() : false;
}
/**
* Releases the class mutex
* After the release other processes are able to block the mutex themselfs
* Releases the class mutex.
* After the release other processes are able to block the mutex themselves.
*
* @access protected
* @return boolean
*/
protected function releaseMutex() {
return $this->ipcProvider ? $this->ipcProvider->releaseMutex() : false;
return $this->ipcProvider ? $this->ipcProvider->ReleaseMutex() : false;
}
/**
* Indicates if the requested variable is available in shared memory
* Indicates if the requested variable is available in IPC data.
*
* @param int $id int indicating the variable
*
......@@ -167,11 +177,11 @@ abstract class InterProcessData {
* @return boolean
*/
protected function hasData($id = 2) {
return $this->ipcProvider ? $this->ipcProvider->hasData($id) : false;
return $this->ipcProvider ? $this->ipcProvider->HasData($id) : false;
}
/**
* Returns the requested variable from shared memory
* Returns the requested variable from IPC data.
*
* @param int $id int indicating the variable
*
......@@ -179,20 +189,20 @@ abstract class InterProcessData {
* @return mixed
*/
protected function getData($id = 2) {
return $this->ipcProvider ? $this->ipcProvider->getData($id) : null;
return $this->ipcProvider ? $this->ipcProvider->GetData($id) : null;
}
/**
* Writes the transmitted variable to shared memory
* Writes the transmitted variable to IPC data.
* Subclasses may never use an id < 2!
*
* @param mixed $data data which should be saved into shared memory
* @param mixed $data data which should be saved into IPC data
* @param int $id int indicating the variable (bigger than 2!)
*
* @access protected
* @return boolean
*/
protected function setData($data, $id = 2) {
return $this->ipcProvider ? $this->ipcProvider->setData($data, $id) : false;
return $this->ipcProvider ? $this->ipcProvider->SetData($data, $id) : false;
}
}
......@@ -305,7 +305,7 @@ class LoopDetection extends InterProcessData {
*/
private function updateProcessStack() {
// initialize params
$this->InitializeParams();
$this->initializeParams();
if ($this->blockMutex()) {
$loopdata = ($this->hasData()) ? $this->getData() : array();
......@@ -354,7 +354,7 @@ class LoopDetection extends InterProcessData {
*/
private function getProcessStack() {
// initialize params
$this->InitializeParams();
$this->initializeParams();
$stack = array();
if ($this->blockMutex()) {
......@@ -401,7 +401,7 @@ class LoopDetection extends InterProcessData {
$brokenkey = self::BROKENMSGS ."-". $folderid;
// initialize params
$this->InitializeParams();
$this->initializeParams();
if ($this->blockMutex()) {
$loopdata = ($this->hasData()) ? $this->getData() : array();
......@@ -443,7 +443,7 @@ class LoopDetection extends InterProcessData {
$okIds = array();
// initialize params
$this->InitializeParams();
$this->initializeParams();
if ($this->blockMutex()) {
$loopdata = ($this->hasData()) ? $this->getData() : array();
......@@ -504,7 +504,7 @@ class LoopDetection extends InterProcessData {
*/
public function SetSyncStateUsage($folderid, $uuid, $counter) {
// initialize params
$this->InitializeParams();
$this->initializeParams();
ZLog::Write(LOGLEVEL_DEBUG, sprintf("LoopDetection->SetSyncStateUsage(): uuid: %s counter: %d", $uuid, $counter));
......@@ -551,7 +551,7 @@ class LoopDetection extends InterProcessData {
*/
public function IsSyncStateObsolete($folderid, $uuid, $counter) {
// initialize params
$this->InitializeParams();
$this->initializeParams();
$obsolete = false;
......@@ -636,7 +636,7 @@ class LoopDetection extends InterProcessData {
}
// initialize params
$this->InitializeParams();
$this->initializeParams();
$loop = false;
......
......@@ -89,7 +89,7 @@ class PingTracking extends InterProcessData {
$stat = false;
// initialize params
$this->InitializeParams();
$this->initializeParams();
// exclusive block
if ($this->blockMutex()) {
......
......@@ -63,7 +63,7 @@ class TopCollector extends InterProcessData {
parent::__construct();
// initialize params
$this->InitializeParams();
$this->initializeParams();
$this->preserved = array();
// static vars come from the parent class
......@@ -222,9 +222,10 @@ class TopCollector extends InterProcessData {
}
}
}
foreach ($toClear as $tc)
foreach ($toClear as $tc) {
unset($topdata[$tc[0]][$tc[1]][$tc[2]]);
}
}
$stat = $this->setData($topdata, self::TOPDATA);
$this->releaseMutex();
......@@ -260,6 +261,20 @@ class TopCollector extends InterProcessData {
return true;
}
/**
* Reinitializes the IPC data.
*
* @access public
* @return boolean
*/
public function ReInitIPC() {
$status = parent::ReInitIPC();
if (!status) {
$this->SetData(array(), self::TOPDATA);
}
return $status;
}
/**
* Indicates if top data should be saved or not
* Returns true for 10 seconds after the latest CollectData()
......
......@@ -74,7 +74,7 @@ class SimpleMutex extends InterProcessData {
/**
* Releases the mutex
* After the release other processes are able to block the mutex themselfs
* After the release other processes are able to block the mutex themselves
*
* @access public
* @return boolean
......
......@@ -54,7 +54,16 @@ interface IIpcProvider
public function __construct($type, $allocate, $class);
/**
* Cleans up the shared memory block
* Reinitializes the IPC data. If the provider has no way of performing
* this action, it should return 'false'.
*
* @access public
* @return boolean
*/
public function ReInitIPC();
/**
* Cleans up the IPC data block.
*
* @access public
* @return boolean
......@@ -62,7 +71,7 @@ interface IIpcProvider
public function Clean();
/**
* Indicates if the shared memory is active
* Indicates if the IPC is active.
*
* @access public
* @return boolean
......@@ -70,53 +79,53 @@ interface IIpcProvider
public function IsActive();
/**
* Blocks the class mutex
* Blocks the class mutex.
* Method blocks until mutex is available!
* ATTENTION: make sure that you *always* release a blocked mutex!
*
* @access protected
* @access public
* @return boolean
*/
public function blockMutex();
public function BlockMutex();
/**
* Releases the class mutex
* After the release other processes are able to block the mutex themselfs
* Releases the class mutex.
* After the release other processes are able to block the mutex themselves.
*
* @access protected
* @access public
* @return boolean
*/
public function releaseMutex();
public function ReleaseMutex();
/**
* Indicates if the requested variable is available in shared memory
* Indicates if the requested variable is available in IPC data.
*
* @param int $id int indicating the variable
*
* @access protected
* @access public
* @return boolean
*/
public function hasData($id = 2);
public function HasData($id = 2);
/**
* Returns the requested variable from shared memory
* Returns the requested variable from IPC data.
*
* @param int $id int indicating the variable
*
* @access protected
* @access public
* @return mixed
*/
public function getData($id = 2);
public function GetData($id = 2);
/**
* Writes the transmitted variable to shared memory
* Writes the transmitted variable to IPC data.
* Subclasses may never use an id < 2!
*
* @param mixed $data data which should be saved into shared memory
* @param mixed $data data which should be saved into IPC data
* @param int $id int indicating the variable (bigger than 2!)
*
* @access protected
* @access public
* @return boolean
*/
public function setData($data, $id = 2);
public function SetData($data, $id = 2);
}
......@@ -480,7 +480,7 @@ class ZPushTop {
else if ($cmds[0] == "clear" ) {
$this->topCollector->ClearLatest(true);
$this->topCollector->CollectData(true);
$this->topCollector->ReInitSharedMem();
$this->topCollector->ReInitIPC();
}
else if ($cmds[0] == "filter" || $cmds[0] == "f") {
if (!isset($cmds[1]) || $cmds[1] == "") {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment