Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Simulate a sensor system monitoring a house. Sensor and Dispatcher are Threads. Sensor produces a SensorEvent at random times and adds the event to the

Simulate a sensor system monitoring a house. Sensor and Dispatcher are Threads. Sensor produces a SensorEvent at random times and adds the event to the EventQueue which is implemented as a queue. The type of event depends on the type of the sensor that produced it. Dispatcher consumes events by removing them from the EventQueue. Consuming an event takes 50 ms and involves outputting on the screen the event information: source (id of the sensor), time and type. 1) Implement the above classes and in Main instantiate 4 sensors, 1 dispatcher and start all of them. Use ReentrantLock for synchronization. Use Executors for implementing the producers and consumers. Implement a second version of the program in which you use a BlockingQueue for sychronization instead of using locks.

These are the rest of the classes:image text in transcribedimage text in transcribedimage text in transcribed

EventData class - used to store the event data in a queue by producers and also to retrieve the event data from the queue by consumers for further processing. class EventData \{ private String eventID; public String getEventType() \{ private String eventName; return eventType; private String eventDate; \} private String eventType; public void setEventType(String eventType) \{ private String eventLocation; this.eventType = eventType; public String getEventID() \{ \} return eventID; public String getEventLocation() \{ \} return eventLocation; public void setEventID(String eventID) \{ \} this.eventID = eventID; public void setEventLocation(String eventLocation) \{ \} this.eventLocation = eventLocation; public String getEventName() \{ \} return eventName; \} public void setEventName(String eventName) \{ this.eventName = eventName; \} public String getEventDate() \{ return eventDate; \} public void setEventDate(String eventDate) \{ this.eventDate = eventDate; \} Queueservice class - helps to put the request in the queue as well as take the request in order to process import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; public void putEventlnQueue(EventData eventData) \{ public class QueueService { initialize(); private static QueueService instance = null; eventQueue.put(eventData); private static BlockingQueue eventQueue = null; } catch (InterruptedException ex) \{ private QueueService() \{\} public static QueueService getlnstance() \{ } if (instance == null) { class EventProcessor extends Thread \{ instance = new QueueService(); @Override \} public void run() \{ return instance; for (;;) \{ \} EventData eventData = null; privatevoidinitialize(){eventData=eventQueue.take();try{ if (eventQueue == null) { System.out.println("Process Event Data : Type : " + eventQueue = new LinkedBlockingQueue (); eventData.getEventType() + " / Name : " EventProcessor eventProcessor = new EventProcessor(); + eventData.getEventName()); eventProcessor.start(); \} catch (InterruptedException ex) \{ \} ex.printStackTrace(); \} Eventservice class - load data in the queue public class EventService \{ public static void main(String arg[]){ try{ EventData event = null; for (int i=0;i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Current Trends In Database Technology Edbt 2004 Workshops Edbt 2004 Workshops Phd Datax Pim P2panddb And Clustweb Heraklion Crete Greece March 2004 Revised Selected Papers Lncs 3268

Authors: Wolfgang Lindner ,Marco Mesiti ,Can Turker ,Yannis Tzitzikas ,Athena Vakali

2005th Edition

3540233059, 978-3540233053

More Books

Students also viewed these Databases questions