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()]);
}
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;
}
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;
}
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));
}
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));
}
Aggregations