summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorArtur <Artur@Storm>2012-04-17 22:26:43 +0300
committerArtur Signell <artur@vaadin.com>2012-04-18 23:09:00 +0300
commit52b072d77298bfaee84fc0c5206307fb183c6a85 (patch)
tree1389cebbc393c3213660e6ec5637ed7576a98260 /src
parent34d262dc610d066f1074a96c45d2ab2b9609ab14 (diff)
downloadvaadin-framework-52b072d77298bfaee84fc0c5206307fb183c6a85.tar.gz
vaadin-framework-52b072d77298bfaee84fc0c5206307fb183c6a85.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java171
-rw-r--r--src/com/vaadin/terminal/gwt/server/ClientConnector.java2
-rw-r--r--src/com/vaadin/terminal/gwt/server/DragAndDropService.java5
-rw-r--r--src/com/vaadin/terminal/gwt/server/ServerRpcManager.java14
-rw-r--r--src/com/vaadin/ui/AbstractComponent.java2
-rw-r--r--src/com/vaadin/ui/Component.java4
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<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) {
@@ -1543,34 +1550,6 @@ public abstract class AbstractCommunicationManager implements Serializable {
}
/**
- * 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<ClientMethodInvocation> 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<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;
}
@@ -100,15 +97,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.
*
* @return RPC interface implementation
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 <T> void registerRpc(T implementation, Class<T> rpcInterfaceType) {
- rpcManagerMap.put(rpcInterfaceType, new ServerRpcManager<T>(this,
+ rpcManagerMap.put(rpcInterfaceType, new ServerRpcManager<T>(
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