Example usage for com.vaadin.server ClientConnector getConnectorId

List of usage examples for com.vaadin.server ClientConnector getConnectorId

Introduction

In this page you can find the example usage for com.vaadin.server ClientConnector getConnectorId.

Prototype

public String getConnectorId();

Source Link

Document

Returns the id for this connector.

Usage

From source file:eu.maxschuster.vaadin.jquery.JQueryObject.java

License:Apache License

public JQueryObject setSelector(ClientConnector connector) {
    this.getState().setSelector(connector.getConnectorId());
    this.getState().setConnector(true);
    return this;
}

From source file:org.ikasan.dashboard.ui.IkasanUI.java

License:BSD License

@Override
public ConnectorTracker getConnectorTracker() {
    if (this.tracker == null) {
        this.tracker = new ConnectorTracker(this) {

            @Override/*from ww  w  . ja  va 2s.  c om*/
            public void registerConnector(ClientConnector connector) {
                try {
                    if (super.getConnector(connector.getConnectorId()) == null) {
                        super.registerConnector(connector);
                    } else {
                        unregisterConnector(connector);
                        super.registerConnector(connector);
                    }
                } catch (RuntimeException e) {
                    logger.info("Failed connector: " + connector.getClass().getSimpleName());
                    throw e;
                }
            }

            /* (non-Javadoc)
             * @see com.vaadin.ui.ConnectorTracker#unregisterConnector(com.vaadin.server.ClientConnector)
             */
            @Override
            public void unregisterConnector(ClientConnector connector) {
                super.unregisterConnector(connector);
            }
        };
    }

    return tracker;
}

From source file:org.semanticsoft.vaaclipse.app.servlet.VaaclipseServerRpcHandler.java

License:Open Source License

private void handleInvocations(UI uI, int lastSyncIdSeenByClient, JSONArray invocationsData) {
    // TODO PUSH Refactor so that this is not needed
    LegacyCommunicationManager manager = uI.getSession().getCommunicationManager();

    try {/*from w  ww.j av a  2s  .  c  o m*/
        ConnectorTracker connectorTracker = uI.getConnectorTracker();

        Set<Connector> enabledConnectors = new HashSet<Connector>();

        List<MethodInvocation> invocations = parseInvocations(uI.getConnectorTracker(), invocationsData,
                lastSyncIdSeenByClient);
        for (MethodInvocation invocation : invocations) {
            final ClientConnector connector = connectorTracker.getConnector(invocation.getConnectorId());

            if (connector != null && connector.isConnectorEnabled()) {
                enabledConnectors.add(connector);
            }
        }

        for (int i = 0; i < invocations.size(); i++) {
            MethodInvocation invocation = invocations.get(i);

            final ClientConnector connector = connectorTracker.getConnector(invocation.getConnectorId());
            if (connector == null) {
                getLogger().log(Level.WARNING,
                        "Received RPC call for unknown connector with id {0} (tried to invoke {1}.{2})",
                        new Object[] { invocation.getConnectorId(), invocation.getInterfaceName(),
                                invocation.getMethodName() });
                continue;
            }

            if (!enabledConnectors.contains(connector)) {

                if (invocation instanceof LegacyChangeVariablesInvocation) {
                    LegacyChangeVariablesInvocation legacyInvocation = (LegacyChangeVariablesInvocation) invocation;
                    // TODO convert window close to a separate RPC call and
                    // handle above - not a variable change

                    // Handle special case where window-close is called
                    // after the window has been removed from the
                    // application or the application has closed
                    Map<String, Object> changes = legacyInvocation.getVariableChanges();
                    if (changes.size() == 1 && changes.containsKey("close")
                            && Boolean.TRUE.equals(changes.get("close"))) {
                        // Silently ignore this
                        continue;
                    }
                }

                // Connector is disabled, log a warning and move to the next
                getLogger().warning(getIgnoredDisabledError("RPC call", connector));
                continue;
            }
            // DragAndDropService has null UI
            if (connector.getUI() != null && connector.getUI().isClosing()) {
                String msg = "Ignoring RPC call for connector " + connector.getClass().getName();
                if (connector instanceof Component) {
                    String caption = ((Component) connector).getCaption();
                    if (caption != null) {
                        msg += ", caption=" + caption;
                    }
                }
                msg += " in closed UI";
                getLogger().warning(msg);
                continue;

            }

            if (invocation instanceof ServerRpcMethodInvocation) {
                try {
                    ServerRpcManager.applyInvocation(connector, (ServerRpcMethodInvocation) invocation);
                } catch (RpcInvocationException e) {
                    manager.handleConnectorRelatedException(connector, e);
                }
            } else {
                // All code below is for legacy variable changes
                LegacyChangeVariablesInvocation legacyInvocation = (LegacyChangeVariablesInvocation) invocation;
                Map<String, Object> changes = legacyInvocation.getVariableChanges();
                try {
                    if (connector instanceof VariableOwner) {
                        // The source parameter is never used anywhere
                        changeVariables(null, (VariableOwner) connector, changes);
                        executorService.exec();
                    } else {
                        throw new IllegalStateException("Received legacy variable change for "
                                + connector.getClass().getName() + " (" + connector.getConnectorId()
                                + ") which is not a VariableOwner. The client-side connector sent these legacy varaibles: "
                                + changes.keySet());
                    }
                } catch (Exception e) {
                    manager.handleConnectorRelatedException(connector, e);
                }
            }
        }
    } catch (JSONException e) {
        getLogger().warning("Unable to parse RPC call from the client: " + e.getMessage());
        throw new RuntimeException(e);
    }
}

From source file:org.semanticsoft.vaaclipse.app.servlet.VaadinOSGiCommunicationManager.java

License:Open Source License

public boolean handleBurst(VaadinRequest source, UI uI, final String burst) {

    updateThreadLocals();/*from   w  w  w. j a v a  2s.co m*/

    boolean success = true;
    try {
        Set<Connector> enabledConnectors = new HashSet<Connector>();

        List<MethodInvocation> invocations = _parseInvocations(uI.getConnectorTracker(), burst);
        for (MethodInvocation invocation : invocations) {
            final ClientConnector connector = getConnector(uI, invocation.getConnectorId());

            if (connector != null && connector.isConnectorEnabled()) {
                enabledConnectors.add(connector);
            }
        }

        for (int i = 0; i < invocations.size(); i++) {
            MethodInvocation invocation = invocations.get(i);

            final ClientConnector connector = getConnector(uI, invocation.getConnectorId());

            if (!enabledConnectors.contains(connector)) {

                if (invocation instanceof LegacyChangeVariablesInvocation) {
                    LegacyChangeVariablesInvocation legacyInvocation = (LegacyChangeVariablesInvocation) invocation;
                    // TODO convert window close to a separate RPC call and
                    // handle above - not a variable change

                    // Handle special case where window-close is called
                    // after the window has been removed from the
                    // application or the application has closed
                    Map<String, Object> changes = legacyInvocation.getVariableChanges();
                    if (changes.size() == 1 && changes.containsKey("close")
                            && Boolean.TRUE.equals(changes.get("close"))) {
                        // Silently ignore this
                        continue;
                    }
                }

                // Connector is disabled, log a warning and move to 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;
                    }
                }
                //getLogger().warning(msg);
                continue;
            }

            if (invocation instanceof ServerRpcMethodInvocation) {
                try {
                    ServerRpcManager.applyInvocation(connector, (ServerRpcMethodInvocation) invocation);
                    exec();
                } catch (RpcInvocationException e) {
                    handleConnectorRelatedException(connector, e);
                }
            } else {

                // All code below is for legacy variable changes
                LegacyChangeVariablesInvocation legacyInvocation = (LegacyChangeVariablesInvocation) invocation;
                Map<String, Object> changes = legacyInvocation.getVariableChanges();
                try {
                    if (connector instanceof VariableOwner) {
                        changeVariables(source, (VariableOwner) connector, changes);
                        exec();
                    } else {
                        throw new IllegalStateException("Received legacy variable change for "
                                + connector.getClass().getName() + " (" + connector.getConnectorId()
                                + ") which is not a VariableOwner. The client-side connector sent these legacy varaibles: "
                                + changes.keySet());
                    }
                } catch (Exception e) {
                    handleConnectorRelatedException(connector, e);
                }
            }
        }
    } catch (Exception e) {
        //            getLogger().warning(
        //                    "Unable to parse RPC call from the client: "
        //                            + e.getMessage());
        // TODO or return success = false?
        throw new RuntimeException(e);
    }

    return success;
}