Search in sources :

Example 11 with IContainerEvent

use of org.eclipse.ecf.core.events.IContainerEvent in project ecf by eclipse.

the class SSLClientContainerConnectTest method createServerAndClients.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ecf.tests.connect.ContainerConnectTestCase#createServerAndClients()
	 */
protected void createServerAndClients() throws Exception {
    clientCount = 5;
    super.createServerAndClients();
    getServer().addListener(new IContainerListener() {

        public void handleEvent(IContainerEvent event) {
            if (event instanceof IContainerConnectedEvent)
                serverConnectEvents.add(event);
            if (event instanceof IContainerDisconnectedEvent)
                serverDisconnectEvents.add(event);
        }
    });
}
Also used : IContainerEvent(org.eclipse.ecf.core.events.IContainerEvent) IContainerDisconnectedEvent(org.eclipse.ecf.core.events.IContainerDisconnectedEvent) IContainerListener(org.eclipse.ecf.core.IContainerListener) IContainerConnectedEvent(org.eclipse.ecf.core.events.IContainerConnectedEvent)

Example 12 with IContainerEvent

use of org.eclipse.ecf.core.events.IContainerEvent in project ecf by eclipse.

the class DiscoveryServiceTest method testAddServiceListenerIServiceListenerOSGi.

public void testAddServiceListenerIServiceListenerOSGi() 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(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 any discovery event", 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 was \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)

Example 13 with IContainerEvent

use of org.eclipse.ecf.core.events.IContainerEvent in project ecf by eclipse.

the class DiscoveryServiceTest method testAddServiceListenerWithRefresh.

public void testAddServiceListenerWithRefresh() {
    IServiceInfo[] services = discoveryLocator.getServices();
    assertTrue("No Services must be registerd at this point " + (services.length == 0 ? "" : services[0].toString()), services.length == 0);
    final ThreadTestServiceListener tsl = new ThreadTestServiceListener(eventsToExpect, discoveryLocator, getName(), getTestId());
    // OSGi
    final Properties props = new Properties();
    props.put(IDiscoveryLocator.CONTAINER_NAME, containerUnderTest);
    final BundleContext ctxt = Activator.getDefault().getContext();
    // Lock the listener first so that we won't miss any discovery event
    synchronized (tsl) {
        registerService();
        // Check that services have been registered successfully
        services = discoveryLocator.getServices();
        assertTrue(eventsToExpect + " services must be registerd at this point " + (services.length > 0 ? "" : services.toString()), services.length == eventsToExpect);
        // Register listener with OSGi
        ServiceRegistration registration = ctxt.registerService(IServiceListener.class.getName(), tsl, props);
        // register a service which we expect the test listener to get notified of
        try {
            tsl.wait(waitTimeForProvider);
        } catch (final InterruptedException e) {
            Thread.currentThread().interrupt();
            fail("Some discovery unrelated threading issues?");
        } finally {
            registration.unregister();
        }
    }
    final IContainerEvent[] event = tsl.getEvent();
    assertNotNull("Test listener didn't receive any discovery event", event);
    // Diff the expected ids with what actually has been discovered. The
    // remainig events are those missing.
    final Set ids = new HashSet(idsToExpect);
    ids.removeAll(getContainerIds(event));
    assertTrue("Test misses " + ids.size() + " event(s) from container(s) out of " + idsToExpect + ". Those Ids are: " + ids, ids.size() == 0);
    assertEquals("Test listener received unexpected amount of discovery events: \n\t" + Arrays.asList(event), eventsToExpect, event.length);
    assertTrue("Discovery event must have originated from backend thread. Thread is: " + tsl.getCallingThread(), Thread.currentThread() != tsl.getCallingThread() && tsl.getCallingThread() != null);
    IServiceInfo serviceInfo2 = ((IServiceEvent) event[eventsToExpect - 1]).getServiceInfo();
    assertTrue("IServiceInfo should match, expected:\n\t" + serviceInfo + " but was \n\t" + serviceInfo2, comparator.compare(serviceInfo2, serviceInfo) == 0);
}
Also used : IServiceListener(org.eclipse.ecf.discovery.IServiceListener) Set(java.util.Set) HashSet(java.util.HashSet) ThreadTestServiceListener(org.eclipse.ecf.tests.discovery.listener.ThreadTestServiceListener) 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) HashSet(java.util.HashSet)

Example 14 with IContainerEvent

use of org.eclipse.ecf.core.events.IContainerEvent in project ecf by eclipse.

the class DiscoveryTest method testRemoveServiceTypeListener.

/**
 * Test method for
 * {@link org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#removeServiceTypeListener(org.eclipse.ecf.discovery.IServiceTypeListener)}.
 * @throws ContainerConnectException
 */
public void testRemoveServiceTypeListener() throws ContainerConnectException {
    assertTrue("No Services must be registerd at this point", discoveryLocator.getServices().length == 0);
    final TestServiceTypeListener testTypeListener = new TestServiceTypeListener(eventsToExpect);
    discoveryLocator.addServiceTypeListener(testTypeListener);
    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?");
        }
    }
    discoveryLocator.removeServiceTypeListener(testTypeListener);
    IContainerEvent[] event = testTypeListener.getEvent();
    assertNotNull("Test listener didn't receive any discovery event", event);
    assertEquals("Test listener received unexpected amount of discovery events: \n\t" + Arrays.asList(event), eventsToExpect, event.length);
// TODO reregister and verify the listener doesn't receive any events any longer.
}
Also used : TestServiceTypeListener(org.eclipse.ecf.tests.discovery.listener.TestServiceTypeListener) IContainerEvent(org.eclipse.ecf.core.events.IContainerEvent)

Example 15 with IContainerEvent

use of org.eclipse.ecf.core.events.IContainerEvent in project ecf by eclipse.

the class UserSearchView method addMultiRosterAccount.

/**
 * Add the MultiRosterAccount for add user contact
 * @param multiRosterAccount
 * @return boolean
 */
public boolean addMultiRosterAccount(MultiRosterAccount multiRosterAccount) {
    Assert.isNotNull(multiRosterAccount);
    this.account = multiRosterAccount;
    listener = new IContainerListener() {

        public void handleEvent(IContainerEvent event) {
            if (event instanceof IContainerDisconnectedEvent) {
                users.clear();
                showMessage(Messages.MultiRosterView_HELP_MESSAGE);
            }
        }
    };
    account.container.addListener(listener);
    return true;
}
Also used : IContainerEvent(org.eclipse.ecf.core.events.IContainerEvent) IContainerDisconnectedEvent(org.eclipse.ecf.core.events.IContainerDisconnectedEvent) IContainerListener(org.eclipse.ecf.core.IContainerListener)

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