Skip to content

Commit

Permalink
run formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
rmgk committed Apr 20, 2024
1 parent ffd51a7 commit bd367b5
Show file tree
Hide file tree
Showing 49 changed files with 246 additions and 280 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package reactives.benchmarks.distributed.rtt
import java.util.concurrent._
import org.openjdk.jmh.annotations._
import reactives.core.ReInfo
import reactives.fullmv.DistributedFullMVApi.{
FullMVEngine, ReactiveLocalClone, Signal, Signals, Var, scopedScheduler, transactionWithWrapup
}
import reactives.fullmv.DistributedFullMVApi.{FullMVEngine, ReactiveLocalClone, Signal, Signals, Var, scopedScheduler, transactionWithWrapup}
import reactives.fullmv.mirrors.localcloning.FakeDelayer

import scala.concurrent.duration._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package reactives.benchmarks.distributed.rtt

import org.openjdk.jmh.annotations._
import reactives.core.ReInfo
import reactives.fullmv.DistributedFullMVApi.{
FullMVEngine, ReactiveLocalClone, Signal, Signals, Var, scopedScheduler, transactionWithWrapup
}
import reactives.fullmv.DistributedFullMVApi.{FullMVEngine, ReactiveLocalClone, Signal, Signals, Var, scopedScheduler, transactionWithWrapup}
import reactives.fullmv.mirrors.localcloning.FakeDelayer

import java.util.concurrent._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package reactives.fullmv.mirrors.localcloning
import reactives.fullmv.mirrors._
import reactives.fullmv.sgt.synchronization._
import reactives.fullmv.tasks.TaskBundle
import reactives.fullmv.{
FullMVBundle, FullMVUtil, FullMvStateBundle, TransactionSpanningTreeNode, TurnImplBundle, TurnPhase
}
import reactives.fullmv.{FullMVBundle, FullMVUtil, FullMvStateBundle, TransactionSpanningTreeNode, TurnImplBundle, TurnPhase}

import scala.concurrent.Future
import scala.concurrent.duration.Duration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import de.rmgk.delay.syntax.toAsync
import de.rmgk.delay.{Async, Callback}
import org.scalajs.dom
import org.scalajs.dom.html.{Div, Input, Table}
import org.scalajs.dom.{
MouseEvent, RTCIceConnectionState, RTCIceGatheringState, RTCIceServer, UIEvent, document, window
}
import org.scalajs.dom.{MouseEvent, RTCIceConnectionState, RTCIceGatheringState, RTCIceServer, UIEvent, document, window}
import scalatags.JsDom.all.*
import scalatags.JsDom.tags2.section

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import channel.{InChan, JsArrayBufferMessageBuffer, MessageBuffer, OutChan, Prod
import de.rmgk.delay
import de.rmgk.delay.{Async, Sync, syntax}
import org.scalajs.dom
import org.scalajs.dom.{
RTCConfiguration, RTCIceCandidate, RTCIceConnectionState, RTCIceGatheringState, RTCSessionDescription,
RTCSignalingState
}
import org.scalajs.dom.{RTCConfiguration, RTCIceCandidate, RTCIceConnectionState, RTCIceGatheringState, RTCSessionDescription, RTCSignalingState}

import scala.annotation.nowarn
import scala.concurrent.ExecutionContext.Implicits.global
Expand Down
5 changes: 1 addition & 4 deletions Modules/Channels/jvm/src/main/scala/channel/udp/UDP.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import channel.{ArrayMessageBuffer, BiChan, InChan, MessageBuffer, OutChan, Prod
import de.rmgk.delay.Async

import java.io.{BufferedInputStream, BufferedOutputStream, IOException}
import java.net.{
DatagramPacket, DatagramSocket, InetAddress, InetSocketAddress, ServerSocket, Socket, SocketAddress, SocketException,
SocketTimeoutException
}
import java.net.{DatagramPacket, DatagramSocket, InetAddress, InetSocketAddress, ServerSocket, Socket, SocketAddress, SocketException, SocketTimeoutException}
import java.util.concurrent.{Executors, ScheduledFuture, ThreadFactory, TimeUnit}
import scala.collection.mutable
import scala.concurrent.duration.Duration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package benchmarks.encrdt

import benchmarks.encrdt.mock.insecure.{AlternativeInsecureToDoListClient, AlternativeInsecureToDoListIntermediary}
import benchmarks.encrdt.mock.{
DisseminationStats, IntermediarySizeInfo, SecureToDoListClient, ToDoListClient, ToDoListIntermediary
}
import benchmarks.encrdt.todolist.{
AddToDoItem, CompleteToDoItem, RemoveToDoItems, ToDoEntry, ToDoListInteraction, ToDoListInteractionGenerator
}
import benchmarks.encrdt.mock.{DisseminationStats, IntermediarySizeInfo, SecureToDoListClient, ToDoListClient, ToDoListIntermediary}
import benchmarks.encrdt.todolist.{AddToDoItem, CompleteToDoItem, RemoveToDoItems, ToDoEntry, ToDoListInteraction, ToDoListInteractionGenerator}
import com.google.crypto.tink.Aead
import Codecs.*
import encrdtlib.container.DeltaAddWinsLastWriterWinsMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,15 @@ import reswing.reshapes.actions.{LoadAction, SaveAction}
import reswing.reshapes.drawing.{Command, DrawingSpaceState, MergeDrawingSpaces, NetworkSpaceState}
import reswing.reshapes.figures.Shape
import reswing.reshapes.ui.dialogs.{NewTabDialog, ServerDialog}
import reswing.reshapes.ui.panels.{
CommandPanel, DrawingPanel, InfoPanel, ShapePanel, ShapeSelectionPanel, ShowCoordinateSystem, ShowIntersection,
ShowNameLabels, StrokeInputPanel
}
import reswing.reshapes.ui.panels.{CommandPanel, DrawingPanel, InfoPanel, ShapePanel, ShapeSelectionPanel, ShowCoordinateSystem, ShowIntersection, ShowNameLabels, StrokeInputPanel}
import reswing.reshapes.util.ReactiveUtil.{UnionEvent, bilateralValues}
import reswing.ReMenuItem.toMenuItem
import reswing.{ReMenu, ReMenuItem, ReSwingValue}

import scala.collection.mutable.HashMap
import scala.swing.BorderPanel.Position
import scala.swing.TabbedPane.Page
import scala.swing.{
Action, BorderPanel, Component, Dimension, MainFrame, Menu, MenuBar, MenuItem, Separator, SimpleSwingApplication,
Swing, TabbedPane
}
import scala.swing.{Action, BorderPanel, Component, Dimension, MainFrame, Menu, MenuBar, MenuItem, Separator, SimpleSwingApplication, Swing, TabbedPane}
import scala.swing.event.SelectionChanged

object ReShapes extends SimpleSwingApplication {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,77 +22,82 @@ object ConversionTest {
()
}


/**
* Contains all supported units with their conversion from Celsius. To add support for a unit, simply add it to the
* enum with the lens representing the corresponding conversion
* @param lens the conversion lens from Celsius
*/
/** Contains all supported units with their conversion from Celsius. To add support for a unit, simply add it to the
* enum with the lens representing the corresponding conversion
* @param lens the conversion lens from Celsius
*/
enum TempConversion(val lens: BijectiveLens[Double, Double]):
//All Conversions are given from Celsius
// All Conversions are given from Celsius
case C extends TempConversion(new NeutralLens)
case K extends TempConversion(new AddLens(274.15))
case L extends TempConversion(new AddLens(253))
case F extends TempConversion(new MulLens(1.8).compose(new AddLens(32.0)))
end TempConversion

/**
* Creates a lens which converts between any supported units
*/
def conversionLens(from : TempConversion, to : TempConversion): BijectiveLens[Double, Double] = from.lens.inverse.compose(to.lens)
/** Creates a lens which converts between any supported units */
def conversionLens(from: TempConversion, to: TempConversion): BijectiveLens[Double, Double] =
from.lens.inverse.compose(to.lens)

/**
* A demonstration of reactive lenses using a simple unit converter for temperature units
*/
/** A demonstration of reactive lenses using a simple unit converter for temperature units */
def unitConverter() = {

//Create selection for units and convert selected units to signals
val leftUnitInput: TypedTag[Select] = select(TempConversion.values.map{ unit => option(unit.toString) })
val (leftUnitEvent: Event[String], renderedLeftUnit: Select) = RenderUtil.dropDownHandler(leftUnitInput, oninput, clear = false)
val leftUnitSignal: Signal[TempConversion] = leftUnitEvent.hold(init = renderedLeftUnit.value).map{TempConversion.valueOf(_)}
// Create selection for units and convert selected units to signals
val leftUnitInput: TypedTag[Select] = select(TempConversion.values.map { unit => option(unit.toString) })
val (leftUnitEvent: Event[String], renderedLeftUnit: Select) =
RenderUtil.dropDownHandler(leftUnitInput, oninput, clear = false)
val leftUnitSignal: Signal[TempConversion] =
leftUnitEvent.hold(init = renderedLeftUnit.value).map { TempConversion.valueOf(_) }

val rightUnitInput: TypedTag[Select] = select(TempConversion.values.map { unit => option(unit.toString) })
val (rightUnitEvent: Event[String], renderedRightUnit: Select) = RenderUtil.dropDownHandler(rightUnitInput, oninput, clear = false)
val rightUnitSignal: Signal[TempConversion] = rightUnitEvent.hold(init = renderedRightUnit.value).map{TempConversion.valueOf(_)}
val (rightUnitEvent: Event[String], renderedRightUnit: Select) =
RenderUtil.dropDownHandler(rightUnitInput, oninput, clear = false)
val rightUnitSignal: Signal[TempConversion] =
rightUnitEvent.hold(init = renderedRightUnit.value).map { TempConversion.valueOf(_) }

//Create the two LVars containing the left and right value using reactive lenses.
val leftVar = LVar(0.0)
val rightVar = leftVar.applyLens(SignalLens(Signal{conversionLens(leftUnitSignal.value, rightUnitSignal.value)}))
// Create the two LVars containing the left and right value using reactive lenses.
val leftVar = LVar(0.0)
val rightVar = leftVar.applyLens(SignalLens(Signal { conversionLens(leftUnitSignal.value, rightUnitSignal.value) }))

//Create text fields and input events for the values
// Create text fields and input events for the values
val leftValueInput: TypedTag[Input] = input(value := leftVar.now)
val (leftValueEvent: Event[String], renderedLeftValue: Input) = RenderUtil.inputFieldHandler(leftValueInput, oninput, clear = false)
val (leftValueEvent: Event[String], renderedLeftValue: Input) =
RenderUtil.inputFieldHandler(leftValueInput, oninput, clear = false)

val rightValueInput: TypedTag[Input] = input(value := rightVar.now)
val (rightValueEvent: Event[String], renderedRightValue: Input) = RenderUtil.inputFieldHandler(rightValueInput, oninput, clear = false)

//Register input events as source of change for LVars
leftVar.fire(leftValueEvent.map{toDoubleOr0(_)})
rightVar.fire(rightValueEvent.map{toDoubleOr0(_)})

//Observe LVars to update UI
leftVar.observe{ value => RenderUtil.setInputDisplay(renderedLeftValue, value.toString) }
rightVar.observe{ value => RenderUtil.setInputDisplay(renderedRightValue, value.toString) }

//Combine all UI elements
div(p("Unit Conversion with Lenses"), renderedLeftUnit, renderedRightUnit, br , renderedLeftValue, renderedRightValue)
val (rightValueEvent: Event[String], renderedRightValue: Input) =
RenderUtil.inputFieldHandler(rightValueInput, oninput, clear = false)

// Register input events as source of change for LVars
leftVar.fire(leftValueEvent.map { toDoubleOr0(_) })
rightVar.fire(rightValueEvent.map { toDoubleOr0(_) })

// Observe LVars to update UI
leftVar.observe { value => RenderUtil.setInputDisplay(renderedLeftValue, value.toString) }
rightVar.observe { value => RenderUtil.setInputDisplay(renderedRightValue, value.toString) }

// Combine all UI elements
div(
p("Unit Conversion with Lenses"),
renderedLeftUnit,
renderedRightUnit,
br,
renderedLeftValue,
renderedRightValue
)
}

/**
* Returns the double represented by the string or 0 if no double is represented
*/
def toDoubleOr0(str : String): Double = {
/** Returns the double represented by the string or 0 if no double is represented */
def toDoubleOr0(str: String): Double = {
try {
{str.toDouble}
{ str.toDouble }
} catch {
case _ => {0.0}
case _ => { 0.0 }
}
}

/**
* A demonstration of the effect of declaration order on event execution if an event effects multiple LVars in the same
* cluster. When inverting the definition of b and c, the output changes.
*/
/** A demonstration of the effect of declaration order on event execution if an event effects multiple LVars in the same
* cluster. When inverting the definition of b and c, the output changes.
*/
def raceConditionTest(): Unit = {
val a = LVar(0)
val b = a.applyLens(new AddLens(1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import scalatags.JsDom.{Attr, TypedTag}

object RenderUtil {
def inputFieldHandler(tag: TypedTag[Input], attr: Attr, clear: Boolean = true): (Event[String], Input) = {
val handler = Event.fromCallback(tag(attr := Event.handle[UIEvent]))
val handler = Event.fromCallback(tag(attr := Event.handle[UIEvent]))
val todoInputField: Input = handler.data.render

// observer to prevent form submit and empty content
Expand All @@ -24,7 +24,7 @@ object RenderUtil {
}

def dropDownHandler(tag: TypedTag[Select], attr: Attr, clear: Boolean = true): (Event[String], Select) = {
val handler = Event.fromCallback(tag(attr := Event.handle[UIEvent]))
val handler = Event.fromCallback(tag(attr := Event.handle[UIEvent]))
val todoInputField: Select = handler.data.render

// // observer to prevent form submit and empty content
Expand All @@ -39,7 +39,7 @@ object RenderUtil {
(inputFieldText, todoInputField)
}

def setInputDisplay(in : Input, text : String): Unit = {
def setInputDisplay(in: Input, text: String): Unit = {
in.value = text
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def run(): Unit =
val nodeId = sget(URI.create(s"$api/status/nodeid")).bind
sget(URI.create(s"$api/register?$service")).bind

val replica = Replica(Uid.gen(), nodeId, service, PosNegCounter.zero)
val replica = Replica(Uid.gen(), nodeId, service, PosNegCounter.zero)
given LocalReplicaId = replica.id

val bundleString = sget(URI.create(s"$api/status/bundles")).bind
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ case class Paxos[A, N <: Int](
else
Paxos.unchanged

def write(value: A): Paxos[A,N] =
def write(value: A): Paxos[A, N] =
// TODO: What would write look like? Maybe return false if we can't write at the moment?
???

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class AWSetTest extends munit.ScalaCheckSuite {
implicit val IntCodec: JsonValueCodec[Int] = JsonCodecMaker.make
property("add") {
forAll { (set: AntiEntropyContainer[ReplicatedSet[Int]], e: Int) =>
given LocalReplicaId = set.replicaID
given LocalReplicaId = set.replicaID
val added: AntiEntropyContainer[ReplicatedSet[Int]] = set.add(e)

val elems = added.elements
Expand All @@ -58,7 +58,7 @@ class AWSetTest extends munit.ScalaCheckSuite {
}
property("remove") {
forAll { (set: AntiEntropyContainer[ReplicatedSet[Int]], e: Int) =>
given LocalReplicaId = set.replicaID
given LocalReplicaId = set.replicaID
val removedNotContained = set.remove(e)
val added = set.add(e)
val removed = added.remove(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ import Paxos.*
class PaxosTest extends munit.FunSuite {
given Bottom[Int] with
override def empty: Int = Int.MinValue
given dots: Dots = Dots.empty
val id1 = LocalReplicaId.gen()
val id2 = LocalReplicaId.gen()
val id3 = LocalReplicaId.gen()
test("Paxos for 3 participants without errors"){

given dots: Dots = Dots.empty
val id1 = LocalReplicaId.gen()
val id2 = LocalReplicaId.gen()
val id3 = LocalReplicaId.gen()

test("Paxos for 3 participants without errors") {
var a: Paxos[Int, 2] = Paxos.unchanged(using 2)

a = a merge a.prepare()(using id1)
a = a merge a.upkeep()(using id1) merge a.upkeep()(using id2) merge a.upkeep()(using id3)
assertEquals(a.read,None)
assertEquals(a.read, None)
a = a merge a.accept(1)(using id1)
a = a merge a.upkeep()(using id1) merge a.upkeep()(using id2) merge a.upkeep()(using id3)
assertEquals(a.read,Some(1))
assertEquals(a.read, Some(1))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import rdts.dotted.Dotted
import rdts.syntax.LocalReplicaId

class TokensTest extends munit.FunSuite {
given dots: Dots = Dots.empty
given Lattice[Dotted[Token]] = Lattice.derived
val numOfReplicas = 5
given dots: Dots = Dots.empty
given Lattice[Dotted[Token]] = Lattice.derived
val numOfReplicas = 5
val replicas: Seq[LocalReplicaId] = List.tabulate(numOfReplicas)(_ => LocalReplicaId.gen())
var token = Dotted(Token(
os = Ownership.unchanged,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class ConnectionManager(lrid: LocalReplicaId) {

val addPeerRef: Evt[PeerRef[?]] = Evt()

val peers: Signal[List[PeerRef[?]]] = Fold(List.empty){
addPeerRef act {_ :: current}
val peers: Signal[List[PeerRef[?]]] = Fold(List.empty) {
addPeerRef act { _ :: current }
}

def addConnection[T](connection: BiChan, coder: MessageCoder[T]): Async[Ctx, Unit] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import rdts.base.Uid
import rdts.datatypes.alternatives.ResettableCounter
import rdts.datatypes.contextual.{ReplicatedSet, EnableWinsFlag, MultiVersionRegister, ObserveRemoveMap, ReplicatedList}
import rdts.datatypes.experiments.AuctionInterface.AuctionData
import rdts.datatypes.{
Epoch, GrowOnlyCounter, GrowOnlyList, GrowOnlyMap, GrowOnlySet, LastWriterWins, PosNegCounter, TwoPhaseSet
}
import rdts.datatypes.{Epoch, GrowOnlyCounter, GrowOnlyList, GrowOnlyMap, GrowOnlySet, LastWriterWins, PosNegCounter, TwoPhaseSet}
import rdts.dotted.Dotted
import rdts.time.{ArrayRanges, Dot, Dots, Time}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ given [T](using JsonValueCodec[T]): Conversion[T, MessageBuffer] = v => ArrayMes

given JsonValueCodec[BroadcastCommunication] = JsonCodecMaker.make




object Example {

// label seems mostly for auto negotiation
Expand All @@ -57,12 +54,12 @@ object Example {
val renderedAddConnectionButton = button("new peerConnection").render

Async.fromCallback {
renderedAddConnectionButton.onclick = (ev: MouseEvent) =>
Async.handler.succeed(())
}.map: _ =>
val handling = WebRTCHandling(None)
renderedConnectionTable.appendChild(handling.controlRow().render)
addDataChannel(handling)
renderedAddConnectionButton.onclick = (ev: MouseEvent) =>
Async.handler.succeed(())
}.map: _ =>
val handling = WebRTCHandling(None)
renderedConnectionTable.appendChild(handling.controlRow().render)
addDataChannel(handling)
.run(using ExecutionContext.global)(errorReporter)

useLocalBroadcastChannel(renderedConnectionTable)
Expand Down
Loading

0 comments on commit bd367b5

Please sign in to comment.