/** * Set the encapsulated Peer Advertisement. * * @param adv is the RdvAdvertisement to be set. * @return RdvAdvertisement the old Advertisement of the Peer represented by this object */ RdvAdvertisement setRdvAdvertisement(RdvAdvertisement adv) { if (!radv.getPeerID().equals(adv.getPeerID())) { if (LOG.isEnabledFor(Level.ERROR)) { LOG.error("adv refers to a different peer"); } throw new IllegalArgumentException("adv refers to a different peer"); } RdvAdvertisement old = radv; this.radv = adv; setLastUpdateTime(TimeUtils.timeNow()); return old; }
/** * Initialize from a RdvAdvertisement. * * @param rendezvous The rendezvous the element works for. * @param adv the RdvAdvertisement from which to initialize */ PeerViewElement(EndpointService endpoint, RdvAdvertisement radv) { super(radv.getPeerID()); this.endpoint = endpoint; this.radv = radv; created = TimeUtils.timeNow(); lastUpdate = created; }
/** * Return a messenger suitable for sending to this peer. * * @return a messenger to this PVE peer or if <code>null</code> if peer is unreachable. */ private Messenger getCachedMessenger() { boolean updateAlive = false; synchronized (this) { if ((null == cachedMessenger) || cachedMessenger.isClosed()) { cachedMessenger = null; if (LOG.isEnabledFor(Level.DEBUG)) { LOG.debug("Getting cached Messenger for " + radv.getName()); } updateAlive = true; cachedMessenger = endpoint.getMessenger(getDestAddress(), radv.getRouteAdv()); } } if (updateAlive) { setAlive(null != cachedMessenger); } return cachedMessenger; }
/** {@inheritDoc} */ public String toString() { StringBuffer asString = new StringBuffer(); asString.append('"'); asString.append(radv.getName()); asString.append('"'); asString.append(alive ? " A " : " a "); asString.append(isInPeerView() ? " P " : " p "); asString.append(throttling ? " T " : " t "); asString.append(" ["); asString.append( TimeUtils.toRelativeTimeMillis(TimeUtils.timeNow(), created) / TimeUtils.ASECOND); asString.append("/"); asString.append( TimeUtils.toRelativeTimeMillis(TimeUtils.timeNow(), lastUpdate) / TimeUtils.ASECOND); asString.append("]"); return asString.toString(); }