Skip to content

Updating names to reflect purpose of the Object Action #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: async-action-changes
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.liferay.clarity;

import org.springframework.security.oauth2.jwt.Jwt;

/**
* Represents an account creation request.
*
* @author dnebing
*/
public class AccountCreationRequest {

public AccountCreationRequest(String accountJSON, Jwt jwt) {
_accountJSON = accountJSON;
_jwt = jwt;
}

public Jwt getJwt() {
return _jwt;
}

public String getAccountJSON() {
return _accountJSON;
}

private final Jwt _jwt;
private final String _accountJSON;

}
Original file line number Diff line number Diff line change
@@ -20,22 +20,22 @@
import reactor.core.publisher.Mono;

/**
* Processes user creation requests.
* Processes account creation requests.
*
* @author dnebing
*/
@Service
public class UserCreatedRequestProcessorService {
public class AccountCreationRequestProcessorService {

/**
* Constructs a new UserCreationRequestProcessorService.
* Constructs a new AccountCreationRequestProcessorService.
*
* @param queueManager the queue manager
* @param taskExecutor the task executor
*/
@Autowired
public UserCreatedRequestProcessorService(
UserCreatedRequestQueueManager queueManager,
public AccountCreationRequestProcessorService(
AccountCreationRequestQueueManager queueManager,
TaskExecutor taskExecutor) {

_queueManager = queueManager;
@@ -57,13 +57,13 @@ private void _log(String message) {
}

/**
* Processes a user creation request.
* Processes an account creation request.
*
* @param userJson the user creation request in JSON format
* @param accountJson the account creation request in JSON format
*/
private void _processRequest(UserCreatedRequest request) {
private void _processRequest(AccountCreationRequest request) {
try {
JSONObject jsonObject = new JSONObject(request.getUserJSON());
JSONObject jsonObject = new JSONObject(request.getAccountJSON());

JSONObject objectEntryDTODistributorApplicationJSONObject =
jsonObject.getJSONObject(
@@ -181,12 +181,12 @@ private void _processRequest(UserCreatedRequest request) {
}
catch (Exception exception) {
_log.error(
"Failed to process user: {}", request.getUserJSON(), exception);
"Failed to process account: {}", request.getAccountJSON(), exception);
}
}

/**
* Starts the processing of user creation requests.
* Starts the processing of account creation requests.
*/
private void _startProcessing() {
_taskExecutor.execute(
@@ -196,7 +196,7 @@ private void _startProcessing() {
_queueManager.awaitWork(); // Wait for work if the queue is empty

while (!_queueManager.isEmpty()) {
UserCreatedRequest request =
AccountCreationRequest request =
_queueManager.dequeue();

_processRequest(request);
@@ -230,9 +230,9 @@ private Mono<ResponseEntity<String>> _transform(
}

private static final Logger _log = LoggerFactory.getLogger(
UserCreatedRequestProcessorService.class);
AccountCreationRequestProcessorService.class);

private final UserCreatedRequestQueueManager _queueManager;
private final AccountCreationRequestQueueManager _queueManager;
private final TaskExecutor _taskExecutor;

}
Original file line number Diff line number Diff line change
@@ -8,12 +8,12 @@
import org.springframework.stereotype.Service;

/**
* Manages the queue of user creation requests.
* Manages the queue of account creation requests.
*
* @author dnebing
*/
@Service
public class UserCreatedRequestQueueManager {
public class AccountCreationRequestQueueManager {

/**
* Waits for work to be available.
@@ -34,28 +34,28 @@ public void awaitWork() throws InterruptedException {
}

/**
* Dequeues a user creation request.
* Dequeues an account creation request.
*
* @return the user creation request
* @throws InterruptedException if the thread is interrupted while waiting for a user creation request
* @return the account creation request
* @throws InterruptedException if the thread is interrupted while waiting for an account creation request
*/
public UserCreatedRequest dequeue() throws InterruptedException {
public AccountCreationRequest dequeue() throws InterruptedException {

// Remove the request from the queue

return _queue.take();
}

/**
* Enqueues a user creation request.
* Enqueues an account creation request.
*
* @param userCreatedRequest the user creation request
* @param accountCreationRequest the account creation request
*/
public void enqueue(UserCreatedRequest userCreatedRequest) {
public void enqueue(AccountCreationRequest accountCreationRequest) {

// Add the request to the queue

_queue.add(userCreatedRequest);
_queue.add(accountCreationRequest);

// signal the executor that work is available

@@ -87,7 +87,7 @@ private void _signalExecutor() {

private final ReentrantLock _lock = new ReentrantLock();
private final Condition _notEmpty = _lock.newCondition();
private final BlockingQueue<UserCreatedRequest> _queue =
private final BlockingQueue<AccountCreationRequest> _queue =
new LinkedBlockingQueue<>();

}
Original file line number Diff line number Diff line change
@@ -19,7 +19,8 @@
import org.springframework.web.bind.annotation.RestController;

/**
* Invoked when a new user account has been created.
* Invoked when a Distributor Application is approved and an Account
* needs to be created.
*
* @author Raymond Augé
* @author Gregory Amerson
@@ -32,13 +33,14 @@ public class ObjectActionAccountRestController extends BaseRestController {

@Autowired
public ObjectActionAccountRestController(
UserCreatedRequestQueueManager queueManager) {
AccountCreationRequestQueueManager queueManager) {

_queueManager = queueManager;
}

/**
* Invoked when a new user account has been created.
* Invoked when a Distributor Application is approved and an Account
* needs to be created.
*
* @param jwt the JWT token
* @param json the user creation request in JSON format
@@ -54,7 +56,7 @@ public ResponseEntity<String> post(

// Create the request instance

UserCreatedRequest request = new UserCreatedRequest(json, jwt);
AccountCreationRequest request = new AccountCreationRequest(json, jwt);

// Enqueue the request

@@ -68,6 +70,6 @@ public ResponseEntity<String> post(
private static final Log _log = LogFactory.getLog(
ObjectActionAccountRestController.class);

private final UserCreatedRequestQueueManager _queueManager;
private final AccountCreationRequestQueueManager _queueManager;

}
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
* Creates the task executor which will be processing the user creation requests.
* Creates the task executor which will be processing the account creation requests.
*
* @author dnebing
*/
@@ -26,7 +26,7 @@ public TaskExecutor taskExecutor() {
threadPoolTaskExecutor.setCorePoolSize(0);
threadPoolTaskExecutor.setMaxPoolSize(10);
threadPoolTaskExecutor.setQueueCapacity(100);
threadPoolTaskExecutor.setThreadNamePrefix("CreateUserTaskExecutor-");
threadPoolTaskExecutor.setThreadNamePrefix("CreateAccountTaskExecutor-");

// initialize the task executor

This file was deleted.