Package com.yahoo.jrt.slobrok.api
Class Mirror
- java.lang.Object
-
- com.yahoo.jrt.slobrok.api.Mirror
-
- All Implemented Interfaces:
IMirror
public class Mirror extends java.lang.Object implements IMirror
A Mirror object is used to keep track of the services registered with a slobrok cluster. Updates to the service repository are fetched in the background. Lookups against this object is done using an internal mirror of the service repository.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Mirror.Entry
An Entry contains the name and connection spec for a single service.
-
Constructor Summary
Constructors Constructor Description Mirror(Supervisor orb, SlobrokList slobroks)
Create a new MirrorAPI using the given Supervisor and slobrok connect specs.Mirror(Supervisor orb, SlobrokList slobroks, BackOffPolicy bop)
Create a new MirrorAPI using the given Supervisor and slobrok connect specs.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
connected()
Returns whether this mirror is connected to the slobrok server at this time or not.java.util.List<Mirror.Entry>
lookup(java.lang.String pattern)
Obtain all the services matching a given pattern.boolean
ready()
Ask if the MirrorAPI has got any useful information from the Slobrok.void
shutdown()
Shut down the Mirror.int
updates()
Obtain the number of updates seen by this mirror.
-
-
-
Constructor Detail
-
Mirror
public Mirror(Supervisor orb, SlobrokList slobroks, BackOffPolicy bop)
Create a new MirrorAPI using the given Supervisor and slobrok connect specs.- Parameters:
orb
- the Supervisor to useslobroks
- slobrok connect spec listbop
- custom backoff policy, mostly useful for testing
-
Mirror
public Mirror(Supervisor orb, SlobrokList slobroks)
Create a new MirrorAPI using the given Supervisor and slobrok connect specs.- Parameters:
orb
- the Supervisor to useslobroks
- slobrok connect spec list
-
-
Method Detail
-
shutdown
public void shutdown()
Shut down the Mirror. This will close any open connections, stop the regular mirror updates, and discard all entries.
-
lookup
public java.util.List<Mirror.Entry> lookup(java.lang.String pattern)
Description copied from interface:IMirror
Obtain all the services matching a given pattern. The pattern is matched against all service names in the local mirror repository. A service name may contain '/' as a separator token. A pattern may contain '*' to match anything up to the next '/' (or the end of the name). This means that the pattern 'foo/*/baz' would match the service names 'foo/bar/baz' and 'foo/xyz/baz'. The pattern 'foo/b*' would match 'foo/bar', but neither 'foo/xyz' nor 'foo/bar/baz'. The pattern 'a*b' will never match anything. As a special case, a pattern can end in '**' to match the rest of a name including '/' separators.
-
updates
public int updates()
Description copied from interface:IMirror
Obtain the number of updates seen by this mirror. The value may wrap, but will never become 0 again. This can be used for name lookup optimization, because the results returned by lookup() will never change unless this number also changes.
-
ready
public boolean ready()
Ask if the MirrorAPI has got any useful information from the Slobrok. On application startup it is often useful to run the event loop for some time until this functions returns true (or if it never does, time out and tell the user there was no answer from any Service Location Broker).- Returns:
- true if the MirrorAPI object has asked for updates from a Slobrok and got any answer back
-
connected
public boolean connected()
Returns whether this mirror is connected to the slobrok server at this time or not.
-
-