Skip to content

Commit

Permalink
Refactoring for sample
Browse files Browse the repository at this point in the history
  • Loading branch information
Yasara Dissanayake committed Aug 1, 2017
1 parent 1ec8a9f commit 36897a5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
public class HttpServerListener implements HttpHandler {
private static final Logger logger = Logger.getLogger(HttpServerListener.class);
private AtomicBoolean isEventArraved = new AtomicBoolean(false);
private StringBuilder strBld;
private StringBuilder strBld = new StringBuilder();
private Headers headers;

HttpServerListener() {
Expand All @@ -48,25 +48,25 @@ public void handle(HttpExchange t) throws IOException {
headers = t.getRequestHeaders();
InputStream is = t.getRequestBody();
BufferedReader in = new BufferedReader(new InputStreamReader(is)); // initiating
strBld = new StringBuilder();
String name = null;
while ((line = in.readLine()) != null) {
strBld = strBld.append(line).append("\n");
strBld = strBld.append(line).append(" , ");
name = line;
}

logger.info("Event Arrived: " + strBld.toString());
logger.info("Event Name Arrived: " + name);
isEventArraved.set(true);
}

String getData() {
isEventArraved = new AtomicBoolean(false);
return strBld.toString();
}

Headers getHeaders() {
return headers;
}

boolean iaMessageArrive() {
boolean isMessageArrive() {
return isEventArraved.get();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ public class HttpServerMain {
public static void main(String[] args) throws InterruptedException {
while (true) {
HttpServerListenerHandler lst = new HttpServerListenerHandler(8080);
while (!lst.getServerListner().iaMessageArrive()) {
while (!lst.getServerListner().isMessageArrive()) {
Thread.sleep(100);
}
logger.info("Received Event :" + lst.getServerListner().getData());
logger.info("Received Event Names:" + lst.getServerListner().getData());
logger.info("Received Event Headers key set:" + lst.getServerListner().getHeaders().keySet().toString());
logger.info("Received Event Headers value set:" + lst.getServerListner().getHeaders().values().toString());
lst.shutdown();
Expand Down

0 comments on commit 36897a5

Please sign in to comment.