Package net.jini.core.event

Examples of net.jini.core.event.EventRegistration


  lrm.renewFor(prepareLease(set.getRenewalSetLease()), Lease.FOREVER, null);

  // register a listener to receive renewal failure events
  logger.log(Level.FINE, "Registering listener to receive " +
        "RenewalFailureEvents.");
  EventRegistration reg = set.setRenewalFailureListener(rrl, null);
  reg = prepareRegistration(reg);

  // validate the registration (just for grins)
  if (rstUtil.isValidRenewFailEventReg(reg, set) == false) {
      String message = "Registration is invalid because:\n" +
View Full Code Here


        final Listener listener2 = new Listener(c, false);
        final JavaSpace space = (JavaSpace) services[0];
        final Entry aEntry = new UninterestingEntry();

        // Register ill-behaved handler  and write matching entry
        EventRegistration reg = space.notify(aEntry, null, listener1,
                                             Lease.ANY, null);
  reg = (EventRegistration)
              getConfig().prepare("test.outriggerEventRegistrationPreparer",
                                  reg);
        logger.log(Level.INFO, "Registered first event handler");
        Lease lease1 = reg.getLease();
        lease1 = (Lease)
                 getConfig().prepare("test.outriggerLeasePreparer", lease1);
        /*
         * The sequence number the first event should have, this would
         * be dicey in a real application but the QA tests assume a
         * very controled enviroment
         */
        final long ev1 = reg.getSequenceNumber() + 1;
        addOutriggerLease(lease1, true);
        addOutriggerLease(space.write(aEntry, null, Lease.ANY), false);
        logger.log(Level.INFO, "Wrote first Entry");

        /*
         * Wait for event and check to see if it is the right one and
         * that the lease was canceled
         */
        long listener1Rcvd;
        synchronized (listener1) {

            // Did it already happen?
            listener1Rcvd = listener1.lastEvent();

            if (listener1Rcvd < ev1) {

                // No, wait
                listener1.wait(wait);
                listener1Rcvd = listener1.lastEvent();

                if (listener1Rcvd < 0) {
                    throw new TestException(
                            "First listener never received event");
                } else if (ev1 < listener1Rcvd) {
                    throw new TestException(
                            "First listener received too many events");
                }
                logger.log(Level.INFO, "Received correct event");
            }
        }

        // Give the cancel a chance to happen
        Thread.sleep(10000);

        try {
            lease1.cancel();
            throw new TestException(
                    "Lease on first registion not cancled by"
                    + " Runtime exception");
        } catch (UnknownLeaseException e) {

            // Result we are looking for
        }
        logger.log(Level.INFO, "Lease on first registration is gone");

        // Register second handler and write second entry2
        EventRegistration reg2 = space.notify(aEntry, null, listener2,
                Lease.ANY, null);
  reg2 = (EventRegistration)
               getConfig().prepare("test.outriggerEventRegistrationPreparer",
                                   reg2);
        logger.log(Level.INFO, "Registered 2nd handler");
        Lease lease2 = reg2.getLease();
        lease2 = (Lease)
                 getConfig().prepare("test.outriggerLeasePreparer", lease2);
        addOutriggerLease(lease2, false);

        /*
         * The sequence number the first event should have, this would
         * be dicey in a real application but the QA tests assume a
         * very controled enviroment
         */
        final long ev2 = reg2.getSequenceNumber() + 1;
        addOutriggerLease(space.write(aEntry, null, Lease.ANY), false);
        logger.log(Level.INFO, "Wrote 2nd Entry");

        // Wait for event and check to see if it is the right one
        synchronized (listener2) {
View Full Code Here

  set = prepareSet(set);
  logger.log(Level.FINE, "Created Set with lease duration of " +
        "Lease.FOREVER.");

  // register listener to receive events
  EventRegistration evReg = set.setRenewalFailureListener(rrl, null);
  evReg = prepareRegistration(evReg);

  // check event registration (not formally part of this test)
  if (rstUtil.isValidRenewFailEventReg(evReg, set) == false) {
      String message = "Registration is invalid because:\n" +
View Full Code Here

      concurrentObj.waiterNotify(leaseExpireThreadSyncObj);
  }
        FiddlerLease regLease =
                   FiddlerLease.createLease
                           (innerProxy, proxyID, regID, leaseID, expiration);
        EventRegistration eventReg = new EventRegistration( regInfo.eventID,
                                                            outerProxy,
                                                            regLease,
                                                            regInfo.seqNum );
        logInfoGroups();
        logInfoLocators();
View Full Code Here

     * <P>Notes:<BR>For more information see the JavaSpaces specification
     * section 2.7.</P>
     */
    public void run() throws Exception {
        NotifyCounter[] ncs = new NotifyCounter[12];
        EventRegistration er;
        long[] leaseMatrix = new long[] {
            -199, -5000, -13999, Long.MIN_VALUE, -2, Long.MIN_VALUE, -345,
            -8999, -15000, -16000000, Long.MIN_VALUE, -3 };
        SimpleEntry sampleEntry1 = new SimpleEntry("TestEntry #1", 1);
        SimpleEntry sampleEntry2 = new SimpleEntry("TestEntry #2", 2);
        SimpleEntry sampleEntry3 = new SimpleEntry("TestEntry #1", 2);
        SimpleEntry template;
        Transaction txn;

        // first check that space is empty
        if (!checkSpace(space)) {
            throw new TestException("Space is not empty in the beginning.");
        }

        // create the non null transaction
        txn = getTransaction();

        // init 3 RemoteEvent counters for each of sample entries
        ncs[0] = new NotifyCounter(sampleEntry1, leaseMatrix[0]);
        ncs[1] = new NotifyCounter(sampleEntry2, leaseMatrix[1]);
        ncs[2] = new NotifyCounter(sampleEntry3, leaseMatrix[2]);

        // init 5 counters with wrong templates
        template = new SimpleEntry("TestEntry #3", 1);
        ncs[3] = new NotifyCounter(template, leaseMatrix[3]);

        // 2-nd wrong template
        template = new SimpleEntry("TestEntry #1", 3);
        ncs[4] = new NotifyCounter(template, leaseMatrix[4]);

        // 3-rd wrong template
        template = new SimpleEntry("TestEntry #3", 3);
        ncs[5] = new NotifyCounter(template, leaseMatrix[5]);

        // 4-th wrong template
        template = new SimpleEntry(null, 3);
        ncs[6] = new NotifyCounter(template, leaseMatrix[6]);

        // 5-th wrong template
        template = new SimpleEntry("TestEntry #3", null);
        ncs[7] = new NotifyCounter(template, leaseMatrix[7]);

        // init counter with null entry as a template
        ncs[8] = new NotifyCounter(null, leaseMatrix[8]);

        // init 3 counters with null values for different fields
        template = new SimpleEntry("TestEntry #1", null);
        ncs[9] = new NotifyCounter(template, leaseMatrix[9]);

        // 2-nd template
        template = new SimpleEntry(null, 2);
        ncs[10] = new NotifyCounter(template, leaseMatrix[10]);

        // 3-rd template
        template = new SimpleEntry(null, null);
        ncs[11] = new NotifyCounter(template, leaseMatrix[11]);

        // try to register them
        for (int i = 0; i < 12; i++) {
            try {
                er = space.notify(ncs[i].getTemplate(), txn, ncs[i],
                        ncs[i].getLeaseTime(), null);
                throw new TestException(" Notify operation for "
                        + ncs[i]
                        + " has not thrown IllegalArgumentException"
                        + " and returned " + er.toString());
            } catch (IllegalArgumentException iae) {
                logDebugText("IllegalArgumentException has been catched"
                        + " while trying to register " + ncs[i]
                        + " as expected.");
            }
View Full Code Here

             new StorableObject[]{tmpl});

      templates.add(reg, tmpl);
  }

  return new EventRegistration(eventID, spaceProxy,
      leaseFactory.newLease(cookie, reg.getExpiration()),
      0);
    }
View Full Code Here

      for (int i=0; i<tmpls.length; i++) {
    templates.add(reg, tmpls[i]);
      }
  }

  return new EventRegistration(eventID, spaceProxy,
      leaseFactory.newLease(cookie, reg.getExpiration()),
      0);
    }
View Full Code Here

  throws RemoteException
   
  concurrentObj.writeLock();
  try {
      ready.check();
      EventRegistration reg = notifyDo(
    tmpl, transitions, listener, handback, leaseDuration);
      if (logger.isLoggable(Level.FINE)) {
    logger.log(
        Level.FINE,
        "registered event listener {0} as {1}",
        new Object[]{
      listener,
      ((ReferentUuid) reg.getLease()).getReferentUuid()
        });
      }
      return reg;
  } finally {
      concurrentObj.writeUnlock();
View Full Code Here

  /* see if the expire thread needs to wake up earlier */
  if (reg.leaseExpiration < minEventExpiration) {
      minEventExpiration = reg.leaseExpiration;
      concurrentObj.waiterNotify(eventNotifier);
  }
  return new EventRegistration(
      reg.eventID,
      proxy,
      EventLease.getInstance(
    myRef,
    myServiceID,
View Full Code Here

                    ServiceTemplate tmpl,
                    RemoteEventListener listenerProxy,
                    long durationthrows RemoteException
    {
        /* Register with the event mechanism of the given lookup service */
        EventRegistration e = null;
        int transition = (   ServiceRegistrar.TRANSITION_NOMATCH_MATCH
                           | ServiceRegistrar.TRANSITION_MATCH_NOMATCH
                           | ServiceRegistrar.TRANSITION_MATCH_MATCH   );
        e = proxy.notify(tmpl, transition, listenerProxy, null, duration);
        /* Proxy preparation -
         *
         * Prepare the proxy to the lease on the event registration just
         * returned. Because lease management (renewal and cancellation)
         * involves remote calls, lease proxies should be prepared before
         * management of the associated leases begins. This allows one to
         * verify trust in the lease, and ensures that the appropriate
         * constraints are attached to the lease.
         */
        Lease eventLease = e.getLease();
        eventLease = (Lease)eventLeasePreparer.prepareProxy(eventLease);
        logger.log(Level.FINEST, "ServiceDiscoveryManager - proxy to event "
                   +"registration lease prepared: {0}", eventLease);
        /* Management the lease on the event registration */
        leaseRenewalMgr.renewFor(eventLease,
                                 duration,
                                 new LeaseListenerImpl(proxy));
        /* Wrap source, id, event sequence & lease in EventReg, and return. */
        return ( new EventReg(e.getSource(),
                              e.getID(),
                              e.getSequenceNumber(),
                              eventLease) );
    }//end registerListener
View Full Code Here

TOP

Related Classes of net.jini.core.event.EventRegistration

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.