From 7efe76d4721a8bbea6574f84f6b12c0f90199785 Mon Sep 17 00:00:00 2001 From: Vinay Date: Fri, 10 Nov 2017 12:17:52 +0000 Subject: [PATCH] Refactored SockJS Code --- .../in/erail/common/FramworkConstants.java | 5 ++ .../sockjs/DefaultBridgeEventHandler.java | 77 ++++++++++++++++++- 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/src/main/java/in/erail/common/FramworkConstants.java b/src/main/java/in/erail/common/FramworkConstants.java index 15b5ef9..655edb1 100644 --- a/src/main/java/in/erail/common/FramworkConstants.java +++ b/src/main/java/in/erail/common/FramworkConstants.java @@ -22,4 +22,9 @@ public static class Json { } } + + public static class SockJS { + public static final String BRIDGE_EVENT_RAW_MESSAGE_ADDRESS = "address"; + } + } diff --git a/src/main/java/io/vertx/reactivex/ext/web/handler/sockjs/DefaultBridgeEventHandler.java b/src/main/java/io/vertx/reactivex/ext/web/handler/sockjs/DefaultBridgeEventHandler.java index f32e79c..2da1c89 100644 --- a/src/main/java/io/vertx/reactivex/ext/web/handler/sockjs/DefaultBridgeEventHandler.java +++ b/src/main/java/io/vertx/reactivex/ext/web/handler/sockjs/DefaultBridgeEventHandler.java @@ -1,6 +1,8 @@ package io.vertx.reactivex.ext.web.handler.sockjs; +import in.erail.common.FramworkConstants; import io.vertx.core.Handler; +import io.vertx.core.json.JsonObject; /** * @@ -10,7 +12,80 @@ public class DefaultBridgeEventHandler implements Handler { @Override public void handle(BridgeEvent pEvent) { + + JsonObject rawMessage = pEvent.getRawMessage(); + String address = null; + + if (rawMessage != null) { + address = rawMessage.getString(FramworkConstants.SockJS.BRIDGE_EVENT_RAW_MESSAGE_ADDRESS); + } + + switch (pEvent.type()) { + case PUBLISH: + handlePublish(address, pEvent); + break; + case RECEIVE: + handleRecieve(address, pEvent); + break; + case REGISTER: + handleRegister(address, pEvent); + break; + case SEND: + handleSend(address, pEvent); + break; + case SOCKET_CLOSED: + handleSocketClose(pEvent); + break; + case SOCKET_CREATED: + handleSocketCreated(pEvent); + break; + case SOCKET_IDLE: + handleSocketIdle(pEvent); + break; + case SOCKET_PING: + handleSocketPing(pEvent); + break; + case UNREGISTER: + handleUnregister(address, pEvent); + break; + } + + } + + public void handlePublish(String pAddress, BridgeEvent pEvent) { + pEvent.complete(true); + } + + public void handleRecieve(String pAddress, BridgeEvent pEvent) { + pEvent.complete(true); + } + + public void handleRegister(String pAddress, BridgeEvent pEvent) { pEvent.complete(true); } - + + public void handleSend(String pAddress, BridgeEvent pEvent) { + pEvent.complete(true); + } + + public void handleSocketClose(BridgeEvent pEvent) { + pEvent.complete(true); + } + + public void handleSocketCreated(BridgeEvent pEvent) { + pEvent.complete(true); + } + + public void handleSocketIdle(BridgeEvent pEvent) { + pEvent.complete(true); + } + + public void handleSocketPing(BridgeEvent pEvent) { + pEvent.complete(true); + } + + public void handleUnregister(String pAddress, BridgeEvent pEvent) { + pEvent.complete(true); + } + }