Revision 1a79c76b src/com/rackspacecloud/android/ConnectionThrottleActivity.java
b/src/com/rackspacecloud/android/ConnectionThrottleActivity.java | ||
---|---|---|
18 | 18 |
import com.rackspace.cloud.servers.api.client.http.HttpBundle; |
19 | 19 |
|
20 | 20 |
public class ConnectionThrottleActivity extends CloudActivity{ |
21 |
|
|
21 |
|
|
22 | 22 |
private LoadBalancer loadBalancer; |
23 | 23 |
private ConnectionThrottle connectionThrottle; |
24 | 24 |
private EditText minCons; |
25 | 25 |
private EditText maxCons; |
26 | 26 |
private EditText maxConRate; |
27 | 27 |
private EditText rateInterval; |
28 |
|
|
28 |
|
|
29 | 29 |
private final String ENABLE = "Enable Throttle"; |
30 | 30 |
private final String DISABLE = "Disable Throttle"; |
31 |
|
|
31 |
|
|
32 | 32 |
@Override |
33 | 33 |
public void onCreate(Bundle savedInstanceState) { |
34 | 34 |
super.onCreate(savedInstanceState); |
... | ... | |
37 | 37 |
restoreState(savedInstanceState); |
38 | 38 |
} |
39 | 39 |
|
40 |
@Override |
|
41 |
protected void onSaveInstanceState(Bundle outState) { |
|
42 |
super.onSaveInstanceState(outState); |
|
43 |
outState.putSerializable("loadBalancer", loadBalancer); |
|
44 |
} |
|
45 |
|
|
46 |
|
|
40 | 47 |
protected void restoreState(Bundle state) { |
41 | 48 |
super.restoreState(state); |
42 | 49 |
|
50 |
if(state != null && state.containsKey("loadBalancer")){ |
|
51 |
loadBalancer = (LoadBalancer)state.getSerializable("loadBalancer"); |
|
52 |
} |
|
43 | 53 |
minCons = (EditText)findViewById(R.id.min_connections_text); |
44 | 54 |
maxCons = (EditText)findViewById(R.id.max_connections_text); |
45 | 55 |
maxConRate = (EditText)findViewById(R.id.max_connection_rate); |
46 | 56 |
rateInterval = (EditText)findViewById(R.id.rate_interval); |
47 |
|
|
57 |
|
|
48 | 58 |
setupButtons(); |
49 | 59 |
setupText(); |
50 | 60 |
} |
51 |
|
|
61 |
|
|
52 | 62 |
private void setupButtons(){ |
53 | 63 |
Button enable = (Button)findViewById(R.id.enable_throttle_button); |
54 | 64 |
if(loadBalancer.getConnectionThrottle() == null){ |
... | ... | |
61 | 71 |
@Override |
62 | 72 |
public void onClick(View v) { |
63 | 73 |
if(enable.getText().toString().equals(ENABLE)){ |
74 |
ConnectionThrottle connectionThrottle = new ConnectionThrottle(); |
|
75 |
connectionThrottle.setMinConnections("25"); |
|
76 |
connectionThrottle.setMaxConnections("100"); |
|
77 |
connectionThrottle.setMaxConnectionRate("25"); |
|
78 |
connectionThrottle.setRateInterval("5"); |
|
79 |
|
|
80 |
loadBalancer.setConnectionThrottle(connectionThrottle); |
|
64 | 81 |
//Turn on EditTexts |
65 | 82 |
minCons.setEnabled(true); |
66 | 83 |
maxCons.setEnabled(true); |
... | ... | |
68 | 85 |
rateInterval.setEnabled(true); |
69 | 86 |
enable.setText(DISABLE); |
70 | 87 |
} else { |
88 |
loadBalancer.setConnectionThrottle(null); |
|
71 | 89 |
//Turn off EditTexts |
72 | 90 |
minCons.setEnabled(false); |
73 | 91 |
maxCons.setEnabled(false); |
... | ... | |
80 | 98 |
|
81 | 99 |
Button submit = (Button)findViewById(R.id.save_throttle_button); |
82 | 100 |
submit.setOnClickListener(new OnClickListener() { |
83 |
|
|
101 |
|
|
84 | 102 |
Button enable = (Button)findViewById(R.id.enable_throttle_button); |
85 |
|
|
103 |
|
|
86 | 104 |
@Override |
87 | 105 |
public void onClick(View v) { |
88 |
|
|
106 |
|
|
89 | 107 |
connectionThrottle = new ConnectionThrottle(); |
90 | 108 |
connectionThrottle.setMaxConnectionRate(maxConRate.getText().toString()); |
91 | 109 |
connectionThrottle.setMinConnections(minCons.getText().toString()); |
92 | 110 |
connectionThrottle.setMaxConnections(maxCons.getText().toString()); |
93 | 111 |
connectionThrottle.setRateInterval(rateInterval.getText().toString()); |
94 |
|
|
112 |
|
|
95 | 113 |
if(enable.getText().toString().equals(DISABLE)){ |
96 | 114 |
if(validText()){ |
97 | 115 |
new UpdateConnectionThrottleTask().execute(); |
... | ... | |
108 | 126 |
} |
109 | 127 |
}); |
110 | 128 |
} |
111 |
|
|
129 |
|
|
112 | 130 |
private void setupText(){ |
113 | 131 |
if(loadBalancer.getConnectionThrottle() == null){ |
114 | 132 |
minCons.setEnabled(false); |
115 | 133 |
maxCons.setEnabled(false); |
116 | 134 |
maxConRate.setEnabled(false); |
117 | 135 |
rateInterval.setEnabled(false); |
118 |
|
|
136 |
|
|
119 | 137 |
//Set boxes to default values |
120 | 138 |
minCons.setText("25"); |
121 | 139 |
maxCons.setText("100"); |
... | ... | |
123 | 141 |
rateInterval.setText("5"); |
124 | 142 |
} else { |
125 | 143 |
ConnectionThrottle throttle = loadBalancer.getConnectionThrottle(); |
126 |
|
|
144 |
|
|
127 | 145 |
//restore the current values to the boxes |
128 | 146 |
minCons.setText(throttle.getMinConnections()); |
129 | 147 |
maxCons.setText(throttle.getMaxConnections()); |
... | ... | |
131 | 149 |
rateInterval.setText(throttle.getRateInterval()); |
132 | 150 |
} |
133 | 151 |
} |
134 |
|
|
152 |
|
|
135 | 153 |
private Boolean validText(){ |
136 | 154 |
return validEditText(maxCons, 0, 100000, "Max Connections") |
137 |
&& validEditText(minCons, 0, 1000, "Min Connections")
|
|
138 |
&& validEditText(maxConRate, 0, 100000, "Max Connection Rate")
|
|
139 |
&& validEditText(rateInterval, 1, 3600, "Rate Interval");
|
|
155 |
&& validEditText(minCons, 0, 1000, "Min Connections") |
|
156 |
&& validEditText(maxConRate, 0, 100000, "Max Connection Rate") |
|
157 |
&& validEditText(rateInterval, 1, 3600, "Rate Interval"); |
|
140 | 158 |
} |
141 |
|
|
159 |
|
|
142 | 160 |
private Boolean validEditText(EditText box, int min, int max, String boxName){ |
143 | 161 |
String result = box.getText().toString(); |
144 | 162 |
if(result.equals("")){ |
... | ... | |
160 | 178 |
} |
161 | 179 |
} |
162 | 180 |
} |
163 |
|
|
181 |
|
|
164 | 182 |
public class UpdateConnectionThrottleTask extends AsyncTask<Void, Void, HttpBundle> { |
165 | 183 |
|
166 | 184 |
private CloudServersException exception; |
... | ... | |
203 | 221 |
} |
204 | 222 |
} |
205 | 223 |
} |
206 |
|
|
224 |
|
|
207 | 225 |
public class DeleteConnectionThrottleTask extends AsyncTask<Void, Void, HttpBundle> { |
208 | 226 |
|
209 | 227 |
private CloudServersException exception; |
Also available in: Unified diff