From 52b072d77298bfaee84fc0c5206307fb183c6a85 Mon Sep 17 00:00:00 2001 From: Artur Date: Tue, 17 Apr 2012 22:26:43 +0300 Subject: [PATCH] Simplified RPC handling for client to server RPC Target connector validity (enabled) is checked for all RPC calls ClientConnector is always an RpcTarget Removed unused RpcManager.target --- .../server/AbstractCommunicationManager.java | 171 ++++++++---------- .../terminal/gwt/server/ClientConnector.java | 2 +- .../gwt/server/DragAndDropService.java | 5 + .../terminal/gwt/server/ServerRpcManager.java | 14 +- src/com/vaadin/ui/AbstractComponent.java | 2 +- src/com/vaadin/ui/Component.java | 4 +- 6 files changed, 84 insertions(+), 114 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index 87d147d55b..31297c0c6c 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -1448,88 +1448,95 @@ public abstract class AbstractCommunicationManager implements Serializable { final String interfaceName = invocation.getInterfaceName(); - if (!ApplicationConnection.UPDATE_VARIABLE_INTERFACE - .equals(interfaceName)) { - // handle other RPC calls than variable changes - applyInvocation(app, invocation); - continue; - } final ClientConnector connector = getConnector(app, invocation.getConnectorId()); - final VariableOwner owner = (VariableOwner) connector; - boolean connectorEnabled = (connector != null && connector - .isConnectorEnabled()); - - if (owner != null && connectorEnabled) { - VariableChange change = new VariableChange(invocation); - - // TODO could optimize with a single value map if only one - // change for a paintable - - Map m = new HashMap(); - m.put(change.getName(), change.getValue()); - while (nextInvocation != null - && invocation.getConnectorId().equals( - nextInvocation.getConnectorId()) - && ApplicationConnection.UPDATE_VARIABLE_METHOD - .equals(nextInvocation.getMethodName())) { - i++; - invocation = nextInvocation; - change = new VariableChange(invocation); - m.put(change.getName(), change.getValue()); - if (i + 1 < invocations.size()) { - nextInvocation = invocations.get(i + 1); - } else { - nextInvocation = null; - } - } + if (connector == null) { + logger.log( + Level.WARNING, + "RPC call to " + invocation.getInterfaceName() + + "." + invocation.getMethodName() + + " received for connector " + + invocation.getConnectorId() + + " but no such connector could be found"); + continue; + } - try { - changeVariables(source, owner, m); - } catch (Exception e) { - Component errorComponent = null; - if (owner instanceof Component) { - errorComponent = (Component) owner; - } else if (owner instanceof DragAndDropService) { - if (m.get("dhowner") instanceof Component) { - errorComponent = (Component) m.get("dhowner"); - } + if (!connector.isConnectorEnabled()) { + + if (ApplicationConnection.UPDATE_VARIABLE_INTERFACE + .equals(interfaceName)) { + // TODO convert window close to a separate RPC call and + // handle above - not a variable change + VariableChange change = new VariableChange(invocation); + + // Handle special case where window-close is called + // after the window has been removed from the + // application or the application has closed + if ("close".equals(change.getName()) + && Boolean.TRUE.equals(change.getValue())) { + // Silently ignore this + continue; } - handleChangeVariablesError(app, errorComponent, e, m); - } - } else { - // TODO convert window close to a separate RPC call and - // handle above - not a variable change - - VariableChange change = new VariableChange(invocation); - - // Handle special case where window-close is called - // after the window has been removed from the - // application or the application has closed - if ("close".equals(change.getName()) - && Boolean.TRUE.equals(change.getValue())) { - // Silently ignore this - continue; } - // Ignore variable change - String msg = "Warning: Ignoring RPC call for "; - if (owner != null) { - msg += "disabled component " + owner.getClass(); - String caption = ((Component) owner).getCaption(); + // Connector is disabled, log a warning and move the next + String msg = "Ignoring RPC call for disabled connector " + + connector.getClass().getName(); + if (connector instanceof Component) { + String caption = ((Component) connector).getCaption(); if (caption != null) { msg += ", caption=" + caption; } - } else { - msg += "non-existent component, VAR_PID=" - + invocation.getConnectorId(); - // TODO should this cause the message to be ignored? - success = false; } logger.warning(msg); continue; } + + if (!ApplicationConnection.UPDATE_VARIABLE_INTERFACE + .equals(interfaceName)) { + // handle other RPC calls than variable changes + ServerRpcManager.applyInvocation(connector, invocation); + continue; + } + + // All code below is for legacy variable changes + final VariableOwner owner = (VariableOwner) connector; + + VariableChange change = new VariableChange(invocation); + + Map m = new HashMap(); + m.put(change.getName(), change.getValue()); + while (nextInvocation != null + && invocation.getConnectorId().equals( + nextInvocation.getConnectorId()) + && ApplicationConnection.UPDATE_VARIABLE_METHOD + .equals(nextInvocation.getMethodName())) { + i++; + invocation = nextInvocation; + change = new VariableChange(invocation); + m.put(change.getName(), change.getValue()); + if (i + 1 < invocations.size()) { + nextInvocation = invocations.get(i + 1); + } else { + nextInvocation = null; + } + } + + try { + changeVariables(source, owner, m); + } catch (Exception e) { + Component errorComponent = null; + if (owner instanceof Component) { + errorComponent = (Component) owner; + } else if (owner instanceof DragAndDropService) { + if (m.get("dhowner") instanceof Component) { + errorComponent = (Component) m.get("dhowner"); + } + } + handleChangeVariablesError(app, errorComponent, e, m); + + } } } catch (JSONException e) { @@ -1542,34 +1549,6 @@ public abstract class AbstractCommunicationManager implements Serializable { return success; } - /** - * Execute an RPC call from the client by finding its target and letting the - * RPC mechanism call the correct method for it. - * - * @param app - * - * @param invocation - */ - protected void applyInvocation(Application app, MethodInvocation invocation) { - Connector c = app.getConnector(invocation.getConnectorId()); - if (c instanceof RpcTarget) { - ServerRpcManager.applyInvocation((RpcTarget) c, invocation); - } else if (c == null) { - logger.log( - Level.WARNING, - "RPC call " + invocation.getInterfaceName() + "." - + invocation.getMethodName() - + " received for connector id " - + invocation.getConnectorId() - + " but no such connector could be found"); - - } else { - logger.log(Level.WARNING, "RPC call received for connector " - + c.getClass().getName() + " (" + c.getConnectorId() - + ") but the connector is not a ServerRpcTarget"); - } - } - /** * Parse a message burst from the client into a list of MethodInvocation * instances. diff --git a/src/com/vaadin/terminal/gwt/server/ClientConnector.java b/src/com/vaadin/terminal/gwt/server/ClientConnector.java index cc4c1161a0..7a1f0fad68 100644 --- a/src/com/vaadin/terminal/gwt/server/ClientConnector.java +++ b/src/com/vaadin/terminal/gwt/server/ClientConnector.java @@ -16,7 +16,7 @@ import com.vaadin.terminal.gwt.client.Connector; * @since 7.0.0 * */ -public interface ClientConnector extends Connector { +public interface ClientConnector extends Connector, RpcTarget { /** * Returns the list of pending server to client RPC calls and clears the * list. diff --git a/src/com/vaadin/terminal/gwt/server/DragAndDropService.java b/src/com/vaadin/terminal/gwt/server/DragAndDropService.java index ca499d024d..d3fe5a890b 100644 --- a/src/com/vaadin/terminal/gwt/server/DragAndDropService.java +++ b/src/com/vaadin/terminal/gwt/server/DragAndDropService.java @@ -233,4 +233,9 @@ public class DragAndDropService implements VariableOwner, ClientConnector { public List retrievePendingRpcCalls() { return null; } + + public RpcManager getRpcManager(Class rpcInterface) { + // TODO Use rpc for drag'n'drop + return null; + } } diff --git a/src/com/vaadin/terminal/gwt/server/ServerRpcManager.java b/src/com/vaadin/terminal/gwt/server/ServerRpcManager.java index cdab4b327f..288e0bf933 100644 --- a/src/com/vaadin/terminal/gwt/server/ServerRpcManager.java +++ b/src/com/vaadin/terminal/gwt/server/ServerRpcManager.java @@ -26,7 +26,6 @@ import com.vaadin.terminal.gwt.client.communication.MethodInvocation; */ public class ServerRpcManager implements RpcManager { - private final RpcTarget target; private final T implementation; private final Class rpcInterface; @@ -59,9 +58,7 @@ public class ServerRpcManager implements RpcManager { * @param rpcInterface * RPC interface type */ - public ServerRpcManager(RpcTarget target, T implementation, - Class rpcInterface) { - this.target = target; + public ServerRpcManager(T implementation, Class rpcInterface) { this.implementation = implementation; this.rpcInterface = rpcInterface; } @@ -99,15 +96,6 @@ public class ServerRpcManager implements RpcManager { } } - /** - * Returns the RPC target of this RPC manager instance. - * - * @return RpcTarget, typically a {@link Connector} - */ - public RpcTarget getTarget() { - return target; - } - /** * Returns the RPC interface implementation for the RPC target. * diff --git a/src/com/vaadin/ui/AbstractComponent.java b/src/com/vaadin/ui/AbstractComponent.java index 5ef7cfd242..cca0edc001 100644 --- a/src/com/vaadin/ui/AbstractComponent.java +++ b/src/com/vaadin/ui/AbstractComponent.java @@ -1522,7 +1522,7 @@ public abstract class AbstractComponent implements Component, MethodEventSource * registered */ protected void registerRpc(T implementation, Class rpcInterfaceType) { - rpcManagerMap.put(rpcInterfaceType, new ServerRpcManager(this, + rpcManagerMap.put(rpcInterfaceType, new ServerRpcManager( implementation, rpcInterfaceType)); } diff --git a/src/com/vaadin/ui/Component.java b/src/com/vaadin/ui/Component.java index eacf17b6a7..3632c4ca5e 100644 --- a/src/com/vaadin/ui/Component.java +++ b/src/com/vaadin/ui/Component.java @@ -17,7 +17,6 @@ import com.vaadin.terminal.Sizeable; import com.vaadin.terminal.VariableOwner; import com.vaadin.terminal.gwt.client.ComponentState; import com.vaadin.terminal.gwt.server.ClientConnector; -import com.vaadin.terminal.gwt.server.RpcTarget; /** * {@code Component} is the top-level interface that is and must be implemented @@ -52,8 +51,7 @@ import com.vaadin.terminal.gwt.server.RpcTarget; * @VERSION@ * @since 3.0 */ -public interface Component extends ClientConnector, Sizeable, Serializable, - RpcTarget { +public interface Component extends ClientConnector, Sizeable, Serializable { /** * Gets all user-defined CSS style names of a component. If the component -- 2.39.5