]> source.dussan.org Git - vaadin-framework.git/commitdiff
Simplified RPC handling for client to server RPC
authorArtur <Artur@Storm>
Tue, 17 Apr 2012 19:26:43 +0000 (22:26 +0300)
committerArtur Signell <artur@vaadin.com>
Wed, 18 Apr 2012 20:09:00 +0000 (23:09 +0300)
Target connector validity (enabled) is checked for all RPC calls
ClientConnector is always an RpcTarget
Removed unused RpcManager.target

src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
src/com/vaadin/terminal/gwt/server/ClientConnector.java
src/com/vaadin/terminal/gwt/server/DragAndDropService.java
src/com/vaadin/terminal/gwt/server/ServerRpcManager.java
src/com/vaadin/ui/AbstractComponent.java
src/com/vaadin/ui/Component.java

index 87d147d55b5d862a2b4c2f032ac782e11a3a0fd3..31297c0c6ca6d3067fbedc3ba7b9a063f86842c7 100644 (file)
@@ -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<String, Object> m = new HashMap<String, Object>();
-                    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<String, Object> m = new HashMap<String, Object>();
+                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.
index cc4c1161a0e2a65429757445c817e95010ad423e..7a1f0fad685fd7a20e64e83f446b085f3b3b7ab9 100644 (file)
@@ -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.
index ca499d024d3586a7bbf7718108e7c1dac2a4507f..d3fe5a890ba5f5e91318e7bc9b4466b107d5e19f 100644 (file)
@@ -233,4 +233,9 @@ public class DragAndDropService implements VariableOwner, ClientConnector {
     public List<ClientMethodInvocation> retrievePendingRpcCalls() {
         return null;
     }
+
+    public RpcManager getRpcManager(Class<?> rpcInterface) {
+        // TODO Use rpc for drag'n'drop
+        return null;
+    }
 }
index cdab4b327fd9f838808200c1b07566d57d3e24bc..288e0bf9330f17fc94d54d475ade94ae7f0a6db1 100644 (file)
@@ -26,7 +26,6 @@ import com.vaadin.terminal.gwt.client.communication.MethodInvocation;
  */
 public class ServerRpcManager<T> implements RpcManager {
 
-    private final RpcTarget target;
     private final T implementation;
     private final Class<T> rpcInterface;
 
@@ -59,9 +58,7 @@ public class ServerRpcManager<T> implements RpcManager {
      * @param rpcInterface
      *            RPC interface type
      */
-    public ServerRpcManager(RpcTarget target, T implementation,
-            Class<T> rpcInterface) {
-        this.target = target;
+    public ServerRpcManager(T implementation, Class<T> rpcInterface) {
         this.implementation = implementation;
         this.rpcInterface = rpcInterface;
     }
@@ -99,15 +96,6 @@ public class ServerRpcManager<T> 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.
      * 
index 5ef7cfd242c3ddb9ffa5f84776f756b70f5874f1..cca0edc00139ab12398b700a6db1cefbbbc639b1 100644 (file)
@@ -1522,7 +1522,7 @@ public abstract class AbstractComponent implements Component, MethodEventSource
      *            registered
      */
     protected <T> void registerRpc(T implementation, Class<T> rpcInterfaceType) {
-        rpcManagerMap.put(rpcInterfaceType, new ServerRpcManager<T>(this,
+        rpcManagerMap.put(rpcInterfaceType, new ServerRpcManager<T>(
                 implementation, rpcInterfaceType));
     }
 
index eacf17b6a769a969cb3a2959667ef3fb2fb19845..3632c4ca5efa7a14ec80be961d9ab776f1c3e8ff 100644 (file)
@@ -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