Package com.sun.jini.discovery

Examples of com.sun.jini.discovery.UnicastResponse


                            long deltaT = curTime - tStamp;
                            if(deltaT > timeThreshold) {
                                /* announcements stopped, queue reachability
                                 * test and potential discarded event
                                 */
                                UnicastResponse resp =
            (UnicastResponse)registrars.get(srvcID);
        Object req = new CheckReachabilityMarker(resp);
                                synchronized (pendingDiscoveries) {
                                    if(pendingDiscoveries.add(req)) {
                                        restoreContextAddTask(
View Full Code Here


       * 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
View Full Code Here

      }
        }
    }
    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());
View Full Code Here

        DEFAULT_SOCKET_TIMEOUT));

      int pv = new DataInputStream(socket.getInputStream()).readInt();
      unicastDiscoveryConstraints.checkProtocolVersion(pv);
      getDiscovery(pv).handleUnicastDiscovery(
    new UnicastResponse(lookupLocator.getHost(),
            lookupLocator.getPort(),
            memberGroups,
            lookupProxy),
    socket,
    unicastDiscoveryConstraints.getUnfulfilledConstraints(),
View Full Code Here

      listeners.add(l);
      if (registrars.isEmpty()) return;//nothing to send the new listener
            HashMap groupsMap = new HashMap(registrars.size());
      Iterator iter = registrars.values().iterator();
      while (iter.hasNext()) {
                UnicastResponse resp = (UnicastResponse)iter.next();
                groupsMap.put(resp.getRegistrar(),resp.getGroups());
      }
      ArrayList list = new ArrayList(1);
      list.add(l);
      addNotify(list, groupsMap, DISCOVERED);
  }
View Full Code Here

                            return proxy;
                        }//end run
                    }),//end PrivilegedExceptionAction and wrap
                  securityContext.getAccessControlContext());//end doPrivileged
      if (prepReg != srcReg) {
    resp = new UnicastResponse(resp.getHost(),
             resp.getPort(),
             resp.getGroups(),
             prepReg);
      }
  } catch (Exception e) {
View Full Code Here

     */
    private void maybeDiscardRegistrars() {
  synchronized (registrars) {
            HashMap groupsMap = new HashMap(registrars.size());
      for(Iterator iter=registrars.values().iterator();iter.hasNext(); ){
    UnicastResponse ent = (UnicastResponse)iter.next();
    if(!groupsOverlap(ent.getGroups())) { // not interested anymore
                    groupsMap.put(ent.getRegistrar(),ent.getGroups());
                    regInfo.remove(ent.getRegistrar().getServiceID());
        iter.remove(); // remove (srvcID,response) mapping
    }//endif
      }//end loop
            if( !groupsMap.isEmpty() && !listeners.isEmpty() ) {
    addNotify((ArrayList)listeners.clone(), groupsMap, DISCARDED);
View Full Code Here

        }//endif
 
  synchronized (registrars) {
      // Other events may have occured to registrars while we were
      // making our remote call.
      UnicastResponse resp =
    (UnicastResponse) registrars.get(reg.getServiceID());
      if (resp == null) {
    // The registrar was discarded in the meantime. Oh well.
    return;
      }
      notifyOnGroupChange(reg, resp.getGroups(), actualGroups);
  }
    }//end maybeSendEvent
View Full Code Here

     *                   <code>reg</code> parameter
     */
    private void sendDiscarded(ServiceRegistrar reg, String[] curGroups) {
        ServiceID srvcID = reg.getServiceID();
        if(curGroups == null) { // discard request is from external source
            UnicastResponse resp = (UnicastResponse)registrars.get(srvcID);
            if(resp == null) return;
            curGroups = resp.getGroups();
        }//endif
        if( registrars.remove(srvcID) != null ) {
            regInfo.remove(srvcID);
            if( !listeners.isEmpty() ) {
                addNotify((ArrayList)listeners.clone(),
View Full Code Here

     *                   member groups of the registrar referenced by the
     *                   <code>reg</code> parameter
     */
    private void sendChanged(ServiceRegistrar reg, String[] curGroups) {
        /* replace old groups with new; prevents repeated changed events */
        UnicastResponse resp =
                   (UnicastResponse)registrars.get(reg.getServiceID());
  registrars.put(reg.getServiceID(),
           new UnicastResponse(resp.getHost(),
             resp.getPort(),
             curGroups,
             resp.getRegistrar()));
        if( !listeners.isEmpty() ) {
            addNotify((ArrayList)listeners.clone(),
                       mapRegToGroups(reg,curGroups), CHANGED);
        }//endif
    }//end sendChanged
View Full Code Here

TOP

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

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.