use of com.hazelcast.spi.impl.operationservice.Offload in project hazelcast by hazelcast.
the class OperationRunnerImpl method call.
private void call(Operation op) throws Exception {
CallStatus callStatus = op.call();
switch(callStatus.ordinal()) {
case RESPONSE_ORDINAL:
int backupAcks = backupHandler.sendBackups(op);
Object response = op.getResponse();
if (backupAcks > 0) {
response = new NormalResponse(response, op.getCallId(), backupAcks, op.isUrgent());
}
try {
op.sendResponse(response);
} catch (ResponseAlreadySentException e) {
logOperationError(op, e);
}
afterRun(op);
break;
case VOID_ORDINAL:
backupHandler.sendBackups(op);
afterRun(op);
break;
case OFFLOAD_ORDINAL:
op.afterRun();
Offload offload = (Offload) callStatus;
offload.init(nodeEngine, operationService.asyncOperations);
offload.start();
break;
case WAIT_ORDINAL:
nodeEngine.getOperationParker().park((BlockingOperation) op);
break;
default:
throw new IllegalStateException();
}
}
use of com.hazelcast.spi.impl.operationservice.Offload in project hazelcast by hazelcast.
the class Invocation_OffloadedTest method whenStartThrowsException_thenExceptionPropagated.
@Test(expected = ExpectedRuntimeException.class)
public void whenStartThrowsException_thenExceptionPropagated() {
InternalCompletableFuture f = localOperationService.invokeOnPartition(new OffloadingOperation(op -> new Offload(op) {
@Override
public void start() {
throw new ExpectedRuntimeException();
}
}));
assertCompletesEventually(f);
f.joinInternal();
}
use of com.hazelcast.spi.impl.operationservice.Offload in project hazelcast by hazelcast.
the class Invocation_OffloadedTest method whenOffloaded_thenAsyncOperationRegisteredOnStart_andUnregisteredOnCompletion.
@Test
public void whenOffloaded_thenAsyncOperationRegisteredOnStart_andUnregisteredOnCompletion() {
OffloadingOperation source = new OffloadingOperation(op -> new Offload(op) {
@Override
public void start() {
// we make sure that the operation is registered
assertTrue(localOperationService.asyncOperations.contains(offloadedOperation()));
offloadedOperation().sendResponse("someresponse");
}
});
InternalCompletableFuture<String> f = localOperationService.invokeOnPartition(source);
assertCompletesEventually(f);
// make sure the source operation isn't registered anymore
assertFalse(localOperationService.asyncOperations.contains(source));
}
use of com.hazelcast.spi.impl.operationservice.Offload in project hazelcast by hazelcast.
the class Invocation_OffloadedTest method whenCompletesInStart.
@Test
public void whenCompletesInStart() throws Exception {
final String response = "someresponse";
OffloadingOperation source = new OffloadingOperation(op -> new Offload(op) {
@Override
public void start() {
offloadedOperation().sendResponse("someresponse");
}
});
InternalCompletableFuture<String> f = localOperationService.invokeOnPartition(source);
assertCompletesEventually(f);
assertEquals(response, f.get());
// make sure the source operation isn't registered anymore
assertFalse(localOperationService.asyncOperations.contains(source));
}
Aggregations