The Traffic Management System is an enterprise-level application designed to optimize urban traffic flow by collecting and analyzing real-time data from IoT devices and traffic lights. It leverages Java EE technologies to provide a scalable, modular, and efficient solution for monitoring vehicle speeds, analyzing traffic patterns, and dynamically generating route attributes. The system integrates multiple components, including an EJB application server, a web application server, a MySQL database, and a RabbitMQ message broker for asynchronous communication.
This repository contains the core components of the Traffic Management System, including the EJB application server, web application server, and database configurations. The IoT device simulator is maintained in a separate repository: TrafficManagementSystemIotDeviceSimulator.
The system aims to:
- Monitor Traffic: Collect real-time data on vehicle locations, speeds, and traffic light statuses.
- Analyze Traffic Flow: Calculate average vehicle speeds and analyze traffic patterns to optimize signal timings.
- Generate Route Attributes: Provide dynamic route suggestions based on traffic conditions.
- Enhance Scalability: Use a modular architecture with enterprise technologies for efficient resource management.
The Traffic Management System is built using a distributed, modular architecture with the following components:
-
EJB Application Server:
- Centralized server using the Enterprise JavaBeans (EJB) framework.
- Handles core logic, including:
- Registering and managing IoT devices and traffic lights.
- Collecting IoT device locations and speeds.
- Calculating average vehicle speeds and analyzing traffic flow.
- Generating route attributes for navigation.
- Communicates with other components via Remote Method Invocation (RMI).
-
Web Application Server:
- Servlet-based server that communicates with the EJB server via RMI.
- Displays analyzed traffic data, including:
- Average vehicle speeds.
- Traffic flow details.
- Route attributes visualized on a map.
-
Database Server:
- MySQL database for storing traffic light statuses and IoT device locations.
- Integrated with the EJB server using Hibernate for ORM.
-
RabbitMQ Message Broker:
- Acts as an alternative to Java Message Service (JMS) for asynchronous communication.
- Manages a queue (
IotLocationData) for updating IoT device locations between the IoT simulator and the EJB server.
-
IoT Device Simulator (Separate Repository):
- A Java SE application simulating IoT devices and traffic light statuses.
- Communicates with the EJB server via RMI and RabbitMQ.
- Java EE: EJB (Stateless and Singleton Session Beans), Servlets, JNDI.
- RabbitMQ: Message broker for asynchronous IoT location updates.
- MySQL: Database for persistent storage.
- Hibernate: ORM for database interactions.
- RMI: For communication between components.
- Maven: Build tool for dependency management.
- IotDeviceBean (Stateless Session Bean):
- Manages IoT device registration and location/speed data collection.
- Uses
@Remoteinterface for RMI.
- TrafficLightBean (Stateless Session Bean):
- Handles traffic light location registration and status collection.
- Uses
@Remoteinterface for RMI.
- TrafficDataBean (Stateless Session Bean):
- Calculates average vehicle speeds, analyzes traffic flow, and generates route attributes.
- Uses
@Remoteinterface for RMI.
- IotLocationListener (Singleton Session Bean):
- Uses
@Startupand@PostConstructto initialize a RabbitMQ listener for IoT location updates. - Communicates with
IotDeviceBeanto process location data.
- Uses
- Servlet-based interface to display traffic data and route attributes.
- Requests data from
TrafficDataBeanvia RMI.
- Stores IoT device information (
IotDeviceInfo), locations (IotDeviceLocation), traffic light details (TrafficLight), and statuses (TrafficLightStatus). - Configured via Hibernate (
hibernate.cfg.xml).
- Java 8 or higher
- Maven
- MySQL Server
- RabbitMQ Server
- Application Server (e.g., WildFly or GlassFish) for EJB deployment
- Web Server (e.g., Tomcat) for the web application
-
Clone the Repository:
git clone https://github.com/sheronfdo/TrafficManagementSystem.git cd TrafficManagementSystem -
Set Up MySQL Database:
-
Create a database named
traffic_management_system. -
Update the Hibernate configuration (
hibernate.cfg.xml) with your MySQL credentials:<property name="connection.url">jdbc:mysql://localhost:3306/traffic_management_system?useSSL=false</property> <property name="connection.username">your_username</property> <property name="connection.password">your_password</property>
-
-
Configure RabbitMQ:
- Install and start RabbitMQ server.
- Ensure the
IotLocationDataqueue is accessible onlocalhost.
-
Build the Project:
mvn clean install
-
Deploy the EJB Application:
- Deploy the generated
.earfile to an EJB-compatible application server (e.g., WildFly).
- Deploy the generated
-
Deploy the Web Application:
- Deploy the generated
.warfile to a servlet container (e.g., Tomcat).
- Deploy the generated
-
Run the IoT Device Simulator:
- Clone and set up the TrafficManagementSystemIotDeviceSimulator repository (see its README for details).
-
Start the Application:
- Ensure all servers (MySQL, RabbitMQ, EJB, and web) are running.
- Access the web interface via the configured URL (e.g.,
http://localhost:8080/TrafficManagementSystem).
-
IoT Device Simulation:
- The IoT simulator (from the separate repository) generates mock IoT device locations and traffic light statuses.
- Data is sent to the
IotLocationDataRabbitMQ queue and processed byIotLocationListener.
-
Traffic Monitoring:
- The EJB server collects and processes IoT data, calculating average vehicle speeds and traffic flow metrics.
- Data is stored in the MySQL database.
-
Web Interface:
- Access the web application to view:
- Real-time traffic flow analysis.
- Average vehicle speeds.
- Route attributes displayed on a map.
- Access the web application to view:
- Modular Design: Uses EJB containers for transaction management, concurrency, and scalability.
- Asynchronous Processing: RabbitMQ ensures efficient handling of high-volume IoT location updates.
- Connection Pooling: Hibernate manages database connections for performance.
- Distributed Computing: EJB supports deployment across multiple servers for fault tolerance.
Contributions are welcome! Please fork the repository, create a feature branch, and submit a pull request with your changes.
This project is licensed under the MIT License.
For questions or feedback, contact sheronfdo.