Open Kilda Java Documentation
ResponseCollector.java
Go to the documentation of this file.
1 /* Copyright 2017 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.northbound.utils;
17 
21 
22 import org.apache.commons.lang3.StringUtils;
23 import org.springframework.beans.factory.annotation.Autowired;
24 import org.springframework.stereotype.Component;
25 
26 import java.util.ArrayList;
27 import java.util.List;
28 
29 @Component
30 public class ResponseCollector<T extends InfoData> {
31 
32  @Autowired
33  private MessageConsumer<ChunkedInfoMessage> messageConsumer;
34 
35  public ResponseCollector() {
36  }
37 
45  public List<T> getResult(String requestId) {
46  List<T> result = new ArrayList<>();
47  ChunkedInfoMessage message;
48  String nextRequest = requestId;
49  do {
50  message = messageConsumer.poll(nextRequest);
51  nextRequest = message.getNextRequestId();
52 
53  @SuppressWarnings("unchecked")
54  T response = (T) message.getData();
55  if (response != null) {
56  result.add(response);
57  }
58  } while (StringUtils.isNoneBlank(message.getNextRequestId()));
59 
60  return result;
61  }
62 
63 }
list result
Definition: plan-d.py:72