Search in sources :

Example 1 with IModelChangeMessage

use of org.eclipse.ecf.sync.IModelChangeMessage in project ecf by eclipse.

the class Initiator method run.

public void run() {
    for (int i = 0; i < 10; i++) {
        String text = fDocument.get();
        String newText = ">";
        text = text.concat(newText);
        fDocument.set(text);
        IModelChange change = new DocumentChangeMessage(i + 150, newText.length(), newText);
        IModelChangeMessage[] changes = initiator.registerLocalChange(change);
        getReceiverQueue().put(changes);
    }
}
Also used : IModelChange(org.eclipse.ecf.sync.IModelChange) IModelChangeMessage(org.eclipse.ecf.sync.IModelChangeMessage) DocumentChangeMessage(org.eclipse.ecf.sync.doc.DocumentChangeMessage)

Example 2 with IModelChangeMessage

use of org.eclipse.ecf.sync.IModelChangeMessage in project ecf by eclipse.

the class Message method deserialize.

/**
 * Deserialize in to message
 * @param bytes
 * @return IModelChangeMessage
 * @throws SerializationException
 */
public static IModelChangeMessage deserialize(byte[] bytes) throws SerializationException {
    try {
        final ByteArrayInputStream bins = new ByteArrayInputStream(bytes);
        final ObjectInputStream oins = new ObjectInputStream(bins);
        return (IModelChangeMessage) oins.readObject();
    } catch (final Exception e) {
        throw new SerializationException(Messages.DocShare_EXCEPTION_DESERIALIZING_MESSAGE0, e);
    }
}
Also used : SerializationException(org.eclipse.ecf.sync.SerializationException) IModelChangeMessage(org.eclipse.ecf.sync.IModelChangeMessage) SerializationException(org.eclipse.ecf.sync.SerializationException)

Example 3 with IModelChangeMessage

use of org.eclipse.ecf.sync.IModelChangeMessage in project ecf by eclipse.

the class ResourcesShare method sendResourceChangeMessage.

void sendResourceChangeMessage(IResource resource, int kind) {
    try {
        IModelChange change = ResourceChangeMessage.createResourceChange(resource, kind);
        IModelChangeMessage[] messages = ResourcesSynchronizationStrategy.getInstance().registerLocalChange(change);
        for (int i = 0; i < messages.length; i++) {
            send(messages[i].serialize());
        }
    } catch (ECFException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : ECFException(org.eclipse.ecf.core.util.ECFException) IModelChange(org.eclipse.ecf.sync.IModelChange) IModelChangeMessage(org.eclipse.ecf.sync.IModelChangeMessage)

Example 4 with IModelChangeMessage

use of org.eclipse.ecf.sync.IModelChangeMessage in project ecf by eclipse.

the class DocShare method handleMessage.

protected void handleMessage(ID fromContainerID, byte[] data) {
    try {
        IModelChangeMessage message = Message.deserialize(data);
        Assert.isNotNull(message);
        if (message instanceof SelectionMessage) {
            handleSelectionMessage((SelectionMessage) message);
        } else if (message instanceof FileSystemDocumentChangeMessage) {
            handleFileSystemDocumentChangeMessage((FileSystemDocumentChangeMessage) message);
        } else if (message instanceof StartMessage) {
            handleStartMessage((StartMessage) message);
        } else if (message instanceof StopMessage) {
            handleStopMessage((StopMessage) message);
        }
    } catch (SerializationException e) {
        // $NON-NLS-1$
        DocShareActivator.log(new Status(IStatus.ERROR, DocShareActivator.PLUGIN_ID, "Could not deserialize message from " + fromContainerID, e));
    } catch (CoreException e) {
        // $NON-NLS-1$
        DocShareActivator.log(new Status(IStatus.ERROR, DocShareActivator.PLUGIN_ID, "Could not connect to file buffer", e));
    } catch (RuntimeException e) {
        // $NON-NLS-1$
        DocShareActivator.log(new Status(IStatus.ERROR, DocShareActivator.PLUGIN_ID, "Runtime exception has occurred while handling message from " + fromContainerID, e));
    }
}
Also used : SerializationException(org.eclipse.ecf.sync.SerializationException) IModelChangeMessage(org.eclipse.ecf.sync.IModelChangeMessage)

Example 5 with IModelChangeMessage

use of org.eclipse.ecf.sync.IModelChangeMessage in project ecf by eclipse.

the class Message method deserialize.

/**
 * Deserialize in to message
 * @param bytes
 * @return IModelChangeMessage
 * @throws SerializationException
 */
public static IModelChangeMessage deserialize(byte[] bytes) throws SerializationException {
    try {
        final ByteArrayInputStream bins = new ByteArrayInputStream(bytes);
        final ObjectInputStream oins = new ObjectInputStream(bins);
        return (IModelChangeMessage) oins.readObject();
    } catch (final Exception e) {
        throw new SerializationException(Messages.DocShare_EXCEPTION_DESERIALIZING_MESSAGE0, e);
    }
}
Also used : SerializationException(org.eclipse.ecf.sync.SerializationException) IModelChangeMessage(org.eclipse.ecf.sync.IModelChangeMessage) SerializationException(org.eclipse.ecf.sync.SerializationException)

Aggregations

IModelChangeMessage (org.eclipse.ecf.sync.IModelChangeMessage)6 SerializationException (org.eclipse.ecf.sync.SerializationException)3 ECFException (org.eclipse.ecf.core.util.ECFException)2 IModelChange (org.eclipse.ecf.sync.IModelChange)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 DocumentChangeMessage (org.eclipse.ecf.sync.doc.DocumentChangeMessage)1