Project JXTA

net.jxta.impl.endpoint.router
Class Destinations

java.lang.Object
  extended by net.jxta.impl.endpoint.router.Destinations
All Implemented Interfaces:
Runnable

public class Destinations
extends Object
implements Runnable

This class is a repository of wisdom regarding destinations. It also provides a messenger if there is one. Currently, the wisdom is very limited and is only about direct destinations (for which a messenger once existed). The wisdom that can be obtained is:

This could be extended to manage more of the life cycle, such as knowing about messengers being resolved or having failed to. This primitive interface is temporary; it is only meant to replace messengerPool without having to change the router too much.


Nested Class Summary
(package private)  class Destinations.Wisdom
          This class stores knowlege about one particular destination.
 
Constructor Summary
Destinations(EndpointService endpoint)
           
 
Method Summary
 boolean addIncomingMessenger(EndpointAddress destination, Messenger messenger)
          Here is an incoming messenger that just poped out.
 boolean addOutgoingMessenger(EndpointAddress destination, Messenger messenger)
          Here is a messenger that we were able to obtain.
 List allDestinations()
           
 void close()
          Shutdown this cache.
 Messenger getCurrentMessenger(EndpointAddress destination)
          If there is a messenger at hand (incoming or otherwise), return it.
 boolean isCurrentlyReachable(EndpointAddress destination)
          Is there a messenger at hand, or is it likely that we can make one ?
 boolean isNormallyReachable(EndpointAddress destination)
          Is it likely that one can be made from this end.
 boolean isWelcomeNeeded(EndpointAddress destination)
          Are we supposed to send a welcome to that destination (we can't remember having done it).
 void noOutgoingMessenger(EndpointAddress destination)
          We tried to get a messenger but could not.
 void run()
          garbage collector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Destinations

public Destinations(EndpointService endpoint)
Method Detail

close

public void close()
Shutdown this cache. (stop the gc)


run

public void run()
garbage collector. We use soft references to messengers, but we use a strong hashmap to keep the wisdom around in a more predictible manner. Entries are simply removed when they no-longer carry relevant information; so there's no change in the total meaning of the map when an entry is removed.

Specified by:
run in interface Runnable

allDestinations

public List allDestinations()

getCurrentMessenger

public Messenger getCurrentMessenger(EndpointAddress destination)
If there is a messenger at hand (incoming or otherwise), return it.

Parameters:
destination - The destination as an endpoint address (is automatically normalized to protocol and address only).

isNormallyReachable

public boolean isNormallyReachable(EndpointAddress destination)
Is it likely that one can be made from this end. (the last attempt succeeded, not only incoming, and that was not long ago) ? This is a conservative test. It means that declaring that we can route to that destination is a very safe bet, as opposed to isNormallyReachable and getCurrentMessenger, which could be misleading if the only messenger we can ever get is incoming. Not currently used. Should likely be.

Parameters:
destination - The destination as an endpoint address (is automatically normalized to protocol and address only).
Returns:
true if it is likely that we can get a messenger to that destination in the future.

isCurrentlyReachable

public boolean isCurrentlyReachable(EndpointAddress destination)
Is there a messenger at hand, or is it likely that we can make one ? (This is more often true than isNormallyReachable, since it can be true even when all we have is an incoming messenger). This is the equivalent of the former "exists()". Just testing that there is an entry is no-longer the same because we may keep the entries beyond the point where we would keep them before, so that we can add some longer-lived information in the future, and do not interfere as much with the gc thread.

Parameters:
destination - The destination as an endpoint address (is automatically normalized to protocol and address only).
Returns:
true is we are confident that we can obtain a messenger, either because we can get one instantly, or because this destination is normally reachable. (So, it is ok to try and route to that destination, now).

isWelcomeNeeded

public boolean isWelcomeNeeded(EndpointAddress destination)
Are we supposed to send a welcome to that destination (we can't remember having done it). It is assumed that once true was returned, it will be acted upon. So, true is not returned a second time.

Parameters:
destination - The destination as an endpoint address (is automatically normalized to protocol and address only).
Returns:
true if this a destination to whish we can't remember sending a welcome message.

addOutgoingMessenger

public boolean addOutgoingMessenger(EndpointAddress destination,
                                    Messenger messenger)
Here is a messenger that we were able to obtain.

Parameters:
destination - The destination as an endpoint address (is automatically normalized to protocol and address only).
messenger - The incoming messenger for that destination.
Returns:
true if this messenger was added (keep it open). false otherwise (do what you want with it).

addIncomingMessenger

public boolean addIncomingMessenger(EndpointAddress destination,
                                    Messenger messenger)
Here is an incoming messenger that just poped out.

Parameters:
destination - The destination as an endpoint address (is automatically normalized to protocol and address only).
messenger - The incoming messenger for that destination.
Returns:
true if this messenger was added (keep it open). false otherwise (do what you want with it).

noOutgoingMessenger

public void noOutgoingMessenger(EndpointAddress destination)
We tried to get a messenger but could not. We know that we do not have connectivity from our end, for now. we may still have an incoming. However, if we had to try and make a messenger, there probably isn't an incoming, but that's not our business here. isNormallyReachable becomes false; but we can still try when sollicited.

Parameters:
destination - The destination as an endpoint address (is automatically normalized to protocol and address only).

JXTA J2SE