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));
}
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);
}
}
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;
}
};
}
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));
}
}
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);
}
}
}
Aggregations