Search in sources :

Example 1 with ContainerConnectException

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

the class DnsSdDiscoveryLocator 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 aTargetID, IConnectContext connectContext) throws ContainerConnectException {
    // connect can only be called once
    if (targetID != null || getConfig() == null) {
        throw new ContainerConnectException(Messages.DnsSdDiscoveryLocator_Container_Already_Connected);
    }
    // fall back to the search path as last resort
    if (aTargetID == null || !(aTargetID instanceof DnsSdServiceTypeID)) {
        ResolverConfig config = new ResolverConfig();
        Name[] searchPaths = config.searchPath();
        if (searchPaths != null && searchPaths.length > 0) {
            targetID = new DnsSdServiceTypeID();
            targetID.setSearchPath(searchPaths);
        } else {
            throw new ContainerConnectException(Messages.DnsSdDiscoveryLocator_No_Target_ID);
        }
    } 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();
        } catch (UnknownHostException e) {
            throw new ContainerConnectException(e);
        }
    }
    // read browsing domains for the given targetID/searchpath and merge with existing
    targetID.addSearchPath(getBrowsingDomains(targetID));
    // done setting up this provider, send event
    fireContainerEvent(new ContainerConnectingEvent(this.getID(), targetID, connectContext));
    fireContainerEvent(new ContainerConnectedEvent(this.getID(), targetID));
}
Also used : ResolverConfig(org.xbill.DNS.ResolverConfig) 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) Name(org.xbill.DNS.Name)

Example 2 with ContainerConnectException

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

the class CompositeDiscoveryContainer method addContainer.

/**
 * @param object
 * @return true on success
 * @see java.util.List#add(java.lang.Object)
 */
public boolean addContainer(final Object object) {
    // connect the new container if necessary and register ourself as listeners
    IContainer iContainer = (IContainer) object;
    if (iContainer.getConnectedID() == null) {
        try {
            iContainer.connect(targetID, null);
        } catch (ContainerConnectException e) {
            // we eat the exception here
            // $NON-NLS-1$
            Trace.catching(Activator.PLUGIN_ID, METHODS_CATCHING, this.getClass(), "addContainer(Object)", e);
            return false;
        }
    }
    final IDiscoveryLocator idca = (IDiscoveryLocator) object;
    idca.addServiceListener(ccsl);
    idca.addServiceTypeListener(ccstl);
    // register previously registered with the new IDS
    synchronized (registeredServices) {
        final IDiscoveryAdvertiser ida = (IDiscoveryAdvertiser) object;
        for (final Iterator itr = registeredServices.iterator(); itr.hasNext(); ) {
            final IServiceInfo serviceInfo = (IServiceInfo) itr.next();
            try {
                ida.registerService(serviceInfo);
            } catch (final ECFRuntimeException e) {
                // we eat the exception here since the original registerService call is long done
                // $NON-NLS-1$
                Trace.catching(Activator.PLUGIN_ID, METHODS_CATCHING, this.getClass(), "addContainer(Object)", e);
            }
        }
    }
    synchronized (containers) {
        Trace.trace(Activator.PLUGIN_ID, METHODS_TRACING, this.getClass(), "addContainer(Object)", // $NON-NLS-1$ //$NON-NLS-2$
        "addContainer " + object.toString());
        return containers.add(object);
    }
}
Also used : ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) IContainer(org.eclipse.ecf.core.IContainer) ECFRuntimeException(org.eclipse.ecf.core.util.ECFRuntimeException)

Example 3 with ContainerConnectException

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

the class ConnectRemoteServicehandler method getJob.

protected Job getJob(final ExecutionEvent event) throws ExecutionException {
    final ID createConnectId = RemoteServiceHandlerUtil.getActiveConnectIDChecked(event);
    final IContainer container = RemoteServiceHandlerUtil.getActiveIRemoteServiceContainerChecked(event);
    // decouple the long running connect call from the ui thread
    return new // $NON-NLS-1$
    Job(// $NON-NLS-1$
    NLS.bind("Connecting {0}", createConnectId.getName())) {

        protected IStatus run(IProgressMonitor monitor) {
            try {
                if (container != null)
                    container.connect(createConnectId, null);
            } catch (ContainerConnectException e) {
                showException(e);
                return Status.CANCEL_STATUS;
            }
            return Status.OK_STATUS;
        }
    };
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) ID(org.eclipse.ecf.core.identity.ID) IContainer(org.eclipse.ecf.core.IContainer) Job(org.eclipse.core.runtime.jobs.Job)

Example 4 with ContainerConnectException

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

the class JMDNSDiscoveryContainer 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 targetID1, final IConnectContext joinContext) throws ContainerConnectException {
    synchronized (lock) {
        if (disposed)
            // $NON-NLS-1$
            throw new ContainerConnectException("Container has been disposed");
        if (this.targetID != null)
            // $NON-NLS-1$
            throw new ContainerConnectException("Already connected");
        this.targetID = (targetID1 == null) ? getConfig().getID() : targetID1;
        fireContainerEvent(new ContainerConnectingEvent(this.getID(), this.targetID, joinContext));
        initializeQueue();
        try {
            this.jmdns = JmDNS.create();
            jmdns.addServiceTypeListener(this);
        } catch (final IOException e) {
            // $NON-NLS-1$
            Trace.catching(JMDNSPlugin.PLUGIN_ID, JMDNSDebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "connect", e);
            if (this.jmdns != null) {
                jmdns.close();
                jmdns = null;
            }
            // $NON-NLS-1$
            throw new ContainerConnectException("Cannot create JmDNS instance", e);
        }
        fireContainerEvent(new ContainerConnectedEvent(this.getID(), this.targetID));
    }
}
Also used : ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException)

Example 5 with ContainerConnectException

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

the class AbstractBBContainer method connect.

public void connect(ID targetID, IConnectContext connectContext) throws ContainerConnectException {
    this.targetID = targetID;
    bb.postConnect();
    IBBCredentials creds = getCredentialsFromConnectContext(connectContext);
    if (creds != null) {
        try {
            bb.login(creds);
        } catch (BBException e) {
            throw new ContainerConnectException(e);
        }
    }
}
Also used : ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) IBBCredentials(org.eclipse.ecf.bulletinboard.IBBCredentials) BBException(org.eclipse.ecf.bulletinboard.BBException)

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