use of org.eclipse.ecf.core.events.IContainerEvent in project ecf by eclipse.
the class SharedModelFactory method createSharedDataSource.
public IMasterModel createSharedDataSource(ISharedObjectContainer container, final ID id, Object data, String updaterID) throws SharedObjectCreateException {
final ISharedObjectManager mgr = container.getSharedObjectManager();
final Object[] result = new Object[1];
final Object monitor = new Object();
IContainerListener listener = new IContainerListener() {
public void handleEvent(IContainerEvent event) {
if (event instanceof ISharedObjectActivatedEvent) {
ISharedObjectActivatedEvent e = (ISharedObjectActivatedEvent) event;
if (e.getActivatedID().equals(id)) {
result[0] = mgr.getSharedObject(id);
synchronized (monitor) {
monitor.notify();
}
}
}
}
};
try {
container.addListener(listener);
/* SharedObjectDescription desc = createLocalAgentDescription(id, container.getID(), data, updaterID);
synchronized (monitor) {
mgr.createSharedObject(desc);
if (result[0] == null)
monitor.wait(getCreationTimeout());
}
*/
synchronized (monitor) {
addSharedObject(mgr, id, data, updaterID);
if (result[0] == null)
monitor.wait(getCreationTimeout());
}
} catch (InterruptedException e) {
throw new SharedObjectCreateException(e);
} finally {
container.removeListener(listener);
}
return (IMasterModel) result[0];
}
use of org.eclipse.ecf.core.events.IContainerEvent in project ecf by eclipse.
the class DiscoveryServiceTest method testAddServiceTypeListenerOSGi.
public void testAddServiceTypeListenerOSGi() 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 TestServiceTypeListener testTypeListener = new TestServiceTypeListener(eventsToExpect);
Properties props = new Properties();
props.put(IDiscoveryLocator.CONTAINER_NAME, containerUnderTest);
BundleContext ctxt = Activator.getDefault().getContext();
ServiceRegistration registration = ctxt.registerService(IServiceTypeListener.class.getName(), testTypeListener, props);
synchronized (testTypeListener) {
// register a service which we expect the test listener to get notified of
registerService();
try {
testTypeListener.wait(waitTimeForProvider);
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
fail("Some discovery unrelated threading issues?");
}
}
registration.unregister();
IContainerEvent[] event = testTypeListener.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);
}
use of org.eclipse.ecf.core.events.IContainerEvent 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.core.events.IContainerEvent in project ecf by eclipse.
the class DiscoveryServiceTest method getContainerIds.
protected Collection getContainerIds(IContainerEvent[] events) {
final Collection originalIds = new HashSet();
for (int i = 0; i < events.length; i++) {
final IContainerEvent iContainerEvent = events[i];
originalIds.add(iContainerEvent.getLocalContainerID());
}
return originalIds;
}
use of org.eclipse.ecf.core.events.IContainerEvent in project ecf by eclipse.
the class DiscoveryServiceTest method testAddServiceListenerIServiceTypeIDIServiceListenerOSGiWildcards.
public void testAddServiceListenerIServiceTypeIDIServiceListenerOSGiWildcards() 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());
Properties props = new Properties();
props.put("org.eclipse.ecf.discovery.services", "*");
props.put("org.eclipse.ecf.discovery.scopes", "*");
props.put("org.eclipse.ecf.discovery.protocols", "*");
props.put("org.eclipse.ecf.discovery.namingauthority", "*");
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);
}
Aggregations