server

Clone or download

Modified Files

--- 'a/src/main/java/com/stream_pi/server/connection/ClientConnection.java'
+++ b/src/main/java/com/stream_pi/server/connection/ClientConnection.java
@@ -34,6 +34,7 @@ import java.io.*;
import java.net.Socket;
import java.net.SocketAddress;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -251,9 +252,9 @@ public class ClientConnection extends Th
{
while(!stop.get())
{
-
try
{
+
Message message = (Message) ois.readObject();
String header = message.getHeader();
@@ -261,7 +262,7 @@ public class ClientConnection extends Th
switch (header)
{
case "action_icon" : onActionIconReceived(message);
- break;
+ break;
case "disconnect" : clientDisconnected(message);
break;
@@ -446,19 +447,23 @@ public class ClientConnection extends Th
}
}
- int totalActions;
+ private HashMap<String, Integer> temporaryProfilesCheck = null;
+
+
public void registerProfilesFromClient(Message message) throws StreamPiException
{
logger.info("Registering profiles ...");
- String[] r = message.getStringArrValue();
+ String[] profileIds = message.getStringArrValue();
+
+ int[] profilesActionIds = message.getIntArrValue();
- totalActions = message.getIntValue();
- System.out.println("TTOOOX : "+totalActions);
+ temporaryProfilesCheck = new HashMap<>();
- for (String profileID : r)
+ for (int i = 0;i<profileIds.length;i++)
{
- getProfileDetailsFromClient(profileID);
+ temporaryProfilesCheck.put(profileIds[i], profilesActionIds[i]);
+ getProfileDetailsFromClient(profileIds[i]);
}
}
@@ -502,7 +507,7 @@ public class ClientConnection extends Th
public synchronized void registerActionToProfile(Message message) throws StreamPiException
{
- totalActions--;
+
String[] r = message.getStringArrValue();
@@ -557,6 +562,17 @@ public class ClientConnection extends Th
//set up action
+ temporaryProfilesCheck.replace(
+ profileID,
+ (temporaryProfilesCheck.get(profileID) - 1)
+ );
+
+ if(temporaryProfilesCheck.get(profileID) == 0)
+ {
+ temporaryProfilesCheck.remove(profileID);
+ }
+
+
//action toBeAdded = null;
boolean isInvalidAction = false;
@@ -701,6 +717,7 @@ public class ClientConnection extends Th
action.setClientProperties(clientProperties);
+
try
{
getClient().getProfileByID(profileID).addAction(action);
@@ -716,10 +733,16 @@ public class ClientConnection extends Th
public void checkIfReady() throws SevereException
{
- if(totalActions == 0)
+ if(temporaryProfilesCheck.size() == 0)
{
+ getLogger().info("PASSS");
+ temporaryProfilesCheck = null;
sendMessage(new Message("ready"));
}
+ else
+ {
+ getLogger().info("FAIL");
+ }
}
public synchronized void saveActionDetails(String profileID, Action action) throws SevereException
@@ -891,7 +914,7 @@ public class ClientConnection extends Th
String actionID = r[1];
boolean toggle = r[2].equals("true");
- Action action = client.getProfileByID(profileID).getActionByID(actionID);
+ Action action = client.getProfileByID(profileID).getActionByID(actionID);
if(action.getActionType() == ActionType.NORMAL || action.getActionType() == ActionType.TOGGLE)
{