forked from steger/pr3-ws202627
baggage Handling
parent
40426f54d5
commit
d1d2753280
|
|
@ -1,9 +1,9 @@
|
|||
package airport
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"gitty.informatik.hs-mannheim.de/3010261/pr3-code/go/06-airport/airport"
|
||||
)
|
||||
|
||||
type BaggageProcessor interface {
|
||||
|
|
@ -14,7 +14,14 @@ type BaggageHandlingSystem struct {
|
|||
processingTime time.Duration
|
||||
sinks map[FlightNumber]BaggageProcessor
|
||||
//TODO: extend
|
||||
baggae airport.Baggage
|
||||
queue chan baggageData
|
||||
list []LostBaggage
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
type baggageData struct {
|
||||
fn FlightNumber
|
||||
b Baggage
|
||||
}
|
||||
|
||||
type LostBaggage struct {
|
||||
|
|
@ -29,19 +36,42 @@ func NewBaggageHandlingSystem(processingTime time.Duration, sinks map[FlightNumb
|
|||
return BaggageHandlingSystem{
|
||||
processingTime: processingTime,
|
||||
sinks: sinks,
|
||||
queue: make(chan baggageData),
|
||||
list: make([]LostBaggage, 0),
|
||||
}
|
||||
}
|
||||
|
||||
func (bhs *BaggageHandlingSystem) ProcessBaggage(fn FlightNumber, b Baggage) error {
|
||||
//TODO: implement
|
||||
_, ok := bhs.sinks[fn]
|
||||
if !ok {
|
||||
return fmt.Errorf("Keine Flugnummer passend gefunden")
|
||||
}
|
||||
bhs.queue <- baggageData{fn: fn, b: b}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (bhs *BaggageHandlingSystem) CollectLostBaggage() []LostBaggage {
|
||||
//TODO: implement
|
||||
return nil
|
||||
bhs.mu.Lock()
|
||||
verloren := bhs.list
|
||||
bhs.list = make([]LostBaggage, 0)
|
||||
bhs.mu.Unlock()
|
||||
return verloren
|
||||
|
||||
}
|
||||
|
||||
func (bhs *BaggageHandlingSystem) Start() {
|
||||
//TODO: implement
|
||||
for element := range bhs.queue {
|
||||
|
||||
time.Sleep(bhs.processingTime)
|
||||
sink := bhs.sinks[element.fn]
|
||||
err := sink.ProcessBaggage(element.fn, element.b)
|
||||
if err != nil {
|
||||
bhs.mu.Lock()
|
||||
bhs.list = append(bhs.list, LostBaggage{element.b, element.fn, err})
|
||||
bhs.mu.Unlock()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue