8. •bulk data transfer
•batch processing of large data sets
•micro-batching
•real-time data sources
•embedded data-processing
•monitoring and analytics
•metrics, statistics composition
•event processing
•error handling
25. Java IO
A PipedOutputStream
PipedInputStream
protected byte buffer[];
B
26. Java IO
A PipedOutputStream PipedInputStream B
protected byte buffer[];
27. Java IO
A PipedOutputStream PipedInputStream B
Write
Block
Transfer
Block
Read
Block
28. Java IO
val alice = new SThread("RS-Alice") {
override def swap(n: Int) {
val out = new PipedOutputStream()
val in = new PipedInputStream(out, size)
super.swap(n)
for (i <- 0 to n * rateA) out.write(Env.BEER)
}
}
val borice = new SThread("RS-Borice") {
override def swap(n: Int) {
super.swap(n)
for (i <- 0 to n * rateB) in.read()
}
}
29. Java IO
val alice = new SThread("RS-Alice") {
override def swap(n: Int) {
val out = new PipedOutputStream()
val in = new PipedInputStream(out, size)
super.swap(n)
for (i <- 0 to n * rateA) out.write(Env.BEER)
}
}
INCREASE
val borice = new SThread("RS-Borice") {
override def swap(n: Int) {
super.swap(n)
for (i <- 0 to n * rateB) in.read()
}
}
30. Java IO
val alice = new SThread("RS-Alice") {
override def swap(n: Int) {
val out = new PipedOutputStream()
val in = new PipedInputStream(out, size)
super.swap(n)
for (i <- 0 to n * rateA) out.write(Env.BEER)
}
}
INCREASE
val borice = new SThread("RS-Borice") {
override def swap(n: Int) {
super.swap(n)
for (i <- 0 to n * rateB) in.read()
}
}
31. Java IO
val alice = new SThread("RS-Alice") {
override def swap(n: Int) {
val out = new PipedOutputStream()
val in = new PipedInputStream(out, size)
super.swap(n)
for (i <- 0 to n * rateA) out.write(Env.BEER)
}
}
val borice = new SThread("RS-Borice") {
override def swap(n: Int) {
super.swap(n)
for (i <- 0 to n * rateB) in.read()
}
}
INCREASE
34. Java NIO
A Buffer SinkChannel SourceChannel Buffer
B
Write
Block
Transfer
Read
Block
Read
Fill
35. Java NIO
val alice = new SThread("RS-Alice") {
override def swap(n: Int) {
val cnt = n * rateA
val buffer = ByteBuffer.allocate(cnt)
buffer.put(Vector.fill(cnt)(BEER).toArray)
buffer.flip()
val written = sinkChannel.write(buffer)
super.swap(written)
}
}
val pipe = Pipe.open()
val sinkChannel = pipe.sink
val sourceChannel = pipe.source
sourceChannel.configureBlocking(true)
sinkChannel.configureBlocking(false)
BLOCKING
val borice = new SThread("RS-Borice") {
override def swap(n: Int) {
val buffer = ByteBuffer.allocate(n * rateB)
val cnt = sourceChannel.read(buffer)
super.swap(cnt)
}
}
36. Java NIO
val alice = new SThread("RS-Alice") {
override def swap(n: Int) {
val cnt = n * rateA
val buffer = ByteBuffer.allocate(cnt)
buffer.put(Vector.fill(cnt)(BEER).toArray)
buffer.flip()
val written = sinkChannel.write(buffer)
super.swap(written)
}
}
val pipe = Pipe.open()
val sinkChannel = pipe.sink
val sourceChannel = pipe.source
sourceChannel.configureBlocking(false)
sinkChannel.configureBlocking(false)
NON-BLOCKING
val borice = new SThread("RS-Borice") {
override def swap(n: Int) {
val buffer = ByteBuffer.allocate(n * rateB)
val cnt = sourceChannel.read(buffer)
super.swap(cnt)
}
}