@Override public boolean waitUntilReady(double seconds) { for (int i = 0; i < seconds * 100; ++i) { if (mirror.ready()) { return true; } try { Thread.sleep(10); } catch (InterruptedException e) { // empty } } return false; }
public void run() { checkForUpdate(); } });
public void run() { handleShutdown(); } });
/** * Updates the list of matching recipients by querying the extern slobrok. */ private void update() { int upd = mirror.updates(); if (generation != upd) { generation = upd; recipients.clear(); Mirror.Entry[] arr = mirror.lookup(pattern); for (Mirror.Entry entry : arr) { recipients.add(Hop.parse(entry.getSpec() + session)); } } }
/** * Constructs a new instance of this policy. The argument given is the connection spec to the slobrok to use for * resolving recipients, as well as the pattern to use when querying. This constructor does _not_ wait for the * mirror to become ready. * * @param arg The slobrok connection spec. */ public ExternPolicy(String arg) { if (arg == null || arg.length() == 0) { error = "Expected parameter, got empty string."; return; } String[] args = arg.split(";", 2); if (args.length != 2 || args[0].length() == 0 || args[1].length() == 0) { error = "Expected parameter on the form '<spec>;<pattern>', got '" + arg + "'."; return; } int pos = args[1].lastIndexOf('/'); if (pos < 0) { error = "Expected pattern on the form '<service>/<session>', got '" + args[1] + "'."; return; } SlobrokList slobroks = new SlobrokList(); slobroks.setup(args[0].split(",")); pattern = args[1]; session = pattern.substring(pos); orb = new Supervisor(new Transport()); mirror = new Mirror(orb, slobroks); error = null; }
@Override public void destroy() { if (destroyed.getAndSet(true)) throw new RuntimeException("Already destroyed"); mirror.shutdown(); orb.transport().shutdown().join(); }
@Override public Entry[] lookup(String pattern) { ArrayList<Entry> found = new ArrayList<>(); char[] p = pattern.toCharArray(); for (Entry specEntry : specs) { if (match(specEntry.getNameArray(), p)) { found.add(specEntry); } } return found.toArray(new Entry[found.size()]); }
handleUpdate(); requestDone = false; return;
@Override public synchronized void configure(SlobroksConfig config) { String[] slist = new String[config.slobrok().size()]; for(int i = 0; i < config.slobrok().size(); i++) { slist[i] = config.slobrok(i).connectionspec(); } if (slobroks == null) { slobroks = new SlobrokList(); } slobroks.setup(slist); if (mirror == null) { mirror = new Mirror(orb, slobroks); } }
/** * Sets the destroyed flag to true. The very first time this method is called, it cleans up all its dependencies. * Even if you retain a reference to this object, all of its content is allowed to be garbage collected. * * @return True if content existed and was destroyed. */ public boolean destroy() { if (!destroyed.getAndSet(true)) { if (slobroksConfig != null) { slobroksConfig.shutdown(); } register.shutdown(); mirror.shutdown(); listener.shutdown().join(); orb.transport().shutdown().join(); targetPool.flushTargets(true); executor.shutdown(); return true; } return false; }
@Override public void init() { if (slobroks != null) { orb = new Supervisor(new Transport()); mirror = new Mirror(orb, slobroks); } if (configSources != null) { if (mirror == null) { orb = new Supervisor(new Transport()); subscriber = subscribe(slobrokConfigId, new ConfigSourceSet(configSources)); } } }
@Override public void select(RoutingContext ctx) { if (error != null) { ctx.setError(DocumentProtocol.ERROR_POLICY_FAILURE, error); } else if (mirror.ready()) { Hop hop = getRecipient(); if (hop != null) { Route route = new Route(ctx.getRoute()); route.setHop(0, hop); ctx.addChild(route); } else { ctx.setError(ErrorCode.NO_ADDRESS_FOR_SERVICE, "Could not resolve any recipients from '" + pattern + "'."); } } else { ctx.setError(ErrorCode.APP_TRANSIENT_ERROR, "Extern slobrok not ready."); } }
task.jrtTask.scheduleNow(); register = new Register(orb, slobrokConfig.getSlobroks(), identity.getHostname(), listener.port()); mirror = new Mirror(orb, slobrokConfig.getSlobroks());