use of org.eclipse.ecf.discovery.identity.IServiceTypeID in project ecf by eclipse.
the class JSLPServiceIDTest method testCreateByjSLPAndRemoveServicePrefix.
/* (non-Javadoc)
* @see org.eclipse.ecf.tests.discovery.identity.ServiceIDTest#testCreateServiceTypeIDFromInternalString()
*
* test from jSLP -> ECF discovery which needs to remove the first occurrence of "service:"
*/
public void testCreateByjSLPAndRemoveServicePrefix() throws ServiceLocationException {
final String internalRep = "service:foo.eclipse:bar";
final ServiceURL sUrl = new ServiceURL(internalRep + "://localhost:1234/a/path/to/something", ServiceURL.LIFETIME_PERMANENT);
final IServiceInfo serviceInfo = new JSLPServiceInfo(DiscoveryTestHelper.SERVICENAME, new ServiceURLAdapter(sUrl), DiscoveryTestHelper.PRIORITY, DiscoveryTestHelper.WEIGHT, new ServicePropertiesAdapter(new ArrayList()));
assertEquals(serviceInfo.getPriority(), DiscoveryTestHelper.PRIORITY);
assertEquals(serviceInfo.getWeight(), DiscoveryTestHelper.WEIGHT);
final IServiceID sid = serviceInfo.getServiceID();
assertEquals(serviceInfo.getServiceName(), DiscoveryTestHelper.SERVICENAME);
final IServiceTypeID stid = sid.getServiceTypeID();
String internal = stid.getInternal();
assertEquals(internalRep, internal);
assertEquals("_foo._bar._" + IServiceTypeID.DEFAULT_PROTO[0] + "." + IServiceTypeID.DEFAULT_SCOPE[0] + "._eclipse", stid.getName());
assertEquals("eclipse", stid.getNamingAuthority());
assertTrue(Arrays.equals(new String[] { "foo", "bar" }, stid.getServices()));
assertTrue(Arrays.equals(IServiceTypeID.DEFAULT_SCOPE, stid.getScopes()));
assertTrue(Arrays.equals(IServiceTypeID.DEFAULT_PROTO, stid.getProtocols()));
}
use of org.eclipse.ecf.discovery.identity.IServiceTypeID in project ecf by eclipse.
the class DiscoverableServer method start.
/* (non-Javadoc)
* @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext)
*/
public Object start(IApplicationContext ctxt) throws Exception {
Map args = ctxt.getArguments();
// $NON-NLS-1$
initializeFromArguments((String[]) args.get("application.args"));
// Load and start ECF core bundles (to execute ecfstart jobs like discovery providers)
ContainerFactory.getDefault().getDescriptions();
// get discovery service
discovery = Activator.getDefault().waitForDiscoveryService(5000);
// Create service id
IServiceTypeID serviceTypeID = ServiceIDFactory.getDefault().createServiceTypeID(discovery.getServicesNamespace(), new String[] { PROTO }, IServiceTypeID.DEFAULT_PROTO);
// create service info
// $NON-NLS-1$ //$NON-NLS-2$
URI uri = URI.create(PROTO + "://" + InetAddress.getLocalHost().getHostAddress() + ":" + getServicePort() + servicePath);
serviceInfo = new ServiceInfo(uri, serviceName, serviceTypeID, 0, 0, new ServiceProperties(new UpdateSiteProperties(serviceName).toProperties()));
// get http service
final HttpService httpService = Activator.getDefault().waitForHttpService(2000);
// start http service
// $NON-NLS-1$
httpService.registerResources(servicePath, "/", new UpdateSiteContext(httpService.createDefaultHttpContext(), updateSiteLocation));
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println("http server\n\tupdateSiteLocation=" + updateSiteLocation + "\n\turl=" + serviceInfo.getServiceID().getLocation());
// setup discovery
discovery.registerService(serviceInfo);
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println("discovery publish\n\tserviceName=" + serviceName + "\n\tserviceTypeID=" + serviceTypeID);
// wait until done
synchronized (this) {
while (!done) {
wait();
}
}
return new Integer(0);
}
use of org.eclipse.ecf.discovery.identity.IServiceTypeID in project ecf by eclipse.
the class DiscoveryServiceRegistryTest method setUp.
protected void setUp() throws Exception {
super.setUp();
// override the service info with a _generic_ service info. Generic in
// the sense that its namespace if the parent DiscoveryNamespace and not
// a provider specific one. We need to use the parent DN because users of the
// whiteboard pattern do not interact with the IDA directly.
IServiceTypeID serviceTypeID = ServiceIDFactory.getDefault().createServiceTypeID(IDFactory.getDefault().getNamespaceByName(DiscoveryNamespace.NAME), services, new String[] { scope }, new String[] { protocol }, namingAuthority);
assertNotNull(serviceTypeID);
// Register a generic IServiceInfo (discovery generic) in the OSGi
// service registry. Let all comparison be done on the provider specific
// ("serviceInfo") super class member though Otherwise we would have to
// register a specific type ignoring ServiceInfoComparator (see below) because the
// generic IServiceInfo will never be equal to the (converted) discovery
// provider .
genericServiceInfo = new ServiceInfo(serviceInfo.getLocation(), DiscoveryTestHelper.SERVICENAME, serviceTypeID, 1, 1, serviceInfo.getServiceProperties(), ttl);
}
use of org.eclipse.ecf.discovery.identity.IServiceTypeID in project ecf by eclipse.
the class DiscoveryServiceTest method testAddServiceListenerIServiceTypeIDIServiceListenerOSGi.
public void testAddServiceListenerIServiceTypeIDIServiceListenerOSGi() throws ContainerConnectException {
IServiceInfo[] services = discoveryLocator.getServices();
assertTrue("No Services must be registerd at this point " + (services.length == 0 ? "" : services[0].toString()), services.length == 0);
final TestServiceListener tsl = new TestServiceListener(eventsToExpect, discoveryLocator, getName(), getTestId());
IServiceTypeID serviceTypeID = serviceInfo.getServiceID().getServiceTypeID();
Properties props = new Properties();
props.put("org.eclipse.ecf.discovery.services", serviceTypeID.getServices());
props.put("org.eclipse.ecf.discovery.scopes", serviceTypeID.getScopes());
props.put("org.eclipse.ecf.discovery.protocols", serviceTypeID.getProtocols());
props.put("org.eclipse.ecf.discovery.namingauthority", serviceTypeID.getNamingAuthority());
props.put(IDiscoveryLocator.CONTAINER_NAME, containerUnderTest);
BundleContext ctxt = Activator.getDefault().getContext();
ServiceRegistration registration = ctxt.registerService(IServiceListener.class.getName(), tsl, props);
addListenerRegisterAndWait(tsl, serviceInfo);
registration.unregister();
IContainerEvent[] event = tsl.getEvent();
assertNotNull("Test listener didn't receive discovery", event);
assertEquals("Test listener received unexpected amount of discovery events: \n\t" + Arrays.asList(event), eventsToExpect, event.length);
IServiceInfo serviceInfo2 = ((IServiceEvent) event[eventsToExpect - 1]).getServiceInfo();
assertTrue("IServiceInfo should match, expected:\n\t" + serviceInfo + " but:\n\t" + serviceInfo2, comparator.compare(serviceInfo2, serviceInfo) == 0);
}
use of org.eclipse.ecf.discovery.identity.IServiceTypeID in project ecf by eclipse.
the class DiscoveryTest method testGetServiceTypes.
/**
* Test method for
* {@link org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#getServiceTypes()}.
* @throws ContainerConnectException
*/
public void testGetServiceTypes() throws ContainerConnectException {
registerService();
final IServiceTypeID[] serviceTypeIDs = discoveryLocator.getServiceTypes();
assertTrue("IServiceInfo[] is empty", serviceTypeIDs.length >= 1);
for (int i = 0; i < serviceTypeIDs.length; i++) {
IServiceTypeID iServiceTypeId = serviceTypeIDs[i];
if (serviceInfo.getServiceID().getServiceTypeID().equals(iServiceTypeId)) {
return;
}
}
fail("Self registered service not found");
}
Aggregations