Changeset 278:1d296597c9a6 in finroc_tools_finstruct-java


Ignore:
Timestamp:
16.08.2019 18:39:13 (6 months ago)
Author:
Max Reichardt <max.reichardt@…>
Branch:
default
Phase:
public
Message:

Allows to create host-specific (inter-part) connectors in finstruct

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • SmartConnecting.java

    r268 r278  
    3131import java.util.Set; 
    3232 
     33import org.finroc.core.FrameworkElement; 
    3334import org.finroc.core.FrameworkElementFlags; 
    3435import org.finroc.core.datatype.DataTypeReference; 
     
    804805        return result; 
    805806    } 
     807 
     808    /** 
     809     * @param runtime Runtime to check 
     810     * @return Generic Protocol Runtime Object if provided runtime has such 
     811     */ 
     812    public static org.finroc.core.net.generic_protocol.RemoteRuntime getRuntimeElement(RemoteRuntime runtime) { 
     813        for (RemotePort port : runtime.getRemotePorts()) { 
     814            if (port.getPort() != null) { 
     815                FrameworkElement candidateRuntime = port.getPort().getParentWithFlags(FrameworkElementFlags.ALTERNATIVE_LINK_ROOT); 
     816                if (candidateRuntime instanceof org.finroc.core.net.generic_protocol.RemoteRuntime) { 
     817                    return (org.finroc.core.net.generic_protocol.RemoteRuntime)candidateRuntime; 
     818                } 
     819            } 
     820        } 
     821        return null; 
     822    } 
     823 
     824    /** 
     825     * @param runtime Runtime whose URI alternatives to obtain 
     826     * @param sourceRuntime Runtime from which to obtain URI alternatives 
     827     * @return List with alternatives for URI authorities to use 
     828     */ 
     829    public static List<String> getUriAuthorityAlternatives(RemoteRuntime runtime, RemoteRuntime sourceRuntime) { 
     830        org.finroc.core.net.generic_protocol.RemoteRuntime runtimeElement = getRuntimeElement(runtime); 
     831        org.finroc.core.net.generic_protocol.RemoteRuntime sourceRuntimeElement = getRuntimeElement(sourceRuntime); 
     832 
     833        if (runtimeElement != null) { 
     834            boolean sameHost = sourceRuntimeElement != null && runtimeElement.hasSameHost(sourceRuntimeElement); 
     835            return runtimeElement.getUriAuthorityAlternatives(sameHost); 
     836        } 
     837 
     838        ArrayList<String> result = new ArrayList<String>(); 
     839        result.add(runtime.uuid); 
     840        return result; 
     841    } 
    806842} 
  • actions/ConnectAction.java

    r262 r278  
    145145            } 
    146146 
     147            String host = null; 
     148            int port = -1; 
     149            try { 
     150                if (uriAuthority != null && uriAuthority.length() > 0) { 
     151                    if (uriAuthority.contains(":") && uriAuthority.lastIndexOf(":") == uriAuthority.indexOf(":")) { 
     152                        host = uriAuthority.substring(0, uriAuthority.lastIndexOf(":")); 
     153                        port = Integer.parseInt(uriAuthority.substring(uriAuthority.lastIndexOf(":") + 1)); 
     154                    } else { 
     155                        host = uriAuthority; 
     156                    } 
     157                } 
     158            } catch (Exception e) { 
     159                throw new Exception("Error parsing URI authority: " + uriAuthority); 
     160            } 
     161 
    147162            if (sourceRuntime.getAdminInterface() != null && destinationPort.getFlag(FrameworkElementFlags.SHARED)) { 
    148163                if (legacySourceRuntime && legacyDestinationRuntime) { 
    149164                    result = sourceRuntime.getAdminInterface().networkConnect(sourcePort, "", RemoteRuntime.find(destinationPort).uuid, destinationPort.getRemoteHandle(), destinationPort.getURI().getPath(), disconnect); 
    150165                } else if ((!disconnect) && (!legacySourceRuntime)) { 
    151                     URI uri = new URI("tcp", null, SmartConnecting.getUriPath(destinationPort), null); 
    152                     System.out.println(); 
     166                    URI uri = new URI("tcp", null, host, port, SmartConnecting.getUriPath(destinationPort), null, null); 
    153167                    org.finroc.core.net.generic_protocol.Definitions.setServerSideConversionOptions(connectOptions, destinationConnectOptions, serializedType); 
    154168                    result = sourceRuntime.getAdminInterface().createUriConnector(sourcePort, uri.normalize().toString(), connectOptions); 
     
    159173                    result = destinationRuntime.getAdminInterface().networkConnect(destinationPort, "", RemoteRuntime.find(sourcePort).uuid, sourcePort.getRemoteHandle(), sourcePort.getURI().getPath(), disconnect); 
    160174                } else if ((!disconnect) && (!legacyDestinationRuntime)) { 
    161                     URI uri = new URI("tcp", null, SmartConnecting.getUriPath(sourcePort), null); 
     175                    URI uri = new URI("tcp", null, host, port, SmartConnecting.getUriPath(sourcePort), null, null); 
    162176                    org.finroc.core.net.generic_protocol.Definitions.setServerSideConversionOptions(destinationConnectOptions, connectOptions, serializedType); 
    163177                    result = destinationRuntime.getAdminInterface().createUriConnector(destinationPort, uri.normalize().toString(), destinationConnectOptions); 
     
    266280     * @param serializedType Type serialized/sent over the network 
    267281     * @param destinationConnectOptions Connect options to be used in destination runtime 
    268      */ 
    269     public void setConnectOptions(RemoteConnectOptions sourceConnectOptions, String serializedType, RemoteConnectOptions destinationConnectOptions) { 
     282     * @param uriAuthority URI authority (host) to use in connection URI; null or "" for none 
     283     */ 
     284    public void setConnectOptions(RemoteConnectOptions sourceConnectOptions, String serializedType, RemoteConnectOptions destinationConnectOptions, String uriAuthority) { 
    270285        this.connectOptions = sourceConnectOptions; 
    271286        this.serializedType = serializedType; 
    272287        this.destinationConnectOptions = destinationConnectOptions; 
     288        this.uriAuthority = uriAuthority; 
    273289    } 
    274290 
     
    289305    private String serializedType; 
    290306 
     307    /** URI authority (host) to use in connection URI; null or "" for none */ 
     308    private String uriAuthority; 
    291309} 
  • dialogs/CreateConnectorOptionsDialog.java

    r266 r278  
    152152        flagPanel.add(schedulingNeutral); 
    153153        if (tcpConnectors) { 
     154 
     155            ArrayList<RemoteRuntime> runtimes = new ArrayList<RemoteRuntime>(); 
     156            for (CreateConnectActionBatch batch : actionBatches) { 
     157                if (!runtimes.contains(batch.sourceRuntime)) { 
     158                    runtimes.add(batch.sourceRuntime); 
     159                } 
     160                if (!runtimes.contains(batch.destinationRuntime)) { 
     161                    runtimes.add(batch.destinationRuntime); 
     162                } 
     163            } 
     164 
     165            if (runtimes.size() == 2) { 
     166                List<String> authorityOptions = SmartConnecting.getUriAuthorityAlternatives(actionBatches.get(0).destinationRuntime, actionBatches.get(0).sourceRuntime); 
     167                authorityOptions.add(0, ANY_URI_AUTHORITY); 
     168                JPanel host = new JPanel(); 
     169                host.setBorder(BorderFactory.createTitledBorder("<html>Host-specific Connector<br><small>(URI Authority)</small></html>")); 
     170                uriAuthority = new JComboBox<String>(authorityOptions.toArray(new String[] {})); 
     171                uriAuthority.setEditable(true); 
     172                host.add(uriAuthority); 
     173                flagPanel.add(host); 
     174            } 
     175 
     176 
    154177            JPanel minUpdate = new JPanel(); 
    155178            minUpdate.setBorder(BorderFactory.createTitledBorder("Min. Network Update Interval [ms]")); 
     
    344367                            action.setConnectOptions(options[0]); 
    345368                        } else if (options.length > 1) { 
    346                             action.setConnectOptions(options[0], batch.streamedType.getSelectedItem().toString(), options[1]); 
     369                            String authority = uriAuthority == null ? null : uriAuthority.getEditor().getItem().toString(); 
     370                            if ("".equals(authority) || ANY_URI_AUTHORITY.equals(authority)) { 
     371                                authority = null; 
     372                            } 
     373                            action.setConnectOptions(options[0], batch.streamedType.getSelectedItem().toString(), options[1], authority); 
    347374                        } else if (batch.tcpConnector) { 
    348375                            throw new RuntimeException("Should have 2 conversion options (programming error)"); 
     
    427454    private JTextField minNetworkUpdateInterval; 
    428455 
     456    /** Combo box for URI authority */ 
     457    private JComboBox<String> uriAuthority; 
     458 
    429459    /** Buttons at bottom */ 
    430460    private JButton create, cancel; 
    431461 
    432462    /** Whether creation of connectors was cancelled */ 
    433     private boolean cancelled; 
     463    private boolean cancelled = true; 
    434464 
    435465    /** UID */ 
    436466    private static final long serialVersionUID = 8309357653548834926L; 
    437467 
     468    /** String constant for any URI authority */ 
     469    private static final String ANY_URI_AUTHORITY = "<any host>"; 
    438470 
    439471    /** 
Note: See TracChangeset for help on using the changeset viewer.