@Override public Connection getConnection ( final MasterServer master ) { return Locator.findConnection ( master, name, DataAccessConnection.class ); } } );
public static <T extends Exporter> T findExporter ( final EObject start, final Class<T> clazz ) { final List<T> result = findExporters ( start, clazz ); if ( result.isEmpty () ) { throw new IllegalStateException ( String.format ( "There must be exactly one exporter of type %s. There is none.", clazz.getName () ) ); } if ( result.size () > 1 ) { throw new IllegalStateException ( String.format ( "There must be exactly one exporter of type %s. There are %s.", clazz.getName (), result.size () ) ); } return result.get ( 0 ); }
private DataAccessConnection findConnection ( final Item item ) { return Locator.findPossibleConnection ( this.app, (EquinoxApplication)item.eContainer (), DataAccessConnection.class ); }
private String makeUri ( final MasterServer from, final NamedDocumentable remote ) { final MasterServer to = Locator.findApplication ( remote, MasterServer.class ); if ( to == null ) { throw new IllegalStateException ( String.format ( "No master server found for pool %s", remote.getName () ) ); } final AlarmsEventsConnection connection = Locator.findPossibleConnection ( from, to, AlarmsEventsConnection.class ); return connection.getName () + "#" + Names.makeName ( remote ); } }
@Override public void setMaster ( final SourceItem item, final MasterContext master ) { Helper.setSourceConnectionFromEndpoints ( item, master.getImplementation (), Locator.getSelfEndpoints ( master.getImplementation () ) ); } } );
/** * Find all connections of the give type from master server <q>from</q> to * master server <q>to</q> */ public static <T extends Connection> List<T> findPossibleConnections ( final EquinoxApplication from, final EquinoxApplication to, final Class<T> clazz ) { final List<T> result = new LinkedList<> (); for ( final T connection : findConnections ( from, clazz ) ) { for ( final Exporter exporter : to.getExporter () ) { final EList<Endpoint> possibleEndpoints = connection.getPossibleEndpoints ( exporter ); if ( possibleEndpoints.isEmpty () ) { continue; } if ( possibleEndpoints.contains ( connection.getEndpoint () ) ) { result.add ( connection ); } } } return result; }
/** * Find exactly one connection between two master servers * <p> * Calls {@link #findPossibleConnections(MasterServer, MasterServer, Class)} * but fails if the result is not equal to * <q>one</q> exactly. * </p> */ public static <T extends Connection> T findPossibleConnection ( final EquinoxApplication from, final EquinoxApplication to, final Class<T> clazz ) { final List<T> result = findPossibleConnections ( from, to, clazz ); if ( result.isEmpty () ) { throw new IllegalStateException ( String.format ( "There must be exactly one connection of type %s. There is none.", clazz.getName () ) ); } if ( result.size () > 1 ) { throw new IllegalStateException ( String.format ( "There must be exactly one connection of type %s. There are %s.", clazz.getName (), result.size () ) ); } return result.get ( 0 ); }
@Override protected Collection<?> getComboBoxObjects ( final Object object ) { if ( ! ( object instanceof Exporter ) ) { return Collections.emptyList (); } return Locator.findLocalEndpoints ( (Exporter)object ); } };
private String makeUri ( final MasterServer from, final NamedDocumentable remote ) { final MasterServer to = Locator.findApplication ( remote, MasterServer.class ); if ( to == null ) { throw new IllegalStateException ( String.format ( "No master server found for pool %s", remote.getName () ) ); } final AlarmsEventsConnection connection = Locator.findPossibleConnection ( from, to, AlarmsEventsConnection.class ); return connection.getName () + "#" + Names.makeName ( remote ); } }
@Override public void setMaster ( final SourceItem item, final MasterContext master ) { Helper.setSourceConnectionFromEndpoints ( item, master.getImplementation (), Locator.getSelfEndpoints ( master.getImplementation () ) ); } } );
/** * Find all connections of the give type from master server <q>from</q> to * master server <q>to</q> */ public static <T extends Connection> List<T> findPossibleConnections ( final EquinoxApplication from, final EquinoxApplication to, final Class<T> clazz ) { final List<T> result = new LinkedList<> (); for ( final T connection : findConnections ( from, clazz ) ) { for ( final Exporter exporter : to.getExporter () ) { final EList<Endpoint> possibleEndpoints = connection.getPossibleEndpoints ( exporter ); if ( possibleEndpoints.isEmpty () ) { continue; } if ( possibleEndpoints.contains ( connection.getEndpoint () ) ) { result.add ( connection ); } } } return result; }
/** * Find exactly one connection between two master servers * <p> * Calls {@link #findPossibleConnections(MasterServer, MasterServer, Class)} * but fails if the result is not equal to * <q>one</q> exactly. * </p> */ public static <T extends Connection> T findPossibleConnection ( final EquinoxApplication from, final EquinoxApplication to, final Class<T> clazz ) { final List<T> result = findPossibleConnections ( from, to, clazz ); if ( result.isEmpty () ) { throw new IllegalStateException ( String.format ( "There must be exactly one connection of type %s. There is none.", clazz.getName () ) ); } if ( result.size () > 1 ) { throw new IllegalStateException ( String.format ( "There must be exactly one connection of type %s. There are %s.", clazz.getName (), result.size () ) ); } return result.get ( 0 ); }
@Override public Connection getConnection ( final MasterServer master ) { return Locator.findConnection ( master, name, DataAccessConnection.class ); } } );
@Override public void setMaster ( final SourceItem item, final MasterContext master ) { final List<Endpoint> endpoints = Locator.getSelfEndpoints ( master.getImplementation () ); Helper.setSourceConnectionFromEndpoints ( item, master.getImplementation (), endpoints ); } } );
public static <T extends Exporter> T findExporter ( final EObject start, final Class<T> clazz ) { final List<T> result = findExporters ( start, clazz ); if ( result.isEmpty () ) { throw new IllegalStateException ( String.format ( "There must be exactly one exporter of type %s. There is none.", clazz.getName () ) ); } if ( result.size () > 1 ) { throw new IllegalStateException ( String.format ( "There must be exactly one exporter of type %s. There are %s.", clazz.getName (), result.size () ) ); } return result.get ( 0 ); }
private DataAccessConnection findConnection ( final Item item ) { return Locator.findPossibleConnection ( this.app, (EquinoxApplication)item.eContainer (), DataAccessConnection.class ); }
public static void setSourceConnectionFromEndpoints ( final SourceItem item, final MasterServer master, final Collection<Endpoint> endpoints ) { final Connection connection = Locator.findConnection ( master, endpoints ); if ( connection == null ) { final String nodeName = Nodes.makeName ( Nodes.fromApp ( master ) ); throw new IllegalStateException ( String.format ( "Master '%s' on node '%s' does not have a connection to endpoints %s", master.getName (), nodeName, StringHelper.join ( endpoints, ", " ) ) ); } if ( ! ( connection instanceof DataAccessConnection ) ) { throw new IllegalStateException ( String.format ( "Connection is of type %s but must be of type %s (Endpoints: %s)", connection.getClass ().getName (), DataAccessConnection.class.getName (), StringHelper.join ( endpoints, ", " ) ) ); } item.setConnection ( (DataAccessConnection)connection ); }
@Override public void setMaster ( final SourceItem item, final MasterContext master ) { final List<Endpoint> endpoints = Locator.getSelfEndpoints ( master.getImplementation () ); Helper.setSourceConnectionFromEndpoints ( item, master.getImplementation (), endpoints ); } } );
public static void setSourceConnectionFromEndpoints ( final SourceItem item, final MasterServer master, final Collection<Endpoint> endpoints ) { final Connection connection = Locator.findConnection ( master, endpoints ); if ( connection == null ) { final String nodeName = Nodes.makeName ( Nodes.fromApp ( master ) ); throw new IllegalStateException ( String.format ( "Master '%s' on node '%s' does not have a connection to endpoints %s", master.getName (), nodeName, StringHelper.join ( endpoints, ", " ) ) ); } if ( ! ( connection instanceof DataAccessConnection ) ) { throw new IllegalStateException ( String.format ( "Connection is of type %s but must be of type %s (Endpoints: %s)", connection.getClass ().getName (), DataAccessConnection.class.getName (), StringHelper.join ( endpoints, ", " ) ) ); } item.setConnection ( (DataAccessConnection)connection ); }