⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 notifier.java

📁 jsr-180 (SIP) 实现源码。可以在真实手机上使用
💻 JAVA
字号:
package com.micromethod.sipstack.ri;

import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.EmptyStackException;
import java.util.Vector;

import com.micromethod.sipstack.i.*;

/**
 * Notifier
 */
public class Notifier implements SipConnectionNotifier {
  /**
   * m_txHandler
   */
  private TxHandler m_txHandler = null;

  /**
   * m_localAddress
   */
  private String m_localAddress = null;

  /**
   * m_sipServerConnectionListener
   */
  private SipServerConnectionListener m_sipServerConnectionListener = null;

  /**
   * m_isOpening
   */
  private boolean m_isOpening = false;

  /**
   * m_listener
   */
  private Listener m_listener = null;

  /**
   * m_scheme
   */
  private String m_scheme = null;

  /**
   * m_sipServerConnections
   */
  private Vector m_sipServerConnections = null;

  private boolean _fldint = false;

  /**
   * Notifier Constructor
   * 
   * @param localPort
   * @param k
   * @param flag
   * @param s
   *          type
   * @throws IOException
   */
  public Notifier(int localPort, int k, boolean flag, String s)
      throws IOException {
    m_txHandler = null;
    m_localAddress = null;
    m_sipServerConnectionListener = null;
    m_isOpening = true;
    m_scheme = null;
    m_sipServerConnections = new Vector();
    _fldint = false;
    m_scheme = s;
    m_txHandler = TxHandler.getInstance();
    m_listener = m_txHandler.getListener(localPort, this);
    m_localAddress = m_txHandler.getLoaclAddress();
  }

  /**
   * checkOpenState
   * 
   * @throws IOException
   */
  private void checkOpenState() throws IOException {
    if (!m_isOpening) {
      throw new IOException("SipConnectionNotifier closed");
    }
    return;
  }

  /**
   * acceptAndOpen
   * 
   * @return sipServerConnection
   * @throws IOException
   * @throws InterruptedIOException
   */
  public SipServerConnection acceptAndOpen() throws IOException,
      InterruptedIOException {
    checkOpenState();
    // SipConnectionNotifierImpl m1 = this;
    try {
      ServerConnection j;
      while (m_sipServerConnections.isEmpty()) {
        Protocol.echo("Notifier.acceptAndOpen(): port: " + m_listener.getPort()
            + " waiting for request...");
        ((Object) this).wait();
        if (!m_isOpening)
          throw new IOException("SipConnectionNotifier closed");
        Protocol.echo("Notifier.acceptAndOpen(): port: " + m_listener.getPort()
            + " running...");
        if (m_sipServerConnections.isEmpty())
          throw new InterruptedIOException(
              "Error opening SIP server connection, empty receive buffer");
      }
      j = (ServerConnection) m_sipServerConnections.firstElement();
      m_sipServerConnections.removeElement(((Object) (j)));
      j.refresh();
      return ((SipServerConnection) (j));
    }
    catch (EmptyStackException e) {
      throw new IOException(e.getMessage());
    }
    catch (InterruptedException e) {
      throw new IOException(e.getMessage());
    }
  }

  /**
   * addSipServerConnectionNotifier
   * 
   * @param transaction
   * @param sipRequest
   */
  protected void addSipServerConnectionNotifier(BaseTransaction transaction,
      SipRequest sipRequest) {
    synchronized (this) {
      ServerConnection j = new ServerConnection(transaction, sipRequest,
          m_listener, this);
      m_sipServerConnections.addElement(((Object) (j)));
      ((Object) this).notify();
    }
    try {
      if (m_sipServerConnectionListener != null)
        m_sipServerConnectionListener
            .notifyRequest(((SipConnectionNotifier) (this)));
    }
    catch (Exception exception) {
    }
  }

  /**
   * close
   */
  public void close() {
    synchronized (this) {
      if (m_isOpening) {
        m_isOpening = false;
        ((Object) this).notify();
        m_listener.removeNotifier(this);
      }
    }
  }

  /**
   * setListener
   */
  public void setListener(
      SipServerConnectionListener sipserverconnectionlistener)
      throws IOException {
    checkOpenState();
    m_sipServerConnectionListener = sipserverconnectionlistener;
  }

  /**
   * getLocalAddress
   * 
   * @return localAddress
   * @throws IOException
   */
  public String getLocalAddress() throws IOException {
    checkOpenState();
    return m_localAddress;
  }

  /**
   * getLocalPort
   * 
   * @return localPort
   * @throws IOException
   */
  public int getLocalPort() throws IOException {
    checkOpenState();
    return m_listener.getPort();
  }

  /**
   * getSipAddress
   * 
   * @return sipAddress
   */
  protected SipAddress getSipAddress() {
    return m_listener.getSipAddress();
  }

  /**
   * getScheme
   * 
   * @return scheme
   */
  public String getScheme() {
    return m_scheme;
  }

  protected boolean _mthif() {
    return _fldint;
  }

  protected void a(boolean flag) {
    _fldint = flag;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -