Ejemplo n.º 1
0
  /** Run method specified by runnnable. */
  public void run() {
    // Assume no thread pooling (bug fix by spierhj)
    ThreadAuditor.ThreadHandle threadHandle = null;

    while (true) {
      // Create a new string message parser to parse the list of messages.
      if (myParser == null) {
        myParser = new StringMsgParser();
        myParser.setParseExceptionListener(this);
      }
      // messages that we write out to him.
      DatagramPacket packet;

      if (sipStack.threadPoolSize != -1) {
        synchronized (((UDPMessageProcessor) messageProcessor).messageQueue) {
          while (((UDPMessageProcessor) messageProcessor).messageQueue.isEmpty()) {
            // Check to see if we need to exit.
            if (!((UDPMessageProcessor) messageProcessor).isRunning) return;
            try {
              // We're part of a thread pool. Ask the auditor to
              // monitor this thread.
              if (threadHandle == null) {
                threadHandle = sipStack.getThreadAuditor().addCurrentThread();
              }

              // Send a heartbeat to the thread auditor
              threadHandle.ping();

              // Wait for packets
              // Note: getPingInterval returns 0 (infinite) if the
              // thread auditor is disabled.
              ((UDPMessageProcessor) messageProcessor)
                  .messageQueue.wait(threadHandle.getPingIntervalInMillisecs());
            } catch (InterruptedException ex) {
              if (!((UDPMessageProcessor) messageProcessor).isRunning) return;
            }
          }
          packet =
              (DatagramPacket) ((UDPMessageProcessor) messageProcessor).messageQueue.removeFirst();
        }
        this.incomingPacket = packet;
      } else {
        packet = this.incomingPacket;
      }

      // Process the packet. Catch and log any exception we may throw.
      try {
        processIncomingDataPacket(packet);
      } catch (Exception e) {

        sipStack.logWriter.logError("Error while processing incoming UDP packet", e);
      }

      if (sipStack.threadPoolSize == -1) {
        return;
      }
    }
  }
Ejemplo n.º 2
0
  /** Run method specified by runnnable. */
  public void run() {
    // Assume no thread pooling (bug fix by spierhj)
    ThreadAuditor.ThreadHandle threadHandle = null;

    final UDPMessageProcessor udpMessageProcessor = (UDPMessageProcessor) messageProcessor;

    while (true) {
      // messages that we write out to him.
      DatagramPacket packet = null;

      if (sipStack.threadPoolSize != -1) {
        //                synchronized (((UDPMessageProcessor) messageProcessor).messageQueue) {

        //                    while (udpMessageProcessor.messageQueue.isEmpty()) {
        //                        // Check to see if we need to exit.
        //                        if (!udpMessageProcessor.isRunning)
        //                            return;
        ////                        try {
        // We're part of a thread pool. Ask the auditor to
        // monitor this thread.
        if (threadHandle == null) {
          threadHandle = sipStack.getThreadAuditor().addCurrentThread();
        }

        // Send a heartbeat to the thread auditor
        threadHandle.ping();
        ////                            long pingInterval =
        // threadHandle.getPingIntervalInMillisecs();
        //                            // Wait for packets
        //                            // Note: getPingInterval returns 0 (infinite) if the
        //                            // thread auditor is disabled.
        ////                            synchronized (udpMessageProcessor.messageQueue) {
        ////                            	udpMessageProcessor.messageQueue.wait();
        ////                            }
        ////                        } catch (InterruptedException ex) {
        ////                            if (!udpMessageProcessor.isRunning)
        ////                                return;
        ////                        }
        //                    }
        try {
          packet = udpMessageProcessor.messageQueue.take();
        } catch (InterruptedException ex) {
          if (!udpMessageProcessor.isRunning) return;
        }
        //                }
        this.incomingPacket = packet;
      } else {
        packet = this.incomingPacket;
      }

      // Process the packet. Catch and log any exception we may throw.
      try {
        processIncomingDataPacket(packet);
      } catch (Exception e) {

        sipStack.getStackLogger().logError("Error while processing incoming UDP packet", e);
      }

      if (sipStack.threadPoolSize == -1) {
        return;
      }
    }
  }