Java Code Examples for io.atomix.primitive.operation.OperationType#QUERY
The following examples show how to use
io.atomix.primitive.operation.OperationType#QUERY .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PrimaryRole.java From atomix with Apache License 2.0 | 5 votes |
@Override public CompletableFuture<ExecuteResponse> execute(ExecuteRequest request) { logRequest(request); if (request.operation().id().type() == OperationType.COMMAND) { return executeCommand(request).thenApply(this::logResponse); } else if (request.operation().id().type() == OperationType.QUERY) { return executeQuery(request).thenApply(this::logResponse); } return Futures.exceptionalFuture(new IllegalArgumentException("Unknown operation type")); }
Example 2
Source File: LogProxySession.java From atomix with Apache License 2.0 | 4 votes |
/** * Consumes a record from the log. * * @param record the record to consume */ @SuppressWarnings("unchecked") private void consume(LogRecord record) { // Decode the raw log operation from the record. LogOperation operation = decodeInternal(record.value()); // If this operation is not destined for this primitive, ignore it. // TODO: If multiple primitives of different types are created and destroyed on the same distributed log, // we need to be able to differentiate between different instances of a service by the service ID. if (!operation.primitive().equals(name())) { return; } // Create a session from the log record. Session session = getOrCreateSession(operation.sessionId()); // Update the local context for the service. currentIndex = record.index(); currentSession = session; currentOperation = operation.operationId().type(); currentTimestamp = record.timestamp(); // Apply the operation to the service. byte[] output = service.apply(new DefaultCommit<>( currentIndex, operation.operationId(), operation.operation(), currentSession, currentTimestamp)); // If the operation session matches the local session, complete the write future. if (operation.sessionId().equals(this.session.sessionId())) { CompletableFuture future = writeFutures.remove(operation.operationIndex()); if (future != null) { future.complete(decode(output)); } } // Iterate through pending reads and complete any reads at indexes less than or equal to the applied index. PendingRead pendingRead = pendingReads.peek(); while (pendingRead != null && pendingRead.index <= record.index()) { session = getOrCreateSession(this.session.sessionId()); currentSession = session; currentOperation = OperationType.QUERY; try { output = service.apply(new DefaultCommit<>( currentIndex, pendingRead.operationId, pendingRead.bytes, session, currentTimestamp)); pendingRead.future.complete(output); } catch (Exception e) { pendingRead.future.completeExceptionally(new PrimitiveException.ServiceException()); } pendingReads.remove(); pendingRead = pendingReads.peek(); } }
Example 3
Source File: AtomicSemaphoreService.java From atomix with Apache License 2.0 | 4 votes |
@Operation(value = "available", type = OperationType.QUERY) int available();
Example 4
Source File: AtomicSemaphoreService.java From atomix with Apache License 2.0 | 4 votes |
@Operation(value = "queueStatus", type = OperationType.QUERY) QueueStatus queueStatus();
Example 5
Source File: AtomicSemaphoreService.java From atomix with Apache License 2.0 | 4 votes |
@Operation(value = "holderStatus", type = OperationType.QUERY) Map<Long, Integer> holderStatus();
Example 6
Source File: PrimaryBackupServiceContext.java From atomix with Apache License 2.0 | 2 votes |
/** * Returns the current service index and sets the service to read-only mode. * * @return the current index */ public long getIndex() { currentOperation = OperationType.QUERY; return currentIndex; }