Skip to content

Commit

Permalink
Some JSON RPC requests are not processed by RequestHandlerManage (ecl…
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmytro Kulieshov committed Sep 4, 2017
1 parent 47f2ae5 commit 1f27537
Show file tree
Hide file tree
Showing 17 changed files with 107 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,6 @@ public <R> FunctionConfiguratorManyToOne<P, R> resultAsDto(Class<R> rClass) {
return new FunctionConfiguratorManyToOne<>(requestHandlerManager, method, pClass, rClass);
}

public ConsumerConfiguratorManyToNone<P> resultAsEmpty() {
LOGGER.debug(
"Configuring incoming request result: method: "
+ method
+ ", result object class: "
+ Void.class);

return new ConsumerConfiguratorManyToNone<>(requestHandlerManager, method, pClass);
}

public FunctionConfiguratorManyToOne<P, String> resultAsString() {
LOGGER.debug(
"Configuring incoming request result: method: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public <R> FunctionConfiguratorOneToMany<P, R> resultAsListOfDto(Class<R> rClass
return new FunctionConfiguratorOneToMany<>(requestHandlerManager, method, pClass, rClass);
}

public FunctionConfiguratorOneToOne<P, String> resultAsDtoString() {
public FunctionConfiguratorOneToMany<P, String> resultAsListOfString() {
LOGGER.debug(
"Configuring incoming request result: "
+ "method: "
Expand All @@ -60,10 +60,10 @@ public FunctionConfiguratorOneToOne<P, String> resultAsDtoString() {
+ "result list items class: "
+ String.class);

return new FunctionConfiguratorOneToOne<>(requestHandlerManager, method, pClass, String.class);
return new FunctionConfiguratorOneToMany<>(requestHandlerManager, method, pClass, String.class);
}

public FunctionConfiguratorOneToOne<P, Double> resultAsDtoDouble() {
public FunctionConfiguratorOneToMany<P, Double> resultAsListOfDouble() {
LOGGER.debug(
"Configuring incoming request result: "
+ "method: "
Expand All @@ -72,10 +72,10 @@ public FunctionConfiguratorOneToOne<P, Double> resultAsDtoDouble() {
+ "result list items class: "
+ Double.class);

return new FunctionConfiguratorOneToOne<>(requestHandlerManager, method, pClass, Double.class);
return new FunctionConfiguratorOneToMany<>(requestHandlerManager, method, pClass, Double.class);
}

public FunctionConfiguratorOneToOne<P, Boolean> resultAsDtoBoolean() {
public FunctionConfiguratorOneToMany<P, Boolean> resultAsListOfBoolean() {
LOGGER.debug(
"Configuring incoming request result: "
+ "method: "
Expand All @@ -84,7 +84,8 @@ public FunctionConfiguratorOneToOne<P, Boolean> resultAsDtoBoolean() {
+ "result list items class: "
+ Boolean.class);

return new FunctionConfiguratorOneToOne<>(requestHandlerManager, method, pClass, Boolean.class);
return new FunctionConfiguratorOneToMany<>(
requestHandlerManager, method, pClass, Boolean.class);
}

public <R> FunctionConfiguratorOneToOne<P, R> resultAsDto(Class<R> rClass) {
Expand All @@ -101,18 +102,6 @@ public <R> FunctionConfiguratorOneToOne<P, R> resultAsDto(Class<R> rClass) {
return new FunctionConfiguratorOneToOne<>(requestHandlerManager, method, pClass, rClass);
}

public FunctionConfiguratorOneToOne<P, Void> resultAsEmpty() {
LOGGER.debug(
"Configuring incoming request result: "
+ "method: "
+ method
+ ", "
+ "result object class: "
+ Void.class);

return new FunctionConfiguratorOneToOne<>(requestHandlerManager, method, pClass, Void.class);
}

public FunctionConfiguratorOneToOne<P, String> resultAsString() {
LOGGER.debug(
"Configuring incoming request result: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,37 @@ public JsonRpcPromise<Boolean> sendAndReceiveResultAsBoolean(int timeoutInMillis
endpointId, requestId, Boolean.class, timeoutInMillis);
}

public JsonRpcPromise<Double> sendAndReceiveResultAsDouble() {
return sendAndReceiveResultAsDouble(0);
}

public JsonRpcPromise<Double> sendAndReceiveResultAsDouble(int timeoutInMillis) {
final String requestId = transmitRequest();

LOGGER.debug(
"Transmitting request: "
+ "endpoint ID: "
+ endpointId
+ ", "
+ "request ID: "
+ requestId
+ ", "
+ "method: "
+ method
+ ", "
+ "params list items class: "
+ pListValue.iterator().next().getClass()
+ ", "
+ "params list value"
+ pListValue
+ ", "
+ "result object class: "
+ Double.class);

return dispatcher.registerPromiseForSingleObject(
endpointId, requestId, Double.class, timeoutInMillis);
}

public <R> JsonRpcPromise<List<R>> sendAndReceiveResultAsListOfDto(Class<R> rClass) {
return sendAndReceiveResultAsListOfDto(rClass, 0);
}
Expand Down Expand Up @@ -265,11 +296,11 @@ public JsonRpcPromise<List<Boolean>> sendAndReceiveResultAsListOfBoolean(int tim
endpointId, requestId, Boolean.class, timeoutInMillis);
}

public JsonRpcPromise<Void> sendAndReceiveResultAsEmpty() {
return sendAndReceiveResultAsEmpty(0);
public JsonRpcPromise<List<Double>> sendAndReceiveResultAsListOfDouble() {
return sendAndReceiveResultAsListOfDouble(0);
}

public JsonRpcPromise<Void> sendAndReceiveResultAsEmpty(int timeoutInMillis) {
public JsonRpcPromise<List<Double>> sendAndReceiveResultAsListOfDouble(int timeoutInMillis) {
final String requestId = transmitRequest();

LOGGER.debug(
Expand All @@ -289,11 +320,11 @@ public JsonRpcPromise<Void> sendAndReceiveResultAsEmpty(int timeoutInMillis) {
+ "params list value"
+ pListValue
+ ", "
+ "result object class: "
+ Void.class);
+ "result list items class: "
+ Double.class);

return dispatcher.registerPromiseForSingleObject(
endpointId, requestId, Void.class, timeoutInMillis);
return dispatcher.registerPromiseForListOfObjects(
endpointId, requestId, Double.class, timeoutInMillis);
}

private void transmitNotification() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,11 @@ public JsonRpcPromise<List<Boolean>> sendAndReceiveResultAsListOfBoolean(int tim
endpointId, requestId, Boolean.class, timeInMillis);
}

public JsonRpcPromise<Void> sendAndReceiveResultAsEmpty() {
return sendAndReceiveResultAsEmpty(0);
public JsonRpcPromise<List<Double>> sendAndReceiveResultAsListOfDouble() {
return sendAndReceiveResultAsListOfDouble(0);
}

public JsonRpcPromise<Void> sendAndReceiveResultAsEmpty(int timeInMillis) {
public JsonRpcPromise<List<Double>> sendAndReceiveResultAsListOfDouble(int timeInMillis) {
final String requestId = transmitRequest();

LOGGER.debug(
Expand All @@ -254,10 +254,10 @@ public JsonRpcPromise<Void> sendAndReceiveResultAsEmpty(int timeInMillis) {
+ method
+ ", "
+ "result list items class: "
+ Void.class);
+ Double.class);

return dispatcher.registerPromiseForSingleObject(
endpointId, requestId, Void.class, timeInMillis);
return dispatcher.registerPromiseForListOfObjects(
endpointId, requestId, Double.class, timeInMillis);
}

private void transmitNotification() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,11 @@ public JsonRpcPromise<List<Boolean>> sendAndReceiveResultAsListOfBoolean(int tim
endpointId, requestId, Boolean.class, timeoutInMillis);
}

public JsonRpcPromise<Void> sendAndReceiveResultAsEmpty() {
return sendAndReceiveResultAsEmpty(0);
public JsonRpcPromise<List<Double>> sendAndReceiveResultAsListOfDouble() {
return sendAndReceiveResultAsListOfDouble(0);
}

public JsonRpcPromise<Void> sendAndReceiveResultAsEmpty(int timeoutInMillis) {
public JsonRpcPromise<List<Double>> sendAndReceiveResultAsListOfDouble(int timeoutInMillis) {
final String requestId = transmitRequest();

LOGGER.debug(
Expand All @@ -304,10 +304,10 @@ public JsonRpcPromise<Void> sendAndReceiveResultAsEmpty(int timeoutInMillis) {
+ pValue
+ ", "
+ "result list items class: "
+ Void.class);
+ Double.class);

return dispatcher.registerPromiseForSingleObject(
endpointId, requestId, Void.class, timeoutInMillis);
return dispatcher.registerPromiseForListOfObjects(
endpointId, requestId, Double.class, timeoutInMillis);
}

private void transmitNotification() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,32 @@ public interface ClientServerEventService {
*
* @param path the path to the specific file
*/
Promise<Void> sendFileTrackingStartEvent(String path);
Promise<Boolean> sendFileTrackingStartEvent(String path);

/**
* Sends event on server side which tells to stop tracking specific file
*
* @param path the path to the specific file
*/
Promise<Void> sendFileTrackingStopEvent(String path);
Promise<Boolean> sendFileTrackingStopEvent(String path);

/**
* Sends event on server side which tells to suspend tracking all files registered for specific
* endpoint
*/
Promise<Void> sendFileTrackingSuspendEvent();
Promise<Boolean> sendFileTrackingSuspendEvent();

/**
* Sends event on server side which tells to resume tracking all files registered for specific
* endpoint
*/
Promise<Void> sendFileTrackingResumeEvent();
Promise<Boolean> sendFileTrackingResumeEvent();

/**
* Sends event on server side which tells file that is being tracked should be moved (renamed)
*
* @param oldPath the old path to the specific file
* @param newPath the new path to the specific file
*/
Promise<Void> sendFileTrackingMoveEvent(String oldPath, String newPath);
Promise<Boolean> sendFileTrackingMoveEvent(String oldPath, String newPath);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.google.gwt.user.client.rpc.AsyncCallback;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.eclipse.che.api.core.jsonrpc.commons.JsonRpcPromise;
import org.eclipse.che.api.core.jsonrpc.commons.RequestTransmitter;
import org.eclipse.che.api.project.shared.dto.event.FileTrackingOperationDto;
import org.eclipse.che.api.promises.client.Promise;
Expand All @@ -29,6 +28,7 @@
/** @author Roman Nikitenko */
@Singleton
public class ClientServerEventServiceImpl implements ClientServerEventService {

private static final String ENDPOINT_ID = "ws-agent";
private static final String OUTCOMING_METHOD = "track:editor-file";

Expand All @@ -45,55 +45,48 @@ public ClientServerEventServiceImpl(
}

@Override
public Promise<Void> sendFileTrackingStartEvent(String path) {
public Promise<Boolean> sendFileTrackingStartEvent(String path) {
return transmit(path, "", START);
}

@Override
public Promise<Void> sendFileTrackingStopEvent(String path) {
public Promise<Boolean> sendFileTrackingStopEvent(String path) {
return transmit(path, "", STOP);
}

@Override
public Promise<Void> sendFileTrackingSuspendEvent() {
public Promise<Boolean> sendFileTrackingSuspendEvent() {
return transmit("", "", SUSPEND);
}

@Override
public Promise<Void> sendFileTrackingResumeEvent() {
public Promise<Boolean> sendFileTrackingResumeEvent() {
return transmit("", "", RESUME);
}

@Override
public Promise<Void> sendFileTrackingMoveEvent(String oldPath, String newPath) {
public Promise<Boolean> sendFileTrackingMoveEvent(String oldPath, String newPath) {
return transmit(oldPath, newPath, MOVE);
}

private Promise<Void> transmit(String path, String oldPath, FileTrackingOperationDto.Type type) {
private Promise<Boolean> transmit(
String path, String oldPath, FileTrackingOperationDto.Type type) {
final FileTrackingOperationDto dto =
dtoFactory
.createDto(FileTrackingOperationDto.class)
.withPath(path)
.withType(type)
.withOldPath(oldPath);
return promises.create(
(AsyncCallback<Void> callback) -> {
JsonRpcPromise<Void> jsonRpcPromise =
requestTransmitter
.newRequest()
.endpointId(ENDPOINT_ID)
.methodName(OUTCOMING_METHOD)
.paramsAsDto(dto)
.sendAndReceiveResultAsEmpty();
jsonRpcPromise.onSuccess(
aVoid -> {
callback.onSuccess(null);
});

jsonRpcPromise.onFailure(
jsonRpcError -> {
callback.onFailure(new Throwable(jsonRpcError.getMessage()));
});
});
return promises.create(
(AsyncCallback<Boolean> callback) ->
requestTransmitter
.newRequest()
.endpointId(ENDPOINT_ID)
.methodName(OUTCOMING_METHOD)
.paramsAsDto(dto)
.sendAndReceiveResultAsBoolean()
.onSuccess(callback::onSuccess)
.onFailure(error -> callback.onFailure(new Throwable(error.getMessage()))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ private void synchronizeWorkingCopy(String filePath, String projectPath) {
editorWorkingCopySynchronizer
.synchronize(filePath, projectPath, region)
.onSuccess(
aVoid -> {
() -> {
syncLock = false;
synchronizeWorkingCopy(filePath, projectPath);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ public interface EditorWorkingCopySynchronizer {
* @param projectPath the path to the project which contains the file to sync
* @param dirtyRegion describes a document range which has been changed
*/
JsonRpcPromise<Void> synchronize(String filePath, String projectPath, DirtyRegion dirtyRegion);
JsonRpcPromise<Boolean> synchronize(String filePath, String projectPath, DirtyRegion dirtyRegion);
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void configureHandler(RequestHandlerConfigurator configurator) {
.withConsumer(this::onError);
}

public JsonRpcPromise<Void> synchronize(
public JsonRpcPromise<Boolean> synchronize(
String filePath, String projectPath, DirtyRegion dirtyRegion) {
Type type = dirtyRegion.getType().equals(DirtyRegion.INSERT) ? INSERT : REMOVE;
EditorChangesDto changes =
Expand All @@ -81,7 +81,7 @@ public JsonRpcPromise<Void> synchronize(
.endpointId(ENDPOINT_ID)
.methodName(EDITOR_CONTENT_CHANGES_METHOD)
.paramsAsDto(changes)
.sendAndReceiveResultAsEmpty();
.sendAndReceiveResultAsBoolean();
}

private void onError(ServerError error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ public class OrganizeImportsPresenterTest {
@Mock private Promise<OrganizeImportResult> importsPromise;
@Mock private Promise<List<Change>> resolveConflictsPromise;
@Mock private Promise<String> contentPromise;
@Mock private Promise<Void> fileTrackingSuspendEventPromise;
@Mock private Promise<Boolean> fileTrackingSuspendEventPromise;
@Mock private OrganizeImportResult organizeImportResult;
@Mock private Change change;

@Captor private ArgumentCaptor<Operation<OrganizeImportResult>> importsOperation;
@Captor private ArgumentCaptor<Operation<List<Change>>> resolveConflictsOperation;
@Captor private ArgumentCaptor<Operation<String>> contentCaptor;
@Captor private ArgumentCaptor<Operation<Void>> clientServerSuspendOperation;
@Captor private ArgumentCaptor<Operation<Boolean>> clientServerSuspendOperation;

private ConflictImportDTO conflict1;
private ConflictImportDTO conflict2;
Expand All @@ -103,7 +103,7 @@ public void setUp() throws Exception {

when(clientServerEventService.sendFileTrackingSuspendEvent())
.thenReturn(fileTrackingSuspendEventPromise);
when(fileTrackingSuspendEventPromise.then(Matchers.<Operation<Void>>anyObject()))
when(fileTrackingSuspendEventPromise.then(Matchers.<Operation<Boolean>>anyObject()))
.thenReturn(fileTrackingSuspendEventPromise);

when(javaCodeAssistClient.organizeImports(anyString(), anyString())).thenReturn(importsPromise);
Expand Down
Loading

0 comments on commit 1f27537

Please sign in to comment.