int requestedProtocol = 0;
int highestProtocol = con.getHighestSupportedProtocol();
int lowestProtocol = PacketType.VERSION1;
String expectedClusterID = null;
UID expectedSessionID = null;
ConnectionUID oldCID = null;
Integer bufsize = null;
boolean badClientType = false;
if (hello_props != null) {
Integer level = (Integer)hello_props.get("JMQProtocolLevel");
if (level == null) {
requestedProtocol=PacketType.VERSION1;
} else {
requestedProtocol=level.intValue();
}
bufsize = (Integer)hello_props.get("JMQSize");
if (bufsize == null) { //XXX try old protocol
bufsize = (Integer)hello_props.get("JMQRBufferSize");
}
// Retrieve HA related properties
Long longUID = (Long)hello_props.get("JMQStoreSession");
if (longUID != null) {
expectedSessionID = new UID(longUID.longValue());
}
expectedClusterID = (String)hello_props.get("JMQClusterID");
Boolean reconnectable = (Boolean)hello_props.get("JMQReconnectable");
Boolean haclient = (Boolean)hello_props.get("JMQHAClient");
if (Globals.getHAEnabled() && haclient != null && haclient.booleanValue()) {
reconnectable = haclient;
}
String s = (String)hello_props.get("JMQUserAgent");
if (!ALLOW_C_CLIENTS && s != null && s.indexOf("C;") != -1) {
badClientType = true;
}
if (s != null) {
con.addClientData(IMQConnection.USER_AGENT, s);
}
longUID = (Long)hello_props.get("JMQConnectionID");
if (longUID != null) {
logger.log(Logger.DEBUG,"Have old connectionUID");
oldCID = new ConnectionUID(longUID.longValue());
logger.log(Logger.INFO,
BrokerResources.I_RECONNECTING, oldCID);
logger.log(Logger.DEBUG,"Checking for active connection");
Connection oldcon = Globals.getConnectionManager().getConnection(oldCID);
DUMP("Before connection Destroy");
if (oldcon != null) {
logger.log(Logger.DEBUG,"Destroying old connection " + oldCID);
oldcon.destroyConnection(true,GoodbyeReason.ADMIN_KILLED_CON, "Destroying old connection with same connectionUID " + oldCID + " - reconnect is happening before connection was reaped");
}
/* LKS
DUMP();
logger.log(Logger.DEBUG,"Updating connection in id list " +
"["+oldcid + "," + uid + "]");
// old code
con.setConnectionUID(oldcid);
Globals.getConnectionManager().updateConnectionUID(
oldcid, uid);
//Globals.getConnectionManager().updateConnectionUID(
// uid, oldcid);
*/
DUMP("After Connection Destroy");
}
con.getConnectionUID().setCanReconnect(reconnectable == null ? false :
reconnectable.booleanValue());
Long interval = (Long)hello_props.get("JMQInterval");
// LKS - XXX just override for testing
long itime = interval == null ? 10000 : interval.intValue();
con.setReconnectInterval(itime);
} else {
requestedProtocol=PacketType.VERSION1;
}
int supportedProtocol = 0;
if (requestedProtocol > highestProtocol) {
supportedProtocol = highestProtocol;
} else if (requestedProtocol < lowestProtocol) {
supportedProtocol = lowestProtocol;
} else {
supportedProtocol = requestedProtocol;
}
con.setClientProtocolVersion(supportedProtocol);
if (bufsize != null) {
logger.log(Logger.DEBUG, "Received JMQRBufferSize -" + bufsize);
con.setFlowCount(bufsize.intValue());
}
Packet pkt = new Packet(con.useDirectBuffers());
pkt.setPacketType(PacketType.HELLO_REPLY);
pkt.setConsumerID(msg.getConsumerID());
Hashtable hash = new Hashtable();
reason = "unavailable";
int status = Status.UNAVAILABLE;
// If the connection's remote IP address was not set by the
// protocol, then use the IP in the message packet.
if (con.getRemoteIP() == null) {
con.setRemoteIP(msg.getIP());
}
if ((alreadyAuthenticated || alreadyStarted)
&& !msg.getIndempotent() ) { // handle ibit
status = Status.ERROR;
reason = "Connection reuse not allowed";
if (alreadyAuthenticated) {
logger.log(Logger.WARNING,"Internal Error: " +
" received HELLO on already authenticated connection "
+ con.getRemoteConnectionString() +
" " + con.getConnectionUID());
} else {
logger.log(Logger.WARNING,"Internal Error: " +
" received HELLO on already started connection "
+ con.getRemoteConnectionString() +
" " + con.getConnectionUID());
}
} else if (badClientType) {
logger.log(Logger.ERROR, rb.E_FEATURE_UNAVAILABLE,
Globals.getBrokerResources().getString(
BrokerResources.M_C_API));
reason = "C clients not allowed on this version";
status = Status.UNAVAILABLE;
} else if (!CAN_RECONNECT && con.getConnectionUID().getCanReconnect()) {
logger.log(Logger.ERROR, rb.E_FEATURE_UNAVAILABLE,
Globals.getBrokerResources().getString(
BrokerResources.M_CLIENT_FAILOVER));
reason = "Client Failover not allowed on this version";
} else if (requestedProtocol != supportedProtocol) {
// Bad protocol level.
logger.log(Logger.WARNING, rb.W_BAD_PROTO_VERSION,
Integer.toString(requestedProtocol),
Integer.toString(supportedProtocol));
reason = "bad version";
status = Status.BAD_VERSION;
} else if (con.getConnectionState() != Connection.STATE_UNAVAILABLE) {
/**
* connection may not be able to be created e.g:
* licensing, being destroyed (e.g due to timeout)
*/
if (con.setConnectionState(Connection.STATE_INITIALIZED)) {
reason = null;
status = Status.OK;
} else {
status = Status.UNAVAILABLE;
}
} else {
status = Status.UNAVAILABLE;
}
UID brokerSessionID = Globals.getBrokerSessionID();
if (brokerSessionID!=null){
hash.put("JMQBrokerSessionID",new Long(brokerSessionID.longValue()));
}
// OK, handle the HA properties HERE
String clusterID = null;
UID sessionUID = null;
Set supportedSessions = null;
ClusterManager cfg = Globals.getClusterManager();
if (cfg != null) {
clusterID = cfg.getClusterId();
sessionUID = cfg.getStoreSessionUID();
hash.put("JMQHA",Boolean.valueOf(cfg.isHA()));
if (clusterID != null) {
hash.put("JMQClusterID", clusterID);
}
if (sessionUID != null) {
hash.put("JMQStoreSession",new Long(sessionUID.longValue()));
}
String list = null;
Iterator itr = null;
if (((IMQService)con.getService()).getServiceType() != ServiceType.ADMIN) {