Package com.sun.jini.discovery

Examples of com.sun.jini.discovery.MulticastAnnouncement


          tickets.remove(ticket);
      }
        }
    }
    Socket sock = null;
    MulticastAnnouncement announcement = null;
    UnicastResponse response = null;
    if (req instanceof Socket) {
        // Perform unicast discovery on the connected socket.
        DiscoveryConstraints unicastDiscoveryConstraints =
      DiscoveryConstraints.process(
          rawUnicastDiscoveryConstraints);
        sock = (Socket)req;
        UnicastResponse resp;
        try {
      prepareSocket(sock, unicastDiscoveryConstraints);
      resp = doUnicastDiscovery(sock,
              unicastDiscoveryConstraints);
        } finally {
      try {
          sock.close();
      } catch (IOException e) { /* ignore */ }
        }
        maybeAddNewRegistrar(resp);
    } else if(req instanceof LookupLocator) {
        // Perform unicast discovery using the LookupLocator
        // host and port.
        LookupLocator loc = (LookupLocator)req;
        UnicastResponse resp = new MultiIPDiscovery() {
      protected UnicastResponse performDiscovery(
              Discovery disco,
              DiscoveryConstraints dc,
              Socket s)
          throws IOException, ClassNotFoundException
      {
          return doUnicastDiscovery(s, dc, disco);
      }
      protected void singleResponseException(Exception e,
                     InetAddress addr,
                     int port)
      {
          logger.log(
        Levels.HANDLED,
        "Exception occured during unicast discovery " +
        addr + ":" + port, e);
      }
        }.getResponse(loc.getHost(),
              loc.getPort(),
              rawUnicastDiscoveryConstraints);
        maybeAddNewRegistrar(resp);
    } else if(req instanceof CheckGroupsMarker) {
        // handle group changes
        announcement = ((CheckGroupsMarker)req).announcement;
        ServiceID srvcID = announcement.getServiceID();
        UnicastResponse resp = null;
        synchronized (registrars) {
      resp = (UnicastResponse)registrars.get(srvcID);
        }
        if(resp != null) {
      maybeSendEvent(resp, announcement.getGroups());
        }//endif
    } else if(req instanceof CheckReachabilityMarker) {
        // test reachability
        response = ((CheckReachabilityMarker)req).response;
        maybeSendEvent(response, null);
View Full Code Here


   * the announcement merits further processing, an appropriate object is
   * added to the pendingDiscoveries set, and control is transferred to a
   * UnicastDiscoveryTask.
   */
  private void doRun() {
      MulticastAnnouncement ann;
      try {
    ann = decodeMulticastAnnouncement(datagram);
      } catch (Exception e) {
    if (!(e instanceof InterruptedIOException)) {
        logger.log(Levels.HANDLED,
             "exception decoding multicast announcement", e);
    }
    return;
      }

      /* If the registrars map contains the service ID of the registrar
       * that sent the current announcement then that registrar has
       * already been discovered.
       *
       * Determine if the member groups of the already-discovered
       * registrar have been replaced by a set containing none of the
       * desired groups. If yes, then discard the registrar.
       *
       * If the registrar that sent the current announcement has not
       * already been discovered, then check to see if any of the
       * group(s) in which the registrar is a member are in the set of
       * desired groups to discover. If yes, then queue the registrar for
       * unicast discovery.
       */
      Object pending = null;
      ServiceID srvcID = ann.getServiceID();
      synchronized (registrars) {
    UnicastResponse resp =
        (UnicastResponse) registrars.get(srvcID);
    if (resp != null) {
        // already in discovered set, timestamp announcement
        AnnouncementInfo aInfo =
      (AnnouncementInfo) regInfo.get(srvcID);
        aInfo.tStamp = System.currentTimeMillis();
        long currNum = ann.getSequenceNumber();
        if ((newSeqNum(currNum, aInfo.seqNum)) &&
      (!groupSetsEqual(resp.getGroups(), ann.getGroups()))) {
      /* Check if the groups have changed. In the case of
       * split announcement messages, eventually, group difference
       * will be seen for the given sequence number. This
       * check ignores other differences, such as port numbers,
       * but for the purposes of LookupDiscovery, this is not
       * important.
       */     
      pending = new CheckGroupsMarker(ann);
        }
    } else if (groupsOverlap(ann.getGroups())) {
        // newly discovered
        pending = new LookupLocator(ann.getHost(), ann.getPort());
    }
      }
      if (pending != null) {
    try {
        checkAnnouncementConstraints(ann);
    } catch (Exception e) {
        if (!(e instanceof InterruptedIOException)) {
      logger.log(Levels.HANDLED,
             "exception decoding multicast announcement", e);
        }
        return;
    }
    if (pending instanceof CheckGroupsMarker) {
        synchronized(registrars) {
      // Since this is a valid announcement, update the
      // sequence number.
      AnnouncementInfo aInfo =
          (AnnouncementInfo) regInfo.get(srvcID);
      aInfo.seqNum = ann.getSequenceNumber();
        }
    }
    boolean added;
    // enqueue and handle pending action, if not already enqueued
    synchronized (pendingDiscoveries) {
View Full Code Here

           .chooseProtocolVersion());
          } catch (DiscoveryProtocolException e) {
        throw new AssertionError(e);
          }
          EncodeIterator ei = disco.encodeMulticastAnnouncement(
        new MulticastAnnouncement(announcementSeqNo++,
            myLocator.getHost(),
            myLocator.getPort(),
            groups,
            myServiceID),
        multicastAnnouncementConstraints
View Full Code Here

 
  MulticastSocket mcSocket = new MulticastSocket(DISCOVERYPORT);
  mcSocket.setTimeToLive(1);
  Discovery d = Discovery.getProtocol1();
  ServiceID sid = new ServiceID(5555, 4444);
  MulticastAnnouncement ma = new MulticastAnnouncement(
            2222,
            InetAddress.getLocalHost().getHostName(),
            DISCOVERYPORT,
            groups,
            sid);
View Full Code Here

TOP

Related Classes of com.sun.jini.discovery.MulticastAnnouncement

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.