use of org.eclipse.ecf.discovery.IDiscoveryLocator in project ecf by eclipse.
the class Activator method start.
/* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
public void start(final BundleContext context) throws Exception {
final ServiceReference configAdminServiceRef = context.getServiceReference(ConfigurationAdmin.class.getName());
if (configAdminServiceRef == null) {
System.err.println("You don't have config admin deployed. Some tests will fail that require configuration!");
return;
}
final ConfigurationAdmin configAdmin = (ConfigurationAdmin) context.getService(configAdminServiceRef);
Configuration config = configAdmin.createFactoryConfiguration(DnsSdTestHelper.ECF_DISCOVERY_DNSSD + ".locator", null);
Dictionary properties = new Hashtable();
properties.put(IDnsSdDiscoveryConstants.CA_SEARCH_PATH, new String[] { DnsSdTestHelper.DOMAIN });
properties.put(IDnsSdDiscoveryConstants.CA_RESOLVER, DnsSdTestHelper.DNS_RESOLVER);
properties.put(IDnsSdDiscoveryConstants.CA_TSIG_KEY, DnsSdTestHelper.TSIG_KEY);
properties.put(IDnsSdDiscoveryConstants.CA_TSIG_KEY_NAME, DnsSdTestHelper.TSIG_KEY_NAME);
config.update(properties);
String filter = "(" + Constants.SERVICE_PID + "=" + config.getPid() + ")";
// add the service listener
locListener = new ServiceListener() {
public void serviceChanged(ServiceEvent event) {
switch(event.getType()) {
case ServiceEvent.REGISTERED:
ServiceReference serviceReference = event.getServiceReference();
discoveryLocator = (IDiscoveryLocator) context.getService(serviceReference);
synchronized (locLock) {
locLock.notifyAll();
}
}
}
};
context.addServiceListener(locListener, filter);
// try to get the service initially
ServiceReference[] references = context.getServiceReferences(IDiscoveryLocator.class.getName(), filter);
if (references != null) {
for (int i = 0; i < references.length; ) {
ServiceReference serviceReference = references[i];
discoveryLocator = (IDiscoveryLocator) context.getService(serviceReference);
synchronized (locLock) {
locLock.notifyAll();
}
}
}
// advertiser
config = configAdmin.createFactoryConfiguration(DnsSdTestHelper.ECF_DISCOVERY_DNSSD + ".advertiser", null);
properties = new Hashtable();
properties.put(IDnsSdDiscoveryConstants.CA_SEARCH_PATH, new String[] { DnsSdTestHelper.DOMAIN });
properties.put(IDnsSdDiscoveryConstants.CA_RESOLVER, DnsSdTestHelper.DNS_RESOLVER);
properties.put(IDnsSdDiscoveryConstants.CA_TSIG_KEY, DnsSdTestHelper.TSIG_KEY);
properties.put(IDnsSdDiscoveryConstants.CA_TSIG_KEY_NAME, DnsSdTestHelper.TSIG_KEY_NAME);
config.update(properties);
filter = "(" + Constants.SERVICE_PID + "=" + config.getPid() + ")";
// add the service listener
advListener = new ServiceListener() {
public void serviceChanged(ServiceEvent event) {
switch(event.getType()) {
case ServiceEvent.REGISTERED:
ServiceReference serviceReference = event.getServiceReference();
discoveryAdvertiser = (IDiscoveryAdvertiser) context.getService(serviceReference);
synchronized (advLock) {
advLock.notifyAll();
}
}
}
};
context.addServiceListener(advListener, filter);
// try to get the service initially
references = context.getServiceReferences(IDiscoveryAdvertiser.class.getName(), filter);
if (references != null) {
for (int i = 0; i < references.length; ) {
ServiceReference serviceReference = references[i];
discoveryAdvertiser = (IDiscoveryAdvertiser) context.getService(serviceReference);
synchronized (advLock) {
advLock.notifyAll();
}
}
}
}
use of org.eclipse.ecf.discovery.IDiscoveryLocator in project ecf by eclipse.
the class Activator method getDiscoveryLocator.
public IDiscoveryLocator getDiscoveryLocator(String containerUnderTest) {
locatorTracker.open();
final ServiceReference[] serviceReferences = locatorTracker.getServiceReferences();
if (serviceReferences != null) {
for (int i = 0; i < serviceReferences.length; i++) {
ServiceReference sr = serviceReferences[i];
if (containerUnderTest.equals(sr.getProperty(IDiscoveryLocator.CONTAINER_NAME))) {
return (IDiscoveryLocator) locatorTracker.getService(sr);
}
}
}
return null;
}
use of org.eclipse.ecf.discovery.IDiscoveryLocator in project ecf by eclipse.
the class DiscoveryContainerTest method getDiscoveryLocator.
protected IDiscoveryLocator getDiscoveryLocator() {
final IDiscoveryLocator adapter = (IDiscoveryLocator) container.getAdapter(IDiscoveryLocator.class);
assertNotNull("Adapter must not be null", adapter);
return adapter;
}
use of org.eclipse.ecf.discovery.IDiscoveryLocator in project ecf by eclipse.
the class DiscoveryTestsWithoutRegister method getDiscoveryLocator.
protected IDiscoveryLocator getDiscoveryLocator() {
final IDiscoveryLocator adapter = (IDiscoveryLocator) container.getAdapter(IDiscoveryLocator.class);
assertNotNull("Adapter must not be null", adapter);
return adapter;
}
use of org.eclipse.ecf.discovery.IDiscoveryLocator in project ecf by eclipse.
the class EndpointDescriptionLocator method close.
public void close() {
if (this.endpointLocatorReg != null) {
this.endpointLocatorReg.unregister();
this.endpointLocatorReg = null;
}
if (bundleTracker != null) {
bundleTracker.close();
bundleTracker = null;
}
if (bundleTrackerCustomizer != null) {
bundleTrackerCustomizer.close();
bundleTrackerCustomizer = null;
}
// shutdown locatorListeners
synchronized (locatorListeners) {
for (IDiscoveryLocator l : locatorListeners.keySet()) {
LocatorServiceListener locatorListener = locatorListeners.get(l);
if (locatorListener != null) {
l.removeServiceListener(locatorListener);
locatorListener.close();
}
}
locatorListeners.clear();
}
Object[] locators = locatorServiceTracker.getServices();
if (locators != null) {
for (int i = 0; i < locators.length; i++) {
// Add service listener to locator
shutdownLocator((IDiscoveryLocator) locators[i]);
}
}
if (endpointListenerTracker != null) {
endpointListenerTracker.close();
endpointListenerTracker = null;
}
if (endpointEventListenerTracker != null) {
endpointEventListenerTracker.close();
endpointEventListenerTracker = null;
}
// Shutdown asynchronous event manager
if (eventManager != null) {
eventManager.close();
eventManager = null;
}
synchronized (endpointDescriptionFactoryTrackerLock) {
if (endpointDescriptionFactoryTracker != null) {
endpointDescriptionFactoryTracker.close();
endpointDescriptionFactoryTracker = null;
}
}
if (defaultEndpointDescriptionFactoryRegistration != null) {
defaultEndpointDescriptionFactoryRegistration.unregister();
defaultEndpointDescriptionFactoryRegistration = null;
}
if (defaultEndpointDescriptionFactory != null) {
defaultEndpointDescriptionFactory.close();
defaultEndpointDescriptionFactory = null;
}
synchronized (serviceInfoFactoryTrackerLock) {
if (serviceInfoFactoryTracker != null) {
serviceInfoFactoryTracker.close();
serviceInfoFactoryTracker = null;
}
}
if (defaultServiceInfoFactoryRegistration != null) {
defaultServiceInfoFactoryRegistration.unregister();
defaultServiceInfoFactoryRegistration = null;
}
if (serviceInfoFactory != null) {
serviceInfoFactory.close();
serviceInfoFactory = null;
}
if (defaultEndpointDescriptionReaderRegistration != null) {
defaultEndpointDescriptionReaderRegistration.unregister();
defaultEndpointDescriptionReaderRegistration = null;
}
if (locatorServiceTracker != null) {
locatorServiceTracker.close();
locatorServiceTracker = null;
}
synchronized (advertiserTrackerLock) {
if (advertiserTracker != null) {
advertiserTracker.close();
advertiserTracker = null;
}
}
synchronized (edToServiceIDMap) {
edToServiceIDMap.clear();
}
this.executor = null;
this.context = null;
}
Aggregations