Package javax.jcr.observation

Examples of javax.jcr.observation.ObservationManager


            throws RepositoryException {
        if (supportsObservation) {
            // register local event listener
            Collection<EventSubscription> subscr = sInfo.getSubscriptions();
            if (subscr.size() != 0) {
                ObservationManager obsMgr = sInfo.getSession().getWorkspace().getObservationManager();
                List<EventListener> listeners = new ArrayList<EventListener>(subscr.size());
                try {
                    for (EventSubscription s : subscr) {
                        EventListener listener = s.getLocalEventListener();
                        listeners.add(listener);
                        obsMgr.addEventListener(listener, EventSubscription.ALL_EVENTS,
                                "/", true, null, null, false);
                    }
                    return call.run();
                } finally {
                    for (EventListener listener : listeners) {
                        try {
                            obsMgr.removeEventListener(listener);
                        } catch (RepositoryException e) {
                            // ignore and remove next
                        }
                    }
                }
View Full Code Here


    @Test
    public void testObservationManager() throws RepositoryException {
        // just mage sure listener methods can be called, although they do
        // nothing
        ObservationManager observationManager = underTest.getObservationManager();
        observationManager.addEventListener(null, 0, null, false, null, null, false);
        observationManager.removeEventListener(null);
    }
View Full Code Here

    private JcrResourceListener jcrResourceListener;
    private EventIterator events;

    @Before
    public void setUp() throws RepositoryException, InvalidSyntaxException {
        ObservationManager observationManager = mock(ObservationManager.class);

        Workspace workspace = mock(Workspace.class);
        when(workspace.getObservationManager()).thenReturn(observationManager);

        Session session = mock(Session.class);
View Full Code Here

        private final Session s;
        private int jcrEventsCounter;

        public JcrEventsCounter() throws RepositoryException {
            s = repository.loginAdministrative(null);
            final ObservationManager om = s.getWorkspace().getObservationManager();
            final int eventTypes = 255; // not sure if that's a recommended value, but common
            final boolean deep = true;
            final String [] uuid = null;
            final String [] nodeTypeNames = new String [] { "mix:language", "sling:Message" };
            final boolean noLocal = true;
            final String root = "/";
            om.addEventListener(this, eventTypes, root, deep, uuid, nodeTypeNames, noLocal);
        }
View Full Code Here

        when(packaging.getPackageManager()).thenReturn(packageManager);

        ResourceResolver resourceResolver = mock(ResourceResolver.class);
        Session session = mock(Session.class);
        Workspace workspace = mock(Workspace.class);
        ObservationManager observationManager = mock(ObservationManager.class);
        when(workspace.getObservationManager()).thenReturn(observationManager);
        when(session.getWorkspace()).thenReturn(workspace);
        when(resourceResolver.adaptTo(Session.class)).thenReturn(session);

        ReplicationEventFactory eventFactory = mock(ReplicationEventFactory.class);
View Full Code Here

                packaging, eventFactory);

        ResourceResolver resourceResolver = mock(ResourceResolver.class);
        Session session = mock(Session.class);
        Workspace workspace = mock(Workspace.class);
        ObservationManager observationManager = mock(ObservationManager.class);
        when(workspace.getObservationManager()).thenReturn(observationManager);
        when(session.getWorkspace()).thenReturn(workspace);
        when(resourceResolver.adaptTo(Session.class)).thenReturn(session);
        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
        when(replicationPackage.getId()).thenReturn(tempFile.getAbsolutePath());
View Full Code Here

                packaging, eventFactory, ImportMode.MERGE.name(), AccessControlHandling.MERGE.name());

        ResourceResolver resourceResolver = mock(ResourceResolver.class);
        Session session = mock(Session.class);
        Workspace workspace = mock(Workspace.class);
        ObservationManager observationManager = mock(ObservationManager.class);
        when(workspace.getObservationManager()).thenReturn(observationManager);
        when(session.getWorkspace()).thenReturn(workspace);
        when(resourceResolver.adaptTo(Session.class)).thenReturn(session);
        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
        when(replicationPackage.getId()).thenReturn(tempFile.getAbsolutePath());
View Full Code Here

                    } else {
                        resolver = fac.getResourceResolver(repoCredentials);
                    }

                    final Session s = resolver.adaptTo(Session.class);
                    ObservationManager om = s.getWorkspace().getObservationManager();
                    om.addEventListener(messageChangeHandler, 255, "/", true, null,
                        new String[] { "sling:Message" }, true);
                    om.addEventListener(languageChangeHandler, 255, "/", true, null,
                        new String[] { "mix:language" }, true);

                    resourceResolver = resolver;

                } catch (RepositoryException re) {
View Full Code Here

            Session s = resolver.adaptTo(Session.class);
            if (s != null) {

                try {
                    ObservationManager om = s.getWorkspace().getObservationManager();
                    om.removeEventListener(messageChangeHandler);
                    om.removeEventListener(languageChangeHandler);
                } catch (Throwable t) {
                    log.info(
                        "releaseRepository: Problem unregistering as event listener",
                        t);
                }
View Full Code Here

     
        //use a davex session to verify the correct JCR events are delivered
        Repository repository = JcrUtils.getRepository(HttpTest.HTTP_BASE_URL + "/server/");
        Session jcrSession = null;
        TestEventListener listener = new TestEventListener();
        ObservationManager observationManager = null;
        try {
            jcrSession = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
            observationManager = jcrSession.getWorkspace().getObservationManager();
          String testNodePath = testNodeUrl.substring(HttpTest.HTTP_BASE_URL.length());
            observationManager.addEventListener(listener,
          Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED, //event types
          testNodePath, //absPath
          true, //isDeep
          null, //uuid
          null, //nodeTypeName
          false); //noLocal
       
            //5. Attempt to update properties of node (OK)
            // curl -FpropOne=propOneValueChanged -FpropTwo=propTwoValueChanged1 -FpropTwo=propTwoValueChanged2 http://myuser:password@localhost:8080/test/node
          H.assertAuthenticatedPostStatus(testUserCreds, testNodeUrl, HttpServletResponse.SC_OK, postParams, expectedMessage);
         
          //verify the change happened
            String afterUpdateContent = H.getContent(testNodeUrl + ".json", HttpTest.CONTENT_TYPE_JSON);
            JSONObject afterUpdateJson = new JSONObject(afterUpdateContent);
            Object afterUpdatePropOneObj = afterUpdateJson.opt("propOne");
            assertTrue(afterUpdatePropOneObj instanceof JSONArray);
            assertEquals(1, ((JSONArray)afterUpdatePropOneObj).length());
            assertEquals("propOneValueChanged", ((JSONArray)afterUpdatePropOneObj).get(0));
         
            Object afterUpdatePropTwoObj = afterUpdateJson.opt("propTwo");
            assertTrue(afterUpdatePropTwoObj instanceof JSONArray);
            assertEquals(2, ((JSONArray)afterUpdatePropTwoObj).length());
            assertEquals("propTwoValueChanged1", ((JSONArray)afterUpdatePropTwoObj).get(0));
            assertEquals("propTwoValueChanged2", ((JSONArray)afterUpdatePropTwoObj).get(1));
           
          //wait for the expected JCR events to be delivered
      for (int second = 0; second < 15; second++) {
        if (listener.getEventBundlesProcessed() > 0) {
          break;
        }
        Thread.sleep(1000);
      }
     
      assertEquals("One property added event was expected: " + listener.toString(),
          1, listener.addedProperties.size());
      assertEquals(testNodePath + "/propTwo", listener.addedProperties.get(0));
      assertEquals("One property removed event was expected: " + listener.toString(),
          1, listener.removedProperties.size());
      assertEquals(testNodePath + "/propTwo", listener.removedProperties.get(0));
      assertEquals("One property changed event was expected: " + listener.toString(),
          1, listener.changedProperties.size());
      assertEquals(testNodePath + "/propOne", listener.changedProperties.get(0));
        } finally {
          //cleanup
          if (observationManager != null) {
              observationManager.removeEventListener(listener);
          }
            jcrSession.logout();
            repository = null;
        }
    }
View Full Code Here

TOP

Related Classes of javax.jcr.observation.ObservationManager

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.