?? jmsswitch.java
字號:
/*
* JmsSwitch.java
*
* Created on 2003年12月15日, 下午6:15
*/
package collector.jms;
import java.util.*;
/**
*
* @author WangJun
*/
public class JmsSwitch {
private JmsFront m_JmsFront1 = null;
private JmsFront m_JmsFront2 = null;
private String m_LocalHostName = "";
private boolean m_JmsFront1Flag = false;
private boolean m_JmsFront2Flag = false;
private int m_JmsFront1Counter = 0;
private int m_JmsFront2Counter = 0;
private String m_AppserverType = "";
private String m_JmsInitContextFactory = "";
private String m_JmsURL1 = "";
private String m_JmsPort1 = "";
private String m_JmsURL2 = "";
private String m_JmsPort2 = "";
private String m_JmsFrontTopicFactory = "";
private String m_JmsFrontTopic = "";
private ArrayList m_ArrayList = null;
private int m_MachineSwitchWaitCounter = 5;
/** Creates a new instance of JmsSwitch */
public JmsSwitch() {
m_ArrayList = new ArrayList();
}
public JmsSwitch(String m_LocalHostName) {
this.m_LocalHostName = m_LocalHostName;
m_ArrayList = new ArrayList();
}
public int setJmsParam(String m_AppserverType, String m_JmsInitContextFactory,
String m_JmsURL1, String m_JmsPort1,
String m_JmsURL2, String m_JmsPort2) {
this.m_AppserverType = m_AppserverType;
this.m_JmsInitContextFactory = m_JmsInitContextFactory;
this.m_JmsURL1 = m_JmsURL1;
this.m_JmsPort1 = m_JmsPort1;
this.m_JmsURL2 = m_JmsURL2;
this.m_JmsPort2 = m_JmsPort2;
return 1;
}
public int setJmsFrontParam(String m_JmsFrontTopicFactory,
String m_JmsFrontTopic) {
this.m_JmsFrontTopicFactory = m_JmsFrontTopicFactory;
this.m_JmsFrontTopic = m_JmsFrontTopic;
return 1;
}
public int setMachineSwitchWaitCounter(int m_MachineSwitchWaitCounter) {
this.m_MachineSwitchWaitCounter = m_MachineSwitchWaitCounter;
return 1;
}
public int initJmsSwitch() {
this.putMsg( (Object) JmsDefine.INIT_MAIN_JMSCOMM);
this.putMsg( (Object) JmsDefine.INIT_MAIN_JMSFRONT);
this.m_JmsFront1 = new JmsFront(this.m_LocalHostName);
if (this.m_JmsFront1.initJMS(this.m_AppserverType,
this.m_JmsInitContextFactory, this.m_JmsURL1,
m_JmsPort1, this.m_JmsFrontTopicFactory,
this.m_JmsFrontTopic) < 0) {
this.putMsg( (Object) JmsDefine.MAIN_SERVER_SHUTDOWN);
m_JmsFront1Flag = false;
JmsDefine.m_CurJmsFront1 = JmsDefine.JMS_DISCONNECT;
}
else {
m_JmsFront1Flag = true;
JmsDefine.m_CurJmsFront1 = JmsDefine.JMS_CONNECT;
}
this.m_JmsFront2 = new JmsFront(this.m_LocalHostName);
if (this.m_JmsFront2.initJMS(this.m_AppserverType,
this.m_JmsInitContextFactory, this.m_JmsURL2,
this.m_JmsPort2, this.m_JmsFrontTopicFactory,
this.m_JmsFrontTopic) < 0) {
this.putMsg( (Object) JmsDefine.SLAVE_SERVER_JMSFRONT_SHUTDOWN);
m_JmsFront2Flag = false;
JmsDefine.m_CurJmsFront2 = JmsDefine.JMS_DISCONNECT;
}
else {
m_JmsFront2Flag = true;
JmsDefine.m_CurJmsFront2 = JmsDefine.JMS_CONNECT;
}
return 1;
}
public int close(int m_JmsHost) {
if (m_JmsHost == JmsDefine.m_JmsHost1) {
this.m_JmsFront1.close();
}
else if (m_JmsHost == JmsDefine.m_JmsHost2) {
this.m_JmsFront2.close();
}
return 1;
}
public int reConnectJMSFront() {
try {
if (JmsDefine.m_CurJmsFront1 == JmsDefine.JMS_DISCONNECT) {
if (this.m_JmsFront1Flag != true) {
close(JmsDefine.m_JmsHost1);
this.m_JmsFront1 = new JmsFront(this.m_LocalHostName);
if (this.m_JmsFront1.initJMS(this.m_AppserverType,
this.m_JmsInitContextFactory,
this.m_JmsURL1,
m_JmsPort1, this.m_JmsFrontTopicFactory,
this.m_JmsFrontTopic) < 0) {
JmsDefine.m_CurJmsFront1 = JmsDefine.JMS_DISCONNECT;
this.putMsg( (Object) JmsDefine.
CONNECT_MAIN_SERVER_JMSFRONT_FAILURE);
}
else {
// this.m_JmsFront1Flag = true;
JmsDefine.m_CurJmsFront1 = JmsDefine.JMS_CONNECT;
this.putMsg( (Object) JmsDefine.
CONNECT_MAIN_SERVER_JMSFRONT_SUCCESS);
}
}
else {
close(JmsDefine.m_JmsHost1);
// if (this.m_JmsFront1.reConnect () > 0 )
if (this.m_JmsFront1.initJMS(this.m_AppserverType,
this.m_JmsInitContextFactory,
this.m_JmsURL1,
m_JmsPort1, this.m_JmsFrontTopicFactory,
this.m_JmsFrontTopic) > 0) {
this.putMsg( (Object) JmsDefine.
RECONNECT_MAIN_SEREVR_JMSFRONT_SUCCESS);
JmsDefine.m_CurJmsFront1 = JmsDefine.JMS_CONNECT;
}
else {
JmsDefine.m_CurJmsFront1 = JmsDefine.JMS_DISCONNECT;
this.putMsg( (Object) JmsDefine.
RECONNECT_MAIN_SERVER_JMSFRONT_FAILURE);
}
}
}
if (JmsDefine.m_CurJmsFront2 == JmsDefine.JMS_DISCONNECT) {
if (this.m_JmsFront2Flag != true) {
close(JmsDefine.m_JmsHost2);
this.m_JmsFront2 = new JmsFront(this.m_LocalHostName);
if (this.m_JmsFront2.initJMS(this.m_AppserverType,
this.m_JmsInitContextFactory,
this.m_JmsURL2,
this.m_JmsPort2,
this.m_JmsFrontTopicFactory,
this.m_JmsFrontTopic) < 0) {
JmsDefine.m_CurJmsFront2 = JmsDefine.JMS_DISCONNECT;
this.putMsg( (Object) JmsDefine.
CONNECT_SLAVE_SERVER_JMSFRONT_FAILURE);
}
else {
// this.m_JmsFront2Flag = true;
JmsDefine.m_CurJmsFront2 = JmsDefine.JMS_CONNECT;
this.putMsg( (Object) JmsDefine.
CONNECT_SLAVE_SERVER_JMSFRONT_SUCCESS);
}
}
else {
close(JmsDefine.m_JmsHost2);
// if (this.m_JmsFront2.reConnect () > 0 )
if (this.m_JmsFront2.initJMS(this.m_AppserverType,
this.m_JmsInitContextFactory,
this.m_JmsURL2,
m_JmsPort2, this.m_JmsFrontTopicFactory,
this.m_JmsFrontTopic) > 0) {
JmsDefine.m_CurJmsFront2 = JmsDefine.JMS_CONNECT;
this.putMsg( (Object) JmsDefine.
RECONNECT_SLAVE_SEREVR_JMSFRONT_SUCCESS);
}
else {
JmsDefine.m_CurJmsFront2 = JmsDefine.JMS_DISCONNECT;
this.putMsg( (Object) JmsDefine.
RECONNECT_SLAVE_SERVER_JMSCOMM_FAILURE);
}
}
}
return 1;
}
catch (Exception m_Exception) {
this.putMsg( (Object) JmsDefine.RECONNECT_JMSfRONT_ERROR_1);
return -1;
}
}
public JmsFront getJmsFront1() {
if (JmsDefine.m_CurJmsFront1 == JmsDefine.JMS_CONNECT) {
JmsDefine.m_JmsFront1SendTimes = this.m_JmsFront1.getSendTimes();
JmsDefine.m_JmsFront1RecTimes = this.m_JmsFront1.getRecTimes();
return this.m_JmsFront1;
}
else {
return null;
}
}
public JmsFront getJmsFront2() {
if (JmsDefine.m_CurJmsFront2 == JmsDefine.JMS_CONNECT) {
JmsDefine.m_JmsFront2SendTimes = this.m_JmsFront2.getSendTimes();
JmsDefine.m_JmsFront2RecTimes = this.m_JmsFront2.getRecTimes();
return this.m_JmsFront2;
}
else {
return null;
}
}
public int adjustJmsFront1(int m_SuccessFlag) {
if (m_SuccessFlag == JmsDefine.JMS_EXCEPTION) {
this.m_JmsFront1Counter++;
}
else {
this.m_JmsFront1Counter = 0;
}
if (m_JmsFront1Counter >= this.m_MachineSwitchWaitCounter) {
JmsDefine.m_CurJmsFront1 = JmsDefine.JMS_DISCONNECT;
m_JmsFront1Counter = 0;
}
return 1;
}
public int adjustJmsFront2(int m_SuccessFlag) {
if (m_SuccessFlag == JmsDefine.JMS_EXCEPTION) {
this.m_JmsFront2Counter++;
}
else {
this.m_JmsFront2Counter = 0;
}
if (m_JmsFront2Counter >= this.m_MachineSwitchWaitCounter) {
JmsDefine.m_CurJmsFront2 = JmsDefine.JMS_DISCONNECT;
m_JmsFront2Counter = 0;
}
return 1;
}
public Object getMsg() {
if (this.m_ArrayList.size() <= 0) {
return null;
}
else {
return (Object)this.m_ArrayList.remove(0);
}
}
public int getMsgNum() {
return this.m_ArrayList.size();
}
public int putMsg(Object m_Object) {
this.m_ArrayList.add(m_Object);
return 1;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -