Implementing Logon manager on client side to manage the sigon or sign off or Echo.
But getting Class Not found Exception. Please help to resolve this issue.
public class LogonManager extends QBeanSupport implements Runnable, Configurable {
private Space sp = SpaceFactory.
getSpace();
public long echoInterval =600000;
private static Logger
logger = Logger.
getLogger(LogonManager.class);
public QMUX mux = null;
public LogonManager() {
super();
}
@Override
protected void startService() throws Exception {
String muxName = SwitchUtil.
getInstance().getMux(PG.
NETWORK_INTL.name());
mux = (QMUX) NameRegistrar.
getIfExists(muxName);
this.run();
}
@Override
public void run() {
String readyKey = cfg.get("channel-ready");
while (running()) {
getLog().info ("Channel [" + readyKey + "] running ready");
Object sessionId = sp.rd(readyKey, cfg.getLong("timeout"));
getLog().info ("sessionId =" + sessionId);
if (sessionId == null) {
getLog().info ("Channel " + readyKey + " not ready");
NameRegistrar.
register("LOGON"+readyKey, false);
continue;
}
try {
if (!sessionId.equals (sp.rdp ("LOGON"+readyKey))) {
doLogOn();
} else if (sp.rdp ("ECHO"+readyKey) == null) {
doEcho ();
}
} catch (Throwable t) {
getLog().warn (t);
}
ISOUtil.
sleep(10000);
}
}
public void doLogOn() {
try {
String readyKey = cfg.get("channel-ready");
String muxName = SwitchUtil.
getInstance().getMux(PG.
NETWORK_INTL.name());
QMUX qmx = (QMUX) NameRegistrar.
get(muxName);
ISOMsg logOn = createMsg(PG.
NETWORK_INTL.name());
logOn.set(70,"001");
logOn.set(48,"6011002112N007842");
ISOMsg resp = qmx.request(logOn, Long.
parseLong(SwitchUtil
.
getInstance().getTimeOut(PG.
NETWORK_INTL.name())));
logger.debug("LOGIN RESPONSE = [" + resp + "]");
if(resp!=null && resp.getString(39).equals(SwitchConstants.
SUCCESS)) {
logger.info("Logon response from host:"+PG.
NETWORK_INTL.name()+"success");
sp.out ("LOGON", new Object());
NameRegistrar.
register("LOGON"+readyKey, true);
} else {
logger.error("Logon response failure from host:" + PG.
NETWORK_INTL.name());
new SwitchException("Logon Response failure from host:"+PG.
NETWORK_INTL.name());
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
public void doEcho() {
try {
String readyKey = cfg.get("channel-ready");
String muxName = SwitchUtil.
getInstance().getMux(PG.
NETWORK_INTL.name());
QMUX qmx = (QMUX) NameRegistrar.
get(muxName);
ISOMsg resp = qmx.request(createMsg(PG.
NETWORK_INTL.name()), Long.
parseLong(SwitchUtil
.
getInstance().getTimeOut(PG.
NETWORK_INTL.name())));
if (resp != null
&& resp.getString(39).equals(SwitchConstants.
SUCCESS)) {
logger.info("Echo response from host:" + PG.
NETWORK_INTL.name() + "success");
NameRegistrar.
register("LOGON"+readyKey, true);
sp.out ("ECHO", new Object(),echoInterval);
} else {
logger.error("Echo Response failure from host:" + PG.
NETWORK_INTL.name()
+ "Connectivity might be down...");
new SwitchException("Echo Response failure from host:" + PG.
NETWORK_INTL.name()
+ "Connectivity might be down...");
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
private ISOMsg createMsg(String host) throws ISOException {
Date d = new Date();
String gmt = ISODate.
getDateTime(d, TimeZone.
getTimeZone("GMT"));
String stan = getSTAN();
ISOMsg login = new ISOMsg("0800");
login.set(7, gmt);
login.set(11, stan);
login.set(70, "301");
login.setHeader(("ISO026000070").getBytes());
return login;
}
public String getSTAN() throws ISOException {
long stan = SpaceUtil.
nextLong(sp, "stan") + 7400L;
if (stan >= 999999) {
sp.in("stan", 10000);
stan = SpaceUtil.
nextLong(sp, "stan") + 7400L;
}
String sstan = ISOUtil.
padleft((new StringBuffer(String.
valueOf(stan)))
.toString(), 6, '0');
return sstan;
}
private Configuration configuration;
@Override
public void setConfiguration(Configuration configuration) throws ConfigurationException {
this.configuration = configuration;
}
}