use of javax.ejb.Schedule in project quickstart by wildfly.
the class ScheduleExample method doWork.
@Schedule(second = "*/6", minute = "*", hour = "*", persistent = false)
public void doWork() {
Date currentTime = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd G 'at' HH:mm:ss z");
System.out.println("ScheduleExample.doWork() invoked at " + simpleDateFormat.format(currentTime));
}
use of javax.ejb.Schedule in project Payara by payara.
the class SchedulesHandler method processAnnotation.
protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
Schedules annotation = (Schedules) ainfo.getAnnotation();
Schedule[] schAnnotations = annotation.value();
List<HandlerProcessingResult> results = new ArrayList<HandlerProcessingResult>();
for (Schedule sch : schAnnotations) {
results.add(processSchedule(sch, ainfo, ejbContexts));
}
return getOverallProcessingResult(results);
}
use of javax.ejb.Schedule in project ART-TIME by Artezio.
the class NotificationScheduler method notifyAboutIncorrectTimesheet.
@Schedule(dayOfMonth = "1", persistent = false, info = NOTIFY_ABOUT_INCORRECT_TIMESHEET_INFO)
public void notifyAboutIncorrectTimesheet() {
if (settingsService.getSettings().isIncorrectTimesheetNotificationEnabled()) {
List<Employee> employees = employeeService.getCurrent();
Period period = getPeriodForPreviousMonth();
notificationManager.notifyAboutIncorrectTimesheet(employees, period);
}
}
use of javax.ejb.Schedule in project muikku by otavanopisto.
the class DeusNexServiceDownloadUpdater method downloadNext.
@Schedule(hour = "*", minute = "*", second = "*/20", persistent = false)
public void downloadNext() {
if (contextInitialized) {
if (!running) {
running = true;
try {
Long pendingDownload = deusNexImportQueueController.getNextPendingDownload();
if (pendingDownload != null) {
logger.info(String.format("Processing dnm document #%d", pendingDownload));
try {
Document document = client.getDocument(pendingDownload);
if (document != null) {
logger.info(String.format("Downloading dnm document #%d (%s)", document.getId(), document.getPath()));
String documentData = client.getDocumentData(pendingDownload);
if (documentData != null) {
String path = document.getPath();
int slashIndex = path.indexOf('/');
String workspacePath = slashIndex > -1 ? path.substring(slashIndex + 1) : null;
String dnmId = slashIndex > -1 ? path.substring(0, slashIndex) : path;
Long workspaceEntityId = deusNexMachinaController.getWorkspaceEntityIdDnmId(dnmId);
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity != null) {
if ("[_FPF_]".equals(workspacePath)) {
logger.info(String.format("Importing front-page document #%d into workspace %s", document.getId(), workspaceEntity.getUrlName()));
InputStream documentStream = new ByteArrayInputStream(documentData.getBytes("UTF-8"));
try {
deusNexMachinaController.importFrontPageDocument(workspaceEntity, documentStream);
} finally {
documentStream.close();
}
} else if ("[_HELP_PAGE_]".equals(workspacePath)) {
logger.info(String.format("Importing help-page document #%d into workspace %s", document.getId(), workspaceEntity.getUrlName()));
InputStream documentStream = new ByteArrayInputStream(documentData.getBytes("UTF-8"));
try {
deusNexMachinaController.importHelpPageDocument(workspaceEntity, documentStream);
} finally {
documentStream.close();
}
} else {
WorkspaceNode parentNode = null;
if (StringUtils.isBlank(workspacePath)) {
parentNode = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
} else {
String[] pathElements = workspacePath.split("/");
parentNode = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
WorkspaceNode parent = parentNode;
for (int i = 0, l = pathElements.length; i < l; i++) {
String pathElement = pathElements[i];
parentNode = workspaceMaterialController.findWorkspaceNodeByParentAndUrlName(parent, pathElement);
if (parentNode == null) {
parentNode = workspaceMaterialController.createWorkspaceFolder(parent, pathElement, pathElement);
}
parent = parentNode;
}
}
logger.info(String.format("Importing dnm document #%d into workspace %s", document.getId(), workspaceEntity.getUrlName()));
InputStream documentStream = new ByteArrayInputStream(documentData.getBytes("UTF-8"));
try {
deusNexMachinaController.importDeusNexDocument(parentNode, documentStream);
} finally {
documentStream.close();
}
}
deusNexImportQueueController.removePendingDownload(pendingDownload);
deusNexImportQueueController.addDownloaded(document.getId());
logger.info(String.format("Processed dnm document #%d (%s)", document.getId(), document.getPath()));
} else {
logger.log(Level.WARNING, String.format("Ignoring import for document %s because maching workspace could not be found", document.getPath()));
}
} else {
logger.severe(String.format("Pending dnm document %d did not contain any data", pendingDownload));
}
} else {
logger.severe(String.format("Pending dnm document %d could not be found", pendingDownload));
}
} catch (Exception e) {
logger.warning(String.format("Dnm document %d processing failed, added it back to queue: " + e.getMessage(), pendingDownload));
}
}
} finally {
running = false;
}
}
}
}
use of javax.ejb.Schedule in project muikku by otavanopisto.
the class ChatRoomSyncScheduler method updateChatRooms.
@Schedule(second = "*", minute = "*/15", hour = "*", persistent = false)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void updateChatRooms() {
String enabledWorkspacesCsv = pluginSettingsController.getPluginSetting("chat", "enabledWorkspaces");
if (enabledWorkspacesCsv == null) {
return;
}
List<String> enabledWorkspaces = Arrays.asList(enabledWorkspacesCsv.split(","));
String openfireToken = pluginSettingsController.getPluginSetting("chat", "openfireToken");
if (openfireToken == null) {
logger.log(Level.INFO, "No openfire token set, skipping room sync");
return;
}
String openfireUrl = pluginSettingsController.getPluginSetting("chat", "openfireUrl");
if (openfireUrl == null) {
logger.log(Level.INFO, "No openfire url set, skipping room sync");
return;
}
String openfirePort = pluginSettingsController.getPluginSetting("chat", "openfirePort");
if (openfirePort == null) {
logger.log(Level.INFO, "No openfire port set, skipping room sync");
return;
}
if (!StringUtils.isNumeric(openfirePort)) {
logger.log(Level.WARNING, "Invalid openfire port, skipping room sync");
return;
}
AuthenticationToken token = new AuthenticationToken(openfireToken);
RestApiClient client = new RestApiClient(openfireUrl, Integer.parseInt(openfirePort, 10), token);
for (String enabledWorkspace : enabledWorkspaces) {
try {
// Checking before creating is subject to a race condition, but in the worst case
// the creation just fails, resulting in a log entry
MUCRoomEntity chatRoomEntity = client.getChatRoom(enabledWorkspace);
if (chatRoomEntity == null) {
logger.log(Level.INFO, "Syncing chat workspace " + enabledWorkspace);
SchoolDataIdentifier identifier = SchoolDataIdentifier.fromId(enabledWorkspace);
if (identifier == null) {
logger.log(Level.WARNING, "Invalid workspace identifier " + enabledWorkspace + ", skipping...");
continue;
}
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceByUrlName(enabledWorkspace);
if (workspaceEntity == null) {
logger.log(Level.WARNING, "No workspace entity found for identifier " + enabledWorkspace + ", skipping...");
continue;
}
Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
chatRoomEntity = new MUCRoomEntity(enabledWorkspace, workspace.getName(), workspace.getDescription());
client.createChatRoom(chatRoomEntity);
}
} catch (Exception e) {
logger.log(Level.INFO, "Exception when syncing chat workspace " + enabledWorkspace, e);
}
}
}
Aggregations