Search in sources :

Example 1 with ContainerConnectedEvent

use of org.eclipse.ecf.core.events.ContainerConnectedEvent 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 ContainerConnectedEvent

use of org.eclipse.ecf.core.events.ContainerConnectedEvent in project ecf by eclipse.

the class UserInputDiscoveryLocator 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 {
    fireContainerEvent(new ContainerConnectingEvent(this.getID(), targetId, connectContext));
    fireContainerEvent(new ContainerConnectedEvent(this.getID(), targetId));
    this.targetId = targetId;
}
Also used : ContainerConnectedEvent(org.eclipse.ecf.core.events.ContainerConnectedEvent) ContainerConnectingEvent(org.eclipse.ecf.core.events.ContainerConnectingEvent)

Example 3 with ContainerConnectedEvent

use of org.eclipse.ecf.core.events.ContainerConnectedEvent in project ecf by eclipse.

the class UserInputDiscoveryLocator method disconnect.

/* (non-Javadoc)
	 * @see org.eclipse.ecf.core.IContainer#disconnect()
	 */
public void disconnect() {
    fireContainerEvent(new ContainerDisconnectingEvent(this.getID(), targetId));
    fireContainerEvent(new ContainerConnectedEvent(this.getID(), targetId));
}
Also used : ContainerConnectedEvent(org.eclipse.ecf.core.events.ContainerConnectedEvent) ContainerDisconnectingEvent(org.eclipse.ecf.core.events.ContainerDisconnectingEvent)

Example 4 with ContainerConnectedEvent

use of org.eclipse.ecf.core.events.ContainerConnectedEvent in project ecf by eclipse.

the class RssClientSOContainer method handleConnectResponse.

protected ID handleConnectResponse(ID originalTarget, Object serverData) throws Exception {
    trace("handleConnectResponse:" + originalTarget + ":" + serverData);
    if (originalTarget != null && !originalTarget.equals(getID())) {
        addNewRemoteMember(originalTarget, null);
        // notify listeners
        fireContainerEvent(new ContainerConnectedEvent(this.getID(), originalTarget));
    }
    return originalTarget;
}
Also used : ContainerConnectedEvent(org.eclipse.ecf.core.events.ContainerConnectedEvent)

Example 5 with ContainerConnectedEvent

use of org.eclipse.ecf.core.events.ContainerConnectedEvent 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)

Aggregations

ContainerConnectedEvent (org.eclipse.ecf.core.events.ContainerConnectedEvent)9 ContainerConnectingEvent (org.eclipse.ecf.core.events.ContainerConnectingEvent)7 ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)6 IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)4 IOException (java.io.IOException)2 UnknownHostException (java.net.UnknownHostException)2 Namespace (org.eclipse.ecf.core.identity.Namespace)2 SimpleResolver (org.xbill.DNS.SimpleResolver)2 ContainerDisconnectingEvent (org.eclipse.ecf.core.events.ContainerDisconnectingEvent)1 ID (org.eclipse.ecf.core.identity.ID)1 Callback (org.eclipse.ecf.core.security.Callback)1 CallbackHandler (org.eclipse.ecf.core.security.CallbackHandler)1 NameCallback (org.eclipse.ecf.core.security.NameCallback)1 ObjectCallback (org.eclipse.ecf.core.security.ObjectCallback)1 UnsupportedCallbackException (org.eclipse.ecf.core.security.UnsupportedCallbackException)1 SharedObjectAddException (org.eclipse.ecf.core.sharedobject.SharedObjectAddException)1 ECFException (org.eclipse.ecf.core.util.ECFException)1 IRosterGroup (org.eclipse.ecf.presence.roster.IRosterGroup)1 ChatSession (org.eclipse.ecf.protocol.msn.ChatSession)1 Contact (org.eclipse.ecf.protocol.msn.Contact)1