/** * The execution function. Executes a server side command. * * @param command * The command to be executed. This command is a wrapper around the actual request object. * @param callback * A <code>CommandCallback</code> function to be executed when the command successfully returns. The * callbacks may implement CommunicationExceptionCallback or CommandExceptionCallback to allow error * handling. * @return deferred object which can be used to add extra callbacks */ public Deferred execute(final GwtCommand command, final CommandCallback... callback) { final Deferred deferred = new Deferred(); for (CommandCallback successCallback : callback) { try { deferred.addCallback(successCallback); } catch (Throwable t) { Log.logError("Command failed on success callback", t); } } return execute(command, deferred); }
@Override public void cancel() { if (deferred != null) { deferred.cancel(); deferred = null; currentTileBounds = null; } }
public static void getVectorCapabilities(final Map<String, String> connectionProps, final DataCallback<List<VectorCapabilitiesInfo>> onFinish, final DataCallback<String> onError) { GetGeotoolsVectorCapabilitiesRequest request = new GetGeotoolsVectorCapabilitiesRequest(); request.setConnectionProperties(connectionProps); GwtCommand command = new GwtCommand(GetGeotoolsVectorCapabilitiesRequest.COMMAND); command.setCommandRequest(request); Deferred def = GwtCommandDispatcher.getInstance().execute(command, new CommandCallback<GetGeotoolsVectorCapabilitiesResponse>() { public void execute(GetGeotoolsVectorCapabilitiesResponse response) { if (onFinish != null) { onFinish.execute(response.getVectorCapabilities()); } } }); def.addCallback(new AbstractCommandCallback<CommandResponse>() { public void execute(CommandResponse response) { } public void onCommandException(CommandResponse response) { if (onError != null && response.getErrorMessages().size() > 0) { onError.execute(response.getErrorMessages().get(0)); } } }); }
public void onSuccess(CommandResponse response) { try { if (response.isError()) { handleError(response); } else { if (!deferred.isCancelled()) { for (CommandCallback callback : deferred.getCallbacks()) { try { callback.execute(response); } catch (Throwable t) { Log.logError("Command failed on success callback", t); } } } } } catch (Throwable t) { Log.logError("Command failed on success callback", t); } finally { decrementDispatched(); deferreds.remove(deferred); } }
public void onFailure(Throwable error) { try { boolean errorHandled = false; for (CommandCallback<?> callback : deferred.getCallbacks()) { if (callback instanceof CommunicationExceptionCallback) { try { ((CommunicationExceptionCallback) callback).onCommunicationException(error); } catch (Throwable t) { Log.logError("Command failed on error callback", t); } errorHandled = true; } } if (!errorHandled && deferred.isLogCommunicationExceptions()) { onCommunicationException(error); } } catch (Throwable t) { if (deferred.isLogCommunicationExceptions()) { Log.logError("Command failed on error callback", t); } } finally { decrementDispatched(); deferreds.remove(deferred); } }
/** * Log a message in the server log. * * @param logLevel log level * @param message message to log * @param throwable exception to include in message */ public static void logServer(int logLevel, String message, Throwable throwable) { String logMessage = message; if (null == logMessage) { logMessage = ""; } if (null != throwable) { logMessage += "\n" + getMessage(throwable); } LogRequest logRequest = new LogRequest(); logRequest.setLevel(logLevel); logRequest.setStatement(logMessage); GwtCommand command = new GwtCommand(LogRequest.COMMAND); command.setCommandRequest(logRequest); Deferred deferred = new Deferred(); deferred.setLogCommunicationExceptions(false); GwtCommandDispatcher.getInstance().execute(command, deferred); }
public void execute(GetVectorTileResponse response) { if (!(deferred != null && deferred.isCancelled())) { VectorTile tile = response.getTile(); for (TileCode relatedTile : tile.getCodes()) { siblings.add(relatedTile); } if (tile.getContentType() == VectorTileContentType.STRING_CONTENT) { // TODO implement me or throw an exception. Do something damnit! // display = new VectorTileObject(); // display.setContent(tile.getFeatureContent()); // renderer.getVectorContainer().add((VectorTileObject) display); } else { Coordinate position = getTilePosition(); display = new RasterTileObject(tile.getFeatureContent(), tile.getScreenWidth(), tile .getScreenHeight(), (int) Math.round(position.getY()), (int) Math.round(position.getX()), onRendered); // We don't want to fetch the images twice... //display.setContent(tile.getFeatureContent()); renderer.getHtmlContainer().add((RasterTileObject) display); } if (renderSiblings) { renderSiblings(); } } } });
for (CommandCallback callback : deferred.getCallbacks()) { if (callback instanceof CommandExceptionCallback) { try {
public static void getRasterCapabilities(final Map<String, String> connectionProps, final DataCallback<List<RasterCapabilitiesInfo>> onFinish, final DataCallback<String> onError) { GetWmsCapabilitiesRequest request = new GetWmsCapabilitiesRequest(); request.setConnectionProperties(connectionProps); GwtCommand command = new GwtCommand(GetWmsCapabilitiesRequest.COMMAND); command.setCommandRequest(request); Deferred def = GwtCommandDispatcher.getInstance().execute(command, new CommandCallback<GetWmsCapabilitiesResponse>() { public void execute(GetWmsCapabilitiesResponse response) { if (onFinish != null) { onFinish.execute(response.getRasterCapabilities()); } } }); def.addCallback(new AbstractCommandCallback<CommandResponse>() { public void execute(CommandResponse response) { } public void onCommandException(CommandResponse response) { if (onError != null && response.getErrorMessages().size() > 0) { onError.execute(response.getErrorMessages().get(0)); } } }); }
@Override public void cancel() { // Perhaps we where busy fetching the correct tiles? if (deferred != null) { deferred.cancel(); deferred = null; } // Perhaps we where busy rendering the tiles? }
public static void getVectorLayerConfiguration(final Map<String, String> connectionProps, String layerTypeName, final DataCallback<DynamicVectorLayerConfiguration> onFinish, final DataCallback<String> onError) { GetVectorLayerConfigRequest request = new GetVectorLayerConfigRequest(); request.setConnectionProperties(connectionProps); request.setLayerName(layerTypeName); GwtCommand command = new GwtCommand(GetVectorLayerConfigRequest.COMMAND); command.setCommandRequest(request); Deferred def = GwtCommandDispatcher.getInstance().execute(command, new CommandCallback<GetVectorLayerConfigResponse>() { public void execute(GetVectorLayerConfigResponse response) { if (onFinish != null) { onFinish.execute(response.getVectorLayerConfiguration()); } } }); def.addCallback(new AbstractCommandCallback<CommandResponse>() { public void execute(CommandResponse response) { } public void onCommandException(CommandResponse response) { if (onError != null && response.getErrorMessages().size() > 0) { onError.execute(response.getErrorMessages().get(0)); } } }); }
/** Cancel the fetching of this tile. No call-back will be executed anymore. */ public void cancel() { if (deferred != null) { deferred.cancel(); } }
def.addCallback(new AbstractCommandCallback<CommandResponse>() {
public void onWindowClosing(ClosingEvent event) { GwtCommandDispatcher.getInstance().setShowError(false); // Cancel all outstanding requests: for (Deferred deferred : deferreds) { deferred.cancel(); } } });