下面列出了org.apache.commons.lang3.text.translate.UnicodeEscaper#javax.ejb.Asynchronous 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Asynchronous
public void publish(final Event event) {
if (BASE_URL == null || BASE_URL.isEmpty()) {
logger.hawkularServerNotConfigured();
return;
}
if (USERNAME == null || USERNAME.isEmpty()) {
logger.hawkularServerUsernameNotConfigured();
return;
}
if (PASSWORD == null || PASSWORD.isEmpty()) {
logger.hawkularServerPasswordNotConfigured();
return;
}
HystrixFeign.builder()
.requestInterceptor(new BasicAuthRequestInterceptor(USERNAME, PASSWORD))
.encoder(new JacksonEncoder())
.decoder(new JacksonDecoder())
.retryer(new Retryer.Default())
.target(AlertsService.class, TARGET)
.addEvent(event);
}
@POST
@Produces({"application/xml", "text/xml", "application/json", "text/yaml", "text/x-yaml", "application/x-yaml", "application/x-protobuf",
"application/x-protostuff"})
@Path("/{logicName}/async/create")
@GZIP
@GenerateQuerySessionId(cookieBasePath = "/DataWave/Query/")
@EnrichQueryMetrics(methodType = MethodType.CREATE)
@Interceptors({RequiredInterceptor.class, ResponseInterceptor.class})
@Asynchronous
@Timed(name = "dw.query.createQueryAsync", absolute = true)
public void createQueryAsync(@Required("logicName") @PathParam("logicName") String queryLogicName, MultivaluedMap<String,String> queryParameters,
@Suspended AsyncResponse asyncResponse) {
try {
GenericResponse<String> response = createQuery(queryLogicName, queryParameters);
asyncResponse.resume(response);
} catch (Throwable t) {
asyncResponse.resume(t);
}
}
@POST
@Produces({"application/xml", "text/xml", "application/json", "text/yaml", "text/x-yaml", "application/x-yaml", "application/x-protobuf",
"application/x-protostuff"})
@Path("/{logicName}/async/createAndNext")
@GZIP
@GenerateQuerySessionId(cookieBasePath = "/DataWave/Query/")
@EnrichQueryMetrics(methodType = MethodType.CREATE_AND_NEXT)
@Interceptors({ResponseInterceptor.class, RequiredInterceptor.class})
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
@Asynchronous
@Timed(name = "dw.query.createAndNextAsync", absolute = true)
public void createQueryAndNextAsync(@Required("logicName") @PathParam("logicName") String logicName, MultivaluedMap<String,String> queryParameters,
@Suspended AsyncResponse asyncResponse) {
try {
BaseQueryResponse response = createQueryAndNext(logicName, queryParameters);
asyncResponse.resume(response);
} catch (Throwable t) {
asyncResponse.resume(t);
}
}
@POST
@Produces("*/*")
@Path("/{logicName}/async/execute")
@GZIP
@Interceptors({ResponseInterceptor.class, RequiredInterceptor.class})
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
@Asynchronous
@Timed(name = "dw.query.executeQueryAsync", absolute = true)
public void executeAsync(@PathParam("logicName") String logicName, MultivaluedMap<String,String> queryParameters, @Context HttpHeaders httpHeaders,
@Suspended AsyncResponse asyncResponse) {
try {
StreamingOutput output = execute(logicName, queryParameters, httpHeaders);
asyncResponse.resume(output);
} catch (Throwable t) {
asyncResponse.resume(t);
}
}
@Asynchronous
public void deleteAll() {
synchronized (bot) {
stop();
// Delete 10 bookings at a time
while(true) {
MultivaluedMap<String,String> params = new MultivaluedHashMap<>();
params.add("maxResults", Integer.toString(10));
List<Booking> bookings = bookingService.getAll(params);
for (Booking booking : bookings) {
bookingService.deleteBooking(booking.getId());
event.fire("Deleted booking " + booking.getId() + " for "
+ booking.getContactEmail() + "\n");
}
if(bookings.size() < 1) {
break;
}
}
}
}
@Asynchronous
public void deleteAll() {
synchronized (bot) {
stop();
// Delete 10 bookings at a time
while(true) {
MultivaluedMap<String,String> params = new MultivaluedHashMap<>();
params.add("maxResults", Integer.toString(10));
List<Booking> bookings = bookingService.getAll(params);
for (Booking booking : bookings) {
bookingService.deleteBooking(booking.getId());
event.fire("Deleted booking " + booking.getId() + " for "
+ booking.getContactEmail() + "\n");
}
if(bookings.size() < 1) {
break;
}
}
}
}
@Asynchronous
public void deleteAll() {
synchronized (bot) {
stop();
// Delete 10 bookings at a time
while(true) {
MultivaluedMap<String,String> params = new MultivaluedHashMap<>();
params.add("maxResults", Integer.toString(10));
List<Booking> bookings = bookingService.getAll(params);
for (Booking booking : bookings) {
bookingService.deleteBooking(booking.getId());
event.fire("Deleted booking " + booking.getId() + " for "
+ booking.getContactEmail() + "\n");
}
if(bookings.size() < 1) {
break;
}
}
}
}
@Asynchronous
@Override
public void sendWorkspaceDeletionNotification(Account admin, String workspaceId) {
LOGGER.info("Sending workspace deletion notification message \n\tfor the user which login is " + admin.getLogin());
Object[] args = {
workspaceId
};
try {
//User admin does not exist anymore as the workspace has been deleted
sendMessage(admin, "WorkspaceDeletion_title", "WorkspaceDeletion_text", args);
} catch (MessagingException pMEx) {
logMessagingException(pMEx);
}
}
@Asynchronous
@Override
public void sendWorkspaceIndexationSuccess(Account account, String workspaceId, String extraMessage) {
Object[] args = {
workspaceId,
extraMessage
};
try {
User adminUser = new User(new Workspace(workspaceId), account);
sendMessage(adminUser, "Indexer_success_title", "Indexer_success_text", args);
} catch (MessagingException pMEx) {
logMessagingException(pMEx);
}
}
@Asynchronous
@Override
public void sendWorkspaceIndexationFailure(Account account, String workspaceId, String extraMessage) {
Object[] args = {
workspaceId,
extraMessage
};
try {
User adminUser = new User(new Workspace(workspaceId), account);
sendMessage(adminUser, "Indexer_failure_title", "Indexer_failure_text", args);
} catch (MessagingException pMEx) {
logMessagingException(pMEx);
}
}
@Asynchronous
@Override
public void sendCredential(Account account) {
String accountDisabledMessage = "";
if (!account.isEnabled()) {
switch (platformOptionsManager.getWorkspaceCreationStrategy()) {
case ADMIN_VALIDATION:
accountDisabledMessage = getString("SignUp_AccountDisabled_text", account.getLocale());
break;
}
}
Object[] args = {
account.getLogin(),
configManager.getCodebase(),
accountDisabledMessage
};
try {
sendMessage(account, "SignUp_success_title", "SignUp_success_text", args);
} catch (MessagingException pMEx) {
logMessagingException(pMEx);
}
}
@Asynchronous // SOLUTION
//public Integer executeWorkItem(String workItem) { // INITIAL
public Future<Integer> executeWorkItem(String workItem) { // SOLUTION
int result = workItem.length();
System.out.println("Worker " + workerId + ": Start processing item '" + workItem + "'");
System.out.println("Worker " + workerId + ": " + Thread.currentThread().getName());
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Worker " + workerId + ": Item '" + workItem + "' done.");
return new AsyncResult<Integer>(result); // SOLUTION
// return result; // INITIAL
}
@Asynchronous
@Override
public Future<HealthDetails> dbStatus() {
HealthDetails details = new HealthDetails();
details.setDescription("Database connection");
details.start();
try {
logger.trace("Call the DB if it is online");
healthDao.dbCheck();
details.setTestStatus(Status.OK);
details.setResult("connected");
} catch (Exception e) {
details.setTestStatus(Status.CRIT);
details.setResult(e.getMessage());
}
details.stop();
return new AsyncResult<>(details);
}
@Override
@Asynchronous
public Future<Void> unsubscribeOldTopics(Installation installation) {
FCMTopicManager topicManager = new FCMTopicManager((AndroidVariant) installation.getVariant());
Set<String> oldCategories = topicManager.getSubscribedCategories(installation);
// Remove current categories from the set of old ones
oldCategories.removeAll(convertToNames(installation.getCategories()));
// Remove global variant topic because we don't want to unsubscribe it
oldCategories.remove(installation.getVariant().getVariantID());
for (String categoryName : oldCategories) {
topicManager.unsubscribe(installation, categoryName);
}
return new AsyncResult<>(null);
}
@Asynchronous
@Override
public Future<List<HealthDetails>> networkStatus() {
final List<HealthDetails> results = new ArrayList<>(PUSH_NETWORKS.size());
PUSH_NETWORKS.forEach(pushNetwork -> {
HealthDetails details = new HealthDetails();
details.start();
details.setDescription(pushNetwork.getName());
if (Ping.isReachable(pushNetwork.getHost(), pushNetwork.getPort())) {
details.setTestStatus(Status.OK);
details.setResult("online");
} else {
details.setResult(String.format("Network not reachable '%s'", pushNetwork.getName()));
details.setTestStatus(Status.WARN);
}
results.add(details);
details.stop();
});
return new AsyncResult<>(results);
}
@Asynchronous
public void executeTask(Runnable work, Object config) {
try {
userTransactions.set(ut);
if (work instanceof BatchWorkUnit) {
runningBatchWorkUnits.add((BatchWorkUnit) work);
}
work.run();
} finally {
if (work instanceof BatchWorkUnit) {
runningBatchWorkUnits.remove(work);
}
userTransactions.remove();
}
}
@Override
@Asynchronous
public Future<String> testB(final long callerThreadId) {
Assert.assertFalse("testB should be executed in asynchronous mode", Thread.currentThread().getId() == callerThreadId);
lastInvokeMethod = "testB";
return new AsyncResult<>("testB");
}
@Override
@Asynchronous
public Future<String> testB(final long callerThreadId) {
Assert.assertFalse("testB should be executed in asynchronous mode", Thread.currentThread().getId() == callerThreadId);
Assert.assertFalse(sessionContext.wasCancelCalled());
try {
Thread.sleep(3000L);
} catch (final InterruptedException e) {
//Ignore
}
Assert.assertTrue(sessionContext.wasCancelCalled());
lastInvokeMethod = "testB";
return new AsyncResult<>("echoB");
}
@Asynchronous
public void doSomeSlowStuff(User user){
try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException ex) {
System.err.println(ex.getMessage());
}
}
@Asynchronous
public void compute(){
try {
//simulate some computation by sleeping 2 seconds
Thread.sleep(2_000);
} catch (InterruptedException e) {
}
//just to check that this method is complete, change x
x = 42;
}
@Asynchronous
@Override
public void sendStateNotification(String workspaceId, Collection<User> pSubscribers,
DocumentRevision pDocumentRevision) {
LOGGER.info("Sending state notification emails \n\tfor the document " + pDocumentRevision.getLastIteration());
try {
for (User pSubscriber : pSubscribers) {
sendStateNotification(pSubscriber, pDocumentRevision);
}
} catch (MessagingException pMEx) {
logMessagingException(pMEx);
}
}
@Asynchronous
@Override
public void sendIterationNotification(String workspaceId, Collection<User> pSubscribers,
DocumentRevision pDocumentRevision) {
LOGGER.info("Sending iteration notification emails \n\tfor the document " + pDocumentRevision.getLastIteration());
try {
for (User pSubscriber : pSubscribers) {
sendIterationNotification(pSubscriber, pDocumentRevision);
}
} catch (MessagingException pMEx) {
logMessagingException(pMEx);
}
}
@Asynchronous
@Override
public void sendTaggedNotification(String workspaceId, Collection<User> pSubscribers, DocumentRevision pDocR, Tag pTag) {
LOGGER.info("Sending tagged notification emails \n\tfor the document " + pDocR.getLastIteration());
try {
for (User pSubscriber : pSubscribers) {
sendTaggedNotification(pSubscriber, pDocR, pTag);
}
} catch (MessagingException pMEx) {
logMessagingException(pMEx);
}
}
@Asynchronous
@Override
public void sendTaggedNotification(String workspaceId, Collection<User> pSubscribers, PartRevision pPartR, Tag pTag) {
LOGGER.info("Sending tagged notification emails \n\tfor the part " + pPartR.getLastIteration());
try {
for (User pSubscriber : pSubscribers) {
sendTaggedNotification(pSubscriber, pPartR, pTag);
}
} catch (MessagingException pMEx) {
logMessagingException(pMEx);
}
}
@Asynchronous
@Override
public void sendUntaggedNotification(String workspaceId, Collection<User> pSubscribers, DocumentRevision pDocR, Tag pTag) {
LOGGER.info("Sending untagged notification emails \n\tfor the document " + pDocR.getLastIteration());
try {
for (User pSubscriber : pSubscribers) {
sendUntaggedNotification(pSubscriber, pDocR, pTag);
}
} catch (MessagingException pMEx) {
logMessagingException(pMEx);
}
}
@Asynchronous
@Override
public void sendUntaggedNotification(String workspaceId, Collection<User> pSubscribers, PartRevision pPartR, Tag pTag) {
LOGGER.info("Sending untagged notification emails \n\tfor the part " + pPartR.getLastIteration());
try {
for (User pSubscriber : pSubscribers) {
sendUntaggedNotification(pSubscriber, pPartR, pTag);
}
} catch (MessagingException pMEx) {
logMessagingException(pMEx);
}
}
@Asynchronous
@Override
public void sendApproval(String workspaceId, Collection<Task> pRunningTasks,
DocumentRevision pDocumentRevision) {
LOGGER.info("Sending approval emails \n\tfor the document " + pDocumentRevision.getLastIteration());
try {
for (Task task : pRunningTasks) {
sendApproval(task, pDocumentRevision);
}
} catch (MessagingException pMEx) {
logMessagingException(pMEx);
}
}
@Asynchronous
@Override
public void sendApproval(String workspaceId, Collection<Task> pRunningTasks, PartRevision partRevision) {
LOGGER.info("Sending approval required emails \n\tfor the part " + partRevision.getLastIteration());
try {
for (Task task : pRunningTasks) {
sendApproval(task, partRevision);
}
} catch (MessagingException pMEx) {
logMessagingException(pMEx);
}
}
@Asynchronous
@Override
public void sendApproval(String workspaceId, Collection<Task> pRunningTasks, WorkspaceWorkflow workspaceWorkflow) {
LOGGER.info("Sending approval required emails \n\tfor the workspace workflow " + workspaceWorkflow.getId());
try {
for (Task task : pRunningTasks) {
sendApproval(task, workspaceWorkflow);
}
} catch (MessagingException pMEx) {
logMessagingException(pMEx);
}
}
@Asynchronous
@Override
public void sendDocumentRevisionWorkflowRelaunchedNotification(String workspaceId, DocumentRevision documentRevision) {
Workspace workspace = documentRevision.getDocumentMaster().getWorkspace();
Account admin = workspace.getAdmin();
User author = documentRevision.getAuthor();
User adminUser = new User(workspace, admin);
// Mail both workspace admin and documentMaster author
sendWorkflowRelaunchedNotification(adminUser, documentRevision);
if (!admin.getLogin().equals(author.getLogin())) {
sendWorkflowRelaunchedNotification(author, documentRevision);
}
}