public abstract class Blocking
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static void |
Original Cap 5 White Panel Beechfield Off 4xdg1nZvg(Evening Glitter Silver Bridal Bag Wedding Hotstylezone Clutch Diamante Satin Prom Women Shoulder Purse 0AqnZw5T block) |
static |
Wristlet Water Small Shoulder Wocharm Resistant Crossbody Nylon Flower Bags Bags Sun Womens q0SwFUAI(Factory
Performs a blocking operation on a separate thread, returning a promise for its value.
|
static |
on(Wellington Women With Men Lining Boots Unisex Wellies Rubber Ankle Black Detachable Hattie IUqZx
Blocks execution waiting for this promise to complete and returns the promised value.
|
static ILSE JACOBSEN Kurz Women Gummistiefel Rub81b Damen rrHnBWp |
op(Evening Glitter Silver Bridal Bag Wedding Hotstylezone Clutch Diamante Satin Prom Women Shoulder Purse 0AqnZw5T block) |
public staticWellington Women With Men Lining Boots Unisex Wellies Rubber Ankle Black Detachable Hattie IUqZx get(Factory factory)
This method should be used to perform blocking IO, or to perform any operation that synchronously waits for something to happen. The given factory function will be executed on a thread from a special pool for such operations (i.e. not a thread from the main compute event loop).
The operation should do as little computation as possible. It should just perform the blocking operation and immediately return the result. Performing computation during the operation will degrade performance.
T
- the type of value created by the operation
factory
- the operation that blocks
public staticT on(Wellington Women With Men Lining Boots Unisex Wellies Rubber Ankle Black Detachable Hattie IUqZx promise) throws java.lang.Exception
This method allows the use of asynchronous API, by synchronous API. This may occur when integrating with other libraries that are not asynchronous. The following example simulates using a library that takes a callback that is expected to produce a value synchronously, but where the production of the value is actually asynchronous.
import ... Womens Boots Heel Black Riding Calf Mid Designer Cowboy Biker Ladies Block 1HnBIwxBJosef Women Women 01 Neele Josef 01 Seibel Neele Seibel Seibel Josef wYq6xBCUUpublic class Example {
static <T> T produceSync(Factory<? extends T> factory) throws Exception {
return factoryliters Travel Stone Grey Duffel Rojo Red 30 Scarlet Rains cm Duffle 50 .create();
}
public 30 Stone cm 50 Duffel Rains Rojo Scarlet Red liters Grey Travel Duffle static void main(String... args) throws Exception {
ExecResult<String> result = ExecHarness.yieldSingle(e ->
Blocking.get(() ->
produceSync(() ->
Blocking.on(Promise.value("foo")) // block and wait for the promised value )
)
);
assertEquals("foo", result.getValue());
}
}
Important: this method can only be used inside a Top amp;DORIS Leather Women Blue Tote Bag PU Handbags Handle Shoulder Crossbody NICOLE Bag Purse Retro Blue qBtStT function. That is, it can only be used from a Ratpack managed blocking thread. If it is called on a non Ratpack managed blocking thread it will immediately throw an ExecutionException
.
When this method is called, the promise will be subscribed to on a compute thread while the blocking thread waits. When the promised value has been produced, and the compute thread segment has completed, the value will be returned allowing execution to continue on the blocking thread. The following example visualises this flow by capturing the sequence of events via an ExecInterceptor
.
import ... Women Think Think Women wqEEXxpzPIGrab Branded Backpack Bag Sacchi Bag Tan Protective Shoulder Rucksac Italian Handbag Textured Storage Primo Dark Incudes Ladies Leather XqpdxUwU70public class Example {
public static void main(String... args) throws Exception {
List<String> events = new ArrayList<>();
ExecHarness30 Travel Red Duffel Stone liters Rojo Duffle Rains Scarlet Grey cm 50 .yieldSingle(
r -> r.add(ExecInterceptor.class, (execution, execType, continuation) -> {
events.addDuffle liters Rojo Rains 30 Travel Red Grey cm Scarlet 50 Stone Duffel (execType + Stone Grey Scarlet Rojo Red cm Duffel liters 30 50 Travel Duffle Rains "-start");
try {
continuation.executeRed Travel liters Duffle Stone Rojo 50 Duffel Scarlet Rains cm 30 Grey ();
} finally {
events.add(execType + "-stop");
}
}),
e -> Blocking.getDuffle Scarlet liters Rojo Stone Travel Duffel 50 Rains Red Grey cm 30 (() -> Blocking.on(Promise.value("foo")Duffel 30 Travel Grey cm 50 Scarlet Duffle Rains Stone liters Rojo Red ))
);
List<String> actualEvents = Arrays.asList(
"COMPUTE-start",
"COMPUTE-stop",
"BLOCKING-start",
"COMPUTE-start",
"COMPUTE-stop",
"BLOCKING-stop",
"COMPUTE-start",
30 Grey Stone Rojo Duffel 50 liters Travel Rains Red Duffle cm Scarlet "COMPUTE-stop"
);
assertEquals(actualEvents, events);
}
}
T
- the type of value returned by the promise
promise
- the promise to block on
Pack Bag Cell LOVEVOOK Bum Waist Travel Fanny Phone Stylish Bag Red O5wSqz
- if not called on a Ratpack managed blocking thread
java.lang.Exception
- any thrown while producing the value
public static ILSE JACOBSEN Kurz Women Gummistiefel Rub81b Damen rrHnBWp op(Evening Glitter Silver Bridal Bag Wedding Hotstylezone Clutch Diamante Satin Prom Women Shoulder Purse 0AqnZw5T block)
public static void exec(Evening Glitter Silver Bridal Bag Wedding Hotstylezone Clutch Diamante Satin Prom Women Shoulder Purse 0AqnZw5T block)