public void run() {
   waitForId();
   do {
     try {
       if (logger.isDebugEnabled()) {
         logger.debug("Resolver running for: " + ibisName);
       }
       ReadMessage readMessage;
       readMessage = requestListenPort.receive();
       if (logger.isDebugEnabled()) {
         logger.debug("Resolver read message for: " + ibisName);
       }
       byte operation = readMessage.readByte();
       switch (operation) {
         case OPP_REQUEST:
           if (logger.isDebugEnabled()) {
             logger.debug("Processing Request for: " + ibisName);
           }
           int hashCode = readMessage.readInt();
           IbisIdentifier requestor = readMessage.origin().ibisIdentifier();
           readMessage.finish();
           if (logger.isDebugEnabled()) {
             logger.debug(
                 "Sending Reply For: " + ibisName + " from: " + requestor + " id:" + ibis.id);
           }
           replyPort.connect(requestor, replyPortName);
           WriteMessage sendMessage = replyPort.newMessage();
           sendMessage.writeByte(OPP_REPLY);
           sendMessage.writeInt(hashCode);
           sendMessage.writeObject(ibis.id);
           sendMessage.finish();
           if (logger.isDebugEnabled()) {
             logger.debug("Disconnecting Reply For: " + ibisName + " from: " + requestor);
           }
           replyPort.disconnect(requestor, replyPortName);
           if (logger.isDebugEnabled()) {
             logger.debug("Reply Complete for: " + ibisName + " from: " + requestor);
           }
           break;
         case OPP_QUIT:
           readMessage.finish();
           if (logger.isDebugEnabled()) {
             logger.debug("Resolver quitting for: " + ibisName);
           }
           quit = true;
           break;
         default:
           if (logger.isDebugEnabled()) {
             logger.debug("Unknown request for: " + ibisName);
           }
           readMessage.finish();
           break;
       }
     } catch (IOException e) {
       // TODO What do we do here now?
       logger.error("Got IOException while resolving: " + e);
       e.printStackTrace();
     }
   } while (!quit);
 }
  public void resolve(IbisIdentifier toResolve, String ibisName) throws IOException {
    if (logger.isDebugEnabled()) {
      logger.debug("Making Resolve Request for: " + ibisName);
    }
    Integer id = new Integer(toResolve.hashCode());
    synchronized (resolveQueue) {
      // Make sure we don't collide
      while (resolveQueue.get(id) != null) {
        try {
          resolveQueue.wait();
        } catch (InterruptedException e) {
          // Ignored
        }
      }
      resolveQueue.put(id, toResolve);
    }
    synchronized (toResolve) {
      this.requestPort.connect(toResolve, resolvePortName);
      if (logger.isDebugEnabled()) {
        logger.debug("Sending Request for: " + ibisName);
      }
      WriteMessage writeMessage = this.requestPort.newMessage();
      writeMessage.writeByte(OPP_REQUEST);
      writeMessage.writeInt(toResolve.hashCode());
      if (logger.isDebugEnabled()) {
        logger.debug("Finishing Request for: " + ibisName);
      }
      writeMessage.finish();
      if (logger.isDebugEnabled()) {
        logger.debug("Disconnecting Request for: " + ibisName);
      }
      this.requestPort.disconnect(toResolve, resolvePortName);

      while (!ibis.isResolved(toResolve)) {
        try {
          // Wait for the resolution to finish.
          if (logger.isDebugEnabled()) {
            logger.debug("Waiting For Resolution For: " + ibisName + " on: " + this);
          }
          toResolve.wait();
        } catch (InterruptedException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
      if (logger.isDebugEnabled()) {
        logger.debug("Resolution Complete for: " + ibisName);
      }
    }
  }
Beispiel #3
0
 void sendInt(int value) throws IOException {
   WriteMessage wm = sender.newMessage();
   wm.writeInt(value);
   wm.finish();
 }