package org.ingrahamrobotics.robottables;

import java.util.Hashtable;
import org.ingrahamrobotics.robottables.interfaces.InternalTableHandler;
import org.ingrahamrobotics.robottables.interfaces.RobotProtocol;

// TODO: Implement
public class ProtocolHandler implements RobotProtocol {

    public void sendPublishRequest(final String tableName) {

    }

    public void sendFullUpdate(final String tableName, final Hashtable tableValues) {

    }

    public void sendKeyUpdate(final String tableName, final String keyName, final String keyValue) {

    }

    public void sendKeyDelete(final String tableName, final String keyName) {

    }

    public void setInternalHandler(final InternalTableHandler handler) {

    }

    public void dispatch(final Message msg) {
        // Sleep longer than the sender interval to induce a queue overload
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ex) {
        }

        // Do something with the message
        System.out.println("Handled message:\n" + msg.displayStr());
    }
}

@@ -36,16 +36,44 @@
 ables;%0A%0A
+import java.io.IOException;%0A
 import j
@@ -235,27 +235,60 @@
 ol;%0A
-%0A// TODO: Implement
+import org.ingrahamrobotics.robottables.network.IO;%0A
 %0Apub
@@ -350,64 +350,292 @@
    p
-ublic void sendPublishRequest(final String tableName) %7B%0A
+rivate InternalTableHandler handler;%0A    private final IO io;%0A%0A    public ProtocolHandler() throws IOException %7B%0A        io = new IO();%0A    %7D%0A%0A    public void sendPublishRequest(final String tableName) %7B%0A        sendMessage(new Message(Message.Type.QUERY, tableName, %22publish%22, %22_%22));
 %0A   
@@ -802,20 +802,16 @@
 ring key
-Name
 , final 
@@ -821,20 +821,17 @@
 ing 
-keyV
+v
 alue) %7B%0A
 %0A   
@@ -822,24 +822,107 @@
 ng value) %7B%0A
+        sendMessage(new Message(Message.Type.PUBLISH_USER, tableName, key, value));
 %0A    %7D%0A%0A    
@@ -999,308 +999,722 @@
 ) %7B%0A
-%0A    %7D%0A%0A    public void setInternalHandler(final InternalTableHandler handler) %7B%0A%0A    %7D%0A%0A    public void dispatch(final Message msg) %7B%0A        // Sleep longer than the sender interval to induce a queue overload%0A        try %7B%0A            Thread.sleep(1000);%0A        %7D catch (InterruptedException ex) %7B
+        sendMessage(new Message(Message.Type.DELETE_USER, tableName, keyName, %22_%22));%0A    %7D%0A%0A    public void sendAdminKeyUpdate(final String tableName, final String key, final String value) %7B%0A        sendMessage(new Message(Message.Type.PUBLISH_ADMIN, tableName, key, value));%0A    %7D%0A%0A    public void sendAdminKeyDelete(final String tableName, final String key) %7B%0A        sendMessage(new Message(Message.Type.DELETE_ADMIN, tableName, key, %22_%22));%0A    %7D%0A%0A    public void sendMessage(final Message message) %7B%0A        try %7B%0A            io.send(message.toString());%0A        %7D catch (IOException e) %7B%0A            System.err.println(%22Error sending message '%22 + message.displayStr() + %22'.%22);%0A            e.printStackTrace();
 %0A   
@@ -1724,49 +1724,60 @@
   %7D%0A
-%0A
     
+%7D%0A%0A
     
-// Do something with the message
+public void dispatch(final Message msg) %7B
 %0A   
@@ -1801,21 +1801,22 @@
 rintln(%22
-Handl
+Receiv
 ed messa
@@ -1848,11 +1848,123 @@
 );%0A    %7D
+%0A%0A    public void setInternalHandler(final InternalTableHandler handler) %7B%0A        this.handler = handler;%0A    %7D
 %0A%7D%0A

Add a few message calls to ProtocolHandler. Not complete.