Search in sources :

Example 6 with ContainerConnectedEvent

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

the class DnsSdDiscoveryAdvertiser method connect.

/* (non-Javadoc)
	 * @see org.eclipse.ecf.provider.dnssd.DnsSdDiscoveryLocator#connect(org.eclipse.ecf.core.identity.ID, org.eclipse.ecf.core.security.IConnectContext)
	 */
public void connect(final ID aTargetID, final IConnectContext connectContext) throws ContainerConnectException {
    // $NON-NLS-1$ //$NON-NLS-2$
    Trace.trace(Activator.PLUGIN_ID, DnsSdDebugOptions.METHODS_TRACING, this.getClass(), "connect(ID aTargetID, IConnectContext connectContext)", "connecting container");
    // connect can only be called once
    if (targetID != null || getConfig() == null) {
        throw new ContainerConnectException(Messages.DnsSdDiscoveryAdvertiser_Container_Already_Connected);
    }
    // TODO convert non DnsSdServiceTypeIDs into DSTIDs
    if (aTargetID == null) {
        targetID = new DnsSdServiceTypeID();
    } 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();
            resolver.setTCP(true);
        } catch (UnknownHostException e) {
            throw new ContainerConnectException(e);
        }
    }
    // done setting up this provider, send event
    fireContainerEvent(new ContainerConnectingEvent(this.getID(), targetID, connectContext));
    fireContainerEvent(new ContainerConnectedEvent(this.getID(), targetID));
}
Also used : 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)

Example 7 with ContainerConnectedEvent

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

the class RSExampleContainer 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 {
    if (!targetID.getNamespace().getName().equals(getConnectNamespace().getName()))
        throw new ContainerConnectException("targetID not of appropriate Namespace");
    fireContainerEvent(new ContainerConnectingEvent(getID(), targetID));
    // XXX connect to remote service here
    this.targetID = targetID;
    fireContainerEvent(new ContainerConnectedEvent(getID(), targetID));
}
Also used : ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) ContainerConnectedEvent(org.eclipse.ecf.core.events.ContainerConnectedEvent) ContainerConnectingEvent(org.eclipse.ecf.core.events.ContainerConnectingEvent)

Example 8 with ContainerConnectedEvent

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

the class TrivialContainer 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 {
    if (!targetID.getNamespace().getName().equals(getConnectNamespace().getName()))
        throw new ContainerConnectException("targetID not of appropriate Namespace");
    fireContainerEvent(new ContainerConnectingEvent(getID(), targetID));
    // XXX connect to remote service here
    this.targetID = targetID;
    fireContainerEvent(new ContainerConnectedEvent(getID(), targetID));
}
Also used : ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) ContainerConnectedEvent(org.eclipse.ecf.core.events.ContainerConnectedEvent) ContainerConnectingEvent(org.eclipse.ecf.core.events.ContainerConnectingEvent)

Example 9 with ContainerConnectedEvent

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

the class XMPPChatRoomContainer method connect.

public void connect(ID remote, IConnectContext connectContext) throws ContainerConnectException {
    if (!(remote instanceof XMPPRoomID)) {
        throw new ContainerConnectException(NLS.bind(Messages.XMPPChatRoomContainer_Exception_Connect_Wrong_Type, remote));
    }
    final XMPPRoomID roomID = (XMPPRoomID) remote;
    fireContainerEvent(new ContainerConnectingEvent(this.getID(), remote, connectContext));
    synchronized (getConnectLock()) {
        try {
            connectionState = CONNECTING;
            remoteServerID = null;
            addSharedObjectToContainer(remote);
            multiuserchat = new MultiUserChat(getXMPPConnection(), roomID.getMucString());
            // Get nickname from join context
            String nick = null;
            try {
                final Callback[] callbacks = new Callback[1];
                callbacks[0] = new NameCallback(Messages.XMPPChatRoomContainer_NAME_CALLBACK_NICK, roomID.getNickname());
                if (connectContext != null) {
                    final CallbackHandler handler = connectContext.getCallbackHandler();
                    if (handler != null) {
                        handler.handle(callbacks);
                    }
                }
                if (callbacks[0] instanceof NameCallback) {
                    final NameCallback cb = (NameCallback) callbacks[0];
                    nick = cb.getName();
                }
            } catch (final Exception e) {
                throw new ContainerConnectException(Messages.XMPPChatRoomContainer_EXCEPTION_CALLBACKHANDLER, e);
            }
            String nickname = null;
            if (// $NON-NLS-1$
            nick == null || nick.equals(""))
                nickname = roomID.getNickname();
            else
                nickname = nick;
            multiuserchat.addSubjectUpdatedListener(new SubjectUpdatedListener() {

                public void subjectUpdated(String subject, String from) {
                    fireSubjectUpdated(subject, from);
                }
            });
            multiuserchat.addMessageListener(new PacketListener() {

                public void processPacket(Packet arg0) {
                    handleXMPPMessage(arg0);
                }
            });
            multiuserchat.addParticipantListener(new PacketListener() {

                public void processPacket(Packet arg0) {
                    handleXMPPMessage(arg0);
                }
            });
            multiuserchat.addParticipantStatusListener(new ParticipantStatusListener() {

                public void joined(String arg0) {
                    handleChatMembershipEvent(arg0, true);
                }

                public void left(String arg0) {
                    handleChatMembershipEvent(arg0, false);
                }

                public void voiceGranted(String arg0) {
                    // TODO Auto-generated method stub
                    // $NON-NLS-1$ //$NON-NLS-2$
                    System.out.println("voiceGranted(" + arg0 + ")");
                }

                public void voiceRevoked(String arg0) {
                    // TODO Auto-generated method stub
                    // $NON-NLS-1$ //$NON-NLS-2$
                    System.out.println("voiceRevoked(" + arg0 + ")");
                }

                public void membershipGranted(String arg0) {
                    // TODO Auto-generated method stub
                    System.out.println(// $NON-NLS-1$
                    "membershipGranted(" + arg0 + // $NON-NLS-1$
                    ")");
                }

                public void membershipRevoked(String arg0) {
                    // TODO Auto-generated method stub
                    System.out.println(// $NON-NLS-1$
                    "membershipRevoked(" + arg0 + // $NON-NLS-1$
                    ")");
                }

                public void moderatorGranted(String arg0) {
                    // TODO Auto-generated method stub
                    System.out.println(// $NON-NLS-1$
                    "moderatorGranted(" + arg0 + // $NON-NLS-1$
                    ")");
                }

                public void moderatorRevoked(String arg0) {
                    // TODO Auto-generated method stub
                    System.out.println(// $NON-NLS-1$
                    "moderatorRevoked(" + arg0 + // $NON-NLS-1$
                    ")");
                }

                public void ownershipGranted(String arg0) {
                    // TODO Auto-generated method stub
                    System.out.println(// $NON-NLS-1$
                    "ownershipGranted(" + arg0 + // $NON-NLS-1$
                    ")");
                }

                public void ownershipRevoked(String arg0) {
                    // TODO Auto-generated method stub
                    System.out.println(// $NON-NLS-1$
                    "ownershipRevoked(" + arg0 + // $NON-NLS-1$
                    ")");
                }

                public void adminGranted(String arg0) {
                    // TODO Auto-generated method stub
                    // $NON-NLS-1$ //$NON-NLS-2$
                    System.out.println("adminGranted(" + arg0 + ")");
                }

                public void adminRevoked(String arg0) {
                    // TODO Auto-generated method stub
                    // $NON-NLS-1$ //$NON-NLS-2$
                    System.out.println("adminRevoked(" + arg0 + ")");
                }

                public void kicked(String arg0, String arg1, String arg2) {
                    // TODO Auto-generated method stub
                    System.out.println(// $NON-NLS-1$ //$NON-NLS-2$
                    "kicked(" + arg0 + "," + arg1 + "," + arg2 + // $NON-NLS-1$ //$NON-NLS-2$
                    ")");
                }

                public void banned(String arg0, String arg1, String arg2) {
                    // TODO Auto-generated method stub
                    System.out.println(// $NON-NLS-1$ //$NON-NLS-2$
                    "banned(" + arg0 + "," + arg1 + "," + arg2 + // $NON-NLS-1$ //$NON-NLS-2$
                    ")");
                }

                public void nicknameChanged(String arg0, String arg1) {
                    // TODO Auto-generated method stub
                    System.out.println(// $NON-NLS-1$
                    "nicknameChanged(" + arg0 + "," + arg1 + // $NON-NLS-1$ //$NON-NLS-2$
                    ")");
                }
            });
            multiuserchat.addInvitationRejectionListener(new InvitationRejectionListener() {

                public void invitationDeclined(String arg0, String arg1) {
                    // TODO Auto-generated method stub
                    System.out.println(// $NON-NLS-1$
                    "invitationDeclined(" + arg0 + "," + arg1 + // $NON-NLS-1$ //$NON-NLS-2$
                    ")");
                }
            });
            multiuserchat.join(nickname);
            connectionState = CONNECTED;
            remoteServerID = roomID;
            containerHelper.setRoomID(remoteServerID);
            fireContainerEvent(new ContainerConnectedEvent(this.getID(), roomID));
        } catch (final Exception e) {
            cleanUpConnectFail();
            final ContainerConnectException ce = new ContainerConnectException(NLS.bind(Messages.XMPPChatRoomContainer_EXCEPTION_JOINING_ROOM, roomID));
            ce.setStackTrace(e.getStackTrace());
            throw ce;
        }
    }
}
Also used : ParticipantStatusListener(org.jivesoftware.smackx.muc.ParticipantStatusListener) Packet(org.jivesoftware.smack.packet.Packet) MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) CallbackHandler(org.eclipse.ecf.core.security.CallbackHandler) ContainerConnectedEvent(org.eclipse.ecf.core.events.ContainerConnectedEvent) XMPPRoomID(org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID) SubjectUpdatedListener(org.jivesoftware.smackx.muc.SubjectUpdatedListener) PacketListener(org.jivesoftware.smack.PacketListener) ECFException(org.eclipse.ecf.core.util.ECFException) ConnectionCreateException(org.eclipse.ecf.provider.comm.ConnectionCreateException) XMPPException(org.jivesoftware.smack.XMPPException) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) IOException(java.io.IOException) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) SharedObjectAddException(org.eclipse.ecf.core.sharedobject.SharedObjectAddException) InvitationRejectionListener(org.jivesoftware.smackx.muc.InvitationRejectionListener) 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) ContainerConnectingEvent(org.eclipse.ecf.core.events.ContainerConnectingEvent)

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