Search in sources :

Example 1 with Schedule

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));
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Schedule(javax.ejb.Schedule)

Example 2 with Schedule

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();
        }
    }
}
Also used : InputStream(java.io.InputStream) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) FeedException(com.rometools.rome.io.FeedException) XmlReader(com.rometools.rome.io.XmlReader) IOException(java.io.IOException) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndFeedInput(com.rometools.rome.io.SyndFeedInput) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) Feed(fi.otavanopisto.muikku.plugins.feed.model.Feed) TransactionAttribute(javax.ejb.TransactionAttribute) Schedule(javax.ejb.Schedule)

Example 3 with Schedule

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;
            }
        }
    }
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) ArrayList(java.util.ArrayList) Schedule(javax.ejb.Schedule)

Example 4 with Schedule

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());
                }
            }
        }
    }
}
Also used : Instant(java.time.Instant) Schedule(javax.ejb.Schedule)

Example 5 with Schedule

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);
        }
    }
}
Also used : HiddenMonitor(eu.ggnet.saft.api.progress.HiddenMonitor) Schedule(javax.ejb.Schedule)

Aggregations

Schedule (javax.ejb.Schedule)9 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)3 TransactionAttribute (javax.ejb.TransactionAttribute)3 RestApiClient (fi.otavanopisto.muikku.openfire.rest.client.RestApiClient)2 AuthenticationToken (fi.otavanopisto.muikku.openfire.rest.client.entity.AuthenticationToken)2 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 SyndEntry (com.rometools.rome.feed.synd.SyndEntry)1 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)1 FeedException (com.rometools.rome.io.FeedException)1 SyndFeedInput (com.rometools.rome.io.SyndFeedInput)1 XmlReader (com.rometools.rome.io.XmlReader)1 HiddenMonitor (eu.ggnet.saft.api.progress.HiddenMonitor)1 MUCRoomEntity (fi.otavanopisto.muikku.openfire.rest.client.entity.MUCRoomEntity)1 UserEntity (fi.otavanopisto.muikku.openfire.rest.client.entity.UserEntity)1 Feed (fi.otavanopisto.muikku.plugins.feed.model.Feed)1 WorkspaceNode (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode)1 User (fi.otavanopisto.muikku.schooldata.entity.User)1 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)1