Search in sources :

Example 86 with ID

use of org.eclipse.ecf.core.identity.ID in project ecf by eclipse.

the class ClientSOContainer method handleViewChangeMessage.

protected void handleViewChangeMessage(ContainerMessage mess) throws IOException {
    if (!isConnected())
        return;
    final ContainerMessage.ViewChangeMessage vc = (ContainerMessage.ViewChangeMessage) mess.getData();
    if (vc == null)
        // $NON-NLS-1$
        throw new IOException("view change message cannot be null");
    final ID fromID = mess.getFromContainerID();
    if (fromID == null || !fromID.equals(remoteServerID)) {
        // $NON-NLS-1$ //$NON-NLS-2$
        throw new IOException("view change message fromID=" + fromID + " is not from remoteServerID=" + remoteServerID);
    }
    final ID[] changeIDs = vc.getChangeIDs();
    if (changeIDs == null) {
    // do nothing if we've got no changes
    } else {
        for (int i = 0; i < changeIDs.length; i++) {
            if (vc.isAdd()) {
                boolean wasAdded = false;
                synchronized (getGroupMembershipLock()) {
                    // known
                    if (groupManager.getMemberForID(changeIDs[i]) == null) {
                        wasAdded = true;
                        groupManager.addMember(new Member(changeIDs[i]));
                    }
                }
                // accomplished
                if (wasAdded)
                    fireContainerEvent(new ContainerConnectedEvent(getID(), changeIDs[i]));
            } else {
                if (changeIDs[i].equals(getID())) {
                    // We've been ejected.
                    final ID serverID = remoteServerID;
                    synchronized (getGroupMembershipLock()) {
                        handleLeave(remoteServerID, connection);
                    }
                    // Notify listeners that we've been ejected
                    fireContainerEvent(new ContainerEjectedEvent(getID(), serverID, vc.getData()));
                } else {
                    synchronized (getGroupMembershipLock()) {
                        groupManager.removeMember(changeIDs[i]);
                    }
                    // Notify listeners that another remote has gone away
                    fireContainerEvent(new ContainerDisconnectedEvent(getID(), changeIDs[i]));
                }
            }
        }
    }
}
Also used : ID(org.eclipse.ecf.core.identity.ID) Member(org.eclipse.ecf.provider.generic.gmm.Member)

Example 87 with ID

use of org.eclipse.ecf.core.identity.ID in project ecf by eclipse.

the class ClientSOContainer method connect.

/* (non-Javadoc)
	 * @see org.eclipse.ecf.provider.generic.SOContainer#connect(org.eclipse.ecf.core.identity.ID, org.eclipse.ecf.core.security.IConnectContext)
	 */
public void connect(ID targetID, IConnectContext joinContext) throws ContainerConnectException {
    try {
        if (isClosing)
            // $NON-NLS-1$
            throw new IllegalStateException("Container closing");
        if (targetID == null)
            // $NON-NLS-1$
            throw new ContainerConnectException("targetID cannot be null");
        Object response = null;
        synchronized (getConnectLock()) {
            // Throw if already connected
            if (isConnected())
                // $NON-NLS-1$
                throw new IllegalStateException("Container already connected connectedID=" + getConnectedID());
            // Throw if connecting
            if (isConnecting())
                // $NON-NLS-1$
                throw new IllegalStateException("Container connecting");
            // else we're entering connecting state
            // first notify synchonously
            final ISynchAsynchConnection aConnection = createConnection(targetID, joinContext);
            setStateConnecting(aConnection);
            fireContainerEvent(new ContainerConnectingEvent(this.getID(), targetID, joinContext));
            final Object connectData = getConnectData(targetID, joinContext);
            final int connectTimeout = getConnectTimeout();
            synchronized (aConnection) {
                try {
                    // Make connect call
                    response = aConnection.connect(targetID, connectData, connectTimeout);
                } catch (final ECFException e) {
                    if (getConnection() != aConnection)
                        disconnect(aConnection);
                    else
                        setStateDisconnected(aConnection);
                    throw e;
                }
                // If not in correct state, disconnect and return
                if (getConnection() != aConnection) {
                    disconnect(aConnection);
                    // $NON-NLS-1$
                    throw new IllegalStateException("Container connect failed because not in correct state");
                }
                ID serverID = null;
                try {
                    serverID = handleConnectResponse(targetID, response);
                } catch (final Exception e) {
                    setStateDisconnected(aConnection);
                    throw e;
                }
                setStateConnected(serverID, aConnection);
                // notify listeners
                fireContainerEvent(new ContainerConnectedEvent(this.getID(), remoteServerID));
                aConnection.start();
            }
        }
    } catch (final ContainerConnectException e) {
        throw e;
    } catch (final ECFException e) {
        final IStatus s = e.getStatus();
        throw new ContainerConnectException(s.getMessage(), s.getException());
    } catch (final Exception e) {
        throw new ContainerConnectException(e.getLocalizedMessage(), e);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) ECFException(org.eclipse.ecf.core.util.ECFException) ID(org.eclipse.ecf.core.identity.ID) ECFException(org.eclipse.ecf.core.util.ECFException) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) ConnectException(java.net.ConnectException)

Example 88 with ID

use of org.eclipse.ecf.core.identity.ID 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 89 with ID

use of org.eclipse.ecf.core.identity.ID in project ecf by eclipse.

the class ClientApplication method main.

/**
 * An ECF client container implementation that runs as an application.
 * <p>
 * Usage: java org.eclipse.ecf.provider.app.ClientApplication
 * &lt;serverid&gt
 * <p>
 * If &lt;serverid&gt; is omitted or "-" is specified,
 * ecftcp://localhost:3282/server" is used.
 */
public static void main(String[] args) throws Exception {
    ClientApplication st = new ClientApplication();
    st.init(args);
    // Get server id to join
    ID serverID = IDFactory.getDefault().createStringID(st.serverName);
    st.connect(serverID);
    st.createSharedObjects();
    // $NON-NLS-1$ //$NON-NLS-2$
    System.out.println("Waiting " + DEFAULT_WAITTIME + " ms...");
    Thread.sleep(DEFAULT_WAITTIME);
    st.removeSharedObjects();
    st.disconnect();
    // $NON-NLS-1$
    System.out.println("Exiting.");
}
Also used : ID(org.eclipse.ecf.core.identity.ID)

Example 90 with ID

use of org.eclipse.ecf.core.identity.ID in project ecf by eclipse.

the class RemoteServiceRegistrationImpl method publish.

public void publish(RemoteServiceRegistryImpl registry, Object svc, String[] clzzes, Dictionary props) {
    this.service = svc;
    this.clazzes = clzzes;
    this.reference = new RemoteServiceReferenceImpl(this);
    synchronized (registry) {
        ID containerID = registry.getContainerID();
        if (containerID == null)
            // $NON-NLS-1$
            throw new NullPointerException("Local containerID must be non-null to register remote services");
        this.remoteServiceID = registry.createRemoteServiceID(registry.getNextServiceId());
        this.properties = createProperties(props);
        registry.publishService(this);
    }
}
Also used : ID(org.eclipse.ecf.core.identity.ID)

Aggregations

ID (org.eclipse.ecf.core.identity.ID)256 IContainer (org.eclipse.ecf.core.IContainer)29 IOException (java.io.IOException)19 IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)18 UUID (java.util.UUID)17 HashMap (java.util.HashMap)12 ArrayList (java.util.ArrayList)11 ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)11 GUID (org.eclipse.ecf.core.identity.GUID)11 ISharedObjectManager (org.eclipse.ecf.core.sharedobject.ISharedObjectManager)11 XMPPRoomID (org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID)11 Namespace (org.eclipse.ecf.core.identity.Namespace)10 XMPPID (org.eclipse.ecf.provider.xmpp.identity.XMPPID)10 Map (java.util.Map)9 Matcher (java.util.regex.Matcher)9 ECFException (org.eclipse.ecf.core.util.ECFException)9 List (java.util.List)8 ISharedObject (org.eclipse.ecf.core.sharedobject.ISharedObject)8 IChannel (org.eclipse.ecf.datashare.IChannel)8 Iterator (java.util.Iterator)7