Skip to content

A multi-threaded program, application that perform mathematical calculations and return the data back to the user | using Java Networking Programming library

Notifications You must be signed in to change notification settings

itsmechelly/math-app-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

math-app-server

What is the purpose of this application?

The main purpose of this application is to perform mathematical calculations and return the data back to the user.

The program consists of 2 parts - the server and the client:
math-app-server 👉🏻 click here to see the source code on GitHub
math-app-client 👉🏻 click here to see the source code on GitHub

CLICK HERE to see the website!

To write this project I used Java Networking Programming tools (java.net) and it's designed to handle several math clients, meaning, it is a multi-threaded system.

For this purpose, I used Java's Thread Object and implemented the singleton pattern as only 1 server should exist per application. In addition, throughout the program I used additional design patterns such as Factory pattern and Mediator pattern.

Plus, on the client server, I added a thread that listens to all input from the server, logs INFO messages and documents data to a local log file.

I wrote this program inspired by a good friend of mine who is very close to my heart. He is a former lecturer at John Bryce College, he helped me a lot and was by my side in my first steps in the programming field, he is the ultimate mentor, and I will always be grateful to him.

Okay, so... shall we dive into more details?

How it works?

math-app-server

I will be covering here the main purpose of each class, extra details about each method can be found in the source code.

image

App class:

This class is the starting point of the math-app-server, this class contain a method with a reference to MathServer class that will be generated an instance of a ServerSocket

MathServer class:

Designed to handle multiple math clients, implements the singleton pattern as only 1 server should exist per application.
This class instantiates different threads who handle different clients.

MathOperationsThread class:

Designed to provide services for a single math-app-client.
This class is the one the communicates de facto with math-app-client.

  • has a method named eventLoop() – that will be call the MathOperationFactory in runtime.

image

MathOperationFactory class:

Implementing the factory pattern, responsible for identifying math operations that received from the math-app-client and creating the right object accordingly.

MathOperation class:

MathOperation class is an abstract class.
The main method in this class is named perform(), this method parses commands received from the math-app-client.
This class will be extended by all the command types that exist in this system (see more details below).
Each one of those sub-classes will be performing and using the methods in this abstract class, and must implement the actual calculation parsenCalc(String n1, String n2) method.

Addition class:

The Addition class extends MathOperation abstract class, the main method in use here is the one that performs the calculation de facto - parseAndCalc(String n1, String n2).

Subtraction class:

The Subtraction class extends MathOperation abstract class, the main method in use here is the one that performs the calculation de facto - parseAndCalc(String n1, String n2).

Multiplication class:

The Multiplication class extends MathOperation abstract class, the main method in use here is the one that performs the calculation de facto - parseAndCalc(String n1, String n2).

Division class:

The Division class extends MathOperation abstract class, the main method in use here is the one that performs the calculation de facto - parseAndCalc(String n1, String n2).

image

More classes:

I also added class that contain constant values and 2 custom exception classes.

image image

math-app-client

I will be covering here the main purpose of each class, extra details about each method can be found in the source code.

image

App class:

This class is the starting point of the math -app-client, this class contains a method with a reference to MathOperationClient class that will generate a Socket.

MathOperationClient class:

MathOperationClient class, designed to enable sending requests from the client to the server.
This class is the one the communicates de facto with math-app-server, an object of the class should be instantiated in order to connect to the server.

ServerListeningThread class:

This class is designed to perform as a log file manager.
I added a thread that listens to all input from the server, logs INFO messages and documents data to a local log file.

MathClientIOMediator class:

This class implements the Mediator pattern, synchronizes the IO operations between logging threads and MathOperationClient.

image

image

ProtocolConstants classe:

I also added class that contain constant values:

image


Thanks for reading,
Chelly 👩🏻‍💻

About

A multi-threaded program, application that perform mathematical calculations and return the data back to the user | using Java Networking Programming library

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages