下面列出了怎么用org.eclipse.lsp4j.jsonrpc.messages.CancelParams的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Cancellation is handled inside this class and not forwarded to the local endpoint.
*
* @return {@code true} if the given message is a cancellation notification,
* {@code false} if it can be handled by the local endpoint
*/
protected boolean handleCancellation(NotificationMessage notificationMessage) {
if (MessageJsonHandler.CANCEL_METHOD.getMethodName().equals(notificationMessage.getMethod())) {
Object cancelParams = notificationMessage.getParams();
if (cancelParams != null) {
if (cancelParams instanceof CancelParams) {
synchronized (receivedRequestMap) {
String id = ((CancelParams) cancelParams).getId();
CompletableFuture<?> future = receivedRequestMap.get(id);
if (future != null)
future.cancel(true);
else
LOG.warning("Unmatched cancel notification for request id " + id);
}
return true;
} else {
LOG.warning("Cancellation support is disabled, since the '" + MessageJsonHandler.CANCEL_METHOD.getMethodName() + "' method has been registered explicitly.");
}
} else {
LOG.warning("Missing 'params' attribute of cancel notification.");
}
}
return false;
}
@Override
protected boolean handleCancellation(NotificationMessage notificationMessage) {
if (MessageJsonHandler.CANCEL_METHOD.getMethodName().equals(notificationMessage.getMethod())) {
Object cancelParams = notificationMessage.getParams();
if (cancelParams != null) {
if (cancelParams instanceof CancelParams) {
String id = ((CancelParams) cancelParams).getId();
LOG.debug("Client cancels: " + id);
CompletableFuture<?> future;
synchronized (receivedRequestMap) {
future = receivedRequestMap.remove(id);
}
if (future != null)
future.cancel(true);
else
LOG.debug("Unmatched cancel notification for request id " + id);
return true;
} else {
LOG.warn("Cancellation support is disabled, since the '"
+ MessageJsonHandler.CANCEL_METHOD.getMethodName()
+ "' method has been registered explicitly.");
}
} else {
LOG.warn("Missing 'params' attribute of cancel notification.");
}
}
return false;
}
protected void sendCancelNotification(Either<String, Number> id) {
CancelParams cancelParams = new CancelParams();
cancelParams.setRawId(id);
notify(MessageJsonHandler.CANCEL_METHOD.getMethodName(), cancelParams);
}
@Override
public void cancelRequest(CancelParams params) {
}
void cancelRequest(CancelParams params);