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 muikku by otavanopisto.
the class FeedSynchronizer method updateFeeds.
@Schedule(second = "0", minute = "0", hour = "*", persistent = false)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void updateFeeds() {
Client client = ClientBuilder.newClient();
feedItemDao.deleteAll();
List<Feed> feeds = feedDao.listAll();
for (Feed feed : feeds) {
WebTarget target = client.target(feed.getUrl());
try (InputStream stream = target.request("*").get(InputStream.class)) {
SyndFeedInput input = new SyndFeedInput();
SyndFeed syndFeed = input.build(new XmlReader(stream));
List<SyndEntry> entries = syndFeed.getEntries();
for (SyndEntry entry : entries) {
feedItemDao.create(entry.getTitle(), entry.getLink(), entry.getAuthor(), entry.getDescription() == null ? null : clean(entry.getDescription().getValue()), entry.getPublishedDate(), (String) null, feed);
}
} catch (IOException | IllegalArgumentException | FeedException e) {
logger.warning(String.format("Error while synchronizing feeds: %s", e.getMessage()));
ejbContext.setRollbackOnly();
}
}
}
use of javax.ejb.Schedule in project muikku by otavanopisto.
the class DeusNexServiceUpdater method findDocuments.
@Schedule(hour = "*", minute = "*/1", second = "0", persistent = false)
public void findDocuments() {
if (contextInitialized) {
if (!running) {
try {
running = true;
List<Document> documents = Arrays.asList(client.listDocuments());
Collections.sort(documents, new Comparator<Document>() {
@Override
public int compare(Document o1, Document o2) {
return o1.getPriority() - o2.getPriority();
}
});
List<Long> importNos = deusNexImportQueueController.getImportNos();
List<Long> newImports = new ArrayList<>();
for (Document document : documents) {
if (importNos != null && !importNos.contains(document.getId())) {
continue;
}
if (deusNexImportQueueController.isDownloaded(document.getId())) {
continue;
}
if (deusNexImportQueueController.isPendingDownload(document.getId())) {
continue;
}
if (document.getPath() == null) {
logger.log(Level.SEVERE, "Document " + document.getId() + " has no path");
}
String path = document.getPath();
int slashIndex = path.indexOf('/');
String dnmId = slashIndex > -1 ? path.substring(0, slashIndex) : path;
Long workspaceEntityId = deusNexMachinaController.getWorkspaceEntityIdDnmId(dnmId);
if (workspaceEntityId == null) {
logger.log(Level.WARNING, String.format("Postponing import because dnm id <> workspace entity id mapping for document %s could not be found", document.getPath()));
return;
} else {
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity != null) {
newImports.add(document.getId());
} else {
logger.log(Level.WARNING, String.format("Postponing import because workspace for document %s could not be found", document.getPath()));
return;
}
}
}
if (!newImports.isEmpty()) {
logger.info(String.format("Queued %d dnm imports", newImports.size()));
deusNexImportQueueController.addPendingDownloads(newImports);
}
deusNexImportQueueController.setLastUpdate(System.currentTimeMillis());
} finally {
running = false;
}
}
}
}
use of javax.ejb.Schedule in project muikku by otavanopisto.
the class ChatClientHolder method cleanUpClients.
@Schedule(second = "0", minute = "*/2", hour = "*", persistent = false)
public void cleanUpClients() {
synchronized (clients) {
Iterator<DatedClient> iterator = clients.iterator();
Instant threshold = Instant.now().minusSeconds(CLIENT_LIFETIME_SECONDS);
while (iterator.hasNext()) {
DatedClient client = iterator.next();
if (client.created.isBefore(threshold)) {
try {
client.client.close();
iterator.remove();
} catch (Exception e) {
logger.info("Error while closing XMPP connection: " + e.getMessage());
}
}
}
}
}
use of javax.ejb.Schedule in project dwoss by gg-net.
the class MonitorFactory method cleanUp.
@Schedule(second = "0", minute = "*/5", hour = "*", dayOfMonth = "*", month = "*", year = "*", info = "Cleanup of Montiors", persistent = false)
private void cleanUp() {
L.debug("cleanUp called by Timer @ {}", new Date());
for (Integer key : new HashSet<>(monitors.keySet())) {
if (monitors.get(key).isFinished()) {
HiddenMonitor m = monitors.remove(key);
L.info("Evicting finished Monitor {}", m);
lastProgress.remove(key);
} else if (monitors.get(key).isStale()) {
HiddenMonitor m = monitors.remove(key);
L.warn("Evicting stale Monitor {}", m);
lastProgress.remove(key);
}
}
}
Aggregations