--------------------------------------------------------------------- Switch setup AddReactor adds the given reactor to the switch. NOTE: Not goroutine safe.
(name string, reactor Reactor)
| 161 | // AddReactor adds the given reactor to the switch. |
| 162 | // NOTE: Not goroutine safe. |
| 163 | func (sw *Switch) AddReactor(name string, reactor Reactor) Reactor { |
| 164 | for _, chDesc := range reactor.GetChannels() { |
| 165 | chID := chDesc.ID |
| 166 | // No two reactors can share the same channel. |
| 167 | if sw.reactorsByCh[chID] != nil { |
| 168 | panic(fmt.Sprintf("Channel %X has multiple reactors %v & %v", chID, sw.reactorsByCh[chID], reactor)) |
| 169 | } |
| 170 | sw.chDescs = append(sw.chDescs, chDesc) |
| 171 | sw.reactorsByCh[chID] = reactor |
| 172 | sw.msgTypeByChID[chID] = chDesc.MessageType |
| 173 | } |
| 174 | sw.reactors[name] = reactor |
| 175 | reactor.SetSwitch(sw) |
| 176 | return reactor |
| 177 | } |
| 178 | |
| 179 | // RemoveReactor removes the given Reactor from the Switch. |
| 180 | // NOTE: Not goroutine safe. |