Example #1
0
 /**
  * Returns a simple event dispatcher that simply implements the dispatcher interface
  * with no additional functionality added to it. This returns a singletion dispatcher,
  * so it is reused each time this method is called (i.e. you get the same object
  * back no matter how many times you call this method).
  * 
  * @return simple dispatcher singleton
  */
 public static function getSimpleDispatcher()
 {
     if (!isset(self::$simple)) {
         self::$simple = new M3_Event_SimpleDispatcher();
     }
     return self::$simple;
 }
Example #2
0
 public function testRemoveListener()
 {
     $event1 = new TEST_DummyEvent();
     $event2 = new TEST_DummyEvent();
     $event1->id = 1;
     $event2->id = 2;
     $dispatcher = M3_Event_DispatcherFactory::getSimpleDispatcher();
     $listener1 = new SimpleEventListener();
     $listener2 = new SimpleEventListener();
     $dispatcher->addListener($listener1);
     $dispatcher->addListener($listener2);
     $dispatcher->addListener($listener2);
     // just making sure this doesn't break things - should be a no-op
     $dispatcher->dispatchEvent($event1);
     $dispatcher->removeListener($listener2);
     $dispatcher->removeListener($listener2);
     // just making sure this doesn't break things - should be a no-op
     $dispatcher->dispatchEvent($event2);
     $this->assertEquals(2, $listener1->getNumEvents());
     $this->assertEquals(1, $listener2->getNumEvents());
     $this->assertEquals(TEST_DummyEvent::KIND, $listener1->getLastEvent()->getKind());
     $this->assertEquals(TEST_DummyEvent::KIND, $listener2->getLastEvent()->getKind());
     $this->assertEquals(2, $listener1->getLastEvent()->id);
     $this->assertEquals(1, $listener2->getLastEvent()->id);
     // just some sanity checking
     $this->assertType("M3_Event_IEvent", $listener1->getLastEvent());
     $this->assertType("M3_Event_IEvent", $listener2->getLastEvent());
     $this->assertType("TEST_DummyEvent", $listener1->getLastEvent());
     $this->assertType("TEST_DummyEvent", $listener2->getLastEvent());
 }
 /**
  * Returns an array containing tabular data describing all the duration metrics
  * for APIs.  The array is a flat list, with each internal element of the list being
  * an associative array with keys: key, count, min, max, avg. The "key" value
  * is the name of the API method; the remaining values are the duration
  * metrics for that API. Note that this follows the convention of returning
  * a top-most associative array with a single element keyed with 'api_duration'. That
  * element value is the flat array described above.
  *
  * @return array all API duration metrics.
  */
 public function execute()
 {
     $_listener = M3_Event_DispatcherFactory::createApiInvocationListener();
     $_stats = $_listener->getApiDurations();
     $_arr = $_stats->getStatsFlatArray();
     // we want it flat so the response can be described via XML Schema
     return array('api_duration' => $_arr);
 }
 public function testPurgeApiDurations()
 {
     // emit 2 metric events
     $_tuple = new M3_Event_Tuple();
     $_dispatcher = M3_Event_DispatcherFactory::createApiResponseTimeTupleDispatcher("some.api.name", $_tuple);
     $_dispatcher->startTimer();
     sleep(1);
     $_dispatcher->stopTimer();
     $_dispatcher->startTimer();
     sleep(1);
     $_dispatcher->stopTimer();
     // make sure we can aggregate those two metrics
     $_apiCall = $this->initRest(new MetricsPurgeApiDurations(), null);
     $_results = $_apiCall->execute();
     $this->assertGreaterThanOrEqual(2, $_results);
     // make sure we really deleted the data
     $_apiCall = $this->initRest(new MetricsGetApiDurations(), null);
     $_results = $_apiCall->execute();
     $this->assertTrue(is_array($_results));
     $this->assertTrue(is_array($_results['api_duration']));
     $this->assertEquals(0, count($_results['api_duration']));
 }
 public function testGetApiDurations()
 {
     // emit 2 metric events
     $_tuple = new M3_Event_Tuple();
     $_dispatcher = M3_Event_DispatcherFactory::createApiResponseTimeTupleDispatcher("some.api.name", $_tuple);
     $_dispatcher->startTimer();
     sleep(1);
     $_dispatcher->stopTimer();
     $_dispatcher->startTimer();
     sleep(1);
     $_dispatcher->stopTimer();
     // make sure we can aggregate those two metrics
     $_apiCall = $this->initRest(new MetricsGetApiDurations(), null);
     $_results = $_apiCall->execute();
     $_results = M3_Util_Stats::unflattenArray($_results['api_duration']);
     $this->assertTrue(is_array($_results));
     $this->assertArrayHasKey('some.api.name', $_results);
     $this->assertGreaterThanOrEqual(2, $_results['some.api.name']['count']);
     $this->assertGreaterThanOrEqual(0, $_results['some.api.name']['min']);
     $this->assertGreaterThanOrEqual(0, $_results['some.api.name']['max']);
     $this->assertGreaterThanOrEqual(0, $_results['some.api.name']['avg']);
 }
 public function execute()
 {
     $_listener = M3_Event_DispatcherFactory::createApiInvocationListener();
     $_results = $_listener->deleteAllData();
     return $_results;
 }
Example #7
0
 /**
  * Execute the request and return the hash results, this
  * was separated soley for the purpose of running test cases.
  *
  * @param unknown_type $requestParams
  */
 function executeRequest(Api_RequestContext &$context)
 {
     $response = array();
     if ($context->getMethod() == null) {
         throw new OpenFBAPIException('Incorrect Signature, Missing METHOD.', FB_ERROR_CODE_INCORRECT_SIGNATURE);
     }
     // Call the object/method.
     $api_name = explode('.', $context->getMethod());
     $api_pkg = $api_name[1];
     $api_class = ucfirst($api_name[1]) . ucfirst($api_name[2]);
     $lasterrorlevel = error_reporting(E_ERROR);
     if (!(include_once $api_name[0] . '/rest/' . $api_class . '.php')) {
         // TODO: Move these to match the packaging standard
         // Default OpenFBServer API implementations are still here
         include_once 'ringside/api/facebook/' . $api_class . '.php';
     }
     error_reporting($lasterrorlevel);
     if (!$api_class) {
         throw new Exception("Class {$api_class} could not be loaded");
     }
     $faf = new $api_class();
     // Set the server object.
     $faf->_setServer($this);
     // set the context
     $faf->_setContext($context);
     // Load the session and setup the session.
     $faf->loadSession();
     // Execute delegation?
     $faf->delegateRequest();
     // Validation steps
     $faf->validateSession();
     $faf->validateApiKey();
     $faf->validateSig();
     $faf->validateVersion();
     $faf->validateCallId();
     $faf->validateRequest();
     // let's invoke the API that is being requested - collect stat around the call
     $tuple = new M3_Event_Tuple($faf->getNetworkId(), $faf->getAppId(), $faf->getUserId());
     $dispatcher = M3_Event_DispatcherFactory::createApiResponseTimeTupleDispatcher($context->getMethod(), $tuple);
     $dispatcher->startTimer();
     $response = $faf->execute();
     $dispatcher->stopTimer();
     // emit event
     return $response;
 }