use of org.eclipse.ecf.sync.IModelChange 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);
}
}
use of org.eclipse.ecf.sync.IModelChange in project ecf by eclipse.
the class SyncResourcesCore method visit.
public boolean visit(IResourceDelta delta) throws CoreException {
if (locked) {
return false;
}
IResource resource = delta.getResource();
int type = resource.getType();
if (type == IResource.ROOT) {
return true;
}
String projectName = resource.getProject().getName();
boolean isSharing = isSharing(projectName);
if (isSharing) {
if (type == IResource.PROJECT) {
return true;
}
} else {
// changes, return false
return false;
}
// we are only interested in non-derived resources
if (!resource.isDerived() && checkDelta(delta)) {
for (Iterator it = channels.values().iterator(); it.hasNext(); ) {
ResourcesShare share = (ResourcesShare) it.next();
if (share.isSharing(projectName)) {
IModelChange change = ResourceChangeMessage.createResourceChange(resource, delta.getKind());
if (change != null) {
List changes = (List) resourceChanges.get(share);
if (changes == null) {
changes = new ArrayList();
resourceChanges.put(share, changes);
}
changes.add(change);
}
}
}
}
return type == IResource.FOLDER;
}
use of org.eclipse.ecf.sync.IModelChange 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();
}
}
use of org.eclipse.ecf.sync.IModelChange in project ecf by eclipse.
the class ResourcesShare method handleResourceChangeMessage.
private void handleResourceChangeMessage(byte[] data) throws Exception {
IModelChange remoteChange = ResourcesSynchronizationStrategy.getInstance().deserializeRemoteChange(data);
final IModelChange[] remoteChanges = ResourcesSynchronizationStrategy.getInstance().transformRemoteChange(remoteChange);
// create a scheduling rule to lock the projects
ISchedulingRule[] rules = new ISchedulingRule[sharedProjects.size()];
int index = 0;
for (Iterator it = sharedProjects.iterator(); it.hasNext(); ) {
String projectName = (String) it.next();
rules[index] = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
index++;
}
try {
// lock to prevent resource changes from being propagated
lock(remoteChanges);
applyRemoteChanges(remoteChanges, new MultiRule(rules));
} finally {
// unlock now that we've applied the remote changes to our
// own workspace
unlock(remoteChanges);
}
if (remoteChange instanceof BatchModelChange) {
BatchModelChange batchChange = (BatchModelChange) remoteChange;
batchChange.setOutgoing(false);
batchChange.setTime(System.currentTimeMillis());
SyncResourcesCore.add(batchChange);
}
}
use of org.eclipse.ecf.sync.IModelChange in project ecf by eclipse.
the class SharedDocClient method processRemoteMessage.
private void processRemoteMessage(byte[] msg) {
if (msg != null) {
try {
synchronized (this.getClass()) {
IModelChange change = syncStrategy.deserializeRemoteChange(msg);
System.out.println(name + ";received=" + change);
IDocumentChange[] documentChanges = (IDocumentChange[]) syncStrategy.transformRemoteChange(change);
for (int i = 0; i < documentChanges.length; i++) {
applyChangeToLocalDocument(false, documentChanges[i]);
}
}
} catch (SerializationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Aggregations