Skip to content
Snippets Groups Projects
Commit 164df670 authored by Sebastian Ebert's avatar Sebastian Ebert
Browse files

initial parallel rsync contribution

parents
Branches
No related tags found
No related merge requests found
Showing
with 419 additions and 0 deletions
package org.rosi_project.model_management.sync.procedures
import scala.collection.mutable.ListBuffer
import org.rosi_project.model_management.sync.lock._
import org.rosi_project.model_management.sync.procedures.data.ServerChangeRecordList
import org.rosi_project.model_management.sync.procedures.data._
/**
* Base class for all synchronization-algorithms (phase of applying updates from clients).
*/
trait BaseSynchronisation {
/**
* Synchronizes updates from the unparsed synchronization-request.
*/
def syncModelToHub(request: String): ServerChangeRecordList
/**
* Synchronizes new elements and uses the lock-object to lock them.
*/
def syncNewElementsToHub(request: String, lock: ElementLock): Map[String, String]
/**
* Synchronizes reference-modifications and uses the lock-object to lock referencing and referenced elements.
*/
def syncReferenceModsToHub(records: ListBuffer[ListBuffer[_ <: ChangeRecord]], idMapping: Map[String, String],
lock: ElementLock): (Int, ListBuffer[ListBuffer[_ <: ChangeRecord]], Set[String])
/**
* Synchronizes element-data-modifications and uses the lock-object to lock them elements to modify.
*/
def syncModificationsToHub(records: ListBuffer[ListBuffer[_ <: ChangeRecord]], lock: ElementLock):
(Int, ListBuffer[ListBuffer[_ <: ChangeRecord]])
/**
* Synchronizes element-deletions and uses the lock-object to lock the elements to be deleted.
*/
def syncDeletionToHub(records: ListBuffer[ListBuffer[_ <: ChangeRecord]], lock: ElementLock):
(Int, ListBuffer[ListBuffer[_ <: ChangeRecord]])
}
\ No newline at end of file
package org.rosi_project.model_management.sync.procedures.data
/**
* Base-class for all data-change-records for CCR and SCR.
*/
abstract class ChangeRecord(var abstractTs: Int, var abstractRv: Int, var abstractGuid: String,
var abstractRefOnly: Boolean, var owner: String) {
}
\ No newline at end of file
package org.rosi_project.model_management.sync.procedures.data
/**
* Entry of CER.
*/
case class ClientEntireRecord(guid: String, ts: Int, rv: Int, elementType: String)
\ No newline at end of file
package org.rosi_project.model_management.sync.procedures.data
package org.rosi_project.model_management.sync.procedures.data
/**
* Base-class for entries of SCR which represent reference-changes.
*/
abstract class IServerReferenceChangeRecord {}
\ No newline at end of file
package org.rosi_project.model_management.sync.procedures.data
import scala.collection.mutable.ListBuffer
/**
* Base-class for all implementations of SCR.
*/
abstract class ServerChangeRecordList {}
\ No newline at end of file
package org.rosi_project.model_management.sync.roles
import org.rosi_project.model_management.core.PlayerSync
import org.rosi_project.model_management.sync.helper.ConstructionContainer
/**
* PART OF RSYNC-CORE by Christopher Werner (TUD)
* Interface for the constructor roles.
*/
trait IConstructor {
/**
* Container list for the construction process.
*/
protected var containers: Set[ConstructionContainer] = Set.empty
/**
* Create a container element with the incoming configuration.
*/
protected def createContainerElement(start: Boolean, con: Boolean, play: PlayerSync, man: IRoleManager): Unit = {
if (play == null)
return
containers += new ConstructionContainer(start, con, play, man)
}
/**
* General construction function for external call.
*/
def construct(comp: PlayerSync, man: IRoleManager): Unit
}
package org.rosi_project.model_management.sync.roles
/**
* PART OF RSYNC-CORE by Christopher Werner (TUD)
* Interface for the destructor roles.
*/
trait IDestructor {
/**
* General destruction function for external call.
*/
def deleteRoleFunction(): Unit
}
package org.rosi_project.model_management.sync.roles
/**
* PART OF RSYNC-CORE by Christopher Werner (TUD)
* Interface for the extension roles.
*/
trait IExtension {
/**
* Function to react on insertion behavior.
*/
def notifyInsertion(): Unit
/**
* Function to react on deletion behavior.
*/
def notifyDeletion(): Unit
/**
* Function to react on update behavior.
*/
def notifyUpdate(): Unit
}
\ No newline at end of file
package org.rosi_project.model_management.sync.roles
import org.rosi_project.model_management.sync.helper.IntegrationContainer
import org.rosi_project.model_management.core.PlayerSync
import org.rosi_project.model_management.core.SynchronizationCompartment
/**
* PART OF RSYNC-CORE by Christopher Werner (TUD)
* Interface for the integration roles.
*/
trait IIntegrator {
/**
* Container list for the integration process.
*/
protected var containers: Set[IntegrationContainer] = Set.empty
/**
* Create a container element with the incoming configuration.
*/
protected def createContainerElement(newPlayer: PlayerSync, oldPlayer: PlayerSync): Unit = {
if (newPlayer == null || oldPlayer == null)
return
containers += new IntegrationContainer(newPlayer, oldPlayer)
}
/**
* General integration function for external call.
*/
def integrate(comp: PlayerSync) : PlayerSync
}
\ No newline at end of file
package org.rosi_project.model_management.sync.roles
import org.rosi_project.model_management.core.PlayerSync
import scala.collection.mutable.ListBuffer
/**
* PART OF RSYNC-CORE by Christopher Werner (TUD)
* Interface for the manager roles.
*/
trait IRoleManager {
private var relatedManager: Set[IRoleManager] = Set.empty
/**
* Add a related manager to the list.
*/
def addRelatedManager(related: IRoleManager): Unit = {
if (related == null || related.equals(this))
return
relatedManager += related
}
/**
* Get the list of related managers.
*/
def getRelatedManager(): Set[IRoleManager] = relatedManager
/**
* Get this manager.
*/
def getManager(): IRoleManager = this
/**
* Get this manager plus related manager.
*/
def getAllManager(): Set[IRoleManager] = relatedManager + this
/**
* Remove a related manager from the list.
*/
def removeRelatedManager(related: IRoleManager): Unit = {
if (related != null)
relatedManager -= related
}
/**
* Remove this manager from the lists of all related managers.
*/
def removeThisManager(): Unit = {
relatedManager.foreach { m =>
m.removeRelatedManager(this)
}
}
/**
* Clear the lists of all related managers,
*/
def clearListsOfRelatedManager(): Unit = {
relatedManager.foreach { m =>
m.clearRelatedManager()
}
}
/**
* Clear the list of this role manager.
*/
def clearRelatedManager(): Unit = {
relatedManager = Set.empty
}
/**
* Create a relation between two IRoleManager instances.
*/
def makeRelated(relate: IRoleManager): Unit = {
this.addRelatedManager(relate)
relate.addRelatedManager(this)
}
/**
* General manage function for external call.
*/
def manage(value: PlayerSync): Unit
/**
* Function to manage the deletion.
*/
def deleteManage(value: PlayerSync): Unit
/**
* Get related PlayerSync with the specific name.
*/
def getRelatedClassFromName(name: String): PlayerSync
/**
* Create a relation between two IRoleManager and RoleManager of other PlayerSync instances.
*/
def makePlayerSyncRelated(playerSync: PlayerSync): Unit
/**
* Print all Manager only for debug.
*/
def printAllManager(): Unit
}
package org.rosi_project.model_management.sync.roles
import org.rosi_project.model_management.sync.ISyncCompartment
/**
* PART OF RSYNC-CORE by Christopher Werner (TUD)
* Interface for the synchronization roles.
*/
trait ISyncRole {
/**
* Function to get the synchronization compartment from a role instance.
*/
def getOuterCompartment: ISyncCompartment
}
package org.rosi_project.model_management.sync.snapshot
/**
* A snapshot of the meta-information of a specific element with GUID of type elementKey.
*/
case class Snapshot(guid: String, ts: Int, rv: Int, elementKey: String)
\ No newline at end of file
package org.rosi_project.model_management.sync.snapshot
import scala.collection.mutable.ListBuffer
import org.rosi_project.model_management.core.ModelElementLists
import org.rosi_project.model_management.core.PlayerSync
import org.rosi_project.model_management.sync.lock._
/**
* Singleton object for creating snapshots. May used for response generation.
*/
object SnapshotProvider {
/**
* Creates a snapshot-list for elements (definition of snapshot-element see snapshot.scala).
* modelElementKeys -> keys of element-types of elements which will be included in snapshot
*/
def provideSnapshot(modelElementKeys: Set[String]) : ListBuffer[Snapshot] = {
val snapshots : ListBuffer[Snapshot] = new ListBuffer[Snapshot]()
modelElementKeys.foreach{ mek =>
val elements: Set[SynchronizationAware] = ModelElementLists.getDirectElementsFromType(mek)
elements.foreach{ e =>
val player: PlayerSync = e.asInstanceOf[PlayerSync]
snapshots += Snapshot(player.asInstanceOf[SynchronizationAware].guid, player.ts, player.rv, mek)
}
}
snapshots
}
/**
* Creates a deep copy of a snapshot-list.
*/
def copySnapshot(original: ListBuffer[Snapshot]) : ListBuffer[Snapshot] = {
var copy: ListBuffer[Snapshot] = new ListBuffer[Snapshot]()
original.foreach{ o =>
copy += new Snapshot(o.guid, o.ts, o.rv, o.elementKey)
}
return copy
}
/**
* Checks if a snapshot-list contains an element with GUID.
*/
def snapshotContains(snapshot: ListBuffer[Snapshot], guid: String): Boolean = {
snapshot.foreach{ s =>
if(s.guid == guid){
return true
}
}
return false
}
}
\ No newline at end of file
package org.rosi_project.model_management.util
object DuplicateValidator {
/**
* Returns true if the given sequence contains any duplicate elements
*/
def containsDuplicates[T](a: Seq[T]): Boolean = a.toSet.size < a.size
}
package org.rosi_project.model_management.util
import java.io.{File, PrintWriter}
import java.lang.ThreadLocal
import scala.collection.mutable.ListBuffer
case class PerformanceInformation(thread: Long, lockFailures: Int, name: String, time: Long, numElements: Int, threads: Int)
case class RsyncOnlyPerformanceInformation(name: String, time: Long, numElements: Int)
object PerformanceCounter {
def writeRecords(iterations: Seq[PerformanceInformation], path: String): Unit = {
synchronized {
val file = new File(path)
val printWriter = new PrintWriter(file)
printWriter.write("thread,lockFailures,name,time,numElements,threads\n")
iterations.foreach(p => {
printWriter.write(s"${p.thread},${p.lockFailures},${p.name},${p.time},${p.numElements},${p.threads}\n")
})
printWriter.close()
}
}
def writeRsyncRecords(iterations: Seq[RsyncOnlyPerformanceInformation], path: String): Unit = {
synchronized {
val file = new File(path)
val printWriter = new PrintWriter(file)
printWriter.write("name,time,numElements\n")
iterations.foreach(p => {
printWriter.write(s"${p.name},${p.time},${p.numElements}\n")
})
printWriter.close()
}
}
}
package org.rosi_project.model_management.util
import java.util.UUID.randomUUID
/**
* Class that encapsulates the UUID-generation used for GUID's.
*/
object UuidUtil {
def generateUuid(): String = {
return randomUUID().toString
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment