Commit 9a0a166f authored by Bas de Nooijer's avatar Bas de Nooijer

Updated plugins to use Symfony eventdispatcher

parent 19d54457
...@@ -36,12 +36,17 @@ ...@@ -36,12 +36,17 @@
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Plugin; namespace Solarium\Plugin\BufferedAdd;
use Solarium\Client; use Solarium\Client;
use Solarium\Core\Plugin; use Solarium\Core\Plugin\Plugin;
use Solarium\QueryType\Update\Result as UpdateResult; use Solarium\QueryType\Update\Result as UpdateResult;
use Solarium\QueryType\Update\Query\Query as UpdateQuery; use Solarium\QueryType\Update\Query\Query as UpdateQuery;
use Solarium\QueryType\Select\Result\Document as ReadOnlyDocument; use Solarium\QueryType\Select\Result\Document as ReadOnlyDocument;
use Solarium\Plugin\BufferedAdd\Event\Events;
use Solarium\Plugin\BufferedAdd\Event\PreFlush as PreFlushEvent;
use Solarium\Plugin\BufferedAdd\Event\PostFlush as PostFlushEvent;
use Solarium\Plugin\BufferedAdd\Event\PreCommit as PreCommitEvent;
use Solarium\Plugin\BufferedAdd\Event\PostCommit as PostCommitEvent;
/** /**
* Buffered add plugin * Buffered add plugin
...@@ -194,13 +199,15 @@ class BufferedAdd extends Plugin ...@@ -194,13 +199,15 @@ class BufferedAdd extends Plugin
return false; return false;
} }
$this->client->triggerEvent('BufferedAddFlushStart', array($this->buffer)); $event = new PreFlushEvent($this->buffer, $overwrite, $commitWithin);
$this->client->getEventDispatcher()->dispatch(Events::PRE_FLUSH, $event);
$this->updateQuery->addDocuments($this->buffer, $overwrite, $commitWithin); $this->updateQuery->addDocuments($event->getBuffer(), $event->getOverwrite(), $event->getCommitWithin());
$result = $this->client->update($this->updateQuery); $result = $this->client->update($this->updateQuery);
$this->clear(); $this->clear();
$this->client->triggerEvent('BufferedAddFlushEnd', array($result)); $event = new PostFlushEvent($this->buffer);
$this->client->getEventDispatcher()->dispatch(Events::POST_FLUSH, $event);
return $result; return $result;
} }
...@@ -218,14 +225,16 @@ class BufferedAdd extends Plugin ...@@ -218,14 +225,16 @@ class BufferedAdd extends Plugin
*/ */
public function commit($overwrite = null, $waitFlush = null, $waitSearcher = null, $expungeDeletes = null) public function commit($overwrite = null, $waitFlush = null, $waitSearcher = null, $expungeDeletes = null)
{ {
$this->client->triggerEvent('BufferedAddCommitStart', array($this->buffer)); $event = new PreCommitEvent($this->buffer, $overwrite, $waitFlush, $waitSearcher, $expungeDeletes);
$this->client->getEventDispatcher()->dispatch(Events::PRE_COMMIT, $event);
$this->updateQuery->addDocuments($this->buffer, $overwrite); $this->updateQuery->addDocuments($this->buffer, $event->getOverwrite());
$this->updateQuery->addCommit($waitFlush, $waitSearcher, $expungeDeletes); $this->updateQuery->addCommit($event->getWaitFlush(), $event->getWaitSearcher(), $event->getExpungeDeletes());
$result = $this->client->update($this->updateQuery); $result = $this->client->update($this->updateQuery);
$this->clear(); $this->clear();
$this->client->triggerEvent('BufferedAddCommitEnd', array($result)); $event = new PostCommitEvent($this->buffer);
$this->client->getEventDispatcher()->dispatch(Events::POST_COMMIT, $event);
return $result; return $result;
} }
......
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Plugin\BufferedAdd\Event;
/**
* Event definitions
*/
class Events
{
/**
* This event is called before a buffer flush
*
* The event listener receives the buffer (array).
*
* @var string
*/
const PRE_FLUSH = 'solarium.bufferedAdd.preFlush';
/**
* This event is called after a buffer flush
*
* The event listener receives the Result
*
* @var string
*/
const POST_FLUSH = 'solarium.bufferedAdd.postFlush';
/**
* This event is called before a buffer commit
*
* The event listener receives the buffer (array).
*
* @var string
*/
const PRE_COMMIT = 'solarium.bufferedAdd.preCommit';
/**
* This event is called after a buffer commit
*
* The event listener receives the Result
*
* @var string
*/
const POST_COMMIT = 'solarium.bufferedAdd.postCommit';
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Plugin\BufferedAdd\Event;
use Symfony\Component\EventDispatcher\Event;
use Solarium\QueryType\Update\Result;
/**
* PostCommit event, see Events for details
*/
class PostCommit extends Event
{
/**
* @var Result
*/
protected $result;
/**
* Event constructor
*
* @param Result $result
*/
public function __construct($result)
{
$this->result = $result;
}
/**
* Get the result for this event
*
* @return array
*/
public function getResult()
{
return $this->result;
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Plugin\BufferedAdd\Event;
use Symfony\Component\EventDispatcher\Event;
use Solarium\QueryType\Update\Result;
/**
* PostFlush event, see Events for details
*/
class PostFlush extends Event
{
/**
* @var Result
*/
protected $result;
/**
* Event constructor
*
* @param Result $result
*/
public function __construct($result)
{
$this->result = $result;
}
/**
* Get the result for this event
*
* @return array
*/
public function getResult()
{
return $this->result;
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Plugin\BufferedAdd\Event;
use Symfony\Component\EventDispatcher\Event;
/**
* PreCommit event, see Events for details
*/
class PreCommit extends Event
{
/**
* @var array
*/
protected $buffer;
/**
* @var boolean
*/
protected $overwrite;
/**
* @var boolean
*/
protected $waitFlush;
/**
* @var boolean
*/
protected $waitSearcher;
/**
* @var boolean
*/
protected $expungeDeletes;
/**
* Event constructor
*
* @param array $buffer
*/
public function __construct($buffer, $overwrite, $waitFlush, $waitSearcher, $expungeDeletes)
{
$this->buffer = $buffer;
$this->overwrite = $overwrite;
$this->waitFlush = $waitFlush;
$this->waitSearcher = $waitSearcher;
$this->expungeDeletes = $expungeDeletes;
}
/**
* Get the buffer for this event
*
* @return array
*/
public function getBuffer()
{
return $this->buffer;
}
/**
* Set the buffer for this event, this way you can alter the buffer before it is committed to Solr
*
* @param array $buffer
* @return void
*/
public function setBuffer($buffer)
{
$this->buffer = $buffer;
}
/**
* Optionally override the value
*
* @param boolean $expungeDeletes
*/
public function setExpungeDeletes($expungeDeletes)
{
$this->expungeDeletes = $expungeDeletes;
}
/**
* @return boolean
*/
public function getExpungeDeletes()
{
return $this->expungeDeletes;
}
/**
* Optionally override the value
*
* @param boolean $overwrite
*/
public function setOverwrite($overwrite)
{
$this->overwrite = $overwrite;
}
/**
* @return boolean
*/
public function getOverwrite()
{
return $this->overwrite;
}
/**
* Optionally override the value
*
* @param boolean $waitFlush
*/
public function setWaitFlush($waitFlush)
{
$this->waitFlush = $waitFlush;
}
/**
* @return boolean
*/
public function getWaitFlush()
{
return $this->waitFlush;
}
/**
* Optionally override the value
*
* @param boolean $waitSearcher
*/
public function setWaitSearcher($waitSearcher)
{
$this->waitSearcher = $waitSearcher;
}
/**
* @return boolean
*/
public function getWaitSearcher()
{
return $this->waitSearcher;
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Plugin\BufferedAdd\Event;
use Symfony\Component\EventDispatcher\Event;
/**
* PreFlush event, see Events for details
*/
class PreFlush extends Event
{
/**
* @var array
*/
protected $buffer;
/**
* @var boolean
*/
protected $overwrite;
/**
* @var int
*/
protected $commitWithin;
/**
* Event constructor
*
* @param array $buffer
* @param boolean $overwrite
* @param int $commitWithin
*/
public function __construct($buffer, $overwrite, $commitWithin)
{
$this->buffer = $buffer;
$this->overwrite = $overwrite;
$this->commitWithin = $commitWithin;
}
/**
* Get the buffer for this event
*
* @return array
*/
public function getBuffer()
{
return $this->buffer;
}
/**
* Set the buffer for this event, this way you can alter the buffer before it is committed to Solr
*
* @param array $buffer
* @return void
*/
public function setBuffer($buffer)
{
$this->buffer = $buffer;
}
/**
* Optionally override the value
*
* @param int $commitWithin
*/
public function setCommitWithin($commitWithin)
{
$this->commitWithin = $commitWithin;
}
/**
* @return int
*/
public function getCommitWithin()
{
return $this->commitWithin;
}
/**
* Optionally override the value
*
* @param boolean $overwrite
*/
public function setOverwrite($overwrite)
{
$this->overwrite = $overwrite;
}
/**
* @return boolean
*/
public function getOverwrite()
{
return $this->overwrite;
}
}
...@@ -37,11 +37,13 @@ ...@@ -37,11 +37,13 @@
* @namespace * @namespace
*/ */
namespace Solarium\Plugin\CustomizeRequest; namespace Solarium\Plugin\CustomizeRequest;
use Solarium\Core\Plugin; use Solarium\Core\Plugin\Plugin;
use Solarium\Core\Query\Query; use Solarium\Core\Query\Query;
use Solarium\Core\Client\Request; use Solarium\Core\Client\Request;
use Solarium\Exception\InvalidArgumentException; use Solarium\Exception\InvalidArgumentException;
use Solarium\Exception\RuntimeException; use Solarium\Exception\RuntimeException;
use Solarium\Core\Event\Events;
use Solarium\Core\Event\preExecuteRequest as preExecuteRequestEvent;
/** /**
* CustomizeRequest plugin * CustomizeRequest plugin
...@@ -75,6 +77,19 @@ class CustomizeRequest extends Plugin ...@@ -75,6 +77,19 @@ class CustomizeRequest extends Plugin
} }
} }
/**
* Plugin init function
*
* Register event listeners
*
* @return void
*/
protected function initPluginType()
{
$dispatcher = $this->client->getEventDispatcher();
$dispatcher->addListener(Events::PRE_EXECUTE_REQUEST, array($this, 'preExecuteRequest'));
}
/** /**
* Create a Customization instance * Create a Customization instance
* *
...@@ -236,12 +251,12 @@ class CustomizeRequest extends Plugin ...@@ -236,12 +251,12 @@ class CustomizeRequest extends Plugin
* Event hook to customize the request object * Event hook to customize the request object
* *
* @throws RuntimeException * @throws RuntimeException
* @param Query $query * @param preExecuteRequestEvent $event
* @param Request $request
* @return void * @return void
*/ */
public function postCreateRequest($query, $request) public function preExecuteRequest(preExecuteRequestEvent $event)
{ {
$request = $event->getRequest();
foreach ($this->getCustomizations() as $key => $customization) { foreach ($this->getCustomizations() as $key => $customization) {
// first validate // first validate
...@@ -268,6 +283,8 @@ class CustomizeRequest extends Plugin ...@@ -268,6 +283,8 @@ class CustomizeRequest extends Plugin
$this->removeCustomization($key); $this->removeCustomization($key);
} }
} }
$event->setRequest($request);
} }
} }
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Plugin\Loadbalancer\Event;
use Symfony\Component\EventDispatcher\Event;
use Solarium\Core\Client\Endpoint;
use Solarium\Exception\HttpException;
/**
* EndpointFailure event, see Events for details
*/
class EndpointFailure extends Event
{
/**
* @var Endpoint
*/
protected $endpoint;
/**
* @var HttpException
*/
protected $exception;
/**
* Constructor
*
* @param Endpoint $endpoint
* @param HttpException $exception
*/
public function __construct(Endpoint $endpoint, HttpException $exception)
{
$this->endpoint = $endpoint;
$this->exception = $exception;
}
/**
* @return Endpoint
*/
public function getEndpoint()
{
return $this->endpoint;
}
/**
* @return HttpException
*/
public function getException()
{
return $this->exception;
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Plugin\Loadbalancer\Event;
/**
* Event definitions
*/
class Events
{
/**
* This event is called after and endpoint has failed.
*
* Gets the endpoint and the HttpException as params
*
* @var string
*/
const ENDPOINT_FAILURE = 'solarium.loadbalancer.endpointFailure';
}
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
* @namespace * @namespace
*/ */
namespace Solarium\Plugin\Loadbalancer; namespace Solarium\Plugin\Loadbalancer;
use Solarium\Core\Plugin; use Solarium\Core\Plugin\Plugin;
use Solarium\Core\Client\Client; use Solarium\Core\Client\Client;
use Solarium\Core\Client\Endpoint; use Solarium\Core\Client\Endpoint;
use Solarium\Core\Query\Query; use Solarium\Core\Query\Query;
...@@ -47,6 +47,11 @@ use Solarium\Exception\InvalidArgumentException; ...@@ -47,6 +47,11 @@ use Solarium\Exception\InvalidArgumentException;
use Solarium\Exception\OutOfBoundsException; use Solarium\Exception\OutOfBoundsException;
use Solarium\Exception\RuntimeException; use Solarium\Exception\RuntimeException;
use Solarium\Exception\HttpException; use Solarium\Exception\HttpException;
use Solarium\Plugin\Loadbalancer\Event\Events;
use Solarium\Plugin\Loadbalancer\Event\EndpointFailure as EndpointFailureEvent;
use Solarium\Core\Event\Events as CoreEvents;
use Solarium\Core\Event\PreCreateRequest as PreCreateRequestEvent;
use Solarium\Core\Event\PreExecuteRequest as PreExecuteRequestEvent;
/** /**
* Loadbalancer plugin * Loadbalancer plugin
...@@ -159,6 +164,20 @@ class Loadbalancer extends Plugin ...@@ -159,6 +164,20 @@ class Loadbalancer extends Plugin
} }
} }
/**
* Plugin init function
*
* Register event listeners
*
* @return void
*/
protected function initPluginType()
{
$dispatcher = $this->client->getEventDispatcher();
$dispatcher->addListener(CoreEvents::PRE_EXECUTE_REQUEST, array($this, 'preExecuteRequest'));
$dispatcher->addListener(CoreEvents::PRE_CREATE_REQUEST, array($this, 'preCreateRequest'));
}
/** /**
* Set failover enabled option * Set failover enabled option
* *
...@@ -426,21 +445,20 @@ class Loadbalancer extends Plugin ...@@ -426,21 +445,20 @@ class Loadbalancer extends Plugin
/** /**
* Event hook to capture querytype * Event hook to capture querytype
* *
* @param Query $query * @param PreCreateRequestEvent $event
* @return void * @return void
*/ */
public function preCreateRequest($query) public function preCreateRequest(PreCreateRequestEvent $event)
{ {
$this->queryType = $query->getType(); $this->queryType = $event->getQuery()->getType();
} }
/** /**
* Event hook to adjust client settings just before query execution * Event hook to adjust client settings just before query execution
* *
* @param Request $request * @param PreExecuteRequestEvent $event
* @return Response
*/ */
public function preExecuteRequest($request) public function preExecuteRequest(PreExecuteRequestEvent $event)
{ {
$adapter = $this->client->getAdapter(); $adapter = $this->client->getAdapter();
...@@ -451,14 +469,16 @@ class Loadbalancer extends Plugin ...@@ -451,14 +469,16 @@ class Loadbalancer extends Plugin
// check querytype: is loadbalancing allowed? // check querytype: is loadbalancing allowed?
if (!array_key_exists($this->queryType, $this->blockedQueryTypes)) { if (!array_key_exists($this->queryType, $this->blockedQueryTypes)) {
return $this->getLoadbalancedResponse($request); $response = $this->getLoadbalancedResponse($event->getRequest());
} else { } else {
$endpoint = $this->client->getEndpoint($this->defaultEndpoint); $endpoint = $this->client->getEndpoint($this->defaultEndpoint);
$this->lastEndpoint = null; $this->lastEndpoint = null;
// execute request and return result // execute request and return result
return $adapter->execute($request, $endpoint); $response = $adapter->execute($event->getRequest(), $endpoint);
} }
$event->setResponse($response);
} }
/** /**
...@@ -481,7 +501,10 @@ class Loadbalancer extends Plugin ...@@ -481,7 +501,10 @@ class Loadbalancer extends Plugin
} catch (HttpException $e) { } catch (HttpException $e) {
// ignore HTTP errors and try again // ignore HTTP errors and try again
// but do issue an event for things like logging // but do issue an event for things like logging
$this->client->triggerEvent('LoadbalancerEndpointFail', array($endpoint->getOptions(), $e)); $this->client->getEventDispatcher()->dispatch(
Events::ENDPOINT_FAILURE,
new EndpointFailureEvent($endpoint, $e)
);
} }
} }
......
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Plugin\ParallelExecution\Event;
/**
* Event definitions
*/
class Events
{
/**
* This event is called just before parallel HTTP request execution, but after init work.
* Intented for timing use only, there are no params.
*
* @var string
*/
const EXECUTE_START = 'solarium.parallelExecution.executeStart';
/**
* This event is called just after parallel HTTP request execution, before further result handling.
* Intented for timing use only, there are no params.
*
* @var string
*/
const EXECUTE_END = 'solarium.parallelExecution.executeEnd';
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Plugin\ParallelExecution\Event;
use Symfony\Component\EventDispatcher\Event;
/**
* ExecuteEnd event, see Events for details
*/
class ExecuteEnd extends Event
{
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Plugin\ParallelExecution\Event;
use Symfony\Component\EventDispatcher\Event;
use Solarium\QueryType\Update\Result;
/**
* ExecuteStart event, see Events for details
*/
class ExecuteStart extends Event
{
}
...@@ -36,11 +36,15 @@ ...@@ -36,11 +36,15 @@
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Plugin; namespace Solarium\Plugin\ParallelExecution;
use Solarium\Core\Plugin; use Solarium\Core\Plugin\Plugin;
use Solarium\Core\Client\HttpException; use Solarium\Core\Client\Endpoint;
use Solarium\Exception\HttpException;
use Solarium\Core\Client\Client; use Solarium\Core\Client\Client;
use Solarium\Core\Query\Query; use Solarium\Core\Query\Query;
use Solarium\Plugin\ParallelExecution\Event\Events;
use Solarium\Plugin\ParallelExecution\Event\ExecuteStart as ExecuteStartEvent;
use Solarium\Plugin\ParallelExecution\Event\ExecuteEnd as ExecuteEndEvent;
/** /**
* ParallelExecution plugin * ParallelExecution plugin
...@@ -150,7 +154,7 @@ class ParallelExecution extends Plugin ...@@ -150,7 +154,7 @@ class ParallelExecution extends Plugin
} }
// executing multihandle (all requests) // executing multihandle (all requests)
$this->client->triggerEvent('ParallelExecutionStart'); $this->client->getEventDispatcher()->dispatch(Events::EXECUTE_START, new ExecuteStartEvent());
do { do {
$mrc = curl_multi_exec($multiHandle, $active); $mrc = curl_multi_exec($multiHandle, $active);
...@@ -165,7 +169,7 @@ class ParallelExecution extends Plugin ...@@ -165,7 +169,7 @@ class ParallelExecution extends Plugin
} }
} }
$this->client->triggerEvent('ParallelExecutionEnd'); $this->client->getEventDispatcher()->dispatch(Events::EXECUTE_END, new ExecuteEndEvent());
// get the results // get the results
$results = array(); $results = array();
......
...@@ -38,9 +38,10 @@ ...@@ -38,9 +38,10 @@
*/ */
namespace Solarium\Plugin; namespace Solarium\Plugin;
use Solarium\Client; use Solarium\Client;
use Solarium\Core\Plugin; use Solarium\Core\Plugin\Plugin;
use Solarium\Core\Query\Query;
use Solarium\Core\Client\Request; use Solarium\Core\Client\Request;
use Solarium\Core\Event\Events;
use Solarium\Core\Event\PostCreateRequest as PostCreateRequestEvent;
/** /**
* PostBigRequest plugin * PostBigRequest plugin
...@@ -64,6 +65,19 @@ class PostBigRequest extends Plugin ...@@ -64,6 +65,19 @@ class PostBigRequest extends Plugin
'maxquerystringlength' => 1024, 'maxquerystringlength' => 1024,
); );
/**
* Plugin init function
*
* Register event listeners
*
* @return void
*/
protected function initPluginType()
{
$dispatcher = $this->client->getEventDispatcher();
$dispatcher->addListener(Events::POST_CREATE_REQUEST, array($this, 'postCreateRequest'));
}
/** /**
* Set maxquerystringlength enabled option * Set maxquerystringlength enabled option
* *
...@@ -88,12 +102,12 @@ class PostBigRequest extends Plugin ...@@ -88,12 +102,12 @@ class PostBigRequest extends Plugin
/** /**
* Event hook to adjust client settings just before query execution * Event hook to adjust client settings just before query execution
* *
* @param Query $query * @param PostCreateRequestEvent $event
* @param Request $request
* @return void * @return void
*/ */
public function postCreateRequest($query, $request) public function postCreateRequest($event)
{ {
$request = $event->getRequest();
$queryString = $request->getQueryString(); $queryString = $request->getQueryString();
if ($request->getMethod() == Request::METHOD_GET && if ($request->getMethod() == Request::METHOD_GET &&
strlen($queryString) > $this->getMaxQueryStringLength()) { strlen($queryString) > $this->getMaxQueryStringLength()) {
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
*/ */
namespace Solarium\Plugin; namespace Solarium\Plugin;
use Solarium\Client; use Solarium\Client;
use Solarium\Core\Plugin; use Solarium\Core\Plugin\Plugin;
use Solarium\QueryType\Select\Query\Query as SelectQuery; use Solarium\QueryType\Select\Query\Query as SelectQuery;
use Solarium\QueryType\Select\Result\Result as SelectResult; use Solarium\QueryType\Select\Result\Result as SelectResult;
......
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