aboutsummaryrefslogtreecommitdiff
path: root/src/Store/User.java
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.com>2024-11-21 23:54:32 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.com>2024-11-21 23:54:32 +0530
commit3b16f36d497151ea1628491a057da292855a46f1 (patch)
tree65f15c93f550f86a64ff58816a3c8dbf11f6cc3c /src/Store/User.java
parent279415dfe3386e624727d204b304430299d4a6cf (diff)
added multithreading because... yesHEADmaster
Diffstat (limited to 'src/Store/User.java')
-rw-r--r--src/Store/User.java66
1 files changed, 40 insertions, 26 deletions
diff --git a/src/Store/User.java b/src/Store/User.java
index e414520..c253421 100644
--- a/src/Store/User.java
+++ b/src/Store/User.java
@@ -74,39 +74,53 @@ public class User {
public static DataListener<JSONMessage> signUpHandler() {
return ((client, data, ackSender) -> {
- Map<String,String> d = data.getData();
-
- User user = new User(d.get("userName"), d.get("password"));
- try {
- if (user.save()) {
- client.sendEvent("signedUp");
- } else {
- client.sendEvent("usernameTaken");
+ Thread t = new Thread(() -> {
+ Map<String,String> d = data.getData();
+
+ User user = new User(d.get("userName"), d.get("password"));
+ try {
+ if (user.save()) {
+ client.sendEvent("signedUp");
+ } else {
+ client.sendEvent("usernameTaken");
+ client.sendEvent("signUpFailed");
+ }
+ } catch (SQLException e) {
client.sendEvent("signUpFailed");
+ System.out.println(e.getMessage());
}
- } catch (SQLException e) {
- client.sendEvent("signUpFailed");
- System.out.println(e.getMessage());
- }
+ });
+
+ t.start();
+ t.join();
});
}
public static DataListener<JSONMessage> loginHandler() {
return ((client, data, ackSender) -> {
- Map<String,String> d = data.getData();
-
- User user = new User(d.get("userName"), d.get("password"));
- try {
- user.login();
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- }
-
- if (user.login()) {
- client.sendEvent("loggedIn", user.id);
- } else {
- client.sendEvent("loginFailed");
- }
+ Thread t = new Thread(() -> {
+ Map<String,String> d = data.getData();
+
+ User user = new User(d.get("userName"), d.get("password"));
+ try {
+ user.login();
+ } catch (SQLException e) {
+ System.out.println(e.getMessage());
+ }
+
+ try {
+ if (user.login()) {
+ client.sendEvent("loggedIn", user.id);
+ } else {
+ client.sendEvent("loginFailed");
+ }
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ });
+
+ t.start();
+ t.join();
});
}