Search in sources :

Example 31 with IServiceInfo

use of org.eclipse.ecf.discovery.IServiceInfo in project ecf by eclipse.

the class DnsSdDiscoveryLocator method getServices.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ecf.discovery.IDiscoveryLocator#getServices(org.eclipse.ecf
	 * .discovery.identity.IServiceTypeID)
	 */
public IServiceInfo[] getServices(IServiceTypeID aServiceTypeId) {
    Assert.isNotNull(aServiceTypeId);
    DnsSdServiceTypeID serviceTypeId = (DnsSdServiceTypeID) aServiceTypeId;
    Collection srvRecords = getSRVRecords(serviceTypeId.getInternalQueries());
    List serviceInfos = getServiceInfos(srvRecords);
    return (IServiceInfo[]) serviceInfos.toArray(new IServiceInfo[serviceInfos.size()]);
}
Also used : IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List)

Example 32 with IServiceInfo

use of org.eclipse.ecf.discovery.IServiceInfo in project ecf by eclipse.

the class DnsSdDiscoveryLocator method getServiceInfos.

private List getServiceInfos(Collection srvQueryResult) {
    List infos = new ArrayList();
    for (Iterator iterator = srvQueryResult.iterator(); iterator.hasNext(); ) {
        SRVRecord srvRecord = (SRVRecord) iterator.next();
        long ttl = srvRecord.getTTL();
        int priority = srvRecord.getPriority();
        int weight = srvRecord.getWeight();
        int port = srvRecord.getPort();
        Name target = srvRecord.getTarget();
        String host = target.toString();
        host = host.substring(0, host.length() - 1);
        IServiceTypeID aServiceTypeID = new DnsSdServiceTypeID(getConnectNamespace(), srvRecord.getName());
        // query for txt records (attributes)
        Properties props = new Properties();
        Lookup txtQuery = new Lookup(srvRecord.getName(), Type.TXT);
        txtQuery.setResolver(resolver);
        Record[] txtQueryResults = txtQuery.run();
        int length = txtQueryResults == null ? 0 : txtQueryResults.length;
        for (int l = 0; l < length; l++) {
            TXTRecord txtResult = (TXTRecord) txtQueryResults[l];
            List strings = txtResult.getStrings();
            for (Iterator itr = strings.iterator(); itr.hasNext(); ) {
                String str = (String) itr.next();
                // $NON-NLS-1$
                String[] split = str.split("=");
                props.put(split[0], split[1]);
            }
        }
        String path = props.getProperty(DNS_SD_PATH);
        String proto = props.getProperty(DNS_SD_PTCL) == null ? aServiceTypeID.getProtocols()[0] : props.getProperty(DNS_SD_PTCL);
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        URI uri = URI.create(proto + "://" + host + ":" + port + (path == null ? "" : path));
        IServiceInfo info = new ServiceInfo(uri, host, aServiceTypeID, priority, weight, new ServiceProperties(props), ttl);
        infos.add(info);
    }
    return infos;
}
Also used : IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) ArrayList(java.util.ArrayList) Properties(java.util.Properties) ServiceProperties(org.eclipse.ecf.discovery.ServiceProperties) URI(java.net.URI) Name(org.xbill.DNS.Name) IServiceTypeID(org.eclipse.ecf.discovery.identity.IServiceTypeID) ServiceInfo(org.eclipse.ecf.discovery.ServiceInfo) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) ServiceProperties(org.eclipse.ecf.discovery.ServiceProperties) TXTRecord(org.xbill.DNS.TXTRecord) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Lookup(org.xbill.DNS.Lookup) PTRRecord(org.xbill.DNS.PTRRecord) Record(org.xbill.DNS.Record) SRVRecord(org.xbill.DNS.SRVRecord) TXTRecord(org.xbill.DNS.TXTRecord) SRVRecord(org.xbill.DNS.SRVRecord)

Example 33 with IServiceInfo

use of org.eclipse.ecf.discovery.IServiceInfo in project ecf by eclipse.

the class OpenBrowserCommand method execute.

/* (non-Javadoc)
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    // get service
    final IServiceInfo serviceInfo = DiscoveryHandlerUtil.getActiveIServiceInfoChecked(event);
    final URI location = serviceInfo.getLocation();
    // open browser view or reuse existing if already open
    final IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
    try {
        final URL url = location.toURL();
        support.createBrowser(url.toExternalForm()).openURL(url);
    } catch (PartInitException e) {
        throw new ExecutionException(e.getMessage(), e);
    } catch (MalformedURLException e) {
        throw new ExecutionException(e.getMessage(), e);
    }
    return null;
}
Also used : MalformedURLException(java.net.MalformedURLException) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) IWorkbenchBrowserSupport(org.eclipse.ui.browser.IWorkbenchBrowserSupport) PartInitException(org.eclipse.ui.PartInitException) ExecutionException(org.eclipse.core.commands.ExecutionException) URI(java.net.URI) URL(java.net.URL)

Example 34 with IServiceInfo

use of org.eclipse.ecf.discovery.IServiceInfo in project ecf by eclipse.

the class EndpointDescriptionFactoryTest method testCreateRequiredEndpointDescriptionFromServiceInfo.

public void testCreateRequiredEndpointDescriptionFromServiceInfo() throws Exception {
    EndpointDescription published = createRequiredEndpointDescription();
    assertNotNull(published);
    IServiceInfo serviceInfo = createServiceInfoForDiscovery(published);
    assertNotNull(serviceInfo);
    org.osgi.service.remoteserviceadmin.EndpointDescription received = createEndpointDescriptionFromDiscovery(serviceInfo);
    assertNotNull(received);
    assertTrue(published.equals(received));
}
Also used : IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) EndpointDescription(org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription)

Example 35 with IServiceInfo

use of org.eclipse.ecf.discovery.IServiceInfo in project ecf by eclipse.

the class EndpointDescriptionFactoryTest method testCreateFullEndpointDescriptionFromServiceInfo.

public void testCreateFullEndpointDescriptionFromServiceInfo() throws Exception {
    EndpointDescription published = createFullEndpointDescription();
    assertNotNull(published);
    IServiceInfo serviceInfo = createServiceInfoForDiscovery(published);
    assertNotNull(serviceInfo);
    org.osgi.service.remoteserviceadmin.EndpointDescription received = createEndpointDescriptionFromDiscovery(serviceInfo);
    assertNotNull(received);
    assertTrue(published.equals(received));
}
Also used : IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) EndpointDescription(org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription)

Aggregations

IServiceInfo (org.eclipse.ecf.discovery.IServiceInfo)47 IContainerEvent (org.eclipse.ecf.core.events.IContainerEvent)8 IServiceTypeID (org.eclipse.ecf.discovery.identity.IServiceTypeID)8 Properties (java.util.Properties)7 URI (java.net.URI)6 IServiceEvent (org.eclipse.ecf.discovery.IServiceEvent)6 IServiceID (org.eclipse.ecf.discovery.identity.IServiceID)6 BundleContext (org.osgi.framework.BundleContext)6 ArrayList (java.util.ArrayList)5 ExecutionException (org.eclipse.core.commands.ExecutionException)5 ServiceRegistration (org.osgi.framework.ServiceRegistration)5 IServiceListener (org.eclipse.ecf.discovery.IServiceListener)4 ServiceInfo (org.eclipse.ecf.discovery.ServiceInfo)4 TestServiceListener (org.eclipse.ecf.tests.discovery.listener.TestServiceListener)4 ThreadTestServiceListener (org.eclipse.ecf.tests.discovery.listener.ThreadTestServiceListener)4 ServiceURL (ch.ethz.iks.slp.ServiceURL)3 List (java.util.List)3 IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)3 IServiceProperties (org.eclipse.ecf.discovery.IServiceProperties)3 Iterator (java.util.Iterator)2