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

📄 iiopswitch.java

📁 利用JAVA采用IIOP通讯的方式,支持weblogic及websphere
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * IIopSwitch.java
 *
 * Created on 2004年1月2日, 下午1:34
 */

package collector.iiop;

import java.util.*;

import collector.common.*;

/**
 *
 * @author  wj
 */
public class IIopSwitch {

  /** Creates a new instance of IIopSwitch */

  private IIopDown m_IIopDown1 = null;
  private IIopDown m_IIopDown2 = null;

  private IIopSendData m_IIopSendData1 = null;
  private IIopSendData m_IIopSendData2 = null;

  private IIopEvent m_IIopEvent1 = null;
  private IIopEvent m_IIopEvent2 = null;

  private boolean m_IIopDown1Flag = false;
  private boolean m_IIopDown2Flag = false;

  private boolean m_IIopSendData1Flag = false;
  private boolean m_IIopSendData2Flag = false;

  private boolean m_IIopEvent1Flag = false;
  private boolean m_IIopEvent2Flag = false;

  private int m_IIopDownCounter1 = 0;
  private int m_IIopDownCounter2 = 0;

  private int m_IIopSendDataCounter1 = 0;
  private int m_IIopSendDataCounter2 = 0;

  private int m_IIopEventCounter1 = 0;
  private int m_IIopEventCounter2 = 0;

  private String m_InitContextFac = "";
  private String m_IIopURL1 = "";
  private String m_IIopURL2 = "";

  private String m_Down_JndiName = "";
  private String m_SendData_JndiName = "";
  private String m_Event_JndiName = "";

  private ArrayList m_ArrayList = null;
  private int m_ReconnectCounter = 1;

  private int m_CurSendData = IIopDefine.SLAVE_SERVER;
  private int m_CurEvent = IIopDefine.SLAVE_SERVER;
  private int m_CurDown = IIopDefine.SLAVE_SERVER;

  /** Creates a new instance of IIopSwitch */
  public IIopSwitch() {
    m_ArrayList = new ArrayList();
  }

  public int setIIopParam(String m_InitContextFac, String m_IIopURL1,
                          String m_IIopURL2) {
    this.m_InitContextFac = m_InitContextFac;
    this.m_IIopURL1 = m_IIopURL1;
    this.m_IIopURL2 = m_IIopURL2;

    return 1;
  }

  public int setIIopDownParam(String m_Down_JndiName) {
    this.m_Down_JndiName = m_Down_JndiName;

    return 1;
  }

  public int setIIopSendDataParam(String m_SendData_JndiName) {
    this.m_SendData_JndiName = m_SendData_JndiName;

    return 1;
  }

  public int setIIopEventParam(String m_Event_JndiName) {
    this.m_Event_JndiName = m_Event_JndiName;

    return 1;
  }

  public int setReconnectCounter(int m_ReconnectCounter) {
    this.m_ReconnectCounter = m_ReconnectCounter;
    return 1;
  }

  public int initIIopSwitch() {
    if (m_Down_JndiName.toUpperCase().equals(IIopDefine.INVALID_DEFINE)) {
      this.putMsg( (Object) IIopDefine.INIT_MAIN_IIOP_SENDDATA);
      if (initIIop(IIopDefine.SENDDATA_TYPE, IIopDefine.MAIN_SERVER) < 0) {
        if (initIIop(IIopDefine.SENDDATA_TYPE, IIopDefine.SLAVE_SERVER) < 0) {
          return -1;
        }
      }

      this.putMsg( (Object) IIopDefine.INIT_MAIN_IIOP_EVENT);
      if (initIIop(IIopDefine.EVENT_TYPE, IIopDefine.MAIN_SERVER) < 0) {
        if (initIIop(IIopDefine.EVENT_TYPE, IIopDefine.SLAVE_SERVER) < 0) {
          return -1;
        }
      }
    }
    else {
      this.putMsg( (Object) IIopDefine.INIT_MAIN_IIOP_DOWN);
      if (initIIop(IIopDefine.DOWN_TYPE, IIopDefine.MAIN_SERVER) < 0) {
        if (initIIop(IIopDefine.DOWN_TYPE, IIopDefine.SLAVE_SERVER) < 0) {
          return -1;
        }
      }
    }

    return 1;
  }

  public int adjustIIopSendData(int m_SuccessFlag) {
    if (m_CurSendData == IIopDefine.MAIN_SERVER) {
      if (m_SuccessFlag == IIopDefine.IIOP_EXCEPTION) {
        this.m_IIopSendDataCounter1++;
      }
      else {
        this.m_IIopSendDataCounter1 = 0;
      }

      if (m_IIopSendDataCounter1 >= this.m_ReconnectCounter) {
        IIopDefine.m_IIopSendData1 = IIopDefine.IIOP_DISCONNECT;
        m_IIopSendDataCounter1 = 0;
      }
    }
    else {
      if (m_SuccessFlag == IIopDefine.IIOP_EXCEPTION) {
        this.m_IIopSendDataCounter2++;
      }
      else {
        this.m_IIopSendDataCounter2 = 0;
      }

      if (m_IIopSendDataCounter2 >= this.m_ReconnectCounter) {
        IIopDefine.m_IIopSendData2 = IIopDefine.IIOP_DISCONNECT;
        m_IIopSendDataCounter2 = 0;
      }
    }

    return 1;
  }

  public IIopSendData getIIopSendData() {
    if (IIopDefine.m_IIopSendData1 == IIopDefine.IIOP_CONNECT &&
        IIopDefine.m_IIopSendData2 == IIopDefine.IIOP_CONNECT) {
      if (m_CurSendData == IIopDefine.SLAVE_SERVER) {
        m_CurSendData = IIopDefine.MAIN_SERVER;

        IIopDefine.m_IIopSendData1SendTimes++;
        if (IIopDefine.m_IIopSendData1SendTimes > IIopDefine.MAX_SEND_TIMES) {
          IIopDefine.m_IIopSendData1SendTimes = 0;

        }
        return m_IIopSendData1;
      }
      else {
        m_CurSendData = IIopDefine.SLAVE_SERVER;

        IIopDefine.m_IIopSendData2SendTimes++;
        if (IIopDefine.m_IIopSendData2SendTimes > IIopDefine.MAX_SEND_TIMES) {
          IIopDefine.m_IIopSendData2SendTimes = 0;

        }
        return m_IIopSendData2;
      }
    }
    else if (IIopDefine.m_IIopSendData1 == IIopDefine.IIOP_CONNECT &&
             IIopDefine.m_IIopSendData2 != IIopDefine.IIOP_CONNECT) {
      m_CurSendData = IIopDefine.MAIN_SERVER;

      IIopDefine.m_IIopSendData1SendTimes++;
      if (IIopDefine.m_IIopSendData1SendTimes > IIopDefine.MAX_SEND_TIMES) {
        IIopDefine.m_IIopSendData1SendTimes = 0;

      }
      return m_IIopSendData1;
    }
    else if (IIopDefine.m_IIopSendData1 != IIopDefine.IIOP_CONNECT &&
             IIopDefine.m_IIopSendData2 == IIopDefine.IIOP_CONNECT) {
      m_CurSendData = IIopDefine.SLAVE_SERVER;

      IIopDefine.m_IIopSendData2SendTimes++;
      if (IIopDefine.m_IIopSendData2SendTimes > IIopDefine.MAX_SEND_TIMES) {
        IIopDefine.m_IIopSendData2SendTimes = 0;

      }
      return m_IIopSendData2;
    }
    else {
      return null;
    }

  }

  public int reConnectIIopSendData() {
    try {
      if (IIopDefine.m_IIopSendData1 == IIopDefine.IIOP_DISCONNECT) {
        initIIop(IIopDefine.SENDDATA_TYPE, IIopDefine.MAIN_SERVER);

      }
      if (IIopDefine.m_IIopSendData2 == IIopDefine.IIOP_DISCONNECT) {
        initIIop(IIopDefine.SENDDATA_TYPE, IIopDefine.SLAVE_SERVER);

      }
      return 1;
    }
    catch (Exception m_Exception) {
      this.putMsg( (Object) IIopDefine.RECONNECT_IIOP_ERROR_1);
      return -1;
    }
  }

  public int adjustIIopEvent(int m_SuccessFlag) {
    if (m_CurEvent == IIopDefine.MAIN_SERVER) {
      if (m_SuccessFlag == IIopDefine.IIOP_EXCEPTION) {
        this.m_IIopEventCounter1++;
      }
      else {
        this.m_IIopEventCounter1 = 0;
      }

      if (m_IIopEventCounter1 >= this.m_ReconnectCounter) {
        IIopDefine.m_IIopEvent1 = IIopDefine.IIOP_DISCONNECT;
        m_IIopEventCounter1 = 0;
      }
    }
    else {
      if (m_SuccessFlag == IIopDefine.IIOP_EXCEPTION) {
        this.m_IIopEventCounter2++;
      }
      else {
        this.m_IIopEventCounter2 = 0;
      }

      if (m_IIopEventCounter2 >= this.m_ReconnectCounter) {
        IIopDefine.m_IIopEvent2 = IIopDefine.IIOP_DISCONNECT;
        m_IIopEventCounter2 = 0;
      }
    }

    return 1;
  }

  public IIopEvent getIIopEvent() {
    if (IIopDefine.m_IIopEvent1 == IIopDefine.IIOP_CONNECT &&
        IIopDefine.m_IIopEvent2 == IIopDefine.IIOP_CONNECT) {
      if (m_CurEvent == IIopDefine.SLAVE_SERVER) {
        m_CurEvent = IIopDefine.MAIN_SERVER;

        IIopDefine.m_IIopEvent1SendTimes++;
        if (IIopDefine.m_IIopEvent1SendTimes > IIopDefine.MAX_SEND_TIMES) {
          IIopDefine.m_IIopEvent1SendTimes = 0;

        }
        return m_IIopEvent1;
      }
      else {
        m_CurEvent = IIopDefine.SLAVE_SERVER;

        IIopDefine.m_IIopEvent2SendTimes++;
        if (IIopDefine.m_IIopEvent2SendTimes > IIopDefine.MAX_SEND_TIMES) {
          IIopDefine.m_IIopEvent2SendTimes = 0;

        }
        return m_IIopEvent2;
      }
    }
    else if (IIopDefine.m_IIopEvent1 == IIopDefine.IIOP_CONNECT &&
             IIopDefine.m_IIopEvent2 != IIopDefine.IIOP_CONNECT) {
      m_CurEvent = IIopDefine.MAIN_SERVER;

      IIopDefine.m_IIopEvent1SendTimes++;
      if (IIopDefine.m_IIopEvent1SendTimes > IIopDefine.MAX_SEND_TIMES) {
        IIopDefine.m_IIopEvent1SendTimes = 0;

      }
      return m_IIopEvent1;
    }
    else if (IIopDefine.m_IIopEvent1 != IIopDefine.IIOP_CONNECT &&
             IIopDefine.m_IIopEvent2 == IIopDefine.IIOP_CONNECT) {
      m_CurEvent = IIopDefine.SLAVE_SERVER;

      IIopDefine.m_IIopEvent2SendTimes++;
      if (IIopDefine.m_IIopEvent2SendTimes > IIopDefine.MAX_SEND_TIMES) {
        IIopDefine.m_IIopEvent2SendTimes = 0;

      }
      return m_IIopEvent2;
    }
    else {
      return null;
    }

  }

  public int reConnectIIopEvent() {
    try {
      if (IIopDefine.m_IIopEvent1 == IIopDefine.IIOP_DISCONNECT) {
        initIIop(IIopDefine.EVENT_TYPE, IIopDefine.MAIN_SERVER);

      }
      if (IIopDefine.m_IIopEvent2 == IIopDefine.IIOP_DISCONNECT) {
        initIIop(IIopDefine.EVENT_TYPE, IIopDefine.SLAVE_SERVER);

      }
      return 1;
    }
    catch (Exception m_Exception) {
      this.putMsg( (Object) IIopDefine.RECONNECT_IIOP_ERROR_1);
      return -1;
    }
  }

  public int adjustIIopDown(int m_SuccessFlag) {
    if (m_CurDown == IIopDefine.MAIN_SERVER) {
      if (m_SuccessFlag == IIopDefine.IIOP_EXCEPTION) {
        this.m_IIopDownCounter1++;
      }

⌨️ 快捷键说明

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