Examples of Barrier


Examples of org.apache.sling.event.impl.Barrier

     * The job is rescheduled two times before it fails.
     */
    @Test(timeout = DEFAULT_TEST_TIMEOUT)
    public void testStartJobAndReschedule() throws Exception {
        final List<Integer> retryCountList = new ArrayList<Integer>();
        final Barrier cb = new Barrier(2);
        final ServiceRegistration jcReg = this.registerJobConsumer(TOPIC,
                new JobConsumer() {
                    int retryCount;

                    @Override
                    public JobResult process(Job job) {
                        int retry = 0;
                        if ( job.getProperty(Job.PROPERTY_JOB_RETRY_COUNT) != null ) {
                            retry = (Integer)job.getProperty(Job.PROPERTY_JOB_RETRY_COUNT);
                        }
                        if ( retry == retryCount ) {
                            retryCountList.add(retry);
                        }
                        retryCount++;
                        cb.block();
                        return JobResult.FAILED;
                    }
                });
        try {
            final JobManager jobManager = this.getJobManager();
            final Job job = jobManager.addJob(TOPIC, null);

            assertTrue("No event received in the given time.", cb.block(5));
            cb.reset();
            // the job is retried after two seconds, so we wait again
            assertTrue("No event received in the given time.", cb.block(5));
            cb.reset();
            // the job is retried after two seconds, so we wait again
            assertTrue("No event received in the given time.", cb.block(5));
            // we have reached the retry so we expect to not get an event
            cb.reset();
            assertFalse("Unexpected event received in the given time.", cb.block(5));
            assertEquals("Unexpected number of retries", 3, retryCountList.size());

            jobManager.removeJobById(job.getId());
        } finally {
            jcReg.unregister();
View Full Code Here

Examples of org.apache.sling.event.impl.Barrier

    @Test(timeout = DEFAULT_TEST_TIMEOUT)
    public void testOrderedQueue() throws Exception {
        final JobManager jobManager = this.getJobManager();

        // register consumer and event handler
        final Barrier cb = new Barrier(2);
        final AtomicInteger count = new AtomicInteger(0);
        final AtomicInteger parallelCount = new AtomicInteger(0);
        final ServiceRegistration jcReg = this.registerJobConsumer("sling/orderedtest/*",
                new JobConsumer() {

                    private volatile int lastCounter = -1;

                    @Override
                    public JobResult process(final Job job) {
                        final int counter = job.getProperty("counter", -10);
                        assertNotEquals("Counter property is missing", -10, counter);
                        assertTrue("Counter should only increment by max of 1 " + counter + " - " + lastCounter,
                                counter == lastCounter || counter == lastCounter +1);
                        lastCounter = counter;
                        if ("sling/orderedtest/start".equals(job.getTopic()) ) {
                            cb.block();
                            return JobResult.OK;
                        }
                        if ( parallelCount.incrementAndGet() > 1 ) {
                            parallelCount.decrementAndGet();
                            return JobResult.FAILED;
                        }
                        final String topic = job.getTopic();
                        if ( topic.endsWith("sub1") ) {
                            final int i = (Integer)job.getProperty(Job.PROPERTY_JOB_RETRY_COUNT);
                            if ( i == 0 ) {
                                parallelCount.decrementAndGet();
                                return JobResult.FAILED;
                            }
                        }
                        try {
                            Thread.sleep(30);
                        } catch (InterruptedException ie) {
                            // ignore
                        }
                        parallelCount.decrementAndGet();
                        return JobResult.OK;
                    }
                });
        final ServiceRegistration ehReg = this.registerEventHandler(NotificationConstants.TOPIC_JOB_FINISHED,
                new EventHandler() {

                    @Override
                    public void handleEvent(final Event event) {
                        count.incrementAndGet();
                    }
                });

        try {
            // we first sent one event to get the queue started
            final Map<String, Object> properties = new HashMap<String, Object>();
            properties.put("counter", -1);
            jobManager.addJob("sling/orderedtest/start", properties);
            assertTrue("No event received in the given time.", cb.block(5));
            cb.reset();

            // get the queue
            final Queue q = jobManager.getQueue("orderedtest");
            assertNotNull("Queue 'orderedtest' should exist!", q);

View Full Code Here

Examples of org.apache.sling.event.impl.Barrier

    @Test(timeout = DEFAULT_TEST_TIMEOUT)
    public void testRoundRobinQueue() throws Exception {
        final JobManager jobManager = this.getJobManager();

        final Barrier cb = new Barrier(2);

        final ServiceRegistration jc1Reg = this.registerJobConsumer(TOPIC + "/start",
                new JobConsumer() {

                    @Override
                    public JobResult process(final Job job) {
                        cb.block();
                        return JobResult.OK;
                    }
                });

        // register new consumer and event handle
        final AtomicInteger count = new AtomicInteger(0);
        final AtomicInteger parallelCount = new AtomicInteger(0);
        final ServiceRegistration jcReg = this.registerJobConsumer(TOPIC + "/*",
                new JobConsumer() {

                    @Override
                    public JobResult process(final Job job) {
                        if ( parallelCount.incrementAndGet() > MAX_PAR ) {
                            parallelCount.decrementAndGet();
                            return JobResult.FAILED;
                        }
                        sleep(30);
                        parallelCount.decrementAndGet();
                        return JobResult.OK;
                    }
                });
        final ServiceRegistration ehReg = this.registerEventHandler(NotificationConstants.TOPIC_JOB_FINISHED,
                new EventHandler() {

                    @Override
                    public void handleEvent(final Event event) {
                        count.incrementAndGet();
                    }
                });

        try {
            // we first sent one event to get the queue started
            jobManager.addJob(TOPIC + "/start", null);
            assertTrue("No event received in the given time.", cb.block(5));
            cb.reset();

            // get the queue
            final Queue q = jobManager.getQueue(QUEUE_NAME);
            assertNotNull("Queue '" + QUEUE_NAME + "' should exist!", q);

View Full Code Here

Examples of org.goldenorb.zookeeper.Barrier

   * @param String
   *          barrierName
   */
  private void enterBarrier(String barrierName) {
    LOG.debug("p{} creating barrier {}", getPartitionID(), barrierName);
    Barrier barrier = null;
    synchronized (leaderGroupMembers) {
      LOG.debug("{} will wait for {} partitions", barrierName, leaderGroupMembers.size());
      barrier = new OrbFastBarrier(getOrbConf(), jobInProgressPath + "/" + barrierName,
          leaderGroupMembers.size(), Integer.toString(getPartitionID()), zk);
    }
    try {
      barrier.enter();
      LOG.debug("p{} entered {}", getPartitionID(), barrierName);
    } catch (OrbZKFailure e) {
      LOG.error("p{} failed to complete barrier {}: " + e.getMessage(), getPartitionID(), barrierName);
      e.printStackTrace();
    }
View Full Code Here

Examples of org.jboss.switchboard.spi.Barrier

      // EJBTHREE-1335: container name in meta data
      generateContainerName(container, beanMD);
     
      // setup switchboard
      Barrier switchBoard = this.getSwitchBoardBarrier(container);
      // the container cannot function without an SwitchBoard Barrier
      if (switchBoard == null)
      {
         throw new RuntimeException("No SwitchBoard Barrier found for bean: " + container.getEjbName() + " in unit: "
               + this.jbossUnit + " (or its component deployment unit)");
      }
      // add dependency on START (and not INSTALLED) state of Switchboard, since the container only requires a fully populated ENC context,
      // but doesn't require a invokable context. An invokable context is only needed by Injector.
      dependsPolicy.addDependency(this.createSwitchBoardDependency(ejbContainer, switchBoard));
      log.debug("Added dependency on Switchboard " + switchBoard.getId() + " for EJB container " + ejbContainer.getName());
     
     
      // create and setup Injector(s) for InjectionManager 
      InjectionManager injectionManager = this.getInjectionManager(container);
      // the container cannot function without an InjectionManager
View Full Code Here

Examples of org.jboss.switchboard.spi.Barrier

               dependencies.add(sdmd);
            }
         }
        
         // SwitchBoard
         Barrier switchBoard = unit.getAttachment(Barrier.class);
         if (switchBoard != null)
         {
            // Setup switchboard dependency on the deployment
            ServiceDependencyMetaData switchBoardDependency = new AnyStateServiceDependencyMetaData(switchBoard.getId(), ControllerState.START, ControllerState.INSTALLED);
            dependencies.add(switchBoardDependency);
            log.debug("Added switchboard dependency: " + switchBoard.getId() + " for web module: " + name);
         }
         // Injection Manager
         InjectionManager injectionManager = unit.getAttachment(InjectionManager.class);
         if (injectionManager != null)
         {
View Full Code Here

Examples of org.jboss.switchboard.spi.Barrier

      containerBMDBuilder.setConstructorValue(container);

      DependencyPolicy containerDependencyPolicy = container.getDependencyPolicy();

      // Add dependency on switchboard
      Barrier switchBoard = unit.getAttachment(Barrier.class);
      // the container cannot function without an SwitchBoard Barrier
      if (switchBoard == null)
      {
         throw new RuntimeException("No SwitchBoard Barrier found for bean: " + container.getEjbName() + " in unit: " + unit);
      }
      // add dependency on START (and not INSTALLED) state of Switchboard, since the container only requires a fully populated ENC context,
      // but doesn't require a invokable context. An invokable context is only needed by Injector.
      containerBMDBuilder.addDemand(switchBoard.getId(), ControllerState.CREATE, ControllerState.START, null);
      logger.debug("Added dependency on switchboard " + switchBoard.getId() + " for container " + container.getName());
     
      InjectionManager injectionManager = unit.getAttachment(InjectionManager.class);
      // the container cannot function without an InjectionManager
      if (injectionManager == null)
      {
View Full Code Here

Examples of org.jboss.switchboard.spi.Barrier

      // Add dependency on container
      String containerName = container.getMetaData().getContainerName();
      builder.addDependency(containerName);
     
      // Add dependency on switchboard
      Barrier switchBoard = unit.getAttachment(Barrier.class);
      // the container cannot function without an SwitchBoard Barrier
      if (switchBoard == null)
      {
         throw new RuntimeException("No SwitchBoard Barrier in unit: " + unit);
      }
      // add dependency on INSTALLED state (i.e. fully populated and invokable ENC) SwitchBoard
      builder.addDemand(switchBoard.getId(), ControllerState.CREATE, ControllerState.INSTALLED, null);

      // EJBTHREE-2227 https://issues.jboss.org/browse/EJBTHREE-2227 add dependency on INSTALLED state
      // (i.e. fully populated and invokable ENC) of ALL other Barriers in the DU hierarchy to avoid instantiating
      // the @Startup @Singleton too early
      final Set<String> barriers = this.getBarrierIdsFromAllDeploymentUnitsInHierarchy(unit);
View Full Code Here

Examples of org.jgroups.protocols.BARRIER

    stack.addProtocols(new UDP().setValue("bind_addr", InetAddress.getByName(BIND_ADDR)))
        .addProtocol(new PING())
        .addProtocol(new MERGE2())
        .addProtocol(new FD_SOCK())
        .addProtocol(new FD_ALL().setValue("timeout", 12000).setValue("interval", 3000))
        .addProtocol(new VERIFY_SUSPECT()).addProtocol(new BARRIER())
        .addProtocol(new NAKACK()).addProtocol(new UNICAST2())
        .addProtocol(new STABLE()).addProtocol(new GMS())
        .addProtocol(new UFC()).addProtocol(new MFC())
        .addProtocol(new FRAG2());
    stack.init();
View Full Code Here

Examples of org.jgroups.protocols.BARRIER

    stack.addProtocols(new UDP().setValue("bind_addr", InetAddress.getByName("192.168.1.108")))
        .addProtocol(new PING())
        .addProtocol(new MERGE2())
        .addProtocol(new FD_SOCK())
        .addProtocol(new FD_ALL().setValue("timeout", 12000).setValue("interval", 3000))
        .addProtocol(new VERIFY_SUSPECT()).addProtocol(new BARRIER())
        .addProtocol(new NAKACK()).addProtocol(new UNICAST2())
        .addProtocol(new STABLE()).addProtocol(new GMS())
        .addProtocol(new UFC()).addProtocol(new MFC())
        .addProtocol(new FRAG2());
    stack.init();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.