SlideShare a Scribd company logo
https://www.maxpixel.net/Post-Impressionist-Post-Impressionism-Fine-Art-Dutch-1428139
private Connection.Available getConnection(long eta,
long wait,
String token)
{
for(;;) {
if (eta > MAX_ETA_MS) {
throw new EtaExceededException();
}
if (wait > 0) {
Thread.sleep(wait);
}
println("Retrying download after " + wait + "ms wait.");
Connection c = coordinator.requestConnection(token);
if (c instanceof Connection.Available) {
return (Connection.Available) c;
}
Connection.Unavailable unavail = (Connection.Unavailable) c;
eta = unavail.getEta();
wait = unavail.getWait();
token = unavail.getToken();
}
}
public static InputStream blockingRequest(String url, String headers)
throws IOException
{
URL uri = new URL(url);
SocketAddress serverAddress = new InetSocketAddress(uri.getHost(), uri.getP
SocketChannel channel = SocketChannel.open(serverAddress);
ByteBuffer buffer = ByteBuffer.wrap((headers + "Host: " + uri.getHost() + "
do {
channel.write(buffer);
} while(buffer.hasRemaining());
return channel.socket().getInputStream();
}
https://blog.paralleluniverse.co/2014/02/04/littles-law/
private void getThingy(int i, CompletionHandler<Void> handler)
{
println("Start getThingy.");
getConnection(new CompletionHandler<>() {
@Override
public void completed(Connection.Available conn) {
println("Got token, " + conn.getToken());
CompletableFuture<Void> downloadFut = new CompletableFuture<>();
gateway.downloadThingy(new RequestHandler() {
private int total = 0;
private boolean pulsing = false;
private boolean cancelled = false;
@Override
public void received(byte[] data) {
int read = data.length;
println(i + " :: Thingy received " + read);
if (!pulsing) {
Runnable pulse = new PulseRunnable(i, downloadFut, con
boundedPulseExecutor.schedule(pulse, 2_000L, TimeUnit.
pulsing = true;
}
// ... to be continued
public static void asyncNonBlockingRequest(ExecutorService executor,
String url, String headers,
RequestHandler handler) {
executor.submit(() -> {
try {
println("Starting request to " + url);
URL uri = new URL(url);
SocketAddress serverAddress = new InetSocketAddress(uri.getHost(), 80);
AsynchronousSocketChannel channel = AsynchronousSocketChannel.open(group);
channel.connect(serverAddress, null, new CompletionHandler<Void>() {
@Override
public void completed(Void result, Void attachment) {
ByteBuffer headersBuffer = ByteBuffer.wrap((headers + "Host: " +
uri.ge
ByteBuffer responseBuffer = ByteBuffer.allocate(1024);
channel.write(headersBuffer, headersBuffer, new
CompletionHandler<>() {
@Override
public void completed(Integer written, ByteBuffer attachment) {
if (attachment.hasRemaining()) {
channel.write(attachment, attachment, this);
} else {
channel.read(responseBuffer, responseBuffer, new
Completion
@Override
public void completed(Integer read,
ByteBuffer attachment) {
// More
// this
// way
// ==>
private Mono<Connection.Available> getConnection(long eta, long wait, String token)
{
AtomicLong etaRef = new AtomicLong(eta);
AtomicLong waitRef = new AtomicLong(wait);
AtomicReference<String> tokenRef = new AtomicReference<>(token);
return Mono.defer(() -> {
if (etaRef.get() > MAX_ETA_MS) {
return Mono.error(new EtaExceededException());
}
return Mono.delay(Duration.ofMillis(waitRef.get()))
.flatMap(i -> coordinator.requestConnection(tokenRef.get()));
}).flatMap(c -> {
if (c instanceof Connection.Available) {
return Mono.just((Connection.Available) c);
} else {
Connection.Unavailable unavail = (Connection.Unavailable) c;
etaRef.set(unavail.getEta());
waitRef.set(unavail.getWait());
tokenRef.set(unavail.getToken());
return Mono.empty();
}
}).repeatWhenEmpty(Repeat
.onlyIf(ctx -> true)
.doOnRepeat(ctx ->
println(waitRef.get() + ", " + etaRef.get() + ", " + tokenRef.get())));
}
private Mono<Connection.Available> getConnection(long eta, long wait, String token) {
AtomicLong etaRef = new AtomicLong(eta);
AtomicLong waitRef = new AtomicLong(wait);
AtomicReference<String> tokenRef = new AtomicReference<>(token);
return Mono.defer(() -> {
if (etaRef.get() > MAX_ETA_MS) {
return Mono.error(new EtaExceededException());
}
return Mono.delay(Duration.ofMillis(waitRef.get()))
.flatMap(i -> coordinator.requestConnection(tokenRef.get()));
}).flatMap(c -> {
if (c instanceof Connection.Available) {
return Mono.just((Connection.Available) c);
} else {
Connection.Unavailable unavail = (Connection.Unavailable) c;
etaRef.set(unavail.getEta());
waitRef.set(unavail.getWait());
tokenRef.set(unavail.getToken());
return Mono.empty();
}
}).repeatWhenEmpty(Repeat
.onlyIf(ctx -> true)
.doOnRepeat(ctx ->
println(waitRef.get() + ", " + etaRef.get() + ", " + tokenRef.get())));
}
class StateMachineIterator implements Iterator<String> {
private int state;
private int i;
public String next() {
switch(state) {
case 0: state=1; return "A";
case 1: state=2; i=0; return "B";
case 2:
if(i == 3) state = 3;
return "C" + (i++);
case 3: state=4; return "D";
case 4: state=5; return "E";
default: throw new NoSuchElementException();
}
}
public boolean hasNext() {
return state < 5;
}
public void remove() {
throw new UnsupportedOperationException("Not supported");
}
}
class StateMachineIterator implements Iterator<String> {
private int state;
private int i;
public String next() {
switch(state) {
case 0: state=1; return "A";
case 1: state=2; i=0; return "B";
case 2:
if(i == 3) state = 3;
return "C" + (i++);
case 3: state=4; return "D";
case 4: state=5; return "E";
default: throw new NoSuchElementException();
}
}
public boolean hasNext() {
return state < 5;
}
public void remove() {
throw new UnsupportedOperationException("Not supported");
}
}
class StateMachineIterator implements Iterator<String> {
private int state;
private int i;
public String next() {
switch(state) {
case 0: state=1; return "A";
case 1: state=2; i=0; return "B";
case 2:
if(i == 3) state = 3;
return "C" + (i++);
case 3: state=4; return "D";
case 4: state=5; return "E";
default: throw new NoSuchElementException();
}
}
public boolean hasNext() {
return state < 5;
}
public void remove() {
throw new UnsupportedOperationException("Not supported");
}
}
class StateMachineIterator implements Iterator<String> {
private int state;
private int i;
public String next() {
switch(state) {
case 0: state=1; return "A";
case 1: state=2; i=0; return "B";
case 2:
if(i == 3) state = 3;
return "C" + (i++);
case 3: state=4; return "D";
case 4: state=5; return "E";
default: throw new NoSuchElementException();
}
}
public boolean hasNext() {
return state < 5;
}
public void remove() {
throw new UnsupportedOperationException("Not supported");
}
}
private Connection.Available getConnection(long eta,
long wait,
String token)
{
for(;;) {
if (eta > MAX_ETA_MS) {
throw new EtaExceededException();
}
if (wait > 0) {
Thread.sleep(wait);
}
println("Retrying download after " + wait + "ms wait.");
Connection c = coordinator.requestConnection(token);
if (c instanceof Connection.Available) {
return (Connection.Available) c;
}
Connection.Unavailable unavail = (Connection.Unavailable) c;
eta = unavail.getEta();
wait = unavail.getWait();
token = unavail.getToken();
}
}
Connection.Available conn = getConnection();
Runnable pulse = makePulse(conn);
Fiber<Object> f = null;
try (InputStream content = gateway.downloadThingy()) {
f = FiberScope.background().schedule(pulse);
ignoreContent(content);
} catch (IOException e) {
err("Download failed.");
throw e;
}
finally {
if (f!=null) {
f.cancel();
}
}
Papers and Webpages
Flynn, Michael J. - Some Computer Organizations and Their Effectiveness
Haynes, Christopher T. - Logic Continuations
Wand, Mitchell - Continuation-based Multiprocessing
Loitsch, Florian - Exceptional Continuations in JavaScript
Long, James - What's In A Continuation
Reynolds, John C. - The Discoveries of Continuations
Clinger, Hartheimer, Ost - Implementation Strategies for Continuations
Haynes, Friedman, Wand - Obtaining Coroutines with Continuations
Pressler, Ron - Why Continuations are Coming to Java
Repos
https://github.com/forax/loom-fiber/
https://bitbucket.org/arnaudbos/untangled/

More Related Content

What's hot

Security Events correlation with ESPER
Security Events correlation with ESPERSecurity Events correlation with ESPER
Security Events correlation with ESPER
Nikolay Klendar
 
The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181
Mahmoud Samir Fayed
 
PyconKR 2018 Deep dive into Coroutine
PyconKR 2018 Deep dive into CoroutinePyconKR 2018 Deep dive into Coroutine
PyconKR 2018 Deep dive into Coroutine
Daehee Kim
 
MultiClient chatting berbasis gambar
MultiClient chatting berbasis gambarMultiClient chatting berbasis gambar
MultiClient chatting berbasis gambaryoyomay93
 
Deferred
DeferredDeferred
Deferred
daiying-zhang
 
Introducing to Asynchronous Programming
Introducing to Asynchronous  ProgrammingIntroducing to Asynchronous  Programming
Introducing to Asynchronous Programming
Александр Федоров
 
Use C++ to Manipulate mozSettings in Gecko
Use C++ to Manipulate mozSettings in GeckoUse C++ to Manipulate mozSettings in Gecko
Use C++ to Manipulate mozSettings in Gecko
Chih-Hsuan Kuo
 
Deterministic simulation testing
Deterministic simulation testingDeterministic simulation testing
Deterministic simulation testingFoundationDB
 
Extreme JavaScript Performance
Extreme JavaScript PerformanceExtreme JavaScript Performance
Extreme JavaScript Performance
Thomas Fuchs
 
The Ring programming language version 1.5.3 book - Part 88 of 184
The Ring programming language version 1.5.3 book - Part 88 of 184The Ring programming language version 1.5.3 book - Part 88 of 184
The Ring programming language version 1.5.3 book - Part 88 of 184
Mahmoud Samir Fayed
 
Laporan multiclient chatting berbasis grafis (gambar)
Laporan multiclient chatting berbasis grafis (gambar)Laporan multiclient chatting berbasis grafis (gambar)
Laporan multiclient chatting berbasis grafis (gambar)Rara Ariesta
 
Rich and Snappy Apps (No Scaling Required)
Rich and Snappy Apps (No Scaling Required)Rich and Snappy Apps (No Scaling Required)
Rich and Snappy Apps (No Scaling Required)
Thomas Fuchs
 
Towards Reusable Components With Aspects [ICSE 2008]
Towards Reusable Components With Aspects [ICSE 2008]Towards Reusable Components With Aspects [ICSE 2008]
Towards Reusable Components With Aspects [ICSE 2008]
Kevin Hoffman
 
Java practice programs for beginners
Java practice programs for beginnersJava practice programs for beginners
Java practice programs for beginners
ishan0019
 
Java, Up to Date Sources
Java, Up to Date SourcesJava, Up to Date Sources
Java, Up to Date Sources
輝 子安
 
Dagger & rxjava & retrofit
Dagger & rxjava & retrofitDagger & rxjava & retrofit
Dagger & rxjava & retrofit
Ted Liang
 
Laporan multiclient chatting client server
Laporan multiclient chatting client serverLaporan multiclient chatting client server
Laporan multiclient chatting client servertrilestari08
 

What's hot (20)

Security Events correlation with ESPER
Security Events correlation with ESPERSecurity Events correlation with ESPER
Security Events correlation with ESPER
 
The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181
 
PyconKR 2018 Deep dive into Coroutine
PyconKR 2018 Deep dive into CoroutinePyconKR 2018 Deep dive into Coroutine
PyconKR 2018 Deep dive into Coroutine
 
MultiClient chatting berbasis gambar
MultiClient chatting berbasis gambarMultiClient chatting berbasis gambar
MultiClient chatting berbasis gambar
 
Deferred
DeferredDeferred
Deferred
 
Introducing to Asynchronous Programming
Introducing to Asynchronous  ProgrammingIntroducing to Asynchronous  Programming
Introducing to Asynchronous Programming
 
Use C++ to Manipulate mozSettings in Gecko
Use C++ to Manipulate mozSettings in GeckoUse C++ to Manipulate mozSettings in Gecko
Use C++ to Manipulate mozSettings in Gecko
 
Deterministic simulation testing
Deterministic simulation testingDeterministic simulation testing
Deterministic simulation testing
 
Ss
SsSs
Ss
 
Extreme JavaScript Performance
Extreme JavaScript PerformanceExtreme JavaScript Performance
Extreme JavaScript Performance
 
The Ring programming language version 1.5.3 book - Part 88 of 184
The Ring programming language version 1.5.3 book - Part 88 of 184The Ring programming language version 1.5.3 book - Part 88 of 184
The Ring programming language version 1.5.3 book - Part 88 of 184
 
Laporan multiclient chatting berbasis grafis (gambar)
Laporan multiclient chatting berbasis grafis (gambar)Laporan multiclient chatting berbasis grafis (gambar)
Laporan multiclient chatting berbasis grafis (gambar)
 
Rich and Snappy Apps (No Scaling Required)
Rich and Snappy Apps (No Scaling Required)Rich and Snappy Apps (No Scaling Required)
Rich and Snappy Apps (No Scaling Required)
 
Towards Reusable Components With Aspects [ICSE 2008]
Towards Reusable Components With Aspects [ICSE 2008]Towards Reusable Components With Aspects [ICSE 2008]
Towards Reusable Components With Aspects [ICSE 2008]
 
java assignment
java assignmentjava assignment
java assignment
 
Java practice programs for beginners
Java practice programs for beginnersJava practice programs for beginners
Java practice programs for beginners
 
Java, Up to Date Sources
Java, Up to Date SourcesJava, Up to Date Sources
Java, Up to Date Sources
 
JVM Architecture - Java
JVM Architecture - JavaJVM Architecture - Java
JVM Architecture - Java
 
Dagger & rxjava & retrofit
Dagger & rxjava & retrofitDagger & rxjava & retrofit
Dagger & rxjava & retrofit
 
Laporan multiclient chatting client server
Laporan multiclient chatting client serverLaporan multiclient chatting client server
Laporan multiclient chatting client server
 

Similar to 2019-10-05 - Untangled - Voxxed days ticino

Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfImplement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
kostikjaylonshaewe47
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
Tomek Kaczanowski
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVMVaclav Pech
 
Note Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdfNote Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdf
fatoryoutlets
 
Java 8 Puzzlers [as presented at OSCON 2016]
Java 8 Puzzlers [as presented at  OSCON 2016]Java 8 Puzzlers [as presented at  OSCON 2016]
Java 8 Puzzlers [as presented at OSCON 2016]
Baruch Sadogursky
 
Asynchronen Code testen
Asynchronen Code testenAsynchronen Code testen
Asynchronen Code testen
ndrssmn
 
Nantes Jug - Java 7
Nantes Jug - Java 7Nantes Jug - Java 7
Nantes Jug - Java 7
Sébastien Prunier
 
Embracing the-power-of-refactor
Embracing the-power-of-refactorEmbracing the-power-of-refactor
Embracing the-power-of-refactor
Xiaojun REN
 
Test string and array
Test string and arrayTest string and array
Test string and array
Nabeel Ahmed
 
Jason parsing
Jason parsingJason parsing
Jason parsing
parallelminder
 
code for quiz in my sql
code for quiz  in my sql code for quiz  in my sql
code for quiz in my sql
JOYITAKUNDU1
 
Student management system
Student management systemStudent management system
Student management system
geetika goyal
 
RMI Java Programming Lab Manual 2019
RMI Java Programming Lab Manual 2019RMI Java Programming Lab Manual 2019
RMI Java Programming Lab Manual 2019
Gebreigziabher Ab
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good TestsTomek Kaczanowski
 
Non Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJavaNon Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJava
Frank Lyaruu
 
Railway reservation system
Railway reservation systemRailway reservation system
Railway reservation system
Prashant Sharma
 
help me Java projectI put problem and my own code in the linkmy .pdf
help me Java projectI put problem and my own code in the linkmy .pdfhelp me Java projectI put problem and my own code in the linkmy .pdf
help me Java projectI put problem and my own code in the linkmy .pdf
arihantmum
 
4. Обработка ошибок, исключения, отладка
4. Обработка ошибок, исключения, отладка4. Обработка ошибок, исключения, отладка
4. Обработка ошибок, исключения, отладка
DEVTYPE
 

Similar to 2019-10-05 - Untangled - Voxxed days ticino (20)

Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfImplement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVM
 
Note Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdfNote Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdf
 
Java 8 Puzzlers [as presented at OSCON 2016]
Java 8 Puzzlers [as presented at  OSCON 2016]Java 8 Puzzlers [as presented at  OSCON 2016]
Java 8 Puzzlers [as presented at OSCON 2016]
 
Asynchronen Code testen
Asynchronen Code testenAsynchronen Code testen
Asynchronen Code testen
 
Nantes Jug - Java 7
Nantes Jug - Java 7Nantes Jug - Java 7
Nantes Jug - Java 7
 
Embracing the-power-of-refactor
Embracing the-power-of-refactorEmbracing the-power-of-refactor
Embracing the-power-of-refactor
 
Test string and array
Test string and arrayTest string and array
Test string and array
 
Jason parsing
Jason parsingJason parsing
Jason parsing
 
code for quiz in my sql
code for quiz  in my sql code for quiz  in my sql
code for quiz in my sql
 
Student management system
Student management systemStudent management system
Student management system
 
RMI Java Programming Lab Manual 2019
RMI Java Programming Lab Manual 2019RMI Java Programming Lab Manual 2019
RMI Java Programming Lab Manual 2019
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
 
Non Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJavaNon Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJava
 
Railway reservation system
Railway reservation systemRailway reservation system
Railway reservation system
 
Anti patterns
Anti patternsAnti patterns
Anti patterns
 
help me Java projectI put problem and my own code in the linkmy .pdf
help me Java projectI put problem and my own code in the linkmy .pdfhelp me Java projectI put problem and my own code in the linkmy .pdf
help me Java projectI put problem and my own code in the linkmy .pdf
 
4. Обработка ошибок, исключения, отладка
4. Обработка ошибок, исключения, отладка4. Обработка ошибок, исключения, отладка
4. Обработка ошибок, исключения, отладка
 
Sam wd programs
Sam wd programsSam wd programs
Sam wd programs
 

Recently uploaded

Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 

Recently uploaded (20)

Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 

2019-10-05 - Untangled - Voxxed days ticino

  • 2.
  • 3.
  • 4.
  • 5. private Connection.Available getConnection(long eta, long wait, String token) { for(;;) { if (eta > MAX_ETA_MS) { throw new EtaExceededException(); } if (wait > 0) { Thread.sleep(wait); } println("Retrying download after " + wait + "ms wait."); Connection c = coordinator.requestConnection(token); if (c instanceof Connection.Available) { return (Connection.Available) c; } Connection.Unavailable unavail = (Connection.Unavailable) c; eta = unavail.getEta(); wait = unavail.getWait(); token = unavail.getToken(); } }
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11. public static InputStream blockingRequest(String url, String headers) throws IOException { URL uri = new URL(url); SocketAddress serverAddress = new InetSocketAddress(uri.getHost(), uri.getP SocketChannel channel = SocketChannel.open(serverAddress); ByteBuffer buffer = ByteBuffer.wrap((headers + "Host: " + uri.getHost() + " do { channel.write(buffer); } while(buffer.hasRemaining()); return channel.socket().getInputStream(); }
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 19.
  • 20. private void getThingy(int i, CompletionHandler<Void> handler) { println("Start getThingy."); getConnection(new CompletionHandler<>() { @Override public void completed(Connection.Available conn) { println("Got token, " + conn.getToken()); CompletableFuture<Void> downloadFut = new CompletableFuture<>(); gateway.downloadThingy(new RequestHandler() { private int total = 0; private boolean pulsing = false; private boolean cancelled = false; @Override public void received(byte[] data) { int read = data.length; println(i + " :: Thingy received " + read); if (!pulsing) { Runnable pulse = new PulseRunnable(i, downloadFut, con boundedPulseExecutor.schedule(pulse, 2_000L, TimeUnit. pulsing = true; } // ... to be continued
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26. public static void asyncNonBlockingRequest(ExecutorService executor, String url, String headers, RequestHandler handler) { executor.submit(() -> { try { println("Starting request to " + url); URL uri = new URL(url); SocketAddress serverAddress = new InetSocketAddress(uri.getHost(), 80); AsynchronousSocketChannel channel = AsynchronousSocketChannel.open(group); channel.connect(serverAddress, null, new CompletionHandler<Void>() { @Override public void completed(Void result, Void attachment) { ByteBuffer headersBuffer = ByteBuffer.wrap((headers + "Host: " + uri.ge ByteBuffer responseBuffer = ByteBuffer.allocate(1024); channel.write(headersBuffer, headersBuffer, new CompletionHandler<>() { @Override public void completed(Integer written, ByteBuffer attachment) { if (attachment.hasRemaining()) { channel.write(attachment, attachment, this); } else { channel.read(responseBuffer, responseBuffer, new Completion @Override public void completed(Integer read, ByteBuffer attachment) { // More // this // way // ==>
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35. private Mono<Connection.Available> getConnection(long eta, long wait, String token) { AtomicLong etaRef = new AtomicLong(eta); AtomicLong waitRef = new AtomicLong(wait); AtomicReference<String> tokenRef = new AtomicReference<>(token); return Mono.defer(() -> { if (etaRef.get() > MAX_ETA_MS) { return Mono.error(new EtaExceededException()); } return Mono.delay(Duration.ofMillis(waitRef.get())) .flatMap(i -> coordinator.requestConnection(tokenRef.get())); }).flatMap(c -> { if (c instanceof Connection.Available) { return Mono.just((Connection.Available) c); } else { Connection.Unavailable unavail = (Connection.Unavailable) c; etaRef.set(unavail.getEta()); waitRef.set(unavail.getWait()); tokenRef.set(unavail.getToken()); return Mono.empty(); } }).repeatWhenEmpty(Repeat .onlyIf(ctx -> true) .doOnRepeat(ctx -> println(waitRef.get() + ", " + etaRef.get() + ", " + tokenRef.get()))); }
  • 36. private Mono<Connection.Available> getConnection(long eta, long wait, String token) { AtomicLong etaRef = new AtomicLong(eta); AtomicLong waitRef = new AtomicLong(wait); AtomicReference<String> tokenRef = new AtomicReference<>(token); return Mono.defer(() -> { if (etaRef.get() > MAX_ETA_MS) { return Mono.error(new EtaExceededException()); } return Mono.delay(Duration.ofMillis(waitRef.get())) .flatMap(i -> coordinator.requestConnection(tokenRef.get())); }).flatMap(c -> { if (c instanceof Connection.Available) { return Mono.just((Connection.Available) c); } else { Connection.Unavailable unavail = (Connection.Unavailable) c; etaRef.set(unavail.getEta()); waitRef.set(unavail.getWait()); tokenRef.set(unavail.getToken()); return Mono.empty(); } }).repeatWhenEmpty(Repeat .onlyIf(ctx -> true) .doOnRepeat(ctx -> println(waitRef.get() + ", " + etaRef.get() + ", " + tokenRef.get()))); }
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44. class StateMachineIterator implements Iterator<String> { private int state; private int i; public String next() { switch(state) { case 0: state=1; return "A"; case 1: state=2; i=0; return "B"; case 2: if(i == 3) state = 3; return "C" + (i++); case 3: state=4; return "D"; case 4: state=5; return "E"; default: throw new NoSuchElementException(); } } public boolean hasNext() { return state < 5; } public void remove() { throw new UnsupportedOperationException("Not supported"); } }
  • 45. class StateMachineIterator implements Iterator<String> { private int state; private int i; public String next() { switch(state) { case 0: state=1; return "A"; case 1: state=2; i=0; return "B"; case 2: if(i == 3) state = 3; return "C" + (i++); case 3: state=4; return "D"; case 4: state=5; return "E"; default: throw new NoSuchElementException(); } } public boolean hasNext() { return state < 5; } public void remove() { throw new UnsupportedOperationException("Not supported"); } }
  • 46. class StateMachineIterator implements Iterator<String> { private int state; private int i; public String next() { switch(state) { case 0: state=1; return "A"; case 1: state=2; i=0; return "B"; case 2: if(i == 3) state = 3; return "C" + (i++); case 3: state=4; return "D"; case 4: state=5; return "E"; default: throw new NoSuchElementException(); } } public boolean hasNext() { return state < 5; } public void remove() { throw new UnsupportedOperationException("Not supported"); } }
  • 47. class StateMachineIterator implements Iterator<String> { private int state; private int i; public String next() { switch(state) { case 0: state=1; return "A"; case 1: state=2; i=0; return "B"; case 2: if(i == 3) state = 3; return "C" + (i++); case 3: state=4; return "D"; case 4: state=5; return "E"; default: throw new NoSuchElementException(); } } public boolean hasNext() { return state < 5; } public void remove() { throw new UnsupportedOperationException("Not supported"); } }
  • 48.
  • 49. private Connection.Available getConnection(long eta, long wait, String token) { for(;;) { if (eta > MAX_ETA_MS) { throw new EtaExceededException(); } if (wait > 0) { Thread.sleep(wait); } println("Retrying download after " + wait + "ms wait."); Connection c = coordinator.requestConnection(token); if (c instanceof Connection.Available) { return (Connection.Available) c; } Connection.Unavailable unavail = (Connection.Unavailable) c; eta = unavail.getEta(); wait = unavail.getWait(); token = unavail.getToken(); } }
  • 50. Connection.Available conn = getConnection(); Runnable pulse = makePulse(conn); Fiber<Object> f = null; try (InputStream content = gateway.downloadThingy()) { f = FiberScope.background().schedule(pulse); ignoreContent(content); } catch (IOException e) { err("Download failed."); throw e; } finally { if (f!=null) { f.cancel(); } }
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60. Papers and Webpages Flynn, Michael J. - Some Computer Organizations and Their Effectiveness Haynes, Christopher T. - Logic Continuations Wand, Mitchell - Continuation-based Multiprocessing Loitsch, Florian - Exceptional Continuations in JavaScript Long, James - What's In A Continuation Reynolds, John C. - The Discoveries of Continuations Clinger, Hartheimer, Ost - Implementation Strategies for Continuations Haynes, Friedman, Wand - Obtaining Coroutines with Continuations Pressler, Ron - Why Continuations are Coming to Java Repos https://github.com/forax/loom-fiber/ https://bitbucket.org/arnaudbos/untangled/