Skip to content

Instantly share code, notes, and snippets.

@almibe
Created October 27, 2018 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save almibe/493f14dcc0f6d6bcc0769f62574888c5 to your computer and use it in GitHub Desktop.
Save almibe/493f14dcc0f6d6bcc0769f62574888c5 to your computer and use it in GitHub Desktop.
package scratchpad.jgroups
import org.jgroups.*
import java.io.Serializable
fun createWithReceiver(receiver: Receiver): JChannel {
val ch = JChannel()
ch.receiver = receiver
ch.connect("ChatCluster")
return ch
}
fun create(): JChannel {
val ch = JChannel()
ch.connect("ChatCluster")
return ch
}
data class MessageTest1(val text: String, val headers: List<String>): Serializable
//data class MessageTest3(val text: String, val headers: List<String>, val a: List<Map.Entry<String, String>>): Serializable
fun main(args: Array<String>) {
System.setProperty("java.net.preferIPv4Stack", "true")
System.setProperty("jgroups.bind_addr", "127.0.0.1")
val channel1 = create()
var tot = 0;
val channel2 = createWithReceiver(object: ReceiverAdapter() {
override fun viewAccepted(new_view: View) {
//System.out.println("2 - view: " + new_view);
}
override fun receive(msg: Message) {
//System.out.println("2 - << " + msg.getObject() + " [" + msg.getSrc() + "]");
tot++
}
})
val start = System.currentTimeMillis()
println("about to send message")
var i = 0
while (i < 1000000) {
channel1.send(Message(null, "Hey"))
i++
}
val stop = System.currentTimeMillis()
println(stop - start)
Thread.sleep(10)
println("tot: $tot")
System.exit(0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment