home *** CD-ROM | disk | FTP | other *** search
- package org.xbill.DNS;
-
- import java.io.IOException;
- import java.io.InterruptedIOException;
- import java.net.SocketException;
- import java.util.List;
-
- class ExtendedResolver$Resolution implements ResolverListener {
- Resolver[] resolvers;
- int[] sent;
- Object[] inprogress;
- int retries;
- int outstanding;
- boolean done;
- Message query;
- Message response;
- Throwable thrown;
- ResolverListener listener;
-
- public ExtendedResolver$Resolution(ExtendedResolver eres, Message query) {
- List l = ExtendedResolver.access$0(eres);
- this.resolvers = (Resolver[])l.toArray(new Resolver[l.size()]);
- if (ExtendedResolver.access$1(eres)) {
- int nresolvers = this.resolvers.length;
- int var10002 = ExtendedResolver.access$2(eres);
- ExtendedResolver.access$3(eres, var10002 + 1);
- int start = var10002 % nresolvers;
- if (ExtendedResolver.access$2(eres) > nresolvers) {
- ExtendedResolver.access$3(eres, ExtendedResolver.access$2(eres) % nresolvers);
- }
-
- if (start > 0) {
- Resolver[] shuffle = new Resolver[nresolvers];
-
- for(int i = 0; i < nresolvers; ++i) {
- int pos = (i + start) % nresolvers;
- shuffle[i] = this.resolvers[pos];
- }
-
- this.resolvers = shuffle;
- }
- }
-
- this.sent = new int[this.resolvers.length];
- this.inprogress = new Object[this.resolvers.length];
- this.retries = ExtendedResolver.access$4(eres);
- this.query = query;
- }
-
- public void send(int n) {
- int var10002 = this.sent[n]++;
- ++this.outstanding;
-
- try {
- this.inprogress[n] = this.resolvers[n].sendAsync(this.query, this);
- } catch (Throwable t) {
- this.thrown = t;
- this.done = true;
- if (this.listener == null) {
- this.notifyAll();
- return;
- }
- }
-
- }
-
- public Message start() throws IOException {
- try {
- int var10002 = this.sent[0]++;
- ++this.outstanding;
- this.inprogress[0] = new Object();
- return this.resolvers[0].send(this.query);
- } catch (Exception e) {
- this.handleException(this.inprogress[0], e);
- if (!this.done) {
- synchronized(this) {
- while(!this.done) {
- try {
- this.wait();
- } catch (InterruptedException var3) {
- }
- }
- }
- }
-
- if (this.response != null) {
- return this.response;
- } else if (this.thrown instanceof IOException) {
- throw (IOException)this.thrown;
- } else if (this.thrown instanceof RuntimeException) {
- throw (RuntimeException)this.thrown;
- } else if (this.thrown instanceof Error) {
- throw (Error)this.thrown;
- } else {
- throw new IllegalStateException("ExtendedResolver failure");
- }
- }
- }
-
- public void startAsync(ResolverListener listener) {
- this.listener = listener;
- this.send(0);
- }
-
- public void receiveMessage(Object id, Message m) {
- if (Options.check("verbose")) {
- System.err.println("ExtendedResolver: received message");
- }
-
- synchronized(this) {
- if (this.done) {
- return;
- }
-
- this.response = m;
- this.done = true;
- if (this.listener == null) {
- this.notifyAll();
- return;
- }
- }
-
- this.listener.receiveMessage(this, this.response);
- }
-
- public void handleException(Object id, Exception e) {
- if (Options.check("verbose")) {
- System.err.println("ExtendedResolver: got " + e);
- }
-
- synchronized(this) {
- --this.outstanding;
- if (this.done) {
- return;
- }
-
- int n;
- for(n = 0; n < this.inprogress.length && this.inprogress[n] != id; ++n) {
- }
-
- if (n == this.inprogress.length) {
- return;
- }
-
- boolean startnext = false;
- boolean waiting = false;
- if (this.sent[n] == 1 && n < this.resolvers.length - 1) {
- startnext = true;
- }
-
- if (e instanceof InterruptedIOException) {
- if (this.sent[n] < this.retries) {
- this.send(n);
- }
-
- if (this.thrown == null) {
- this.thrown = e;
- }
- } else if (e instanceof SocketException) {
- if (this.thrown == null || this.thrown instanceof InterruptedIOException) {
- this.thrown = e;
- }
- } else {
- this.thrown = e;
- }
-
- if (this.done) {
- return;
- }
-
- if (startnext) {
- this.send(n + 1);
- }
-
- if (this.done) {
- return;
- }
-
- if (this.outstanding == 0) {
- this.done = true;
- if (this.listener == null) {
- this.notifyAll();
- return;
- }
- }
-
- if (!this.done) {
- return;
- }
- }
-
- if (!(this.thrown instanceof Exception)) {
- this.thrown = new RuntimeException(this.thrown.getMessage());
- }
-
- this.listener.handleException(this, (Exception)this.thrown);
- }
- }
-