use of com.pamirs.pradar.event.PradarSwitchEvent in project LinkAgent by shulieTech.
the class ZookeeperRegister method init.
@Override
public void init(RegisterOptions registerOptions) {
if (registerOptions == null) {
throw new NullPointerException("RegisterOptions is null");
}
this.basePath = registerOptions.getRegisterBasePath();
this.appName = registerOptions.getAppName();
this.md5 = registerOptions.getMd5();
this.simulatorConfig = registerOptions.getSimulatorConfig();
if (LOGGER.isInfoEnabled()) {
LOGGER.info("[pradar-register] prepare to init register zookeeper node. {}", Pradar.AGENT_ID_CONTAIN_USER_INFO);
}
String registerBasePath = null;
if (StringUtils.endsWith(basePath, "/")) {
registerBasePath = this.basePath + appName;
} else {
registerBasePath = this.basePath + '/' + appName;
}
try {
ZkClientSpec zkClientSpec = new ZkClientSpec();
zkClientSpec.setZkServers(registerOptions.getZkServers());
zkClientSpec.setConnectionTimeoutMillis(registerOptions.getConnectionTimeoutMillis());
zkClientSpec.setSessionTimeoutMillis(registerOptions.getSessionTimeoutMillis());
zkClientSpec.setThreadName("heartbeat");
this.zkClient = NetflixCuratorZkClientFactory.getInstance().create(zkClientSpec);
} catch (PradarException e) {
LOGGER.error("[pradar-register] ZookeeperRegister init error.", e);
throw e;
} catch (Throwable e) {
LOGGER.error("[pradar-register] ZookeeperRegister init error.", e);
throw new PradarException(e);
}
String client = Pradar.AGENT_ID_CONTAIN_USER_INFO;
try {
this.zkClient.ensureDirectoryExists(registerBasePath);
} catch (Throwable e) {
LOGGER.error("[register] ensureDirectoryExists err:{}", registerBasePath, e);
}
this.heartbeatPath = registerBasePath + '/' + client;
try {
if (this.zkClient.exists(this.heartbeatPath)) {
this.zkClient.deleteQuietly(this.heartbeatPath);
}
} catch (Throwable e) {
}
cleanExpiredNodes(registerBasePath);
this.heartbeatNode = this.zkClient.createHeartbeatNode(this.heartbeatPath);
PradarSwitcher.registerListener(new PradarSwitcher.PradarSwitcherListener() {
@Override
public void onListen(Event event) {
if (event instanceof PradarSwitchEvent || event instanceof ErrorEvent) {
refresh();
}
}
});
if (LOGGER.isInfoEnabled()) {
LOGGER.info("[pradar-register] init register zookeeper node successful. {}", Pradar.AGENT_ID_CONTAIN_USER_INFO);
}
}
use of com.pamirs.pradar.event.PradarSwitchEvent in project LinkAgent by shulieTech.
the class PradarSwitcher method turnConfigSwitcherOn.
public static void turnConfigSwitcherOn(String configName) {
configSwitchers.get(configName);
Boolean oldValue = configSwitchers.put(configName, Boolean.TRUE);
if (oldValue != null && !oldValue) {
for (PradarSwitcherListener listener : listeners) {
listener.onListen(new PradarSwitchEvent(isClusterTestEnabled(), getClusterTestUnableReason()));
}
}
}
use of com.pamirs.pradar.event.PradarSwitchEvent in project LinkAgent by shulieTech.
the class PradarSwitcher method turnConfigSwitcherOff.
public static void turnConfigSwitcherOff(String configName) {
Boolean oldValue = configSwitchers.get(configName);
configSwitchers.put(configName, Boolean.FALSE);
if (oldValue == null || oldValue) {
for (PradarSwitcherListener listener : listeners) {
listener.onListen(new PradarSwitchEvent(isClusterTestEnabled(), getClusterTestUnableReason()));
}
}
}
use of com.pamirs.pradar.event.PradarSwitchEvent in project LinkAgent by shulieTech.
the class PradarSwitcher method invalid.
public static synchronized void invalid() {
boolean before = isClusterTestEnabled();
LOGGER.info("Cluster Tester is force closed....");
isValid = false;
boolean after = isClusterTestEnabled();
if (before != after) {
for (PradarSwitcherListener listener : listeners) {
listener.onListen(new PradarSwitchEvent(after, "Cluster Tester is force closed...."));
}
}
}
use of com.pamirs.pradar.event.PradarSwitchEvent in project LinkAgent by shulieTech.
the class PradarSwitcher method clusterTestPrepare.
/**
* 设置压测环境没有准备完成
*/
public static void clusterTestPrepare() {
/**
* 只要有一次 ready 则不会再 prepare
*/
if (isClusterTestReady) {
return;
}
boolean before = isClusterTestEnabled();
isClusterTestReady = false;
boolean after = isClusterTestEnabled();
if (before != after) {
for (PradarSwitcherListener listener : listeners) {
listener.onListen(new PradarSwitchEvent(after, getClusterTestUnableReason()));
}
}
}
Aggregations