use of org.eclipse.ecf.discovery.identity.IServiceTypeID in project ecf by eclipse.
the class AbstractDiscoveryContainerAdapter method getListeners.
// merges the allServiceListener with the serviceListeners for the given
// type
/**
* Joins the {@link Collection} of {@link IServiceListener}s interested in
* any {@link IServiceTypeID} with the {@link Collection} of the
* {@link IServiceListener} registered for the given {@link IServiceTypeID}
*
* @param aServiceType
* The {@link IServiceTypeID} for which the
* {@link IServiceListener}s are returned
* @return All {@link IServiceListener}s interested in the given
* {@link IServiceTypeID}
*/
protected Collection getListeners(IServiceTypeID aServiceType) {
Assert.isNotNull(aServiceType);
Collection listeners = new HashSet();
synchronized (serviceListeners) {
for (Iterator itr = serviceListeners.keySet().iterator(); itr.hasNext(); ) {
final IServiceTypeID typeID = (IServiceTypeID) itr.next();
int compare = discoveryServiceListenerComparator.compare(aServiceType, typeID);
if (compare == 0) {
Collection collection = (Collection) serviceListeners.get(typeID);
if (collection != null) {
listeners.addAll(collection);
}
}
}
}
synchronized (allServiceListeners) {
listeners.addAll(allServiceListeners);
}
return Collections.unmodifiableCollection(listeners);
}
use of org.eclipse.ecf.discovery.identity.IServiceTypeID in project ecf by eclipse.
the class ServiceIDTest method testServiceTypeIDWithServiceTypeID.
/*
* use case: conversion from one IServiceTypeID to another (provider A -> provider B)
*/
public void testServiceTypeIDWithServiceTypeID() {
final IServiceTypeID aServiceTypeID = createIDFromStringWithEx("_service._ecf._foo._bar._tcp.ecf.eclipse.org._IANA");
final IServiceTypeID stid = createIDFromServiceTypeID(aServiceTypeID);
// this is the only differences
assertNotSame(aServiceTypeID.getInternal(), stid.getInternal());
// members should be the same
assertTrue(aServiceTypeID.getNamingAuthority().equalsIgnoreCase(stid.getNamingAuthority()));
assertTrue(Arrays.equals(aServiceTypeID.getServices(), stid.getServices()));
assertTrue(Arrays.equals(aServiceTypeID.getScopes(), stid.getScopes()));
assertTrue(Arrays.equals(aServiceTypeID.getProtocols(), stid.getProtocols()));
// logically they should be the same
assertTrue(aServiceTypeID.hashCode() == stid.hashCode());
assertEquals(aServiceTypeID, stid);
assertEquals(stid, aServiceTypeID);
// should be possible to create a new instance from the string representation of the other
createFromAnother(aServiceTypeID, stid);
createFromAnother(stid, aServiceTypeID);
}
use of org.eclipse.ecf.discovery.identity.IServiceTypeID in project ecf by eclipse.
the class ServiceIDTest method testServiceTypeIDWithECFGenericString3.
/*
* use case: consumer instantiates a IServiceTypeID with the generic (ECF) String
*/
public void testServiceTypeIDWithECFGenericString3() {
final String serviceType = "_service._dns-srv._udp.ecf.eclipse.org._ECLIPSE";
final IServiceTypeID stid = createIDFromString(serviceType);
assertEquals(stid.getName(), serviceType);
assertEquals(stid.getNamingAuthority(), "ECLIPSE");
assertTrue(Arrays.equals(stid.getProtocols(), new String[] { "udp" }));
assertTrue(Arrays.equals(stid.getScopes(), new String[] { "ecf.eclipse.org" }));
assertTrue(Arrays.equals(stid.getServices(), new String[] { "service", "dns-srv" }));
}
use of org.eclipse.ecf.discovery.identity.IServiceTypeID in project ecf by eclipse.
the class ServiceIDTest method testServiceTypeIDWithECFGenericString.
/*
* use case: consumer instantiates a IServiceTypeID with the generic (ECF) String
*/
public void testServiceTypeIDWithECFGenericString() {
final IServiceTypeID stid = createIDFromString(DiscoveryTestHelper.SERVICE_TYPE);
assertEquals(stid.getName(), DiscoveryTestHelper.SERVICE_TYPE);
assertEquals(stid.getNamingAuthority(), DiscoveryTestHelper.NAMINGAUTHORITY);
assertTrue(Arrays.equals(stid.getProtocols(), new String[] { DiscoveryTestHelper.PROTOCOL }));
assertTrue(Arrays.equals(stid.getScopes(), new String[] { DiscoveryTestHelper.SCOPE }));
assertTrue(Arrays.equals(stid.getServices(), DiscoveryTestHelper.SERVICES));
}
use of org.eclipse.ecf.discovery.identity.IServiceTypeID in project ecf by eclipse.
the class ServiceIDTest method testServiceIDFactory.
/*
* org.eclipse.ecf.discovery.identity.IServiceIDFactory.createServiceID(Namespace, String, String)
*/
public void testServiceIDFactory() {
Namespace namespaceByName = IDFactory.getDefault().getNamespaceByName(namespace);
IServiceTypeID serviceType = ServiceIDFactory.getDefault().createServiceTypeID(namespaceByName, services, scopes, protocols, namingAuthority);
assertNotNull(serviceType);
assertEquals(namingAuthority, serviceType.getNamingAuthority());
assertTrue(Arrays.equals(services, serviceType.getServices()));
assertTrue(Arrays.equals(scopes, serviceType.getScopes()));
assertTrue(Arrays.equals(protocols, serviceType.getProtocols()));
}
Aggregations