Description
- 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:
- Connect
- Perform online activity
- Logout
Note:these actionswillberepresentedbyprintedmessages,suchthatthereisarandomwaitingtimebetweentheprintedmessageswhenaclientconnects,dosomeonlineactivities andloggedout.
- Ifaclientarrivesandallconnectionsareoccupied,itmustwaituntiloneofthecurrentlyavailableclientsfinisheshis service andleave.
- Afteraclientfinisheshisservice,heleaveandoneofthewaitingclients(ifexist)willconnect to the
ProblemDesign
You program must contain thefollowing classes:
- Router Class: that contains a list of connection and methods to occupya connectionandrelease a
- SemaphoreClass:asgiven the synchronization
- DeviceClass:representdifferentdevices(threads)thatcanbeconnectedtotherouter;eachdevicehasitsownname(i.e.C1)andtype(i.e.mobile,pc,tablet…)anditmayperform threeactivities: connect,perform onlineactivityanddisconnect/logout.
- 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)







