Skip to content

Commit 2a24a47

Browse files
author
ywang19
committed
share one method in one client
1 parent 5e67959 commit 2a24a47

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

dev/cosbench-ampli/src/com/intel/cosbench/client/amplistor/AmpliClient.java

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class AmpliClient {
4141

4242
private HttpClient client = null;
4343
/* current operation */
44-
private volatile HttpUriRequest request;
44+
private volatile HttpUriRequest method;
4545
private int port;
4646
private String host;
4747
private String nsRoot;
@@ -54,20 +54,20 @@ public AmpliClient(HttpClient client, String host, int port, String nsRoot) {
5454
}
5555

5656
public void dispose() {
57-
request = null;
57+
method = null;
5858
HttpClientUtil.disposeHttpClient(client);
5959
}
6060

6161
public void abort() {
62-
if (request != null)
63-
request.abort();
64-
request = null;
62+
if (method != null)
63+
method.abort();
64+
method = null;
6565
}
6666

6767
public boolean login() throws IOException, HttpException {
6868
String storageUrl = "http://" + this.host + ":" + this.port;
6969

70-
HttpHead method = HttpClientUtil.makeHttpHead(storageUrl);
70+
method = HttpClientUtil.makeHttpHead(storageUrl);
7171
HttpResponse response = null;
7272
try {
7373
response = client.execute(method);
@@ -89,15 +89,14 @@ public String StoreObject(String sourceFilename, String ampliNamespace,
8989
AmpliException {
9090
File file = new File(sourceFilename);
9191

92-
HttpPut method = null;
9392
HttpResponse response = null;
9493
try {
9594
String storageUrl = "http://" + this.host + ":" + this.port
9695
+ nsRoot;
9796
method = HttpClientUtil.makeHttpPut(storageUrl + "/" + HttpClientUtil.encodeURL(ampliNamespace)
9897
+ "/" + HttpClientUtil.encodeURL(ampliFilename));
9998

100-
method.setEntity(new FileEntity(file, "application/octet-stream"));
99+
((HttpPut)method).setEntity(new FileEntity(file, "application/octet-stream"));
101100

102101
response = client.execute(method);
103102

@@ -127,7 +126,6 @@ public String StoreObject(String sourceFilename, String ampliNamespace,
127126
public String StoreStreamedObject(InputStream stream, long length,
128127
String ampliNamespace, String ampliFilename) throws IOException,
129128
HttpException, AmpliException {
130-
HttpPut method = null;
131129
HttpResponse response = null;
132130
try {
133131
String storageUrl = "http://" + this.host + ":" + this.port
@@ -143,7 +141,7 @@ public String StoreStreamedObject(InputStream stream, long length,
143141
entity.setChunked(false);
144142
}
145143

146-
method.setEntity(entity);
144+
((HttpPut)method).setEntity(entity);
147145

148146
response = client.execute(method);
149147

@@ -191,7 +189,6 @@ public String StoreObject(byte[] data, String ampliNamespace,
191189
String ampliFilename) throws IOException, HttpException,
192190
AmpliException {
193191
// int len = data.length;
194-
HttpPut method = null;
195192
String storageUrl = "http://" + this.host + ":" + this.port + nsRoot;
196193
method = HttpClientUtil.makeHttpPut(storageUrl + "/" + HttpClientUtil.encodeURL(ampliNamespace) + "/"
197194
+ HttpClientUtil.encodeURL(ampliFilename));
@@ -200,7 +197,7 @@ public String StoreObject(byte[] data, String ampliNamespace,
200197

201198
HttpResponse response = null;
202199
try {
203-
method.setEntity(new ByteArrayEntity(data));
200+
((HttpPut)method).setEntity(new ByteArrayEntity(data));
204201
response = client.execute(method);
205202
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_CREATED) {
206203
return response.getFirstHeader("ETag").getValue();
@@ -222,7 +219,7 @@ public byte[] getObject(String namespace, String objName)
222219
throws IOException, HttpException, AmpliException {
223220
String storageUrl = "http://" + this.host + ":" + this.port + nsRoot;
224221

225-
HttpGet method = HttpClientUtil.makeHttpGet(storageUrl + "/" + HttpClientUtil.encodeURL(namespace)
222+
method = HttpClientUtil.makeHttpGet(storageUrl + "/" + HttpClientUtil.encodeURL(namespace)
226223
+ "/" + HttpClientUtil.encodeURL(objName));
227224

228225
HttpResponse response = null;
@@ -249,7 +246,7 @@ public InputStream getObjectAsStream(String namespace, String objName)
249246
throws IOException, HttpException, AmpliException {
250247
String storageUrl = "http://" + this.host + ":" + this.port + nsRoot;
251248

252-
HttpGet method = HttpClientUtil.makeHttpGet(storageUrl + "/" + HttpClientUtil.encodeURL(namespace)
249+
method = HttpClientUtil.makeHttpGet(storageUrl + "/" + HttpClientUtil.encodeURL(namespace)
253250
+ "/" + HttpClientUtil.encodeURL(objName));
254251

255252
HttpResponse response = null;
@@ -272,7 +269,6 @@ public InputStream getObjectAsStream(String namespace, String objName)
272269
public boolean deleteObject(String ampliNamespace, String name)
273270
throws HttpException, IOException, AmpliException {
274271

275-
HttpDelete method = null;
276272
HttpResponse response = null;
277273

278274
try {
@@ -302,7 +298,6 @@ public boolean deleteObject(String ampliNamespace, String name)
302298
public AmpliPolicy createPolicy(AmpliPolicy policy) throws HttpException,
303299
IOException, AmpliException {
304300

305-
HttpPut method = null;
306301
HttpResponse response = null;
307302
try {
308303
String storageUrl = "http://" + this.host + ":" + this.port
@@ -336,7 +331,6 @@ public AmpliPolicy createPolicy(AmpliPolicy policy) throws HttpException,
336331
public AmpliPolicy getPolicy(String policyId) throws HttpException,
337332
IOException, AmpliException {
338333

339-
HttpGet method = null;
340334
HttpResponse response = null;
341335
try {
342336
String storageUrl = "http://" + this.host + ":" + this.port
@@ -366,13 +360,13 @@ public AmpliPolicy getPolicy(String policyId) throws HttpException,
366360

367361
public AmpliNamespace createNamespace(AmpliNamespace namespace)
368362
throws HttpException, IOException, AmpliException {
369-
HttpPut method = null;
370-
HttpResponse response = null;
363+
364+
HttpResponse response = null;
371365
try {
372366
String storageUrl = "http://" + this.host + ":" + this.port
373367
+ nsRoot;
374368

375-
method = new HttpPut(storageUrl);
369+
method = HttpClientUtil.makeHttpGet(storageUrl);
376370

377371
method.setHeader("Content-Type", "text/plain");
378372

@@ -405,7 +399,7 @@ public String createNamespace(String namespace, String policy_id)
405399
String storageUrl = "http://" + this.host + ":" + this.port
406400
+ nsRoot;
407401

408-
method = new HttpPut(storageUrl);
402+
method = HttpClientUtil.makeHttpPut(storageUrl);
409403

410404
method.setHeader("Content-Type", "text/plain");
411405

@@ -438,7 +432,6 @@ public String createNamespace(String namespace, String policy_id)
438432
public AmpliNamespace getNamespace(String name) throws HttpException,
439433
IOException, AmpliException {
440434

441-
HttpGet method = null;
442435
HttpResponse response = null;
443436
try {
444437
String storageUrl = "http://" + this.host + ":" + this.port
@@ -469,7 +462,6 @@ public AmpliNamespace getNamespace(String name) throws HttpException,
469462
public boolean isNamespaceExisted(String name) throws HttpException,
470463
IOException, AmpliException {
471464

472-
HttpHead method = null;
473465
HttpResponse response = null;
474466
try {
475467
String storageUrl = "http://" + this.host + ":" + this.port
@@ -497,7 +489,7 @@ public boolean isNamespaceExisted(String name) throws HttpException,
497489

498490
public boolean deleteNamespace(String namespace) throws HttpException,
499491
IOException, AmpliException {
500-
HttpDelete method = null;
492+
501493
HttpResponse response = null;
502494
try {
503495
String storageUrl = "http://" + this.host + ":" + this.port
@@ -525,7 +517,7 @@ public Map<String, String> getObjectMetadata(String namespace,
525517
String objName) throws IOException, HttpException, AmpliException {
526518
String storageUrl = "http://" + this.host + ":" + this.port + nsRoot;
527519

528-
HttpGet method = HttpClientUtil.makeHttpGet(storageUrl + "/" + HttpClientUtil.encodeURL(namespace)
520+
method = HttpClientUtil.makeHttpGet(storageUrl + "/" + HttpClientUtil.encodeURL(namespace)
529521
+ "/" + HttpClientUtil.encodeURL(objName) + "?meta=http");
530522

531523
HttpResponse response = null;

0 commit comments

Comments
 (0)