Skip to content
Snippets Groups Projects
Commit 55b2187d authored by Oliver Rieger's avatar Oliver Rieger
Browse files

concurrent control mechanism initiated.

parent bc0ce45c
Branches
Tags
No related merge requests found
Showing
with 607 additions and 76 deletions
......@@ -36,6 +36,8 @@ public class EditorActivity implements IActivity {
private IPath path;
private String source;
/**
* @param path
* a valid project-relative path or <code>null</code> if former
......@@ -77,4 +79,12 @@ public class EditorActivity implements IActivity {
public String toString() {
return "EditorActivity(type:" + type + ", path:" + path + ")";
}
public String getSource() {
return this.source;
}
public void setSource(String source) {
this.source = source;
}
}
......@@ -9,6 +9,8 @@ public class FileActivity implements IActivity {
Created, Removed
};
private String source;
private Type type;
private IPath path;
......@@ -56,4 +58,12 @@ public class FileActivity implements IActivity {
return false;
}
public String getSource() {
return this.source;
}
public void setSource(String source) {
this.source = source;
}
}
......@@ -7,6 +7,8 @@ public class FolderActivity implements IActivity {
Created, Removed
};
private String source;
private Type type;
private IPath path;
......@@ -28,4 +30,13 @@ public class FolderActivity implements IActivity {
public String toString() {
return "FolderActivity(type:" + type + ", path:" + path + ")";
}
public String getSource() {
return this.source;
}
public void setSource(String source) {
this.source = source;
}
}
......@@ -27,4 +27,8 @@ package de.fu_berlin.inf.dpp.activities;
* @author rdjemili
*/
public interface IActivity {
public void setSource(String source);
public String getSource();
}
......@@ -22,6 +22,9 @@ package de.fu_berlin.inf.dpp.activities;
import de.fu_berlin.inf.dpp.net.JID;
public class RoleActivity implements IActivity {
private String source;
private JID driver;
public RoleActivity(JID newDriver) {
......@@ -47,4 +50,13 @@ public class RoleActivity implements IActivity {
public String toString() {
return "RoleActivity(driver:" + driver + ")";
}
public String getSource() {
return this.source;
}
public void setSource(String source) {
this.source = source;
}
}
......@@ -19,6 +19,8 @@
*/
package de.fu_berlin.inf.dpp.activities;
import org.eclipse.core.runtime.IPath;
/**
* A simple immutable text activity.
*
......@@ -29,6 +31,7 @@ public class TextEditActivity implements IActivity {
private String source;
private IPath editor;
/**
* This string only uses \n as line delimiter. Keep this in mind when adding
* it to an IDocument with probably other line delimiters.
......@@ -55,6 +58,24 @@ public class TextEditActivity implements IActivity {
}
/**
* @param offset
* the offset inside the document where this activity happend.
* @param text
* the text that was inserted.
* @param replace
* the length of text that was replaced by this activity.
* @param source
* the source ID of this activity
*/
public TextEditActivity(int offset, String text, int replace, IPath editor) {
this.offset = offset;
this.text = text;
this.replace = replace;
this.source = null;
this.editor = editor;
}
public String getSource() {
return source;
}
......@@ -77,6 +98,30 @@ public class TextEditActivity implements IActivity {
@Override
public String toString() {
return "TextEditActivity(offset:" + offset + ",text:" + text + ",replace:" + replace + ")";
return "TextEditActivity(offset:" + offset + ",text:" + text + ",replace:" + replace + ", path : "+editor.toString()+ ")";
}
/**
* Compare text edit information without source settings.
* @param obj TextEditActivity Object
* @return true if edit information equals. false otherwise.
*/
public boolean sameLike(Object obj){
if(obj instanceof TextEditActivity){
TextEditActivity other = (TextEditActivity) obj;
return offset == other.offset &&
editor.equals(other.editor) &&
text.equals(other.text) &&
replace == other.replace ;
}
return false;
}
public IPath getEditor(){
return this.editor;
}
public void setEditor(IPath editor){
this.editor = editor;
}
}
......@@ -5,6 +5,8 @@ public class ViewportActivity implements IActivity {
public final int bottomIndex;
private String source;
public ViewportActivity(int topIndex, int bottomIndex) {
this.topIndex = topIndex;
this.bottomIndex = bottomIndex;
......@@ -32,4 +34,12 @@ public class ViewportActivity implements IActivity {
public String toString() {
return "ViewportActivity(top:" + topIndex + ",bottom:" + bottomIndex + ")";
}
public String getSource() {
return this.source;
}
public void setSource(String source) {
this.source = source;
}
}
package de.fu_berlin.inf.dpp.concurrent;
import java.util.List;
import de.fu_berlin.inf.dpp.User;
import de.fu_berlin.inf.dpp.activities.IActivity;
import de.fu_berlin.inf.dpp.net.JID;
/**
* Interface for management controller class of all jupiter document server.
* @author orieger
......@@ -6,4 +13,24 @@ package de.fu_berlin.inf.dpp.concurrent;
*/
public interface ConcurrentManager {
public static enum Side{
CLIENT_SIDE,
HOST_SIDE
}
public void addDriver(User jid);
public void removeDriver(User jid);
public List<User> getDriver();
public boolean isDriver(User jid);
public boolean isHost();
public void setHost(User jid);
public IActivity activityCreated(IActivity activity);
public IActivity exec(IActivity activity);
}
......@@ -2,11 +2,15 @@ package de.fu_berlin.inf.dpp.concurrent.jupiter;
import de.fu_berlin.inf.dpp.net.JID;
public interface JupiterClient {
public interface JupiterClient extends JupiterEditor{
public Request generateRequest(Operation op);
public Operation receiveRequest(Request req) throws TransformationException;
/**
* get the jid of the appropriate client.
* @return
*/
public JID getJID();
}
package de.fu_berlin.inf.dpp.concurrent.jupiter;
import org.eclipse.core.runtime.IPath;
import de.fu_berlin.inf.dpp.net.JID;
/**
* interface for jupiter editor settings.
* @author orieger
*
*/
public interface JupiterEditor {
public void setEditor(IPath path);
public IPath getEditor();
}
......@@ -2,9 +2,11 @@ package de.fu_berlin.inf.dpp.concurrent.jupiter;
import java.util.HashMap;
import org.eclipse.core.runtime.IPath;
import de.fu_berlin.inf.dpp.net.JID;
public interface JupiterServer extends SynchronizedQueue, RequestForwarder{
public interface JupiterServer extends SynchronizedQueue, RequestForwarder, JupiterEditor{
public void addProxyClient(JID jid);
......@@ -16,4 +18,12 @@ public interface JupiterServer extends SynchronizedQueue, RequestForwarder{
* @throws InterruptedException
*/
public HashMap<JID, JupiterClient> getProxies() throws InterruptedException;
/**
* get exist state of proxy client for given jid.
* @param jid
* @return
*/
public boolean isExist(JID jid);
}
package de.fu_berlin.inf.dpp.concurrent.jupiter.internal;
import org.apache.log4j.Logger;
import org.eclipse.core.runtime.IPath;
import de.fu_berlin.inf.dpp.concurrent.jupiter.Algorithm;
import de.fu_berlin.inf.dpp.concurrent.jupiter.JupiterClient;
import de.fu_berlin.inf.dpp.concurrent.jupiter.Operation;
import de.fu_berlin.inf.dpp.concurrent.jupiter.Request;
import de.fu_berlin.inf.dpp.concurrent.jupiter.RequestForwarder;
import de.fu_berlin.inf.dpp.concurrent.jupiter.TransformationException;
import de.fu_berlin.inf.dpp.net.JID;
public class JupiterDocumentClient implements JupiterClient {
......@@ -14,29 +19,55 @@ public class JupiterDocumentClient implements JupiterClient {
*
*/
private static Logger logger = Logger.getLogger(JupiterDocumentClient.class.toString());
/** jid of remote client*/
private JID jid;
/** jupiter sync algorithm. */
private Algorithm jupiter;
public JupiterDocumentClient(JID jid){
private IPath editor;
/** forwarder send request to server. */
private RequestForwarder forwarder;
public JupiterDocumentClient(JID jid, RequestForwarder forwarder){
this.jid = jid;
this.jupiter = new Jupiter(true);
this.forwarder = forwarder;
}
public Request generateRequest(Operation op) {
// TODO Auto-generated method stub
return null;
Request req = null;
logger.debug(jid.toString()+" client generate request for "+op);
req = jupiter.generateRequest(op);
req.setJID(this.jid);
/* send request*/
forwarder.forwardOutgoingRequest(req);
return req;
}
public Operation receiveRequest(Request req) {
// TODO Auto-generated method stub
return null;
public Operation receiveRequest(Request req)throws TransformationException {
Operation op = null;
logger.debug(jid.toString()+" client receive request "+req.getOperation());
/* receive request action */
op = jupiter.receiveRequest(req);
logger.debug(jid.toString()+" client operation of IT: "+op);
return op;
}
public JID getJID() {
// TODO Auto-generated method stub
return null;
return this.jid;
}
public IPath getEditor() {
return editor;
}
public void setEditor(IPath path) {
this.editor = path;
}
......
......@@ -5,6 +5,7 @@ import java.util.List;
import java.util.Vector;
import org.apache.log4j.Logger;
import org.eclipse.core.runtime.IPath;
import de.fu_berlin.inf.dpp.concurrent.jupiter.JupiterClient;
import de.fu_berlin.inf.dpp.concurrent.jupiter.JupiterServer;
......@@ -26,11 +27,12 @@ public class JupiterDocumentServer implements JupiterServer{
private List<Request> requestList;
// /** outgoing queue to transfer request to appropriate clients. */
public List<Request> outgoingQueue;
private List<Request> outgoingQueue;
// private RequestForwarder outgoing;
public OperationSerializer serializer;
private OperationSerializer serializer;
private IPath editor;
// /** for add and remove client synchronization. */
// public boolean waitForSerializer = false;
// /** counter for remove client synchronization.*/
......@@ -46,14 +48,14 @@ public class JupiterDocumentServer implements JupiterServer{
serializer = new Serializer(this);
}
public JupiterDocumentServer(RequestForwarder forwarder){
proxies = new HashMap<JID, JupiterClient>();
requestList = new Vector<Request>();
this.outgoingQueue = new Vector<Request>();
// this.outgoing = forwarder;
serializer = new Serializer(this);
}
// public JupiterDocumentServer(RequestForwarder forwarder){
// proxies = new HashMap<JID, JupiterClient>();
// requestList = new Vector<Request>();
// this.outgoingQueue = new Vector<Request>();
//
//// this.outgoing = forwarder;
// serializer = new Serializer(this);
// }
......@@ -78,6 +80,9 @@ public class JupiterDocumentServer implements JupiterServer{
notifyAll();
}
/**
* add request from transmitter to request queue.
*/
public synchronized void addRequest(Request request) {
/*TODO: Sync with serializer. */
......@@ -90,6 +95,9 @@ public class JupiterDocumentServer implements JupiterServer{
notifyAll();
}
/**
* next message in request queue.
*/
public synchronized Request getNextRequestInSynchronizedQueue() throws InterruptedException {
/* if queue is empty or proxy managing action is running. */
if(!(requestList.size() > 0)){
......@@ -145,6 +153,22 @@ public class JupiterDocumentServer implements JupiterServer{
// return outgoing.getNextOutgoingRequest();
}
public IPath getEditor() {
return editor;
}
public void setEditor(IPath path) {
this.editor = path;
}
public boolean isExist(JID jid) {
if(proxies.containsKey(jid)){
return true;
}
return false;
}
/* end transfer section */
......
package de.fu_berlin.inf.dpp.concurrent.jupiter.internal;
import org.apache.log4j.Logger;
import org.eclipse.core.runtime.IPath;
import de.fu_berlin.inf.dpp.concurrent.jupiter.Algorithm;
import de.fu_berlin.inf.dpp.concurrent.jupiter.JupiterClient;
......@@ -63,4 +64,16 @@ public class ProxyJupiterDocument implements JupiterClient{
}
public IPath getEditor() {
//implemented in jupiter server
return null;
}
public void setEditor(IPath path) {
//implemented in jupiter server
}
}
package de.fu_berlin.inf.dpp.concurrent.management;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;
import org.apache.log4j.Logger;
import org.eclipse.core.runtime.IPath;
import de.fu_berlin.inf.dpp.User;
import de.fu_berlin.inf.dpp.activities.EditorActivity;
import de.fu_berlin.inf.dpp.activities.IActivity;
import de.fu_berlin.inf.dpp.activities.TextEditActivity;
import de.fu_berlin.inf.dpp.activities.EditorActivity.Type;
import de.fu_berlin.inf.dpp.concurrent.ConcurrentManager;
import de.fu_berlin.inf.dpp.concurrent.jupiter.JupiterClient;
import de.fu_berlin.inf.dpp.concurrent.jupiter.JupiterServer;
import de.fu_berlin.inf.dpp.concurrent.jupiter.internal.JupiterDocumentClient;
import de.fu_berlin.inf.dpp.concurrent.jupiter.internal.JupiterDocumentServer;
import de.fu_berlin.inf.dpp.net.JID;
import de.fu_berlin.inf.dpp.project.IActivityListener;
import de.fu_berlin.inf.dpp.project.IActivityManager;
import de.fu_berlin.inf.dpp.project.IActivityProvider;
public class ConcurrentDocumentManager implements ConcurrentManager {
private static Logger logger = Logger.getLogger(Logger.class);
/** Jupiter server instance documents */
private HashMap<IPath, JupiterDocumentServer> concurrentDocuments;
/** current open editor at client side. */
private HashMap<IPath, JupiterClient> clientDocs;
private List<User> drivers;
private User host;
private JID myJID;
private Side side;
public ConcurrentDocumentManager(Side side, User host, JID myJID) {
if (side == Side.HOST_SIDE) {
concurrentDocuments = new HashMap<IPath, JupiterDocumentServer>();
}
this.clientDocs = new HashMap<IPath, JupiterClient>();
drivers = new Vector<User>();
this.side = side;
this.host = host;
this.myJID = myJID;
}
public void addDriver(User jid) {
drivers.add(jid);
}
public void removeDriver(User jid) {
drivers.remove(jid);
}
public List<User> getDriver() {
return drivers;
}
public boolean isDriver(User jid) {
return drivers.contains(jid);
}
public IActivity activityCreated(IActivity activity) {
// /* create appropriate jupiter document clients. */
// activityCreatedOnClient(activity);
//
// if (side == Side.HOST_SIDE) {
// activityCreatedOnHost(activity);
// }
editorActivitiy(activity, true);
return activity;
}
// private void activityCreatedOnClient(IActivity activity) {
// if (activity instanceof EditorActivity) {
// /* create and closed local jupiter clients. */
// editorActivitiy(activity, true);
// }
//
// if (activity instanceof TextEditActivity) {
//
// }
// }
private void editorActivitiy(IActivity activity, boolean local) {
if (!isHost() || local) {
if (activity instanceof EditorActivity) {
EditorActivity editor = (EditorActivity) activity;
/* if new editor opened */
if (editor.getType() == Type.Activated) {
/* no jupiter client exists for this editor */
if (!clientDocs.containsKey(editor.getPath())) {
// TODO: add Request forwarder
JupiterClient jupiter = new JupiterDocumentClient(
myJID, null);
jupiter.setEditor(editor.getPath());
/* add to current docs */
clientDocs.put(editor.getPath(), jupiter);
}
//send EditorActivity to project host.
}
if (editor.getType() == Type.Closed) {
/* remove editor form jupiter concurrent mechanism. */
if (clientDocs.containsKey(editor.getPath())) {
clientDocs.remove(editor.getPath());
}
}
}
}
/* managing of jupiter server documents. */
if(isHost()){
/* Editor activities. */
if (activity instanceof EditorActivity) {
EditorActivity editor = (EditorActivity) activity;
/* if new editor opened */
if (editor.getType() == Type.Activated) {
/* create new jupiter document server. */
if (!concurrentDocuments.containsKey(editor.getPath())) {
JupiterDocumentServer jup = new JupiterDocumentServer();
jup.setEditor(editor.getPath());
/* create host proxy */
jup.addProxyClient(host.getJid());
/* create client proxy if remote activity. */
if(!local){
jup.addProxyClient(new JID(editor.getSource()));
}
/* add to server list. */
concurrentDocuments.put(editor.getPath(), jup);
/* create host jupiter client for local request handling. */
if (!clientDocs.containsKey(editor.getPath())) {
JupiterClient jupiter = new JupiterDocumentClient(
myJID, null);
jupiter.setEditor(editor.getPath());
}
}
}
/* if document closed. */
if (editor.getType() == Type.Closed) {
if(!local){
/* remove remote client from proxy list. */
JupiterDocumentServer serverDoc = concurrentDocuments.get(editor.getPath());
if(serverDoc != null){
/* remove remote client. */
serverDoc.removeProxyClient(new JID(editor.getSource()));
/* TODO: if only host is exists.*/
// if(serverDoc.getProxies().size() == 1){
//
// }
}
}
}
}
}
}
public class ConcurrentDocumentManager {
private void activityCreatedOnHost(IActivity activity) {
/* Editor activities. */
if (activity instanceof EditorActivity) {
EditorActivity editor = (EditorActivity) activity;
/* if new editor opened */
if (editor.getType() == Type.Activated) {
/* create new jupiter document server. */
if (!concurrentDocuments.containsKey(editor.getPath())) {
JupiterDocumentServer jup = new JupiterDocumentServer();
jup.setEditor(editor.getPath());
private List<JupiterDocumentServer> concurrentDocuments;
/* create host proxy */
jup.addProxyClient(host.getJid());
/* create client proxy. */
jup.addProxyClient(new JID(editor.getSource()));
/* add to server list. */
concurrentDocuments.put(editor.getPath(), jup);
/* create host jupiter client for local request handling. */
if (!clientDocs.containsKey(editor.getPath())) {
JupiterClient jupiter = new JupiterDocumentClient(
myJID, null);
jupiter.setEditor(editor.getPath());
}
}
}
/* if document closed. */
if (editor.getType() == Type.Closed) {
}
}
if (activity instanceof TextEditActivity) {
TextEditActivity text = (TextEditActivity) activity;
}
}
public IActivity exec(IActivity activity) {
editorActivitiy(activity, false);
return activity;
}
public boolean isHost() {
if (side == Side.HOST_SIDE) {
return true;
}
return false;
}
public ConcurrentDocumentManager(){
concurrentDocuments = new Vector<JupiterDocumentServer>();
public void setHost(User host) {
this.host = host;
}
/*
* 1. hinzufügen und löschen von jupiter servern
* 2. list mit transmitter threads, die Nachrichten aus den
* outgoing queues versenden.
* 3. Schnittstelle vom Itransmitter zu den einzelnen jupiter
* document servern, um die Nachrichten vom Itransmitter
* weiterzuleiten.
* 1. hinzufügen und löschen von jupiter servern 2. list mit transmitter
* threads, die Nachrichten aus den outgoing queues versenden. 3.
* Schnittstelle vom Itransmitter zu den einzelnen jupiter document servern,
* um die Nachrichten vom Itransmitter weiterzuleiten.
*
*
* */
*/
}
......@@ -233,6 +233,9 @@ public class EditorManager implements IActivityProvider, ISharedProjectListener
private List<ISharedEditorListener> editorListeners = new ArrayList<ISharedEditorListener>();
/* this activity has arrived and will be execute now. */
private IActivity currentExecuteActivity;
public static EditorManager getDefault() {
if (instance == null)
instance = new EditorManager();
......@@ -354,7 +357,18 @@ public class EditorManager implements IActivityProvider, ISharedProjectListener
if (!isDriver)
return;
fireActivity(new TextEditActivity(offset, text, replace));
TextEditActivity newAct = new TextEditActivity(offset, text, replace);
/* check if text edit activity is executed by other driver activity recently. */
//TODO: check scenario of concurrent edit in same position.
if(newAct.sameLike(currentExecuteActivity)){
return;
}
/* if activity is create be this client. */
TextEditActivity activity = new TextEditActivity(offset, text, replace);
activity.setEditor(this.activeDriverEditor);
fireActivity(activity);
IEditorInput input = editorAPI.getActiveEditor().getEditorInput();
IDocumentProvider provider = editorAPI.getDocumentProvider(input);
......@@ -446,6 +460,10 @@ public class EditorManager implements IActivityProvider, ISharedProjectListener
* @see de.fu_berlin.inf.dpp.IActivityProvider
*/
public void exec(final IActivity activity) {
/* set current execute activity to avoid cirle executions. */
currentExecuteActivity = activity;
if (activity instanceof EditorActivity) {
EditorActivity editorActivity = (EditorActivity) activity;
......@@ -615,7 +633,7 @@ public class EditorManager implements IActivityProvider, ISharedProjectListener
} else if (activity instanceof TextEditActivity) {
TextEditActivity textEditActivity = (TextEditActivity) activity;
return "<edit " + "offset=\"" + textEditActivity.offset + "\" " + "replace=\""
return "<edit " + "path=\"" + textEditActivity.getEditor() + "\" " +"offset=\"" + textEditActivity.offset + "\" " + "replace=\""
+ textEditActivity.replace + "\">" + "<![CDATA[" + textEditActivity.text + "]]>"
+ "</edit>";
......@@ -636,7 +654,10 @@ public class EditorManager implements IActivityProvider, ISharedProjectListener
private IActivity parseTextEditActivity(XmlPullParser parser) throws XmlPullParserException,
IOException {
// TODO extract constants
// extract current editor for text edit.
String pathString = parser.getAttributeValue(null, "path");
Path path = pathString.equals("null") ? null : new Path(pathString);
int offset = Integer.parseInt(parser.getAttributeValue(null, "offset"));
int replace = Integer.parseInt(parser.getAttributeValue(null, "replace"));
......@@ -645,7 +666,7 @@ public class EditorManager implements IActivityProvider, ISharedProjectListener
text = parser.getText();
}
return new TextEditActivity(offset, text, replace);
return new TextEditActivity(offset, text, replace,path);
}
private IActivity parseEditorActivity(XmlPullParser parser) {
......
......@@ -20,4 +20,6 @@ public interface IChatManager extends PacketListener {
* @return
*/
public boolean isConnected();
public void sendActivity();
}
......@@ -28,6 +28,7 @@ import org.jivesoftware.smack.XMPPException;
import de.fu_berlin.inf.dpp.FileList;
import de.fu_berlin.inf.dpp.User;
import de.fu_berlin.inf.dpp.activities.IActivity;
import de.fu_berlin.inf.dpp.invitation.IInvitationProcess;
import de.fu_berlin.inf.dpp.project.ISharedProject;
......@@ -227,4 +228,18 @@ public interface ITransmitter {
* a list of timed activities.
*/
public void sendActivities(ISharedProject sharedProject, List<TimedActivity> activities);
/**
* Sends given list of activities with given timestamp to given participant
* of given shared project.
*
* @param sharedProject
* the shared project the activities refer to.
* @param activity
* activity.
* @param jid
* the recipient
*/
public void sendActivitiyTo(ISharedProject sharedProject, IActivity activity, JID jid);
}
......@@ -32,7 +32,10 @@ import org.eclipse.jface.text.TextSelection;
import de.fu_berlin.inf.dpp.activities.IActivity;
import de.fu_berlin.inf.dpp.activities.TextEditActivity;
import de.fu_berlin.inf.dpp.activities.TextSelectionActivity;
import de.fu_berlin.inf.dpp.concurrent.ConcurrentManager;
import de.fu_berlin.inf.dpp.concurrent.management.ConcurrentDocumentManager;
import de.fu_berlin.inf.dpp.net.IActivitySequencer;
import de.fu_berlin.inf.dpp.net.JID;
import de.fu_berlin.inf.dpp.net.TimedActivity;
import de.fu_berlin.inf.dpp.project.IActivityManager;
import de.fu_berlin.inf.dpp.project.IActivityProvider;
......@@ -47,7 +50,8 @@ public class ActivitySequencer implements IActivitySequencer, IActivityManager {
private static final int UNDEFINED_TIME = -1;
private static Logger log = Logger.getLogger(ActivitySequencer.class.getName());
private static Logger log = Logger.getLogger(ActivitySequencer.class
.getName());
private List<IActivity> activities = new LinkedList<IActivity>();
......@@ -61,6 +65,8 @@ public class ActivitySequencer implements IActivitySequencer, IActivityManager {
private int timestamp = UNDEFINED_TIME;
private ConcurrentManager concurrentManager;
/*
* (non-Javadoc)
*
......@@ -68,9 +74,28 @@ public class ActivitySequencer implements IActivitySequencer, IActivityManager {
*/
public void exec(IActivity activity) {
try {
/* TODO:
* 1. Überprüfung, ob hierfür ein entsprechendes Dokument
* existiert.
* 2. */
// // HOST SIDE
// if (concurrentManager != null && concurrentManager.isHost()) {
// /* concurrent control */
// IActivity transformedActivity = concurrentManager
// .exec(activity);
//
// /* the transformed operation for this client side. */
// for (IActivityProvider executor : providers) {
// executor.exec(transformedActivity);
// }
// }
// // CLIENT SIDE
// else {
for (IActivityProvider executor : providers) {
executor.exec(activity);
}
// }
} catch (Exception e) {
log.log(Level.SEVERE, "Error while executing activity.", e);
......@@ -167,6 +192,17 @@ public class ActivitySequencer implements IActivitySequencer, IActivityManager {
* @see de.fu_berlin.inf.dpp.IActivityListener
*/
public void activityCreated(IActivity activity) {
/*TODO: 1. an dieser stelle muss der entsprechende jupiter server
* beim client oder der komplexe concurrent server des host für
* das jeweilige dokument erzeugt werden.*/
// /* sync with jupiter logic. */
// IActivity ac = concurrentManager.activityCreated(activity);
// /* put into outgoing queue and send to all. */
// if(ac != null){
// activities.add(ac);
// }
activities.add(activity);
}
......@@ -183,7 +219,6 @@ public class ActivitySequencer implements IActivitySequencer, IActivityManager {
return queue.size();
}
public List<TimedActivity> getActivityHistory() {
return activityHistory;
}
......@@ -229,14 +264,16 @@ public class ActivitySequencer implements IActivitySequencer, IActivityManager {
textEdit = joinTextEdits(result, textEdit);
selection = new TextSelection(textEdit.offset + textEdit.text.length(), 0);
selection = new TextSelection(textEdit.offset
+ textEdit.text.length(), 0);
source = textEdit.getSource();
result.add(textEdit);
} else if (activity instanceof TextSelectionActivity) {
TextSelectionActivity textSelection = (TextSelectionActivity) activity;
selection = new TextSelection(textSelection.getOffset(), textSelection.getLength());
selection = new TextSelection(textSelection.getOffset(),
textSelection.getLength());
source = textSelection.getSource();
} else {
......@@ -250,7 +287,8 @@ public class ActivitySequencer implements IActivitySequencer, IActivityManager {
return result;
}
private TextEditActivity joinTextEdits(List<IActivity> result, TextEditActivity textEdit) {
private TextEditActivity joinTextEdits(List<IActivity> result,
TextEditActivity textEdit) {
if (result.size() == 0)
return textEdit;
......@@ -258,20 +296,24 @@ public class ActivitySequencer implements IActivitySequencer, IActivityManager {
if (lastActivity instanceof TextEditActivity) {
TextEditActivity lastTextEdit = (TextEditActivity) lastActivity;
if ( (lastTextEdit.getSource()==null || lastTextEdit.getSource().equals(textEdit.getSource()) ) &&
textEdit.offset == lastTextEdit.offset + lastTextEdit.text.length()) {
if ((lastTextEdit.getSource() == null || lastTextEdit.getSource()
.equals(textEdit.getSource()))
&& textEdit.offset == lastTextEdit.offset
+ lastTextEdit.text.length()) {
result.remove(lastTextEdit);
textEdit = new TextEditActivity(lastTextEdit.offset,
lastTextEdit.text + textEdit.text,
lastTextEdit.replace + textEdit.replace);
lastTextEdit.text + textEdit.text, lastTextEdit.replace
+ textEdit.replace);
textEdit.setSource(lastTextEdit.getSource());
textEdit.setEditor(lastTextEdit.getEditor());
}
}
return textEdit;
}
private ITextSelection addSelection(List<IActivity> result, ITextSelection selection,String source) {
private ITextSelection addSelection(List<IActivity> result,
ITextSelection selection, String source) {
if (selection == null)
return null;
......@@ -280,7 +322,8 @@ public class ActivitySequencer implements IActivitySequencer, IActivityManager {
if (lastActivity instanceof TextEditActivity) {
TextEditActivity lastTextEdit = (TextEditActivity) lastActivity;
if (selection.getOffset() == lastTextEdit.offset + lastTextEdit.text.length()
if (selection.getOffset() == lastTextEdit.offset
+ lastTextEdit.text.length()
&& selection.getLength() == 0) {
return selection;
......@@ -288,10 +331,8 @@ public class ActivitySequencer implements IActivitySequencer, IActivityManager {
}
}
TextSelectionActivity newSel=new TextSelectionActivity(
selection.getOffset(),
selection.getLength()
);
TextSelectionActivity newSel = new TextSelectionActivity(selection
.getOffset(), selection.getLength());
newSel.setSource(source);
result.add(newSel);
......@@ -299,4 +340,11 @@ public class ActivitySequencer implements IActivitySequencer, IActivityManager {
return selection;
}
public void initConcurrentManager(de.fu_berlin.inf.dpp.concurrent.ConcurrentManager.Side side, de.fu_berlin.inf.dpp.User host, JID myJID) {
concurrentManager = new ConcurrentDocumentManager(side,host,myJID);
}
public ConcurrentManager getConcurrentManager() {
return concurrentManager;
}
}
......@@ -486,4 +486,9 @@ public class MultiUserChatManager implements InvitationListener,
return false;
}
public void sendActivity() {
// TODO Auto-generated method stub
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment