[SOLVED] CS241-Assignment 2 Java Synchronization

25.00 $

Category:

Description

5/5 - (1 vote)
  • It s required to simulate a limited number of devices connected to a router’s Wi-Fi using Java threading and semaphore. Routers can design to limit the number of open connections. For example, a router may wish to have only N connections at any point in time. As soon as N connections are made, the router will not accept other incoming connection until an existing connection is released. In this project, I explained how semaphores can be used by a router to limit the number of concurrent connections.

 

 

Consider the followingrules:

 

  • TheWi-Fi numberofconnecteddevices is initially
  • Ifaclientisloggedin(printamessagethataclienthasloggedin)andifitcanbeserved(meansthat it can reach the internet), thentheclient shouldperform thefollowingactivities:
    1. Connect
    2. Perform online activity
    3. Logout

Note:these actionswillberepresentedbyprintedmessages,suchthatthereisarandomwaitingtimebetweentheprintedmessageswhenaclientconnects,dosomeonlineactivities andloggedout.

  • Ifaclientarrivesandallconnectionsareoccupied,itmustwaituntiloneofthecurrentlyavailableclientsfinisheshis service andleave.
  • Afteraclientfinisheshisservice,heleaveandoneofthewaitingclients(ifexist)willconnect to the

 

ProblemDesign

 

You program must contain thefollowing classes:

 

  1. Router Class: that contains a list of connection and methods to occupya connectionandrelease a
  2. SemaphoreClass:asgiven the synchronization
  3. DeviceClass:representdifferentdevices(threads)thatcanbeconnectedtotherouter;eachdevicehasitsownname(i.e.C1)andtype(i.e.mobile,pc,tablet…)anditmayperform threeactivities: connect,perform onlineactivityanddisconnect/logout.
  4. Network Class: this classcontains themain method in which theuseris asked fortwoinputs:
    • N: maxnumberof connections a routercan accept
    • TC: total numberof devices that wishes to connect).
    • TC lines that contain: name ofeachdevice,andits

 

ProgramOutput:

 

You will print the output logs inafile, whichsimulatesthe executionorder ofthedevicesthreads and the printedmessagesofeachdevice.

 

Example:

 

Sample Input:

 

 

Sample output:(Note:output depends on theorder oftheexecutions of thethreads)