Search in sources :

Example 21 with ContainerConnectException

use of org.eclipse.ecf.core.ContainerConnectException 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 22 with ContainerConnectException

use of org.eclipse.ecf.core.ContainerConnectException in project ecf by eclipse.

the class IRCChannelContainer 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 connectID, IConnectContext connectContext) throws ContainerConnectException {
    // Actually do join here
    if (connectID == null)
        throw new ContainerConnectException(Messages.IRCChannelContainer_Exception_TargetID_Null);
    if (connectWaiting)
        throw new ContainerConnectException(Messages.IRCChannelContainer_Exception_Connecting);
    // Get channel name
    String channelName = connectID.getName();
    fireContainerEvent(new ContainerConnectingEvent(this.getID(), connectID, connectContext));
    // Get password via callback in connectContext
    String pw = getPasswordFromConnectContext(connectContext);
    synchronized (connectLock) {
        connectWaiting = true;
        try {
            rootContainer.doJoinChannel(channelName, pw);
            long timeout = CONNECT_TIMEOUT + System.currentTimeMillis();
            while (connectWaiting && timeout > System.currentTimeMillis()) {
                connectLock.wait(2000);
            }
            if (connectWaiting)
                throw new TimeoutException(NLS.bind(Messages.IRCChannelContainer_Exception_Connect_Timeout, connectID.getName()), CONNECT_TIMEOUT);
            this.targetID = connectID;
            fireContainerEvent(new ContainerConnectedEvent(this.getID(), this.targetID));
        } catch (Exception e) {
            this.targetID = null;
            throw new ContainerConnectException(NLS.bind(Messages.IRCChannelContainer_Exception_Connect_Failed, connectID.getName()), e);
        } finally {
            connectWaiting = false;
        }
    }
}
Also used : ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) ECFException(org.eclipse.ecf.core.util.ECFException) TimeoutException(org.eclipse.equinox.concurrent.future.TimeoutException) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) TimeoutException(org.eclipse.equinox.concurrent.future.TimeoutException)

Example 23 with ContainerConnectException

use of org.eclipse.ecf.core.ContainerConnectException in project ecf by eclipse.

the class AbstractClientContainer method connect.

// IContainer implementation methods
public void connect(ID targetID, IConnectContext connectContext1) throws ContainerConnectException {
    if (targetID == null)
        // $NON-NLS-1$
        throw new ContainerConnectException("targetID cannot be null");
    Namespace targetNamespace = targetID.getNamespace();
    Namespace connectNamespace = getConnectNamespace();
    if (connectNamespace == null)
        // $NON-NLS-1$
        throw new ContainerConnectException("targetID namespace cannot be null");
    if (!(targetNamespace.getName().equals(connectNamespace.getName())))
        // $NON-NLS-1$
        throw new ContainerConnectException("targetID of incorrect type");
    fireContainerEvent(new ContainerConnectingEvent(containerID, targetID));
    synchronized (connectLock) {
        if (connectedID == null) {
            connectedID = targetID;
            this.connectContext = connectContext1;
        } else if (!connectedID.equals(targetID))
            // $NON-NLS-1$
            throw new ContainerConnectException("Already connected to " + connectedID.getName());
    }
    fireContainerEvent(new ContainerConnectedEvent(containerID, targetID));
}
Also used : ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) Namespace(org.eclipse.ecf.core.identity.Namespace)

Example 24 with ContainerConnectException

use of org.eclipse.ecf.core.ContainerConnectException in project ecf by eclipse.

the class ChatRoomBot method connect.

public synchronized void connect() throws ECFException {
    fireInitBot();
    try {
        Namespace namespace = null;
        if (container == null) {
            container = ContainerFactory.getDefault().createContainer(bot.getContainerFactoryName());
            namespace = container.getConnectNamespace();
        } else
            // $NON-NLS-1$
            throw new ContainerConnectException("Already connected");
        targetID = IDFactory.getDefault().createID(namespace, bot.getConnectID());
        IChatRoomManager manager = (IChatRoomManager) container.getAdapter(IChatRoomManager.class);
        if (manager == null)
            // $NON-NLS-1$
            throw new ECFException("No chat room manager available");
        firePreConnect();
        String password = bot.getPassword();
        IConnectContext context = (password == null) ? null : ConnectContextFactory.createPasswordConnectContext(password);
        container.connect(targetID, context);
        String[] roomNames = bot.getChatRooms();
        String[] roomPasswords = bot.getChatRoomPasswords();
        for (int i = 0; i < roomNames.length; i++) {
            IChatRoomInfo room = manager.getChatRoomInfo(roomNames[i]);
            roomContainer = room.createChatRoomContainer();
            roomID = room.getRoomID();
            firePreRoomConnect();
            roomContainer.addMessageListener(this);
            IConnectContext roomContext = (roomPasswords[i] == null) ? null : ConnectContextFactory.createPasswordConnectContext(roomPasswords[i]);
            roomContainer.connect(roomID, roomContext);
        }
    } catch (ECFException e) {
        if (container != null) {
            if (container.getConnectedID() != null) {
                container.disconnect();
            }
            container.dispose();
        }
        container = null;
        throw e;
    }
}
Also used : IChatRoomInfo(org.eclipse.ecf.presence.chatroom.IChatRoomInfo) IConnectContext(org.eclipse.ecf.core.security.IConnectContext) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) ECFException(org.eclipse.ecf.core.util.ECFException) IChatRoomManager(org.eclipse.ecf.presence.chatroom.IChatRoomManager) Namespace(org.eclipse.ecf.core.identity.Namespace)

Example 25 with ContainerConnectException

use of org.eclipse.ecf.core.ContainerConnectException in project ecf by eclipse.

the class XMPPChatRoomContainer method connect.

public void connect(String groupName) throws ContainerConnectException {
    ID targetID = null;
    try {
        targetID = createChatRoomID(groupName);
    } catch (final IDCreateException e) {
        throw new ContainerConnectException(Messages.XMPPChatRoomContainer_EXCEPTION_CREATING_ROOM_ID, e);
    }
    this.connect(targetID, null);
}
Also used : ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) XMPPRoomID(org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID) ID(org.eclipse.ecf.core.identity.ID)

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