use of org.eclipse.ecf.core.ContainerConnectException in project ecf by eclipse.
the class RemoteServiceAdmin method importService.
private ImportRegistration importService(final EndpointDescription endpointDescription, IRemoteServiceContainer rsContainer) {
// Get interfaces from endpoint description
Collection<String> interfaces = endpointDescription.getInterfaces();
Assert.isNotNull(interfaces);
Assert.isTrue(interfaces.size() > 0);
// Get ECF endpoint ID...if this throws IDCreateException (because the
// local system does not have
// namespace for creating ID, or no namespace is present in
// endpointDescription or endpoint id,
// then it will be caught by the caller
ID endpointContainerID = endpointDescription.getContainerID();
Assert.isNotNull(endpointContainerID);
// Get connect target ID. May be null
ID tID = endpointDescription.getConnectTargetID();
if (tID == null)
tID = endpointContainerID;
final ID targetID = tID;
// Get idFilter...also may be null
final ID[] idFilter = getIDFilter(endpointDescription, targetID);
// Get remote service filter
final String rsFilter = getRemoteServiceFilter(endpointDescription);
// IRemoteServiceReferences from query
Collection<IRemoteServiceReference> rsRefs = new ArrayList<IRemoteServiceReference>();
// Get IRemoteServiceContainerAdapter
final IRemoteServiceContainerAdapter containerAdapter = rsContainer.getContainerAdapter();
// rsContainerID
ID rsContainerID = rsContainer.getContainer().getID();
try {
final IRSAConsumerContainerAdapter cca = (IRSAConsumerContainerAdapter) containerAdapter.getAdapter(IRSAConsumerContainerAdapter.class);
// Get first interface name for service reference
// lookup
final String intf = interfaces.iterator().next();
// Get/lookup remote service references
IRemoteServiceReference[] refs = AccessController.doPrivileged(new PrivilegedExceptionAction<IRemoteServiceReference[]>() {
public IRemoteServiceReference[] run() throws ContainerConnectException, InvalidSyntaxException {
// If the RSAConsumerContainerAdapter is present, use it
if (cca != null)
// Call importEndpoint if the IRSAConsumerContainerAdapter is present
return cca.importEndpoint(endpointDescription.getProperties());
else
return containerAdapter.getRemoteServiceReferences(targetID, idFilter, intf, rsFilter);
}
});
if (refs == null) {
logWarning(// $NON-NLS-1$
"doImportService", // $NON-NLS-1$
"getRemoteServiceReferences return null for targetID=" + targetID + ",idFilter=" + // $NON-NLS-1$
idFilter + ",intf=" + intf + ",rsFilter=" + // $NON-NLS-1$ //$NON-NLS-2$
rsFilter + " on rsContainerID=" + // $NON-NLS-1$
rsContainerID);
} else
for (int i = 0; i < refs.length; i++) rsRefs.add(refs[i]);
// If there are several refs resulting (should not be)
// we select the one to use
IRemoteServiceReference selectedRsReference = selectRemoteServiceReference(rsRefs, targetID, idFilter, interfaces, rsFilter, rsContainer);
// If none found, we obviously can't continue
if (selectedRsReference == null)
throw new RemoteReferenceNotFoundException(targetID, idFilter, interfaces, rsFilter);
return new ImportRegistration(createAndRegisterProxy(endpointDescription, rsContainer, selectedRsReference));
} catch (PrivilegedActionException e) {
logError("importService", // $NON-NLS-1$ //$NON-NLS-2$
"selectRemoteServiceReference returned null for rsRefs=" + rsRefs + ",targetID=" + // $NON-NLS-1$
targetID + ",idFilter=" + idFilter + // $NON-NLS-1$ //$NON-NLS-2$
",interfaces=" + interfaces + ",rsFilter=" + // $NON-NLS-1$
rsFilter + ",rsContainerID=" + rsContainerID, // $NON-NLS-1$
e.getException());
return new ImportRegistration(endpointDescription, e.getException());
} catch (Exception e) {
logError("importService", // $NON-NLS-1$ //$NON-NLS-2$
"selectRemoteServiceReference returned null for rsRefs=" + rsRefs + ",targetID=" + // $NON-NLS-1$
targetID + ",idFilter=" + idFilter + // $NON-NLS-1$ //$NON-NLS-2$
",interfaces=" + interfaces + ",rsFilter=" + // $NON-NLS-1$
rsFilter + ",rsContainerID=" + rsContainerID, // $NON-NLS-1$
e);
return new ImportRegistration(endpointDescription, e);
}
}
use of org.eclipse.ecf.core.ContainerConnectException in project ecf by eclipse.
the class AbstractConsumerContainerSelector method connectContainerToTarget.
protected void connectContainerToTarget(IRemoteServiceContainer rsContainer, ID connectTargetID) {
if (connectTargetID == null)
return;
IContainer container = rsContainer.getContainer();
ID connectedID = container.getConnectedID();
// it's not already connected
if (connectedID == null) {
// connect to target
try {
connectContainer(container, connectTargetID, getConnectContext(container, connectTargetID));
} catch (ContainerConnectException e) {
logException(// $NON-NLS-1$
"Exception connecting container id=" + container.getID() + // $NON-NLS-1$
" to connectTargetID=" + connectTargetID, e);
}
}
}
use of org.eclipse.ecf.core.ContainerConnectException in project ecf by eclipse.
the class AbstractBBContainer method getCredentialsFromConnectContext.
protected IBBCredentials getCredentialsFromConnectContext(IConnectContext connectContext) throws ContainerConnectException {
try {
if (connectContext == null) {
return null;
}
Callback[] callbacks = new Callback[2];
callbacks[0] = new NameCallback("Username");
callbacks[1] = new ObjectCallback();
CallbackHandler handler = connectContext.getCallbackHandler();
if (handler != null) {
handler.handle(callbacks);
}
NameCallback nc = (NameCallback) callbacks[0];
ObjectCallback cb = (ObjectCallback) callbacks[1];
return new Credentials(nc.getName(), (String) cb.getObject());
} catch (Exception e) {
throw new ContainerConnectException("Exception in CallbackHandler.handle(<callbacks>)", e);
}
}
use of org.eclipse.ecf.core.ContainerConnectException in project ecf by eclipse.
the class MSNContainer method connect.
public void connect(ID targetID, IConnectContext connectContext) throws ContainerConnectException {
if (!(targetID instanceof MSNID)) {
throw new ContainerConnectException(Messages.MSNContainer_TargetIDNotMSNID);
}
client = new MsnClient();
ObjectCallback[] cb = { new ObjectCallback() };
try {
connectContext.getCallbackHandler().handle(cb);
client.addSessionListener(new ISessionListener() {
public void sessionConnected(ChatSession session) {
try {
Contact contact = session.getParticipants()[0];
final ID toID = namespace.createInstance(new Object[] { contact.getEmail() });
chatSessions.put(toID, session);
session.addChatSessionListener(new ChatSessionListener(toID));
} catch (IDCreateException e) {
// ignored since this should not be possible
}
}
});
client.getContactList().addContactListListener(new IContactListListener() {
public void contactAdded(Contact contact) {
final MSNRosterEntry entry = new MSNRosterEntry(MSNContainer.this, contact, namespace);
for (int i = 0; i < entries.size(); i++) {
Object e = entries.get(i);
if (e instanceof MSNRosterGroup) {
MSNRosterGroup group = (MSNRosterGroup) e;
if (group.getGroup().contains(contact)) {
MSNRosterEntry check = group.getEntryFor(contact);
if (check == null) {
check = entry;
contact.addContactListener(new IContactListener() {
public void nameChanged(String name) {
firePresence(entry.getID(), entry.getPresence());
fireRosterUpdate(entry);
}
public void personalMessageChanged(String personalMessage) {
entry.updatePersonalMessage();
firePresence(entry.getID(), entry.getPresence());
fireRosterUpdate(entry);
}
public void statusChanged(Status status) {
firePresence(entry.getID(), entry.getPresence());
fireRosterUpdate(entry);
}
});
group.add(check);
fireRosterEntryAdded(check);
}
fireRosterUpdate(group);
return;
}
} else {
MSNRosterEntry check = (MSNRosterEntry) e;
if (entry.getContact().equals(check.getContact())) {
fireRosterEntryAdded(check);
fireRosterUpdate(check.getParent());
return;
}
}
}
contact.addContactListener(new IContactListener() {
public void nameChanged(String name) {
firePresence(entry.getID(), entry.getPresence());
fireRosterUpdate(entry);
}
public void personalMessageChanged(String personalMessage) {
entry.updatePersonalMessage();
firePresence(entry.getID(), entry.getPresence());
fireRosterUpdate(entry);
}
public void statusChanged(Status status) {
firePresence(entry.getID(), entry.getPresence());
fireRosterUpdate(entry);
}
});
entries.add(entry);
entry.setParent(MSNContainer.this);
fireRosterEntryAdded(entry);
fireRosterUpdate(MSNContainer.this);
}
public void contactRemoved(Contact contact) {
MSNRosterEntry entry = findEntry(entries, contact.getEmail());
if (entry != null) {
fireHandleUnsubscribed(entry.getUser().getID());
fireRosterEntryRemoved(entry);
fireRosterUpdate(entry.getParent());
if (entry.getContact().getGroups().isEmpty()) {
entry.setParent(MSNContainer.this);
fireRosterUpdate(MSNContainer.this);
}
}
}
public void contactAddedUser(String email) {
try {
fireHandleSubscriptionRequest(namespace.createInstance(new Object[] { email }));
} catch (IDCreateException e) {
// ignored
}
}
public void contactRemovedUser(String email) {
// nothing to do
}
public void groupAdded(Group group) {
entries.add(new MSNRosterGroup(MSNContainer.this, group));
}
});
fireContainerEvent(new ContainerConnectingEvent(guid, targetID));
client.connect(targetID.getName(), (String) cb[0].getObject());
connectID = (MSNID) targetID;
fireContainerEvent(new ContainerConnectedEvent(guid, connectID));
Activator.getDefault().registerService(this);
} catch (UnsupportedCallbackException e) {
throw new ContainerConnectException(e);
} catch (IOException e) {
throw new ContainerConnectException(e);
}
}
use of org.eclipse.ecf.core.ContainerConnectException in project ecf by eclipse.
the class RegistrySharedObject method connectToRemoteServiceTarget.
/**
* @param targetID target ID to connect to
* @throws ContainerConnectException if container cannot connect to target ID
* @since 3.3 for preventing issues like bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=304427
*/
protected void connectToRemoteServiceTarget(ID targetID) throws ContainerConnectException {
ISharedObjectContext context = getContext();
ID connectedID = context.getConnectedID();
// If we're already connected to something then we don't need to connect...and we return
if (connectedID != null)
return;
synchronized (rsConnectLock) {
// we just try to connect to target with our given connectContext
context.connect(targetID, connectContext);
// wait to receive connected event
// Wait until we receive the IContainerConnectedEvent on the shared object thread
int rsTimeout = getRSConnectTimeout();
long endTime = System.currentTimeMillis() + rsTimeout;
while (!rsConnected && (endTime >= System.currentTimeMillis())) {
try {
// wait for asynchronous notification of getting connected
rsConnectLock.wait(rsTimeout / 10);
} catch (InterruptedException e) {
// $NON-NLS-1$
throw new ContainerConnectException("No notification of registry connect complete for connect targetID=" + targetID);
}
}
if (!rsConnected)
// $NON-NLS-1$
throw new ContainerConnectException("Could not complete registry connect for targetID=" + targetID);
}
}
Aggregations