Search in sources :

Example 16 with ContainerConnectException

use of org.eclipse.ecf.core.ContainerConnectException in project ecf by eclipse.

the class XMPPSearchTest method testRetrieveBuddiesAllFieldsSync.

/**
 * Try to locate buddies on the XMPP server in a call block way
 *
 * @throws ContainerConnectException
 */
public void testRetrieveBuddiesAllFieldsSync() throws ContainerConnectException {
    try {
        assertNotNull(searchManager);
        IRestriction selection = searchManager.createRestriction();
        assertNotNull(selection);
        // fields to consider on XMPP server side search
        // search field for XMPP, criterion to match the search
        ICriterion name = selection.eq(NAME, "Marcelo*");
        ICriterion email = selection.eq(EMAIL, "zx*");
        ICriterion username = selection.eq(USERNAME, "sl*");
        // create a specific criteria
        ICriteria criteria = searchManager.createCriteria();
        assertNotNull(criteria);
        criteria.add(name);
        criteria.add(email);
        criteria.add(username);
        // call the block search
        ISearch search = searchManager.search(criteria);
        // the collection of IResult
        IResultList resultList = search.getResultList();
        // check if there is at least one result
        assertTrue(0 != resultList.getResults().size());
        Iterator it = resultList.getResults().iterator();
        while (it.hasNext()) {
            IResult type = (IResult) it.next();
            System.out.println(type.getUser().getName() + " : " + type.getUser().getID());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : IRestriction(org.eclipse.ecf.presence.search.IRestriction) ISearch(org.eclipse.ecf.presence.search.ISearch) Iterator(java.util.Iterator) IResultList(org.eclipse.ecf.presence.search.IResultList) ICriterion(org.eclipse.ecf.presence.search.ICriterion) ECFException(org.eclipse.ecf.core.util.ECFException) UserSearchException(org.eclipse.ecf.presence.search.UserSearchException) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) ICriteria(org.eclipse.ecf.presence.search.ICriteria) IResult(org.eclipse.ecf.presence.search.IResult)

Example 17 with ContainerConnectException

use of org.eclipse.ecf.core.ContainerConnectException in project ecf by eclipse.

the class DnsSdDiscoveryAdvertiser method connect.

/* (non-Javadoc)
	 * @see org.eclipse.ecf.provider.dnssd.DnsSdDiscoveryLocator#connect(org.eclipse.ecf.core.identity.ID, org.eclipse.ecf.core.security.IConnectContext)
	 */
public void connect(final ID aTargetID, final IConnectContext connectContext) throws ContainerConnectException {
    // $NON-NLS-1$ //$NON-NLS-2$
    Trace.trace(Activator.PLUGIN_ID, DnsSdDebugOptions.METHODS_TRACING, this.getClass(), "connect(ID aTargetID, IConnectContext connectContext)", "connecting container");
    // connect can only be called once
    if (targetID != null || getConfig() == null) {
        throw new ContainerConnectException(Messages.DnsSdDiscoveryAdvertiser_Container_Already_Connected);
    }
    // TODO convert non DnsSdServiceTypeIDs into DSTIDs
    if (aTargetID == null) {
        targetID = new DnsSdServiceTypeID();
    } else {
        final Namespace ns = getConnectNamespace();
        try {
            targetID = (DnsSdServiceTypeID) ns.createInstance(new Object[] { aTargetID });
        } catch (IDCreateException e) {
            throw new ContainerConnectException(e);
        }
    }
    // instantiate a default resolver
    if (resolver == null) {
        try {
            resolver = new SimpleResolver();
            resolver.setTCP(true);
        } catch (UnknownHostException e) {
            throw new ContainerConnectException(e);
        }
    }
    // done setting up this provider, send event
    fireContainerEvent(new ContainerConnectingEvent(this.getID(), targetID, connectContext));
    fireContainerEvent(new ContainerConnectedEvent(this.getID(), targetID));
}
Also used : ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) UnknownHostException(java.net.UnknownHostException) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) ContainerConnectedEvent(org.eclipse.ecf.core.events.ContainerConnectedEvent) ContainerConnectingEvent(org.eclipse.ecf.core.events.ContainerConnectingEvent) SimpleResolver(org.xbill.DNS.SimpleResolver) Namespace(org.eclipse.ecf.core.identity.Namespace)

Example 18 with ContainerConnectException

use of org.eclipse.ecf.core.ContainerConnectException in project ecf by eclipse.

the class CompositeDiscoveryContainer method connect.

/* (non-Javadoc)
	 * @see org.eclipse.ecf.core.IContainer#connect(org.eclipse.ecf.core.identity.ID, org.eclipse.ecf.core.security.IConnectContext)
	 */
public void connect(final ID aTargetID, final IConnectContext connectContext) throws ContainerConnectException {
    if (targetID != null || getConfig() == null) {
        // $NON-NLS-1$
        throw new ContainerConnectException("Already connected");
    }
    targetID = (aTargetID == null) ? getConfig().getID() : aTargetID;
    fireContainerEvent(new ContainerConnectingEvent(this.getID(), targetID, connectContext));
    synchronized (containers) {
        final Collection containersFailedToConnect = new HashSet();
        for (final Iterator itr = containers.iterator(); itr.hasNext(); ) {
            final IContainer container = (IContainer) itr.next();
            if (container.getConnectedID() == null) {
                try {
                    container.connect(targetID, connectContext);
                } catch (ContainerConnectException cce) {
                    // $NON-NLS-1$
                    Trace.catching(// $NON-NLS-1$
                    Activator.PLUGIN_ID, // $NON-NLS-1$
                    METHODS_TRACING, // $NON-NLS-1$
                    this.getClass(), // $NON-NLS-1$
                    "connect", cce);
                    containersFailedToConnect.add(container);
                    continue;
                }
            }
            final IDiscoveryLocator idca = (IDiscoveryLocator) container;
            idca.addServiceListener(ccsl);
            idca.addServiceTypeListener(ccstl);
        }
        // remove all containers that failed to connect and thus are unusable subsequently
        containers.removeAll(containersFailedToConnect);
    }
    fireContainerEvent(new ContainerConnectedEvent(this.getID(), targetID));
}
Also used : ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) IContainer(org.eclipse.ecf.core.IContainer)

Example 19 with ContainerConnectException

use of org.eclipse.ecf.core.ContainerConnectException in project ecf by eclipse.

the class Activator method start.

/*
	 * (non-Javadoc)
	 * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
	 */
public void start(final BundleContext context) throws Exception {
    if (ENABLED) {
        context.registerService(Namespace.class, new CompositeNamespace(), null);
        // $NON-NLS-1$ //$NON-NLS-2$
        context.registerService(ContainerTypeDescription.class, new ContainerTypeDescription("ecf.discovery.composite", new CompositeDiscoveryContainerInstantiator(), "Composite Discovery Container", true, false), null);
        // $NON-NLS-1$ //$NON-NLS-2$
        context.registerService(ContainerTypeDescription.class, new ContainerTypeDescription("ecf.singleton.discovery", new SingletonDiscoveryContainerInstantiator(), "Composite Discovery Container Locator", true, false), null);
        // $NON-NLS-1$ //$NON-NLS-2$
        context.registerService(ContainerTypeDescription.class, new ContainerTypeDescription("ecf.discovery.composite.locator", new CompositeDiscoveryContainerInstantiator(), "Composite Discovery Container Locator"), null);
        // $NON-NLS-1$ //$NON-NLS-2$
        context.registerService(ContainerTypeDescription.class, new ContainerTypeDescription("ecf.discovery.composite.advertiser", new CompositeDiscoveryContainerInstantiator(), "Composite Discovery Container Advertiser"), null);
        final Hashtable<String, Object> props = new Hashtable<String, Object>();
        props.put(IDiscoveryLocator.CONTAINER_NAME, CompositeDiscoveryContainer.NAME);
        props.put(Constants.SERVICE_RANKING, new Integer(1000));
        String[] clazzes = new String[] { IDiscoveryService.class.getName(), IDiscoveryLocator.class.getName(), IDiscoveryAdvertiser.class.getName() };
        context.registerService(clazzes, new ServiceFactory() {

            public Object getService(final Bundle bundle, final ServiceRegistration registration) {
                // register the composite discovery service)
                final CompositeDiscoveryContainer cdc;
                cdc = new CompositeDiscoveryContainer(new HashSet());
                try {
                    cdc.connect(null, null);
                } catch (final ContainerConnectException e) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    Trace.catching(Activator.PLUGIN_ID, Activator.PLUGIN_ID + "/debug/methods/catching", this.getClass(), "getService(Bundle, ServiceRegistration)", e);
                    return null;
                }
                Filter filter = null;
                // add a service listener to add/remove IDS dynamically
                try {
                    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
                    final String filter2 = "(&(" + Constants.OBJECTCLASS + "=" + IDiscoveryAdvertiser.class.getName() + ")(!(" + IDiscoveryLocator.CONTAINER_NAME + "=" + CompositeDiscoveryContainer.NAME + ")))";
                    filter = context.createFilter(filter2);
                    context.addServiceListener(new ServiceListener() {

                        public void serviceChanged(final ServiceEvent arg0) {
                            final Object anIDS = context.getService(arg0.getServiceReference());
                            switch(arg0.getType()) {
                                case ServiceEvent.REGISTERED:
                                    cdc.addContainer(anIDS);
                                    break;
                                case ServiceEvent.UNREGISTERING:
                                    cdc.removeContainer(anIDS);
                                    break;
                                default:
                                    break;
                            }
                        }
                    }, filter2);
                } catch (final InvalidSyntaxException e) {
                // nop
                }
                // get all previously registered IDS from OSGi (but not this one)
                final ServiceTracker tracker = new ServiceTracker(context, filter, null);
                tracker.open();
                final Object[] services = tracker.getServices();
                tracker.close();
                if (services != null) {
                    for (int i = 0; i < services.length; i++) {
                        final Object obj = services[i];
                        if (obj != cdc)
                            cdc.addContainer(obj);
                    }
                }
                return cdc;
            }

            public void ungetService(final Bundle bundle, final ServiceRegistration registration, final Object service) {
                ((CompositeDiscoveryContainer) service).dispose();
            }
        }, props);
    }
}
Also used : IDiscoveryAdvertiser(org.eclipse.ecf.discovery.IDiscoveryAdvertiser) ServiceTracker(org.osgi.util.tracker.ServiceTracker) ContainerTypeDescription(org.eclipse.ecf.core.ContainerTypeDescription) Hashtable(java.util.Hashtable) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) HashSet(java.util.HashSet)

Example 20 with ContainerConnectException

use of org.eclipse.ecf.core.ContainerConnectException in project ecf by eclipse.

the class RSExampleContainer method connect.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ecf.core.IContainer#connect(org.eclipse.ecf.core.identity.ID,
	 *      org.eclipse.ecf.core.security.IConnectContext)
	 */
public void connect(ID targetID, IConnectContext connectContext) throws ContainerConnectException {
    if (!targetID.getNamespace().getName().equals(getConnectNamespace().getName()))
        throw new ContainerConnectException("targetID not of appropriate Namespace");
    fireContainerEvent(new ContainerConnectingEvent(getID(), targetID));
    // XXX connect to remote service here
    this.targetID = targetID;
    fireContainerEvent(new ContainerConnectedEvent(getID(), targetID));
}
Also used : ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) ContainerConnectedEvent(org.eclipse.ecf.core.events.ContainerConnectedEvent) ContainerConnectingEvent(org.eclipse.ecf.core.events.ContainerConnectingEvent)

Aggregations

ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)26 ECFException (org.eclipse.ecf.core.util.ECFException)8 ContainerConnectedEvent (org.eclipse.ecf.core.events.ContainerConnectedEvent)6 ContainerConnectingEvent (org.eclipse.ecf.core.events.ContainerConnectingEvent)6 ID (org.eclipse.ecf.core.identity.ID)6 IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)5 Namespace (org.eclipse.ecf.core.identity.Namespace)5 IContainer (org.eclipse.ecf.core.IContainer)4 CallbackHandler (org.eclipse.ecf.core.security.CallbackHandler)3 IOException (java.io.IOException)2 UnknownHostException (java.net.UnknownHostException)2 BBException (org.eclipse.ecf.bulletinboard.BBException)2 IBBCredentials (org.eclipse.ecf.bulletinboard.IBBCredentials)2 Callback (org.eclipse.ecf.core.security.Callback)2 IConnectContext (org.eclipse.ecf.core.security.IConnectContext)2 NameCallback (org.eclipse.ecf.core.security.NameCallback)2 ObjectCallback (org.eclipse.ecf.core.security.ObjectCallback)2 SharedObjectAddException (org.eclipse.ecf.core.sharedobject.SharedObjectAddException)2 XMPPRoomID (org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID)2 ConnectException (java.net.ConnectException)1