getInstance() публичный статический Метод

Singleton-Factory for Peer-Instances
public static getInstance ( string $method, string $url = false ) : dropr_Client_Peer_Abstract
$method string
$url string
Результат dropr_Client_Peer_Abstract
Пример #1
0
 public function testPut()
 {
     $peer = dropr_Client_Peer_Abstract::getInstance('HttpUpload', 'http://localhost/droprserver/');
     $dt = time();
     $i = 0;
     // $m = $this->createMessage(1000);
     $m = "ich bin eine test message von " . date("H:m:i");
     while ($i < 1) {
         $msg = $this->queue->createMessage($m, $peer);
         $msg->queue();
         $i++;
         echo '.';
     }
     $dt = time() - $dt;
     echo $dt . "\n";
     echo "\n\n";
 }
Пример #2
0
<?php

require '../../client/classes/autoload.php';
$storage = dropr_Client_Storage_Abstract::factory('filesystem', '/home/soenke/droprclientqueue');
$queue = new dropr_Client($storage);
$peer = dropr_Client_Peer_Abstract::getInstance('HttpUpload', 'http://soenkedroprserver/server/server.php');
$dt = time();
$i = 0;
$m = json_encode(array("ich bin eine test message von " . date("H:i:s"), 'wurstarrayarray'));
while ($i < 10000) {
    $msg = $queue->createMessage($m, $peer);
    $msg->queue();
    $i++;
    echo '.';
}
echo "\n";
Пример #3
0
pcntl_signal(SIGINT, 'handleKill');
/*
 * handle the alarm (wake-up from sleep)
 */
pcntl_signal(SIGALRM, 'handleAlarm');
while ($continue && $msgCount < $maxMessagesPerLife) {
    unset($queuedMessages, $peerMessages);
    if ($queuedMessages = $storage->getQueuedMessages($maxMessagesPerSend, $peerKeyBlackList)) {
        dropr::log("got " . count($queuedMessages, COUNT_RECURSIVE) . " messages from the storage", LOG_DEBUG);
        foreach ($queuedMessages as $peerKey => $peerMessages) {
            /*
             * count the messages regardless they can be sent or not
             */
            $msgCount += count($peerMessages, COUNT_RECURSIVE);
            try {
                $peer = dropr_Client_Peer_Abstract::getInstance($peerKey);
                dropr::log("trying to send messages to peer `" . $peer->getUrl() . "' via method `" . $peer->getTransportMethod() . "'", LOG_DEBUG);
                $result = $peer->send($peerMessages, $storage);
                $storage->checkSentMessages($peerMessages, $result);
                dropr::log("successfully sent messages to the peer!", LOG_DEBUG);
            } catch (Exception $e) {
                $peerKeyBlackList[$peerKey] = time() + $peerTimeout;
                dropr::log("could not sent messages to peer {$peer->getUrl()}- message was: {$e->getMessage()}  - blacklisting the peer for {$peerTimeout} seconds!");
            }
        }
    } else {
        dropr::log("nothing to do. going to sleep.", LOG_DEBUG);
        pcntl_alarm($sleepTimeout);
        @msg_receive($ipcChannel, 1, $msgType, 512, $msg, true, 0, $msgError);
        dropr::log("woke up from sleep - checking for messages ...", LOG_DEBUG);
        pcntl_alarm(0);
Пример #4
0
 public function getQueuedMessages($limit = null, &$peerKeyBlackList = null)
 {
     // expire blacklisted peers
     $now = time();
     foreach ($peerKeyBlackList as $peerKey => $timeout) {
         if ($now > $timeout) {
             unset($peerKeyBlackList[$peerKey]);
         }
     }
     $spoolDir = $this->getSpoolPath(self::SPOOLDIR_TYPE_SPOOL) . DIRECTORY_SEPARATOR;
     $fNames = scandir($spoolDir);
     // unset the "." and the ".."
     unset($fNames[0]);
     unset($fNames[1]);
     $c = 1;
     $messages = array();
     foreach ($fNames as $k => $fName) {
         if ($limit && $c > $limit) {
             break;
         }
         list($priority, $timeStamp, $encodedPeerKey, $encodedChannel) = explode('_', $fName, 4);
         $decodedPeerKey = $this->decodeFromFs($encodedPeerKey);
         $decodedChannel = $this->decodeFromFs($encodedChannel);
         $message = new dropr_Client_Message(NULL, new SplFileInfo($spoolDir . $fName), dropr_Client_Peer_Abstract::getInstance($decodedPeerKey), $decodedChannel, $priority);
         $message->restoreId($fName);
         if (!isset($peerKeyBlackList[$decodedPeerKey])) {
             $messages[$decodedPeerKey][] = $message;
             $c++;
         }
     }
     return $messages;
 }