Search in sources :

Example 1 with IContainerEvent

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];
}
Also used : ISharedObjectActivatedEvent(org.eclipse.ecf.core.sharedobject.events.ISharedObjectActivatedEvent) SharedObjectCreateException(org.eclipse.ecf.core.sharedobject.SharedObjectCreateException) IContainerEvent(org.eclipse.ecf.core.events.IContainerEvent) ISharedObjectManager(org.eclipse.ecf.core.sharedobject.ISharedObjectManager) IContainerListener(org.eclipse.ecf.core.IContainerListener)

Example 2 with IContainerEvent

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);
}
Also used : TestServiceTypeListener(org.eclipse.ecf.tests.discovery.listener.TestServiceTypeListener) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) IContainerEvent(org.eclipse.ecf.core.events.IContainerEvent) IServiceTypeListener(org.eclipse.ecf.discovery.IServiceTypeListener) Properties(java.util.Properties) BundleContext(org.osgi.framework.BundleContext) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 3 with IContainerEvent

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);
}
Also used : ThreadTestServiceListener(org.eclipse.ecf.tests.discovery.listener.ThreadTestServiceListener) TestServiceListener(org.eclipse.ecf.tests.discovery.listener.TestServiceListener) IServiceTypeID(org.eclipse.ecf.discovery.identity.IServiceTypeID) IServiceListener(org.eclipse.ecf.discovery.IServiceListener) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) IContainerEvent(org.eclipse.ecf.core.events.IContainerEvent) Properties(java.util.Properties) IServiceEvent(org.eclipse.ecf.discovery.IServiceEvent) BundleContext(org.osgi.framework.BundleContext) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 4 with IContainerEvent

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;
}
Also used : IContainerEvent(org.eclipse.ecf.core.events.IContainerEvent) Collection(java.util.Collection) HashSet(java.util.HashSet)

Example 5 with IContainerEvent

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);
}
Also used : ThreadTestServiceListener(org.eclipse.ecf.tests.discovery.listener.ThreadTestServiceListener) TestServiceListener(org.eclipse.ecf.tests.discovery.listener.TestServiceListener) IServiceListener(org.eclipse.ecf.discovery.IServiceListener) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) IContainerEvent(org.eclipse.ecf.core.events.IContainerEvent) Properties(java.util.Properties) IServiceEvent(org.eclipse.ecf.discovery.IServiceEvent) BundleContext(org.osgi.framework.BundleContext) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Aggregations

IContainerEvent (org.eclipse.ecf.core.events.IContainerEvent)16 IServiceInfo (org.eclipse.ecf.discovery.IServiceInfo)8 IServiceEvent (org.eclipse.ecf.discovery.IServiceEvent)6 Properties (java.util.Properties)5 IContainerListener (org.eclipse.ecf.core.IContainerListener)5 BundleContext (org.osgi.framework.BundleContext)5 ServiceRegistration (org.osgi.framework.ServiceRegistration)5 IContainerConnectedEvent (org.eclipse.ecf.core.events.IContainerConnectedEvent)4 IServiceListener (org.eclipse.ecf.discovery.IServiceListener)4 TestServiceListener (org.eclipse.ecf.tests.discovery.listener.TestServiceListener)4 ThreadTestServiceListener (org.eclipse.ecf.tests.discovery.listener.ThreadTestServiceListener)4 IContainerDisconnectedEvent (org.eclipse.ecf.core.events.IContainerDisconnectedEvent)3 TestServiceTypeListener (org.eclipse.ecf.tests.discovery.listener.TestServiceTypeListener)3 HashSet (java.util.HashSet)2 AsynchContainerConnectAction (org.eclipse.ecf.ui.actions.AsynchContainerConnectAction)2 IDCreateErrorDialog (org.eclipse.ecf.ui.dialogs.IDCreateErrorDialog)2 Collection (java.util.Collection)1 Set (java.util.Set)1 IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)1 ISharedObjectManager (org.eclipse.ecf.core.sharedobject.ISharedObjectManager)1