We changed our JavaFX configuration. The main class has changed from java_files.MainGUI to java_files.Client.
Below are instructions to change it:
- Click on the configuration on the top right. It should say "JavaFXApp".
- Click on "Edit Configurations..."
- Change the Main Class from
java_files.MainGUItojava_files.Client.
- Wyatt submitted Vocareum Workspace.
- Aneesh submitted the Presentation.
- Wyatt submitted the Report on Brightspace.
Copy and execute the following commands in the terminal:
cd python_backend
source venv/bin/activate
python manage.py runserverBefore running the Client.java class or RunClientTest.java:
Make sure to run ThreadedServer.java first
We implement three layers of thread safety.
It’s important to note that our database is stored in SQLite. We structured our program to minimize the amount of data that Java has to save locally.
Our first layer of thread safety is in Java itself. We have a few data sets that are shared by all threads. For the most part, write-access to these data sets is extremely limited. We try to limit each thread’s write-access to only allow it to change data related to its own user.
Of course, there are instances where threads must edit users’ data. In such cases, we use a manager object to synchronize those calls. These synchronized blocks are placed throughout the ThreadedServer.java class to ensure thread safety.
Our second layer of thread safety is Python serialization. Our Java program sends JSON data to Python, which must be serialized before being sent to the database.
- Methods in
python_backendhandle the serialization of data. - Python processes serialized data one at a time. This ensures that even if multiple threads send JSON data to Python, they are processed sequentially, with other threads waiting in a queue.
This allows multiple threads to make concurrent calls in Java while ensuring that they are handled one-by-one in the backend.
Our last layer of thread safety lies in the database itself. SQLite operations are atomic, meaning that a transaction must complete fully or not at all.
- Only one thread will access the database at a time.
- In Java, we ensure that threads read the database before each call, guaranteeing access to the most recent version of the database.
- SQLite provides additional thread safety through features like rollback, write-ahead logging, and crash recovery.
With these three levels of thread safety, we can confidently claim that our program is thread-safe.
The ‘Client.java’ class has a few commented out sections of code meant to try and create race conditions within the program. Use these to compare expected results with actual results from running the program.
We have three test case files, all implemented using JUnit.
-
RunLocalTest.java and RunLocalTest2.java
- These files test all methods related to the database.
- They can be run independently.
-
RunClientTest.java
- This file tests methods related to the server.
- To run this test, you must first run
ThreadedServer.java.
The Authenticator class handles user authentication.
- It uses the authentication methods provided by Django’s REST framework.
- Takes in a username and password, checks their validity in the database, and returns a boolean.
The Client class manages the connection to the server. (Future development will integrate it with the GUI.)
- The
newClientCommand()method takes a string input and sends it to the server. - This string input corresponds to potential user actions in the GUI (e.g., button clicks).
- For testing, strings can be manually input, adhering to the format of
ThreadedServer's switch cases.
The GUI is currently under development and is used primarily for testing purposes.
Current features include:
- Creating a user
- Logging in and out
- Viewing a user’s profile
- Viewing a list of all other users
The MessageManager class handles message operations.
- Provides methods for creating messages.
- Manages message storage and retrieval responses (success/failure) from the database.
The UserManager class manages user data and interactions within the server. It provides the following methods:
createUser: Creates a new user with specified username, password, and additional info (e.g., email, bio).editUser: Updates user information, excluding username or password.deleteUser: Deletes a user by username.getUser: Retrieves information for a specified username.addFriend: Adds a friend to a user’s friend list.unFriend: Removes a friend from a user’s friend list.block: Blocks a specified user for the given user.unblock: Unblocks a specified user for the given user.
The ThreadedServer class acts as a mediator between the database and the client.
- Reads input from the client.
- Calls methods in
UserManager.java. - Retrieves responses from the database.
- Sends SUCCESS/FAILED messages back to the client.
The Python_backend is a Django project that contains an application called messaging.
The messaging app includes:
- Serializer: Handles data serialization.
- Views.py: Defines view logic.
- Models.py: Defines database models.
- URL routing: Manages URL configurations.
Please make sure .gitignore exists in your project's root directory before making any commits to Github. Otherwise, it will create conflicts for everyone.
Note: These setup instructions are specified for IntelliJ. VSCode-specific instructions are below, and requires a bit more work(or less in another person in the team's opinion). Please do not use any other IDE to run this program.
-
Clone and Pull
- Make sure this is the first time you are cloning the repository. If you have previously cloned it, delete the instance of the repository on your local machine before re-cloning.
-
Navigate to python_backend/
- Run
cd python_backend/ - Remain in this directory. ALL terminal commands in this guide are run from this directory.
- Run
-
Configure the Python Module and Create a Virtual Environment
- Note: Do not reuse an already existing virtual environment.
- Note: Do not use
python -m venv venvto create the venv.
- First, navigate to File -> Project Structure -> Modules. Verify that a module named
python_backendalready exists. Click on it. - Go to Dependencies. You will need to set the Module SDK. Click on it and select
Add Python SDK from disk.... - Make sure New Environment is selected.
- Set Location to
/<your_project_directory>/messagingApp/python_backend/venv- Here is my location, for reference:
/Users/erict/messagingApp/python_backend/venv. Your Location should look similar to this.
- Here is my location, for reference:
- For the base interpreter, set it equal to
/usr/local/bin/python3.12.- Please use python3.12 to run this project to ensure compatibility. Do not use other, earlier versions of Python.
- Do not select/toggle anything else that is not explicitly mentioned above.
- Click Apply, then OK.
- Your Module SDK should be named Python 3.12 (messagingApp). If it's not, navigate to File -> Project Structure -> SDKs. Select your newly created SDK and rename it appropriately. Click Apply, then OK.
- Before moving on, navigate to python_backend/. Verify that inside of the directory is a venv/ directory. If yes, you can move on!
-
Activate the Virtual Environment
- Make sure your terminal is in the python_backend directory before running this step.
cd python_backend/
- For macOS/Linux:
source venv/bin/activate - For Windows:
venv\Scripts\activate - You should see a small (venv) tag next to your terminal's command prompt. If it's there, you have successfully activated your virtual environment!
- Make sure your terminal is in the python_backend directory before running this step.
-
Install Requirements and Apply Migrations
- Run
pip install -r requirements.txt - Run
python manage.py makemigrations - Run
python manage.py migrate - You can move on after running all commands.
- Run
-
Add the JavaFX library
- Download the version of JavaFX that is most compatible with your computer.
- Note: Please ensure that that the JavaFX version you choose is compatible with the version of Java that is running on your project.
- Navigate to File -> Project Structure -> Modules. Verify that a module named 'messagingApp' already exists. Click on it.
- Under the Module SDK dropdown menu, you should see a small +. Click on it. Then, select 2. Library..., and open the necessary JavaFX files.
- Only add files in
lib/that end in.jar. There should be 8 of these. - Your JavaFX files should be located in a directory with a similar name to
javafx-sdk-23.0.1/. Inside of that directory should be a directory namedlib/.
- Only add files in
- Before clicking OK, you should be brought to a window where you can name your library and set its level.
- For Name:, make sure you name your library
javafx-swt. - For Level:, keep the library on the
Project Library
- For Name:, make sure you name your library
- Click OK.
- You will be brought back to the messagingApp module. Click Apply, then OK to apply your library.
- You should see a new library named
javafx-swtinside of the messagingApp module. You just imported the JavaFX libraries!
- Download the version of JavaFX that is most compatible with your computer.
-
Configure the JavaFX Application
- Navigate to Run -> Edit Configurations.
- Click on +. Add an Application.
- Click on Modify options. Find 'Add VM options' and make sure it's toggled on.
- Fill out the fields as such:
- Name: "JavaFXApp"
- Run on: Local Machine
- module not specified: java 21 SDK of 'messagingApp'
- Note: Your Java Program may not run "java 21". As long as the selected module is the "SDK of 'messagingApp'", it should be fine.
- Note: If you select messagingApp as the -cp (do the next step first), it should automatically fill this field with the correct information.
- -cp : messagingApp
- VM options:
--module-path "path/to/your/javafx/lib" --add-modules javafx.controls,javafx.fxml,javafx.graphics- Note: replace
path/to/your/javafx/libwith the complete path on your computer where you saved your javaFXlib/files.
- Note: replace
- Main class: java_files.mainGUI
- Do not modify any other fields. Click Apply, then OK.
- Your JavaFX Application is set up!
-
Run the Program
- In the top right corner, select JavaFXApp instead of Current File.
- Go to Terminal.
- Navigate to the python_backend/ directory.
- Run
python manage.py runserver. Once you see the terminal print a URLhttp://127.0.0.1:8000/, you are ready to start.
- Run it!
-
There will still be errors with JUnit, since it's not imported yet. We assume that we don't need to provide instructions for this setup, and that you are able to configure JUnit to work.
All done!
Since VS Code doesn't have the whole File -> Project Structure thing, they mostly will work with the terminal.
- After finish cloning, open the terminal with the project path, then start running these command line by line:
python -m venv venv
venv\Scripts\activate
pip install -r python_backend/requirements.txt
python python_backend/manage.py makemigrations
python python_backend/manage.py migrate
python python_backend/manage.py runserver
- The first line create the virtual environment, second line activate it, third line install python packages to run properly, fourth and fifth line for migrations and sixth line to run the server.
- That's it, the server is up.
- Download the version of JavaFX that is most compatible with your computer, we recommend 23.0.1, which can be downloaded here:
https://gluonhq.com/products/javafx/, then extracted the downloaded file to some location. - Press Ctrl + Shift + P, type Java: Open Project Settings, go to Libraries and add all of the .jar files of javafx to it, you can find does .jar files under
javafx-sdk-23.0.1\lib(thejavafx-sdk-23.0.1change depends on the version of javafx you have)
- First you may need to create the launch.json file, go to run and debug on the left, find
create a launch.json file, press on it, then a pop up will show up in the middle top of the screen, choose java and vs code will create one for you, then start modifying it. - Add the following line to
launch.json, in the configurations section, betweenrequestandmainClass
"vmArgs": "--module-path \"C:/Program Files/Java/javafx-sdk-23.0.1/lib\" --add-modules javafx.controls,javafx.fxml,javafx.graphics",
- Notes, replace
C:/Program Files/Java/javafx-sdk-23.0.1/libwith the direction to the javafx library in you machine. Example usage:
{
"type": "java",
"name": "Current File",
"request": "launch",
"vmArgs": "--module-path \"C:/Program Files/Java/javafx-sdk-23.0.1/lib\" --add-modules javafx.controls,javafx.fxml,javafx.graphics",
"mainClass": "${file}"
},
- Extension Pack for Java
- JavaFX Support by Shrey Pandya
- Language Support for Java(TM) by Red Hat
After those step, you should be done with the set up part.
- Go the src/java_files, find the MainGUI.java.
- Run it at the main method.
- Alternatively go to the Run Java button on the top right and run the file, and a GUI will pop up.
- We are using 3.12.x, which can be download at: https://www.python.org/downloads/release/python-3126.
- Remember to add python to PATH environments variables when setting up, there is a checkbox for that at the bottom left corner when first running the installer file.
- Go to this site to install pip the first time: https://pip.pypa.io/en/stable/installation/, remember to pick your operating system, we recommend using the ensurepip method(the first one on the site).
- Navigate to the RunLocalTest class.
- Hover over the junit import statement.
- IntelliJ will prompt you to download JUnit 5, click OK, and IntelliJ does the rest for you!