|
11 | 11 |
|
12 | 12 | namespace Spork;
|
13 | 13 |
|
14 |
| -use Spork\Batch\BatchJob; |
15 | 14 | use Spork\Batch\Strategy\StrategyInterface;
|
16 | 15 | use Spork\EventDispatcher\EventDispatcher;
|
17 | 16 | use Spork\EventDispatcher\EventDispatcherInterface;
|
|
24 | 23 | class ProcessManager
|
25 | 24 | {
|
26 | 25 | private $dispatcher;
|
| 26 | + private $factory; |
27 | 27 | private $debug;
|
28 | 28 | private $zombieOkay;
|
29 | 29 | private $signal;
|
30 | 30 |
|
31 | 31 | /** @var Fork[] */
|
32 | 32 | private $forks;
|
33 | 33 |
|
34 |
| - public function __construct(EventDispatcherInterface $dispatcher = null, $debug = false) |
| 34 | + public function __construct(EventDispatcherInterface $dispatcher = null, Factory $factory = null, $debug = false) |
35 | 35 | {
|
36 | 36 | $this->dispatcher = $dispatcher ?: new EventDispatcher();
|
| 37 | + $this->factory = $factory ?: new Factory(); |
37 | 38 | $this->debug = $debug;
|
38 | 39 | $this->zombieOkay = false;
|
39 | 40 | $this->forks = array();
|
@@ -72,7 +73,7 @@ public function zombieOkay($zombieOkay = true)
|
72 | 73 |
|
73 | 74 | public function createBatchJob($data = null, StrategyInterface $strategy = null)
|
74 | 75 | {
|
75 |
| - return new BatchJob($this, $data, $strategy); |
| 76 | + return $this->factory->createBatchJob($this, $data, $strategy); |
76 | 77 | }
|
77 | 78 |
|
78 | 79 | public function process($data, $callable, StrategyInterface $strategy = null)
|
@@ -101,7 +102,7 @@ public function fork($callable)
|
101 | 102 | $this->forks = array();
|
102 | 103 |
|
103 | 104 | // setup the shared memory
|
104 |
| - $shm = new SharedMemory(null, $this->signal); |
| 105 | + $shm = $this->factory->createSharedMemory(null, $this->signal); |
105 | 106 | $message = new ExitMessage();
|
106 | 107 |
|
107 | 108 | // phone home on shutdown
|
@@ -146,9 +147,9 @@ public function fork($callable)
|
146 | 147 | }
|
147 | 148 |
|
148 | 149 | // connect to shared memory
|
149 |
| - $shm = new SharedMemory($pid); |
| 150 | + $shm = $this->factory->createSharedMemory($pid); |
150 | 151 |
|
151 |
| - return $this->forks[$pid] = new Fork($pid, $shm, $this->debug); |
| 152 | + return $this->forks[$pid] = $this->factory->createFork($pid, $shm, $this->debug); |
152 | 153 | }
|
153 | 154 |
|
154 | 155 | public function monitor($signal = SIGUSR1)
|
|
0 commit comments