withaspirit / Elevator-Simulation

Elevator System Simulation project
1 stars 1 forks source link

Choose elevator when replying instead of adding to queue #168

Closed ryandash closed 2 years ago

ryandash commented 2 years ago
withaspirit commented 2 years ago

What are the effects from this change?

ryandash commented 2 years ago

What are the effects from this change?

chooseElevator is called only when the elevatorSubsystem pulls from the scheduler. Since the elevatorSubsystem alternates between sending and receiving, the elevator monitor will be updated between each pull of an event from the scheduler. This should select appropriate elevators instead of the old implementation which probably was probably adding all requests to the first elevator.

withaspirit commented 2 years ago

Getting some errors in Scheduler test -

Exception in thread "Scheduler" java.lang.NullPointerException: Cannot invoke "java.net.DatagramSocket.receive(java.net.DatagramPacket)" because "this.socket" is null
    at client_server_host.MessageTransfer.receiveMessage(MessageTransfer.java:69)
    at client_server_host.IntermediateHost.receivePacket(IntermediateHost.java:37)
    at scheduler.Scheduler.receiveAndProcessPacket(Scheduler.java:67)
    at scheduler.Scheduler.run(Scheduler.java:188)
    at java.base/java.lang.Thread.run(Thread.java:833)
Exception in thread "Scheduler" java.lang.NullPointerException: Cannot invoke "java.net.DatagramSocket.receive(java.net.DatagramPacket)" because "this.socket" is null
    at client_server_host.MessageTransfer.receiveMessage(MessageTransfer.java:69)
    at client_server_host.IntermediateHost.receivePacket(IntermediateHost.java:37)
    at scheduler.Scheduler.receiveAndProcessPacket(Scheduler.java:67)
    at scheduler.Scheduler.run(Scheduler.java:188)
    at java.base/java.lang.Thread.run(Thread.java:833)
ryandash commented 2 years ago

Getting some errors in Scheduler test -

Exception in thread "Scheduler" java.lang.NullPointerException: Cannot invoke "java.net.DatagramSocket.receive(java.net.DatagramPacket)" because "this.socket" is null
  at client_server_host.MessageTransfer.receiveMessage(MessageTransfer.java:69)
  at client_server_host.IntermediateHost.receivePacket(IntermediateHost.java:37)
  at scheduler.Scheduler.receiveAndProcessPacket(Scheduler.java:67)
  at scheduler.Scheduler.run(Scheduler.java:188)
  at java.base/java.lang.Thread.run(Thread.java:833)
Exception in thread "Scheduler" java.lang.NullPointerException: Cannot invoke "java.net.DatagramSocket.receive(java.net.DatagramPacket)" because "this.socket" is null
  at client_server_host.MessageTransfer.receiveMessage(MessageTransfer.java:69)
  at client_server_host.IntermediateHost.receivePacket(IntermediateHost.java:37)
  at scheduler.Scheduler.receiveAndProcessPacket(Scheduler.java:67)
  at scheduler.Scheduler.run(Scheduler.java:188)
  at java.base/java.lang.Thread.run(Thread.java:833)

The scheduler test is broken. It needs a rework to work with UDP or we simply need to give up on it.

withaspirit commented 2 years ago

Perhaps breaking up the receiveAndProcess method into smaller methods would make it easier to test