summaryrefslogtreecommitdiffstats
path: root/simple/simple-http/src/test/java/org/simpleframework/http/socket/table/WebSocketTableRowChanger.java
blob: bdc6755d5688e5c03e37d022ba07a87fd4caaf92 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package org.simpleframework.http.socket.table;

import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

public class WebSocketTableRowChanger extends Thread {
   
   private final WebSocketTableChanger changer;

   public WebSocketTableRowChanger(WebSocketTable table) {
      this.changer = new WebSocketTableChanger(table);
   }
   
   public void run() {
      Random random = new SecureRandom();
      List<String> products = new ArrayList<String>();
      
      products.add("QTC44");
      products.add("NSW22");
      products.add("NSW23");
      products.add("NSW24");
      products.add("WAGA19");
      products.add("CGS19");
      products.add("CGS21");
      products.add("CGS22");
      products.add("CGSJun14");
      products.add("CGSOct14");
      products.add("CGSDec12");
      products.add("QTC33");
      
      for(int i = 0; i < 100; i++) {
         products.add("CGS" + i);
      }

      while(true) {
         try {     
            int rows = products.size();
            long randomWait = random.nextInt(50) + 40;
            int randomRow = random.nextInt(rows);
            int randomBid = random.nextInt(50) + 1;
            int randomOffer = random.nextInt(50) + 1;
            int randomVolume = (random.nextInt(5) + 1) * 10;
            
            if(randomRow != 0) {
               String product = products.get(randomRow);
               Map<String, Object> map = new HashMap<String, Object>();               
               
               map.put("id", randomRow);
               map.put("product", product);
               map.put("bidOutrightVolume", randomVolume);
               map.put("bidOutright", randomBid);
               map.put("offerOutright", randomOffer);
               map.put("offerOutrightVolume", randomVolume);
               map.put("bidEFPVolume", randomVolume);      
               map.put("bidEFP", randomBid);
               map.put("offerEFP", randomOffer);
               map.put("offerEFPVolume", randomVolume);
               map.put("reference", "3ySep");               

               changer.onChange(map);
            }            
            Thread.sleep(randomWait);
         } catch(Exception e) {
            e.printStackTrace();          
         }
      }
   }   

}