Search in sources :

Example 11 with ContainerConnectException

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);
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) ArrayList(java.util.ArrayList) IRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter) ECFException(org.eclipse.ecf.core.util.ECFException) ServiceException(org.osgi.framework.ServiceException) BundleException(org.osgi.framework.BundleException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) PrivilegedActionException(java.security.PrivilegedActionException) ContainerCreateException(org.eclipse.ecf.core.ContainerCreateException) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) IRemoteServiceReference(org.eclipse.ecf.remoteservice.IRemoteServiceReference) IRSAConsumerContainerAdapter(org.eclipse.ecf.remoteservice.IRSAConsumerContainerAdapter) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ID(org.eclipse.ecf.core.identity.ID) IRemoteServiceID(org.eclipse.ecf.remoteservice.IRemoteServiceID) UUID(java.util.UUID) StringID(org.eclipse.ecf.core.identity.StringID)

Example 12 with ContainerConnectException

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);
        }
    }
}
Also used : ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) ID(org.eclipse.ecf.core.identity.ID) IContainer(org.eclipse.ecf.core.IContainer)

Example 13 with ContainerConnectException

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);
    }
}
Also used : CallbackHandler(org.eclipse.ecf.core.security.CallbackHandler) ObjectCallback(org.eclipse.ecf.core.security.ObjectCallback) Callback(org.eclipse.ecf.core.security.Callback) NameCallback(org.eclipse.ecf.core.security.NameCallback) NameCallback(org.eclipse.ecf.core.security.NameCallback) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) ObjectCallback(org.eclipse.ecf.core.security.ObjectCallback) IBBCredentials(org.eclipse.ecf.bulletinboard.IBBCredentials) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) BBException(org.eclipse.ecf.bulletinboard.BBException)

Example 14 with ContainerConnectException

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);
    }
}
Also used : Status(org.eclipse.ecf.protocol.msn.Status) Group(org.eclipse.ecf.protocol.msn.Group) IRosterGroup(org.eclipse.ecf.presence.roster.IRosterGroup) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) ObjectCallback(org.eclipse.ecf.core.security.ObjectCallback) ContainerConnectedEvent(org.eclipse.ecf.core.events.ContainerConnectedEvent) ISessionListener(org.eclipse.ecf.protocol.msn.events.ISessionListener) IContactListener(org.eclipse.ecf.protocol.msn.events.IContactListener) IOException(java.io.IOException) ChatSession(org.eclipse.ecf.protocol.msn.ChatSession) Contact(org.eclipse.ecf.protocol.msn.Contact) IChatSessionListener(org.eclipse.ecf.protocol.msn.events.IChatSessionListener) MsnClient(org.eclipse.ecf.protocol.msn.MsnClient) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) IContactListListener(org.eclipse.ecf.protocol.msn.events.IContactListListener) ContainerConnectingEvent(org.eclipse.ecf.core.events.ContainerConnectingEvent) ID(org.eclipse.ecf.core.identity.ID) UnsupportedCallbackException(org.eclipse.ecf.core.security.UnsupportedCallbackException)

Example 15 with ContainerConnectException

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);
    }
}
Also used : ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException)

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