public class Destinations
Implements:
java.lang.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:
- is there a messenger at hand (incoming or otherwise).
- is it likely that one can be made from this end, should the one we have break. (the last attempt succeeded, not only incoming,
and that was not long ago).
- is either of the above true, (are we confident we can get a messenger as of right now one way or the other).
- are we supposed to send a welcome to that destination (we can't remember having done it).
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.
| Inner Class Summary |
final static class |
This class stores knowlege about one particular destination. |
| Field Summary |
private EndpointService |
|
private Thread |
|
private volatile boolean |
|
final static long |
How long we consider that a past outgoingMessenger is an indication that one is possible in the future. |
private long |
This tells when the outgoing messenger information expires. |
private Messenger |
The channel we last used if it happens to be an incoming messenger. |
private SoftReference |
The channel we last used, if any. |
private boolean |
When a new destination is added, we're supposed to send our welcome along with the first message. |
private EndpointAddress |
The transport destination address of the messenger we're caching (if not incoming). |
private Map |
|
| Constructor Summary |
public |
|
| |
Wisdom(Messenger messenger, boolean incoming) |
| Method Summary |
public synchronized boolean |
Here is an incoming messenger that just poped out. |
public synchronized boolean |
Here is a messenger that we were able to obtain. |
private void |
|
public synchronized List |
|
public synchronized void |
Shutdown this cache. |
public synchronized Messenger |
If there is a messenger at hand (incoming or otherwise), return it. |
|
|
public synchronized boolean |
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). |
public synchronized boolean |
Is it likely that one can be made from this end. |
public synchronized boolean |
Are we supposed to send a welcome to that destination (we can't remember having done it). |
public synchronized void |
We tried to get a messenger but could not. |
public void |
garbage collector. |
boolean |
|
boolean |
|
Messenger |
Returns a channel for this destination if one is there or can be obtained
readily and works. |
private Messenger |
Returns an incoming messenger is there is one that works. |
private Messenger |
Returns an outgoingMessenger if there is one or one can be made without delay. |
boolean |
We think the destination is reachable somehow. |
boolean |
|
boolean |
|
boolean |
Tells whether a welcome message is needed. |
void |
|
private EndpointService endpoint
private Thread gcThread = null
private volatile boolean stopped = false
volatile
private Map wisdoms = new HashMap(64)
public Destinations(EndpointService endpoint)
public synchronized 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.
Return:
true if this messenger was added (keep it open). false otherwise (do what you want with it).
public synchronized 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.
Return:
true if this messenger was added (keep it open). false otherwise (do what you want with it).
public synchronized List allDestinations()
public synchronized void close()
Shutdown this cache. (stop the gc)
public synchronized 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).
retun:
A messenger to that destination if a resolved and usable one is available or can be made instantly. null otherwise.
public synchronized 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).
Return:
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).
public synchronized 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).
Return:
true if it is likely that we can get a messenger to that destination in the future.
public synchronized 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).
Return:
true if this a destination to whish we can't remember sending a welcome message.
public synchronized 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).
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.