Package org.lilyproject.repository.model.api

Examples of org.lilyproject.repository.model.api.RepositoryModelEvent


            Set<RepositoryDefinition> repoDefs = repositoryModel.getRepositories(listener);

            // Perform an initial run over the repository definitions by generating fake events
            for (RepositoryDefinition repoDef : repoDefs) {
                eventWorker.putEvent(new RepositoryModelEvent(RepositoryModelEventType.REPOSITORY_UPDATED, repoDef.getName()));
            }

            log.info("Startup as repository master successful.");
            lilyInfo.setRepositoryMaster(true);
        }
View Full Code Here


        @Override
        public void run() {
            long startedAt = System.currentTimeMillis();

            while (!stop && !Thread.interrupted()) {
                RepositoryModelEvent event = null;
                try {
                    while (!stop && event == null) {
                        event = eventQueue.poll(1000, TimeUnit.MILLISECONDS);
                    }

                    if (stop || event == null || Thread.interrupted()) {
                        return;
                    }

                    // Warn if the queue is getting large, but do not do this just after we started, because
                    // on initial startup a fake update event is added for every defined index, which would lead
                    // to this message always being printed on startup when more than 10 indexes are defined.
                    int queueSize = eventQueue.size();
                    if (queueSize >= 10 && (System.currentTimeMillis() - startedAt > 5000)) {
                        log.warn("EventWorker queue getting large, size = " + queueSize);
                    }

                    try {
                        RepositoryDefinition repoDef = repositoryModel.getRepository(event.getRepositoryName());
                        if (repoDef.getLifecycleState() == RepositoryLifecycleState.CREATE_REQUESTED) {
                            for (RepositoryMasterHook hook : hooks) {
                                try {
                                    hook.postCreate(repoDef.getName());
                                } catch (InterruptedException e) {
                                    return;
                                } catch (Throwable t) {
                                    log.error("Failure executing a repository post-create hook for "
                                            + event.getRepositoryName(), t);
                                }
                            }
                            RepositoryDefinition updatedRepoDef = new RepositoryDefinition(repoDef.getName(),
                                    RepositoryLifecycleState.ACTIVE);
                            repositoryModel.updateRepository(updatedRepoDef);
                        } else if (repoDef.getLifecycleState() == RepositoryLifecycleState.DELETE_REQUESTED) {
                            for (RepositoryMasterHook hook : hooks) {
                                try {
                                    hook.preDelete(repoDef.getName());
                                } catch (InterruptedException e) {
                                    return;
                                } catch (Throwable t) {
                                    log.error("Failure executing a repository pre-delete hook for "
                                            + event.getRepositoryName(), t);
                                }
                            }
                            repositoryModel.deleteDirect(repoDef.getName());
                        }
                    } catch (RepositoryNotFoundException e) {
View Full Code Here

        TestListener listener = new TestListener();
        repositoryModel.registerListener(listener);

        repositoryModel.create("repo1");
        listener.waitForEvents(1);
        listener.verifyEvents(new RepositoryModelEvent(RepositoryModelEventType.REPOSITORY_ADDED, "repo1"));

        assertFalse(repositoryModel.repositoryExistsAndActive("repo1"));

        assertEquals(2, repositoryModel.getRepositories().size()); // 2 because the default repository is also there

        repositoryModel.updateRepository(new RepositoryDefinition("repo1", RepositoryDefinition.RepositoryLifecycleState.ACTIVE));
        listener.waitForEvents(1);
        listener.verifyEvents(new RepositoryModelEvent(RepositoryModelEventType.REPOSITORY_UPDATED, "repo1"));

        assertTrue(repositoryModel.repositoryExistsAndActive("repo1"));

        repositoryModel.delete("repo1");
        listener.waitForEvents(1);
        listener.verifyEvents(new RepositoryModelEvent(RepositoryModelEventType.REPOSITORY_UPDATED, "repo1"));

        assertEquals(2, repositoryModel.getRepositories().size());
        assertEquals(RepositoryDefinition.RepositoryLifecycleState.DELETE_REQUESTED, repositoryModel.getRepository("repo1").getLifecycleState());

        repositoryModel.deleteDirect("repo1");
        assertEquals(1, repositoryModel.getRepositories().size());
        listener.waitForEvents(1);
        listener.verifyEvents(new RepositoryModelEvent(RepositoryModelEventType.REPOSITORY_REMOVED, "repo1"));

        repositoryModel.unregisterListener(listener);
        repositoryModel.create("repo1");
        Thread.sleep(20); // this is not very robust, but if the code would be wrong this will fail most of the time
        listener.waitForEvents(0);
View Full Code Here

            Map<String, RepositoryDefinition> newRepos = loadRepositories(true);

            // Find out changes in repositories
            Set<String> removedRepos = Sets.difference(repos.keySet(), newRepos.keySet());
            for (String id : removedRepos) {
                events.add(new RepositoryModelEvent(RepositoryModelEventType.REPOSITORY_REMOVED, id));
            }

            Set<String> addedRepos = Sets.difference(newRepos.keySet(), repos.keySet());
            for (String id : addedRepos) {
                events.add(new RepositoryModelEvent(RepositoryModelEventType.REPOSITORY_ADDED, id));
            }

            for (RepositoryDefinition repoDef : newRepos.values()) {
                if (repos.containsKey(repoDef.getName()) && !repos.get(repoDef.getName()).equals(repoDef)) {
                    events.add(new RepositoryModelEvent(RepositoryModelEventType.REPOSITORY_UPDATED, repoDef.getName()));
                }
            }

            repos = newRepos;
        }
View Full Code Here

TOP

Related Classes of org.lilyproject.repository.model.api.RepositoryModelEvent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.