summaryrefslogtreecommitdiffstats
path: root/simple/simple-http/src/test/java/org/simpleframework/http/socket/table/WebSocketTableSweeper.java
blob: 5f09efa2f5ee34c0801dbf43adb992adf885b84a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package org.simpleframework.http.socket.table;

import java.util.LinkedHashMap;
import java.util.Map;

public class WebSocketTableSweeper {

   private final WebSocketTable table;

   public WebSocketTableSweeper(WebSocketTable table) {
      this.table = table;     
   }

   public Map<WebSocketTableUpdateType, String> sweep(long time, long count) {
      Map<WebSocketTableUpdateType, String> messages = new LinkedHashMap<WebSocketTableUpdateType, String>();
      
      if(count <= 1) {
         WebSocketTableSchema schema = table.getSchema();
         String schemaUpdate = schema.createStyle();
         messages.put(WebSocketTableUpdateType.SCHEMA, schemaUpdate);
      }
      String highlightUpdate = table.calculateHighlight(time);
      String deltaUpdate = table.calculateChange(time);// really should only take small batches...
      
      highlightUpdate = count + "@" + System.currentTimeMillis() + ":" + highlightUpdate;
      deltaUpdate = count + "@" + System.currentTimeMillis() + ":" + deltaUpdate;
      
      messages.put(WebSocketTableUpdateType.HIGHLIGHT, highlightUpdate);
      messages.put(WebSocketTableUpdateType.DELTA, deltaUpdate);

      return messages;
   }
}