-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
171 additions
and
933 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 80 additions & 80 deletions
160
extended/src/main/kotlin/apoc/kafka/producer/StreamsConstraintsService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,80 @@ | ||
package apoc.kafka.producer | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.GlobalScope | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.cancelAndJoin | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.isActive | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.runBlocking | ||
import org.neo4j.graphdb.DatabaseShutdownException | ||
import org.neo4j.graphdb.GraphDatabaseService | ||
import org.neo4j.graphdb.Label | ||
import org.neo4j.graphdb.RelationshipType | ||
import org.neo4j.graphdb.TransactionFailureException | ||
import apoc.kafka.events.Constraint | ||
import apoc.kafka.utils.KafkaUtil | ||
import java.io.Closeable | ||
import java.util.Collections | ||
import java.util.concurrent.ConcurrentHashMap | ||
|
||
class StreamsConstraintsService(private val db: GraphDatabaseService, private val poolInterval: Long): Closeable { | ||
|
||
private val nodeConstraints = ConcurrentHashMap<String, Set<Constraint>>() | ||
private val relConstraints = ConcurrentHashMap<String, Set<Constraint>>() | ||
|
||
private lateinit var job: Job | ||
|
||
override fun close() { | ||
KafkaUtil.ignoreExceptions({ runBlocking { job.cancelAndJoin() } }, UninitializedPropertyAccessException::class.java) | ||
} | ||
|
||
fun start() { | ||
job = GlobalScope.launch(Dispatchers.IO) { | ||
while (isActive) { | ||
if (!db.isAvailable(5000)) return@launch | ||
KafkaUtil.ignoreExceptions({ | ||
db.beginTx().use { | ||
val constraints = it.schema().constraints | ||
constraints | ||
.filter { it.isNodeConstraint() } | ||
.groupBy { it.label.name() } | ||
.forEach { label, constraints -> | ||
nodeConstraints[label] = constraints | ||
.map { Constraint(label, it.propertyKeys.toSet(), it.streamsConstraintType()) } | ||
.toSet() | ||
} | ||
constraints | ||
.filter { it.isRelationshipConstraint() } | ||
.groupBy { it.relationshipType.name() } | ||
.forEach { relationshipType, constraints -> | ||
relConstraints[relationshipType] = constraints | ||
.map { Constraint(relationshipType, it.propertyKeys.toSet(), it.streamsConstraintType()) } | ||
.toSet() | ||
} | ||
} | ||
}, DatabaseShutdownException::class.java, TransactionFailureException::class.java, IllegalStateException::class.java) | ||
delay(poolInterval) | ||
} | ||
} | ||
} | ||
|
||
fun forLabel(label: Label): Set<Constraint> { | ||
return nodeConstraints[label.name()] ?: emptySet() | ||
} | ||
|
||
fun forRelationshipType(relationshipType: RelationshipType): Set<Constraint> { | ||
return relConstraints[relationshipType.name()] ?: emptySet() | ||
} | ||
|
||
fun allForLabels(): Map<String, Set<Constraint>> { | ||
return Collections.unmodifiableMap(nodeConstraints) | ||
} | ||
|
||
fun allForRelationshipType(): Map<String, Set<Constraint>> { | ||
return Collections.unmodifiableMap(relConstraints) | ||
} | ||
|
||
|
||
} | ||
//package apoc.kafka.producer | ||
// | ||
//import kotlinx.coroutines.Dispatchers | ||
//import kotlinx.coroutines.GlobalScope | ||
//import kotlinx.coroutines.Job | ||
//import kotlinx.coroutines.cancelAndJoin | ||
//import kotlinx.coroutines.delay | ||
//import kotlinx.coroutines.isActive | ||
//import kotlinx.coroutines.launch | ||
//import kotlinx.coroutines.runBlocking | ||
//import org.neo4j.graphdb.DatabaseShutdownException | ||
//import org.neo4j.graphdb.GraphDatabaseService | ||
//import org.neo4j.graphdb.Label | ||
//import org.neo4j.graphdb.RelationshipType | ||
//import org.neo4j.graphdb.TransactionFailureException | ||
//import apoc.kafka.events.Constraint | ||
//import apoc.kafka.utils.KafkaUtil | ||
//import java.io.Closeable | ||
//import java.util.Collections | ||
//import java.util.concurrent.ConcurrentHashMap | ||
// | ||
//class StreamsConstraintsService(private val db: GraphDatabaseService, private val poolInterval: Long): Closeable { | ||
// | ||
// private val nodeConstraints = ConcurrentHashMap<String, Set<Constraint>>() | ||
// private val relConstraints = ConcurrentHashMap<String, Set<Constraint>>() | ||
// | ||
// private lateinit var job: Job | ||
// | ||
// override fun close() { | ||
// KafkaUtil.ignoreExceptions({ runBlocking { job.cancelAndJoin() } }, UninitializedPropertyAccessException::class.java) | ||
// } | ||
// | ||
// fun start() { | ||
// job = GlobalScope.launch(Dispatchers.IO) { | ||
// while (isActive) { | ||
// if (!db.isAvailable(5000)) return@launch | ||
// KafkaUtil.ignoreExceptions({ | ||
// db.beginTx().use { | ||
// val constraints = it.schema().constraints | ||
// constraints | ||
// .filter { it.isNodeConstraint() } | ||
// .groupBy { it.label.name() } | ||
// .forEach { label, constraints -> | ||
// nodeConstraints[label] = constraints | ||
// .map { Constraint(label, it.propertyKeys.toSet(), it.streamsConstraintType()) } | ||
// .toSet() | ||
// } | ||
// constraints | ||
// .filter { it.isRelationshipConstraint() } | ||
// .groupBy { it.relationshipType.name() } | ||
// .forEach { relationshipType, constraints -> | ||
// relConstraints[relationshipType] = constraints | ||
// .map { Constraint(relationshipType, it.propertyKeys.toSet(), it.streamsConstraintType()) } | ||
// .toSet() | ||
// } | ||
// } | ||
// }, DatabaseShutdownException::class.java, TransactionFailureException::class.java, IllegalStateException::class.java) | ||
// delay(poolInterval) | ||
// } | ||
// } | ||
// } | ||
// | ||
// fun forLabel(label: Label): Set<Constraint> { | ||
// return nodeConstraints[label.name()] ?: emptySet() | ||
// } | ||
// | ||
// fun forRelationshipType(relationshipType: RelationshipType): Set<Constraint> { | ||
// return relConstraints[relationshipType.name()] ?: emptySet() | ||
// } | ||
// | ||
// fun allForLabels(): Map<String, Set<Constraint>> { | ||
// return Collections.unmodifiableMap(nodeConstraints) | ||
// } | ||
// | ||
// fun allForRelationshipType(): Map<String, Set<Constraint>> { | ||
// return Collections.unmodifiableMap(relConstraints) | ||
// } | ||
// | ||
// | ||
//} |
32 changes: 0 additions & 32 deletions
32
extended/src/main/kotlin/apoc/kafka/producer/StreamsEventRouter.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.