forked from steger/pr3-sose2026
baggage handling system implementation
parent
89e3c3eab9
commit
5c1338301b
|
|
@ -1,6 +1,7 @@
|
|||
package airport
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
@ -11,7 +12,7 @@ type BaggageProcessor interface {
|
|||
type BaggageHandlingSystem struct {
|
||||
processingTime time.Duration
|
||||
sinks map[FlightNumber]BaggageProcessor
|
||||
//TODO: extend
|
||||
lostBaggage chan LostBaggage
|
||||
}
|
||||
|
||||
type LostBaggage struct {
|
||||
|
|
@ -26,19 +27,39 @@ func NewBaggageHandlingSystem(processingTime time.Duration, sinks map[FlightNumb
|
|||
return BaggageHandlingSystem{
|
||||
processingTime: processingTime,
|
||||
sinks: sinks,
|
||||
lostBaggage: make(chan LostBaggage),
|
||||
}
|
||||
}
|
||||
|
||||
func (bhs *BaggageHandlingSystem) ProcessBaggage(fn FlightNumber, b Baggage) error {
|
||||
//TODO: implement
|
||||
sink, ok := bhs.sinks[fn]
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid flight %v", fn)
|
||||
}
|
||||
|
||||
go func() {
|
||||
time.Sleep(bhs.processingTime)
|
||||
if err := sink.ProcessBaggage(fn, b); err != nil {
|
||||
bhs.lostBaggage <- LostBaggage{b, fn, err}
|
||||
}
|
||||
}()
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (bhs *BaggageHandlingSystem) CollectLostBaggage() []LostBaggage {
|
||||
//TODO: implement
|
||||
return nil
|
||||
lostBaggage := []LostBaggage{}
|
||||
for {
|
||||
select {
|
||||
case lb := <-bhs.lostBaggage:
|
||||
lostBaggage = append(lostBaggage, lb)
|
||||
default:
|
||||
return lostBaggage
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (bhs *BaggageHandlingSystem) Start() {
|
||||
//TODO: implement
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue