Skip to content

Commit

Permalink
minor refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Kuleshov <dkuleshov@codenvy.com>
  • Loading branch information
Dmitry Kuleshov committed Jan 10, 2017
1 parent a0d5dad commit cbe2594
Show file tree
Hide file tree
Showing 17 changed files with 28 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.che.api.core.jsonrpc;


import org.eclipse.che.api.core.jsonrpc.transmission.EndpointIdConfigurator;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.che.api.core.jsonrpc;


import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.che.api.core.jsonrpc;


import org.eclipse.che.api.core.websocket.WebSocketMessageTransmitter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,37 +35,29 @@
public class JsonRpcList {
private final DtoFactory dtoFactory;
private final List<JsonElement> jsonElementList;
private final JsonParser jsonParser;

@AssistedInject
public JsonRpcList(@Assisted("message") String message, JsonParser jsonParser, DtoFactory dtoFactory) {
this.dtoFactory = dtoFactory;

checkNotNull(message, "Message must not be null");
checkArgument(!message.isEmpty(), "Message must not be empty");

this.dtoFactory = dtoFactory;
this.jsonParser = jsonParser;

JsonArray jsonArray = jsonParser.parse(message).getAsJsonArray();
this.jsonElementList = new ArrayList<>(jsonArray.size());
jsonArray.forEach(jsonElementList::add);
}

@AssistedInject
public JsonRpcList(@Assisted("dtoObjectList") List<?> dtoObjectList, JsonParser jsonParser, DtoFactory dtoFactory) {
this.dtoFactory = dtoFactory;

checkNotNull(dtoObjectList, "List must not be null");
checkArgument(!dtoObjectList.isEmpty(), "List must not be empty");

this.dtoFactory = dtoFactory;
this.jsonParser = jsonParser;

this.jsonElementList = dtoObjectList.stream().map(Object::toString).map(jsonParser::parse).collect(Collectors.toList());
}

@SuppressWarnings("unchecked")
private static <T> T cast(Object object) {
return (T)object;
}

public static boolean isArray(String message) {
return isArray(message, new JsonParser());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.che.api.core.jsonrpc;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
Expand Down Expand Up @@ -42,7 +41,7 @@ public class JsonRpcResult {
private final DtoFactory dtoFactory;

private List<JsonElement> resultList;
private JsonElement result;
private JsonElement result;

@AssistedInject
public JsonRpcResult(@Assisted("message") String message, JsonParser jsonParser, DtoFactory dtoFactory) {
Expand Down Expand Up @@ -72,7 +71,7 @@ public JsonRpcResult(@Assisted("result") Object result, DtoFactory dtoFactory, J
public JsonRpcResult(@Assisted("result") List<?> result, JsonParser jsonParser, DtoFactory dtoFactory) {
this.dtoFactory = dtoFactory;

if (result == null || result.isEmpty()){
if (result == null || result.isEmpty()) {
this.resultList = Collections.emptyList();
} else {
this.resultList = result.stream().map(Object::toString).map(jsonParser::parse).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ public void unregisterNotificationHandler(String method) {
notificationHandlers.remove(method);
}

public RequestHandler getRequestHandler(String method) {
RequestHandler getRequestHandler(String method) {
checkNotNull(method, "Method name must not be null");
checkArgument(!method.isEmpty(), "Method name must not be empty");

return requestHandlers.get(method);
}

public NotificationHandler getNotificationHandler(String method) {
NotificationHandler getNotificationHandler(String method) {
checkNotNull(method, "Method name must not be null");
checkArgument(!method.isEmpty(), "Method name must not be empty");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import org.eclipse.che.api.core.jsonrpc.JsonRpcFactory;
import org.eclipse.che.api.core.jsonrpc.RequestHandlerRegistry;
import org.eclipse.che.api.core.jsonrpc.transmission.EndpointIdConfigurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.che.api.core.jsonrpc.reception;


import org.eclipse.che.api.core.jsonrpc.NotificationHandler;
import org.eclipse.che.api.core.jsonrpc.NotificationHandlerManyToNone;
import org.eclipse.che.api.core.jsonrpc.RequestHandlerRegistry;
Expand All @@ -37,7 +36,6 @@ public class OperationConfiguratorManyToNone<P> {
private final String method;
private final Class<P> pClass;


OperationConfiguratorManyToNone(RequestHandlerRegistry registry, String method, Class<P> pClass) {
this.registry = registry;
this.method = method;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public class OperationConfiguratorOneToNone<P> {
private final String method;
private final Class<P> pClass;


OperationConfiguratorOneToNone(RequestHandlerRegistry registry, String method, Class<P> pClass) {
this.registry = registry;
this.method = method;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
*******************************************************************************/
package org.eclipse.che.api.core.jsonrpc.reception;


import org.eclipse.che.api.core.jsonrpc.JsonRpcFactory;
import org.eclipse.che.api.core.jsonrpc.RequestHandlerRegistry;
import org.eclipse.che.api.core.jsonrpc.transmission.EndpointIdConfigurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -32,7 +30,7 @@ public class ParamsConfigurator {
private final JsonRpcFactory factory;
private final String method;

public ParamsConfigurator(RequestHandlerRegistry registry, JsonRpcFactory factory, String method) {
ParamsConfigurator(RequestHandlerRegistry registry, JsonRpcFactory factory, String method) {
this.registry = registry;
this.factory = factory;
this.method = method;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.che.api.core.jsonrpc.reception;


import org.eclipse.che.api.core.jsonrpc.JsonRpcFactory;
import org.eclipse.che.api.core.jsonrpc.RequestHandlerRegistry;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ResultConfiguratorFromOne<P> {
private final String method;
private final Class<P> pClass;

public ResultConfiguratorFromOne(RequestHandlerRegistry registry, JsonRpcFactory factory, String method, Class<P> pClass) {
ResultConfiguratorFromOne(RequestHandlerRegistry registry, JsonRpcFactory factory, String method, Class<P> pClass) {
this.registry = registry;
this.factory = factory;
this.method = method;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.che.api.core.jsonrpc.transmission;


import org.eclipse.che.api.core.jsonrpc.JsonRpcFactory;
import org.eclipse.che.api.core.jsonrpc.ResponseDispatcher;
import org.eclipse.che.api.core.websocket.WebSocketMessageTransmitter;
Expand Down Expand Up @@ -48,6 +47,4 @@ public MethodNameConfigurator endpointId(String id) {

return new MethodNameConfigurator(dispatcher, transmitter, factory, id);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class MethodNameConfigurator {
private final String endpointId;

@Inject
public MethodNameConfigurator(ResponseDispatcher dispatcher, WebSocketMessageTransmitter transmitter, JsonRpcFactory factory,
MethodNameConfigurator(ResponseDispatcher dispatcher, WebSocketMessageTransmitter transmitter, JsonRpcFactory factory,
String endpointId) {
this.dispatcher = dispatcher;
this.transmitter = transmitter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.che.api.core.jsonrpc.transmission;


import org.eclipse.che.api.core.jsonrpc.JsonRpcFactory;
import org.eclipse.che.api.core.jsonrpc.ResponseDispatcher;
import org.eclipse.che.api.core.websocket.WebSocketMessageTransmitter;
Expand Down Expand Up @@ -38,8 +37,8 @@ public class ParamsConfigurator {
private final String method;
private final String endpointId;

public ParamsConfigurator(ResponseDispatcher dispatcher, WebSocketMessageTransmitter transmitter,
JsonRpcFactory factory, String method, String endpointId) {
ParamsConfigurator(ResponseDispatcher dispatcher, WebSocketMessageTransmitter transmitter, JsonRpcFactory factory, String method,
String endpointId) {
this.dispatcher = dispatcher;
this.transmitter = transmitter;
this.factory = factory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.che.api.core.jsonrpc.transmission;


import org.eclipse.che.api.core.jsonrpc.JsonRpcFactory;
import org.eclipse.che.api.core.jsonrpc.JsonRpcParams;
import org.eclipse.che.api.core.jsonrpc.JsonRpcPromise;
Expand All @@ -22,6 +21,8 @@

import java.util.List;

import static com.google.common.base.Preconditions.checkNotNull;

/**
* Configurator defines the type of a result (if present) and send a request.
* Result types that are supported: {@link String}, {@link Boolean},
Expand All @@ -42,8 +43,8 @@ public class SendConfiguratorFromMany<P> {
private final List<P> pListValue;
private final String endpointId;

public SendConfiguratorFromMany(ResponseDispatcher dispatcher, WebSocketMessageTransmitter transmitter,
JsonRpcFactory factory, String method, List<P> pListValue, String endpointId) {
SendConfiguratorFromMany(ResponseDispatcher dispatcher, WebSocketMessageTransmitter transmitter, JsonRpcFactory factory, String method,
List<P> pListValue, String endpointId) {
this.dispatcher = dispatcher;
this.transmitter = transmitter;
this.factory = factory;
Expand Down Expand Up @@ -78,9 +79,6 @@ public <R> JsonRpcPromise<R> sendAndReceiveResultAsDto(final Class<R> rClass) {
return dispatcher.registerPromiseOfOne(endpointId, requestId, rClass, new JsonRpcPromise<>());
}

private <R> void checkNotNull(Class<R> rClass, String s) {
}

public JsonRpcPromise<String> sendAndReceiveResultAsString() {
final String requestId = transmitRequest();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.che.api.core.jsonrpc.transmission;


import org.eclipse.che.api.core.jsonrpc.JsonRpcFactory;
import org.eclipse.che.api.core.jsonrpc.JsonRpcParams;
import org.eclipse.che.api.core.jsonrpc.JsonRpcPromise;
Expand Down Expand Up @@ -43,8 +42,8 @@ public class SendConfiguratorFromOne<P> {
private final P pValue;
private final String endpointId;

public SendConfiguratorFromOne(ResponseDispatcher dispatcher, WebSocketMessageTransmitter transmitter,
JsonRpcFactory factory, String method, P pValue, String endpointId) {
SendConfiguratorFromOne(ResponseDispatcher dispatcher, WebSocketMessageTransmitter transmitter,
JsonRpcFactory factory, String method, P pValue, String endpointId) {
this.dispatcher = dispatcher;
this.transmitter = transmitter;
this.factory = factory;
Expand All @@ -57,7 +56,7 @@ public void sendAndSkipResult() {
LOG.debug("Transmitting request: " +
"endpoint ID: " + endpointId + ", " +
"method: " + method + ", " +
"params object class: " + pValue.getClass() + ", " +
(pValue != null ? "params object class: " + pValue.getClass() + ", " : "") +
"params list value" + pValue);

transmitNotification();
Expand All @@ -72,7 +71,7 @@ public <R> JsonRpcPromise<R> sendAndReceiveResultAsDto(final Class<R> rClass) {
"endpoint ID: " + endpointId + ", " +
"request ID: " + requestId + ", " +
"method: " + method + ", " +
"params object class: " + pValue.getClass() + ", " +
(pValue != null ? "params object class: " + pValue.getClass() + ", " : "") +
"params list value" + pValue + ", " +
"result object class: " + rClass);

Expand All @@ -87,7 +86,7 @@ public JsonRpcPromise<String> sendAndReceiveResultAsString() {
"endpoint ID: " + endpointId + ", " +
"request ID: " + requestId + ", " +
"method: " + method + ", " +
"params object class: " + pValue.getClass() + ", " +
(pValue != null ? "params object class: " + pValue.getClass() + ", " : "") +
"params list value" + pValue + ", " +
"result object class: " + String.class);

Expand All @@ -102,7 +101,7 @@ public JsonRpcPromise<Double> sendAndReceiveResultAsDouble() {
"endpoint ID: " + endpointId + ", " +
"request ID: " + requestId + ", " +
"method: " + method + ", " +
"params object class: " + pValue.getClass() + ", " +
(pValue != null ? "params object class: " + pValue.getClass() + ", " : "") +
"params list value" + pValue + ", " +
"result object class: " + Double.class);

Expand All @@ -117,7 +116,7 @@ public JsonRpcPromise<Boolean> sendAndReceiveResultAsBoolean() {
"endpoint ID: " + endpointId + ", " +
"request ID: " + requestId + ", " +
"method: " + method + ", " +
"params object class: " + pValue.getClass() + ", " +
(pValue != null ? "params object class: " + pValue.getClass() + ", " : "") +
"params list value" + pValue + ", " +
"result object class: " + Boolean.class);

Expand All @@ -133,7 +132,7 @@ public <R> JsonRpcPromise<List<R>> sendAndReceiveResultAsListOfDto(final Class<R
"endpoint ID: " + endpointId + ", " +
"request ID: " + requestId + ", " +
"method: " + method + ", " +
"params object class: " + pValue.getClass() + ", " +
(pValue != null ? "params object class: " + pValue.getClass() + ", " : "") +
"params list value" + pValue + ", " +
"result list items class: " + rClass);

Expand All @@ -148,7 +147,7 @@ public JsonRpcPromise<List<String>> sendAndReceiveResultAsListOfString() {
"endpoint ID: " + endpointId + ", " +
"request ID: " + requestId + ", " +
"method: " + method + ", " +
"params object class: " + pValue.getClass() + ", " +
(pValue != null ? "params object class: " + pValue.getClass() + ", " : "") +
"params list value" + pValue + ", " +
"result list items class: " + String.class);

Expand All @@ -162,7 +161,7 @@ public JsonRpcPromise<List<Boolean>> sendAndReceiveResultAsListOfBoolean() {
"endpoint ID: " + endpointId + ", " +
"request ID: " + requestId + ", " +
"method: " + method + ", " +
"params object class: " + pValue.getClass() + ", " +
(pValue != null ? "params object class: " + pValue.getClass() + ", " : "") +
"params list value" + pValue + ", " +
"result list items class: " + Boolean.class);

Expand All @@ -176,7 +175,7 @@ public JsonRpcPromise<Void> sendAndReceiveResultAsEmpty() {
"endpoint ID: " + endpointId + ", " +
"request ID: " + requestId + ", " +
"method: " + method + ", " +
"params object class: " + pValue.getClass() + ", " +
(pValue != null ? "params object class: " + pValue.getClass() + ", " : "") +
"params list value" + pValue + ", " +
"result list items class: " + Void.class);

Expand Down

0 comments on commit cbe2594

Please sign in to comment.