diff --git a/go/06-airport/airport/baggageHandlingSystem.go b/go/06-airport/airport/baggageHandlingSystem.go index e800172..a1444a2 100644 --- a/go/06-airport/airport/baggageHandlingSystem.go +++ b/go/06-airport/airport/baggageHandlingSystem.go @@ -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() + } + } }