Search in sources :

Example 1 with ISharedObjectContainer

use of org.eclipse.ecf.core.sharedobject.ISharedObjectContainer in project ecf by eclipse.

the class ChatSORobotApplication method start.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.
	 * IApplicationContext)
	 */
public Object start(IApplicationContext context) throws Exception {
    // process program arguments
    String[] originalArgs = (String[]) context.getArguments().get("application.args");
    if (originalArgs.length < 3) {
        System.out.println("Parameters:  <senderAccount> <senderPassword> <targetAccount> [<message>].  e.g. sender@gmail.com senderpassword receiver@gmail.com \"Hello there\"");
        return new Integer(-1);
    }
    String message = null;
    if (originalArgs.length > 3)
        message = originalArgs[3];
    // Create client
    XMPPChatClient client = new XMPPChatClient(this, this);
    // connect
    client.connect(originalArgs[0], originalArgs[1]);
    // Wait for 5s for the roster/presence information to be received
    final Object lock = new Object();
    synchronized (lock) {
        lock.wait(5000);
    }
    // Get desired user ID from rosterUsers map. This is just looking for a
    // user that's active and on our contacts list
    ID targetID = (ID) rosterUsers.get(originalArgs[2]);
    if (targetID == null) {
        System.out.println("target user=" + originalArgs[2] + " is not on active on your contacts list.  Cannot send message to this user");
        return new Integer(0);
    }
    // Construct message
    String msgToSend = (message == null) ? "Hi, I'm an ECF chat robot." : message;
    System.out.println("ECF chat robot example sending to targetAccount=" + originalArgs[2] + " message=" + msgToSend);
    // Send chat message to targetID
    client.sendChat(targetID, msgToSend);
    // Get shared object container adapter
    ISharedObjectContainer socontainer = (ISharedObjectContainer) client.getContainer().getAdapter(ISharedObjectContainer.class);
    // Create and add shared object to container
    TrivialSharedObject sharedObject = new TrivialSharedObject();
    socontainer.getSharedObjectManager().addSharedObject(IDFactory.getDefault().createStringID(TrivialSharedObject.class.getName()), sharedObject, null);
    // Send messages via shared object...and wait a short while before sending the next one
    int count = 0;
    synchronized (lock) {
        while (count++ < 5) {
            // Send shared object message
            sharedObject.sendMessageTo(targetID, "hello from " + originalArgs[0] + " via shared object");
            lock.wait(5000);
        }
    }
    // Close up nicely
    client.close();
    return IApplication.EXIT_OK;
}
Also used : ISharedObjectContainer(org.eclipse.ecf.core.sharedobject.ISharedObjectContainer) ID(org.eclipse.ecf.core.identity.ID) IChatID(org.eclipse.ecf.presence.im.IChatID) XMPPChatClient(org.eclipse.ecf.example.clients.XMPPChatClient)

Example 2 with ISharedObjectContainer

use of org.eclipse.ecf.core.sharedobject.ISharedObjectContainer in project ecf by eclipse.

the class ClientApplication method createClient.

protected ISharedObjectContainer createClient() throws Exception {
    // Make identity instance for the new container
    ID newContainerID = IDFactory.getDefault().createGUID();
    ISharedObjectContainer result = SharedObjectContainerFactory.getDefault().createSharedObjectContainer(contd, new Object[] { newContainerID, new Integer(DEFAULT_TIMEOUT) });
    return result;
}
Also used : ISharedObjectContainer(org.eclipse.ecf.core.sharedobject.ISharedObjectContainer) ID(org.eclipse.ecf.core.identity.ID)

Example 3 with ISharedObjectContainer

use of org.eclipse.ecf.core.sharedobject.ISharedObjectContainer in project ecf by eclipse.

the class GenericServerContainerGroup method createContainer.

public ISharedObjectContainer createContainer(String path, int keepAlive, Map properties) throws ContainerCreateException {
    if (path == null)
        // $NON-NLS-1$
        throw new ContainerCreateException("Path for new container cannot be null");
    Map lock = serverGroup.getMap();
    ISharedObjectContainer newContainer = null;
    synchronized (lock) {
        TCPServerSOContainer existing = (TCPServerSOContainer) lock.get(path);
        if (existing != null)
            // $NON-NLS-1$ //$NON-NLS-2$
            throw new ContainerCreateException("Container with path=" + path + " already exists");
        // create container
        newContainer = createGenericServerContainer(path, keepAlive, properties);
        // add To container manager
        addNewContainerToContainerManager(newContainer);
    }
    return newContainer;
}
Also used : ISharedObjectContainer(org.eclipse.ecf.core.sharedobject.ISharedObjectContainer)

Example 4 with ISharedObjectContainer

use of org.eclipse.ecf.core.sharedobject.ISharedObjectContainer in project ecf by eclipse.

the class AbstractEventAdminApplication method createConfigureAndConnectContainer.

protected void createConfigureAndConnectContainer() throws ContainerCreateException, SharedObjectAddException, ContainerConnectException {
    // get container factory and create container
    IContainerFactory containerFactory = getContainerManager().getContainerFactory();
    container = (containerId == null) ? containerFactory.createContainer(containerType) : containerFactory.createContainer(containerType, new Object[] { containerId });
    // Get socontainer
    ISharedObjectContainer soContainer = (ISharedObjectContainer) container.getAdapter(ISharedObjectContainer.class);
    // Add to soContainer, with topic as name
    soContainer.getSharedObjectManager().addSharedObject(IDFactory.getDefault().createStringID(DEFAULT_TOPIC), eventAdminImpl, null);
    // then connect to target Id
    if (targetId != null)
        container.connect(IDFactory.getDefault().createID(container.getConnectNamespace(), targetId), null);
}
Also used : IContainerFactory(org.eclipse.ecf.core.IContainerFactory) ISharedObjectContainer(org.eclipse.ecf.core.sharedobject.ISharedObjectContainer)

Example 5 with ISharedObjectContainer

use of org.eclipse.ecf.core.sharedobject.ISharedObjectContainer in project ecf by eclipse.

the class CollabClient method createAndConnectClient.

/**
 * Create a new container instance, and connect to a remote server or group.
 *
 * @param containerType
 *            the container type used to create the new container instance.
 *            Must not be null.
 * @param uri
 *            the uri that is used to create a targetID for connection. Must
 *            not be null.
 * @param nickname
 *            an optional String nickname. May be null.
 * @param connectData
 *            optional connection data. May be null.
 * @param resource
 *            the resource that this container instance is associated with.
 *            Must not be null.
 * @throws Exception
 */
public void createAndConnectClient(final String containerType, String uri, String nickname, final Object connectData, final IResource resource) throws Exception {
    // First create the new container instance
    final IContainer newClient = ContainerFactory.getDefault().createContainer(containerType);
    // Create the targetID instance
    ID targetID = IDFactory.getDefault().createID(newClient.getConnectNamespace(), uri);
    // Setup username
    String username = setupUsername(targetID, nickname);
    // Create a new container entry to hold onto container once created
    final ClientEntry newClientEntry = new ClientEntry(containerType, newClient);
    // Setup sharedobject container if the new instance supports
    // this
    ISharedObjectContainer sharedObjectContainer = (ISharedObjectContainer) newClient.getAdapter(ISharedObjectContainer.class);
    SharedObjectContainerUI socui = new SharedObjectContainerUI(this, sharedObjectContainer);
    socui.setup(sharedObjectContainer, newClientEntry, resource, username);
    // Now connect
    try {
        newClient.connect(targetID, ConnectContextFactory.createUsernamePasswordConnectContext(username, connectData));
    } catch (ContainerConnectException e) {
        // If we have a connect exception then we remove any previously
        // added shared object
        EclipseCollabSharedObject so = newClientEntry.getSharedObject();
        if (so != null)
            so.destroySelf();
        throw e;
    }
    // only add container if the connect was successful
    addClientForResource(newClientEntry, resource);
}
Also used : EclipseCollabSharedObject(org.eclipse.ecf.example.collab.share.EclipseCollabSharedObject) SharedObjectContainerUI(org.eclipse.ecf.internal.example.collab.ui.SharedObjectContainerUI) ISharedObjectContainer(org.eclipse.ecf.core.sharedobject.ISharedObjectContainer) ID(org.eclipse.ecf.core.identity.ID) IContainer(org.eclipse.ecf.core.IContainer)

Aggregations

ISharedObjectContainer (org.eclipse.ecf.core.sharedobject.ISharedObjectContainer)12 ID (org.eclipse.ecf.core.identity.ID)8 IContainer (org.eclipse.ecf.core.IContainer)5 ISharedObject (org.eclipse.ecf.core.sharedobject.ISharedObject)5 ISharedObjectManager (org.eclipse.ecf.core.sharedobject.ISharedObjectManager)4 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 IContainerFactory (org.eclipse.ecf.core.IContainerFactory)1 ISharedObjectMessageSerializer (org.eclipse.ecf.core.sharedobject.util.ISharedObjectMessageSerializer)1 XMPPChatClient (org.eclipse.ecf.example.clients.XMPPChatClient)1 EclipseCollabSharedObject (org.eclipse.ecf.example.collab.share.EclipseCollabSharedObject)1 SharedObjectContainerUI (org.eclipse.ecf.internal.example.collab.ui.SharedObjectContainerUI)1 IChatID (org.eclipse.ecf.presence.im.IChatID)1