Skip to content

Commit

Permalink
Sync with Finos main
Browse files Browse the repository at this point in the history
  • Loading branch information
pling-scottlogic committed Sep 18, 2023
1 parent 096c613 commit 6d7a896
Show file tree
Hide file tree
Showing 56 changed files with 721 additions and 629 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.finos.toolbox

import java.util.PriorityQueue

class CoalescingPriorityQueueImpl[VALUE <: AnyRef, KEY](fn: VALUE => KEY, merge: (VALUE, VALUE) => VALUE, compareEqFun: (KEY, KEY) => Int) extends CoalescingQueue[VALUE, KEY] {

case class PrioritizedItem[KEY](KEY: KEY, highPriority: Boolean)

private val keysInOrder = new PriorityQueue[PrioritizedItem[KEY]]((o1: PrioritizedItem[KEY], o2: PrioritizedItem[KEY]) => {
if (o1.highPriority && !o2.highPriority) {
-1
} else if (!o1.highPriority && o2.highPriority) {
1
} else {
compareEqFun(o1.KEY, o2.KEY)
}
})

private val values = new java.util.HashMap[KEY, VALUE]()
private val lock = new Object

def length: Int = keysInOrder.size

def push(item: VALUE) = {
lock.synchronized {
enqueue(fn(item), item, false)
}
}

override def pushHighPriority(item: VALUE): Unit = {
lock.synchronized {
enqueue(fn(item), item, true)
}
}

private def enqueue(key: KEY, value: VALUE, highPriority: Boolean) = {
lock.synchronized {
values.get(key) match {
case null =>
keysInOrder.add(PrioritizedItem(key, highPriority))
values.put(key, value)
case old =>
val merged = merge(old, value)
if (merged ne old) {
values.put(key, merged)
}
}
}
}

def isEmpty() = lock.synchronized {
values.isEmpty
}

private def dequeue: VALUE = {
lock.synchronized {
val key = keysInOrder.poll()
values.remove(key.KEY)
}
}


def popUpTo(i: Int): Seq[VALUE] = {
lock.synchronized {
val entries = for (i <- 0 until i if keysInOrder.size > 0) yield keysInOrder.poll()
entries.map(x => values.remove(x.KEY))
}
}

def pop(): VALUE = dequeue

def popOption(): Option[VALUE] = {
val v = dequeue
Option(v)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package org.finos.toolbox
import scala.collection.mutable

trait CoalescingQueue[VALUE <: AnyRef, KEY]{
def push(item: VALUE)
def push(item: VALUE): Unit
def pushHighPriority(item: VALUE): Unit
def isEmpty(): Boolean
def popUpTo(i: Int): Seq[VALUE]
def pop(): VALUE
Expand All @@ -25,6 +26,8 @@ class CoalescingQueueNaiveImpl[VALUE <: AnyRef, KEY](fn: VALUE => KEY, merge: (V
}
}

override def pushHighPriority(item: VALUE): Unit = push(item)

protected def enqueue(key: KEY, value: VALUE) = {
lock.synchronized{
values.get(key) match {
Expand Down Expand Up @@ -68,8 +71,7 @@ class CoalescingQueueNaiveImpl[VALUE <: AnyRef, KEY](fn: VALUE => KEY, merge: (V
def popOption(): Option[VALUE] = {
val v = dequeue

if(v == null) None
else Some(v)
Option(v)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.finos.toolbox

import org.scalatest.GivenWhenThen
import org.scalatest.featurespec.AnyFeatureSpec
import org.scalatest.matchers.should.Matchers

class CoalescingPriorityQueueTest extends AnyFeatureSpec with Matchers with GivenWhenThen{

Feature("check prioritized queue") {

Scenario("check queue") {

case class QueueEntry(int: Integer, text: String)

val queue = new CoalescingPriorityQueueImpl[QueueEntry, Integer](e => e.int, (x, y) => y, (key1, key2) => {
key1.compareTo(key2)
})

queue.push(QueueEntry(0, "foo"))
queue.push(QueueEntry(1, "bar"))
queue.pushHighPriority(QueueEntry(2, "ping"))
queue.pushHighPriority(QueueEntry(3, "pong"))

queue.pop().int should equal(2)
queue.pop().int should equal(3)
queue.pop().int should equal(0)
queue.pop().int should equal(1)

queue.push(QueueEntry(4, "foo"))
queue.push(QueueEntry(5, "bar"))
queue.pushHighPriority(QueueEntry(6, "ping"))

val dequeued = queue.popUpTo(10)

dequeued.size should be(3)
dequeued(0).int should equal(6)
dequeued(1).int should equal(4)
dequeued(2).int should equal(5)

queue.pushHighPriority(QueueEntry(7, "ping"))
queue.pushHighPriority(QueueEntry(8, "ping"))
queue.pushHighPriority(QueueEntry(9, "ping"))
queue.pushHighPriority(QueueEntry(10, "ping"))

val dequeued2 = queue.popUpTo(10)

dequeued2.size should be(4)
dequeued2(0).int should equal(7)
dequeued2(1).int should equal(8)
dequeued2(2).int should equal(9)
dequeued2(3).int should equal(10)

queue.push(QueueEntry(11, "foo"))
queue.push(QueueEntry(12, "bar"))
queue.push(QueueEntry(13, "bar"))

val dequeued3 = queue.popUpTo(10)

dequeued3.size should be(3)
dequeued3(0).int should equal(11)
dequeued3(1).int should equal(12)
dequeued3(2).int should equal(13)
}
}

}
3 changes: 0 additions & 3 deletions vuu-ui/packages/vuu-layout/src/drag-drop/Draggable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,6 @@ function dragMouseupHandler() {
}

function onDragEnd() {
if (!_dragContainer) {
return
}
if (_dropTarget) {
const dropTarget =
_dropTargetRenderer.hoverDropTarget ||
Expand Down
2 changes: 1 addition & 1 deletion vuu-ui/packages/vuu-layout/src/drag-drop/DropTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Measurements,
Position,
positionValues,
RelativeDropPosition
RelativeDropPosition,
} from "./BoxModel";
import { DragDropRect, DropPos, DropPosTab } from "./dragDropTypes";
import { DragState } from "./DragState";
Expand Down
10 changes: 8 additions & 2 deletions vuu-ui/packages/vuu-layout/src/flexbox/Flexbox.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useForkRef } from "@salt-ds/core";
import cx from "classnames";
import { CSSProperties, forwardRef } from "react";
import { CSSProperties, ForwardedRef, forwardRef } from "react";
import { FlexboxProps } from "./flexboxTypes";
import { useSplitterResizing } from "./useSplitterResizing";

Expand All @@ -9,10 +10,12 @@ const classBase = "hwFlexbox";

const Flexbox = forwardRef(function Flexbox(
props: FlexboxProps,
ref: ForwardedRef<HTMLDivElement>
) {
const {
breakPoints,
children,
// cols: colsProp,
column,
className: classNameProp,
flexFill,
Expand All @@ -28,8 +31,9 @@ const Flexbox = forwardRef(function Flexbox(
...rest
} = props;

const { content } = useSplitterResizing({
const { content, rootRef } = useSplitterResizing({
children,
// cols: colsProp,
onSplitterMoved,
style,
});
Expand All @@ -45,8 +49,10 @@ const Flexbox = forwardRef(function Flexbox(
<div
{...rest}
className={className}
// data-cols={cols}
data-resizeable={resizeable || undefined}
id={id}
ref={useForkRef(rootRef, ref)}
style={
{
...style,
Expand Down
25 changes: 12 additions & 13 deletions vuu-ui/packages/vuu-layout/src/flexbox/FlexboxLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { useCallback } from 'react';
import { useLayoutProviderDispatch } from '../layout-provider';
import { registerComponent } from '../registry/ComponentRegistry';
import Flexbox from './Flexbox';

type FlexboxLayoutProps = {
path: string
}
import { useCallback } from "react";
import { Action } from "../layout-action";
import { useLayoutProviderDispatch } from "../layout-provider";
import { SplitterResizeAction } from "../layout-reducer";
import { registerComponent } from "../registry/ComponentRegistry";
import Flexbox from "./Flexbox";
import { FlexboxLayoutProps } from "./flexboxTypes";

export const FlexboxLayout = function FlexboxLayout(props: FlexboxLayoutProps) {
const { path } = props;
Expand All @@ -14,16 +13,16 @@ export const FlexboxLayout = function FlexboxLayout(props: FlexboxLayoutProps) {
const handleSplitterMoved = useCallback(
(sizes) => {
dispatch({
type: "splitter-resize",
type: Action.SPLITTER_RESIZE,
path,
sizes
});
sizes,
} as SplitterResizeAction);
},
[dispatch, path]
);

return <Flexbox {...props} onSplitterMoved={handleSplitterMoved} />;
};
FlexboxLayout.displayName = 'Flexbox';
FlexboxLayout.displayName = "Flexbox";

registerComponent('Flexbox', FlexboxLayout, 'container');
registerComponent("Flexbox", FlexboxLayout, "container");
2 changes: 1 addition & 1 deletion vuu-ui/packages/vuu-layout/src/flexbox/flexboxTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
HTMLAttributes,
MutableRefObject,
ReactElement,
ReactNode
ReactNode,
} from "react";
import { SplitterProps } from "./Splitter";

Expand Down
6 changes: 3 additions & 3 deletions vuu-ui/packages/vuu-layout/src/flexbox/useSplitterResizing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, {
useCallback,
useMemo,
useRef,
useState
useState,
} from "react";
import { Placeholder } from "../placeholder";
import { Splitter } from "./Splitter";
Expand All @@ -14,14 +14,14 @@ import {
gatherChildMeta,
identifyResizeParties,
PLACEHOLDER,
SPLITTER
SPLITTER,
} from "./flexbox-utils";
import {
ContentMeta,
FlexSize,
SplitterFactory,
SplitterHookProps,
SplitterHookResult
SplitterHookResult,
} from "./flexboxTypes";

const originalContentOnly = (meta: ContentMeta) =>
Expand Down
5 changes: 3 additions & 2 deletions vuu-ui/packages/vuu-layout/src/layout-reducer/layoutUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {
ComponentWithId,
ComponentRegistry,
isContainer,
isLayoutComponent
isLayoutComponent,
} from "../registry/ComponentRegistry";
import {
getPersistentState,
hasPersistentState,
setPersistentState
setPersistentState,
} from "../use-persistent-state";
import { expandFlex, getProps, typeOf } from "../utils";
import { LayoutJSON, LayoutModel, layoutType } from "./layoutTypes";
Expand Down Expand Up @@ -234,6 +234,7 @@ export function layoutFromJson(
id,
...props,
key: id,
path,
},
children
? children.map((child, i) => layoutFromJson(child, `${path}.${i}`))
Expand Down
2 changes: 1 addition & 1 deletion vuu-ui/packages/vuu-layout/src/palette/Palette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
HTMLAttributes,
memo,
MouseEvent,
ReactElement
ReactElement,
} from "react";
import { useLayoutProviderDispatch } from "../layout-provider";
import { View, ViewProps } from "../layout-view";
Expand Down
4 changes: 3 additions & 1 deletion vuu/src/main/scala/org/finos/vuu/api/TableDef.scala
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ class LuceneTableDef(name: String, keyField: String, columns: Array[Column], joi

trait JoinType

object LeftOuterJoin extends JoinType
object LeftOuterJoin extends JoinType{
override def toString: String = "LeftOuterJoin"
}

object InnerJoin extends JoinType

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.finos.vuu.core

import com.typesafe.scalalogging.StrictLogging
import org.finos.toolbox.time.Clock
import org.finos.vuu.api.AvailableViewPortVisualLink
import org.finos.vuu.core.table.{DataType, TableContainer, ViewPortColumnCreator}
import org.finos.vuu.net._
import org.finos.vuu.provider.{ProviderContainer, RpcProvider}
import org.finos.vuu.viewport._
import org.finos.toolbox.time.Clock

import scala.util.{Failure, Success, Try}

Expand Down Expand Up @@ -306,7 +306,7 @@ class CoreServerApiHandler(val viewPortContainer: ViewPortContainer,
val filter = msg.filterSpec

val viewPort = if (msg.groupBy.isEmpty)
viewPortContainer.create(ctx.requestId, ctx.session, ctx.queue, ctx.highPriorityQueue, table, msg.range, vpColumns, sort, filter, NoGroupBy)
viewPortContainer.create(ctx.requestId, ctx.session, ctx.queue, table, msg.range, vpColumns, sort, filter, NoGroupBy)
else {

val groupByColumns = msg.groupBy.filter(vpColumns.getColumnForName(_).get != null).flatMap(vpColumns.getColumnForName).toList
Expand All @@ -315,7 +315,7 @@ class CoreServerApiHandler(val viewPortContainer: ViewPortContainer,

val groupBy = new GroupBy(groupByColumns, aggs)

viewPortContainer.create(ctx.requestId, ctx.session, ctx.queue, ctx.highPriorityQueue, table, msg.range, vpColumns, sort, filter, groupBy)
viewPortContainer.create(ctx.requestId, ctx.session, ctx.queue, table, msg.range, vpColumns, sort, filter, groupBy)
}

vsMsg(CreateViewPortSuccess(viewPort.id, viewPort.table.name, msg.range, msg.columns, msg.sort, msg.groupBy, msg.filterSpec, msg.aggregations))(ctx)
Expand Down
5 changes: 5 additions & 0 deletions vuu/src/main/scala/org/finos/vuu/core/table/JoinTable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,11 @@ class JoinTable(val tableDef: JoinTableDef, val sourceTables: Map[String, DataTa
})
}


override def toString: String = {
"JoinTable(base=" + this.tableDef.baseTable.name + ",joins=" + this.tableDef.joins.map(join => join.table.name + "[" + join.joinSpec.toString + "]").mkString(",") + ")"
}

@volatile private var updateCounterInternal: Long = 0

override def updateCounter: Long = updateCounterInternal
Expand Down
Loading

0 comments on commit 6d7a896

Please sign in to comment.