use of com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection in project openmq by eclipse-ee4j.
the class GoodbyeTask method run.
@Override
public void run() {
LinkedList list = null;
LinkedList reasonlist = null;
synchronized (GoodbyeTask.class) {
synchronized (this) {
if (nextSet.isEmpty()) {
runner.cancel();
runner = null;
} else {
list = nextSet;
reasonlist = reasonSet;
nextSet = new LinkedList();
reasonSet = new LinkedList();
}
}
}
if (list == null) {
return;
}
Iterator itr = list.iterator();
while (itr.hasNext()) {
ConnectionUID uid = (ConnectionUID) itr.next();
IMQConnection con = (IMQConnection) Globals.getConnectionManager().getConnection(uid);
String reason = null;
try {
reason = (String) reasonlist.removeFirst();
} catch (Exception e) {
logger.log(Logger.DEBUG, "Can't get reason string for destroying connection " + uid);
}
if (reason == null) {
reason = "REASON NOTFOUND";
}
if (con != null && con.isValid()) {
try {
con.destroyConnection(false, GoodbyeReason.CLIENT_CLOSED, reason);
} catch (Exception ex) {
logger.logStack(Logger.DEBUG, "error destroying connection " + con, ex);
}
}
itr.remove();
}
}
use of com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection in project openmq by eclipse-ee4j.
the class ClientIDHandler method setClientID.
public void setClientID(IMQConnection con, String cclientid, String namespace, boolean shared) throws BrokerException {
int status = Status.OK;
String reason = null;
try {
// validate and expand the specified clientID
String clientid = cclientid == null ? null : validate(cclientid, con);
// retrieve the old client id
String oldid = (String) con.getClientData(IMQConnection.CLIENT_ID);
if (DEBUG && oldid != null) {
logger.log(Logger.DEBUG, "ClientIDHandler: replacing clientID " + oldid + " with " + clientid);
}
if (clientid != null && (oldid == null || !oldid.equals(clientid))) {
if (namespace != null) {
// a namespace was specified
// lock the combination of namespace and clientID
String unspace = namespace + "${%%}" + clientid;
int lockstatus = Globals.getClusterBroadcast().lockClientID(unspace, con.getConnectionUID(), false);
if (lockstatus != ClusterBroadcast.LOCK_SUCCESS) {
if (lockstatus == ClusterBroadcast.LOCK_TIMEOUT) {
String emsg = Globals.getBrokerResources().getKString(BrokerResources.X_CLUSTER_CLIENTID_LOCK_REQUEST_TIMEOUT, unspace, con.getRemoteConnectionString());
logger.log(Logger.INFO, emsg);
status = Status.TIMEOUT;
throw new BrokerException(emsg, status);
} else {
// namespace/clientID combination already in use
logger.log(Logger.INFO, BrokerResources.I_CLIENT_ID_IN_USE, con.getRemoteConnectionString(), unspace);
Connection owner = Globals.getConnectionManager().matchProperty(IMQConnection.CLIENT_ID, unspace);
assert owner == null || owner instanceof IMQConnection;
if (owner == null) {
// remote
logger.log(Logger.INFO, BrokerResources.I_RMT_CID_OWNER, unspace);
} else {
logger.log(Logger.INFO, BrokerResources.I_LOCAL_CID_OWNER, unspace, ((IMQConnection) owner).getRemoteConnectionString());
}
reason = "conflict w/ clientID";
status = Status.CONFLICT;
throw new BrokerException(reason, status);
}
}
}
// now lock the clientID itself (whether shared or unshared)
int lockstatus = Globals.getClusterBroadcast().lockClientID(clientid, con.getConnectionUID(), shared);
if (lockstatus != ClusterBroadcast.LOCK_SUCCESS) {
if (lockstatus == ClusterBroadcast.LOCK_TIMEOUT) {
String emsg = Globals.getBrokerResources().getKString(BrokerResources.X_CLUSTER_CLIENTID_LOCK_REQUEST_TIMEOUT, clientid, con.getRemoteConnectionString());
logger.log(Logger.INFO, emsg);
status = Status.TIMEOUT;
throw new BrokerException(emsg, status);
} else {
logger.log(Logger.INFO, BrokerResources.I_CLIENT_ID_IN_USE, con.getRemoteConnectionString(), clientid);
Connection owner = Globals.getConnectionManager().matchProperty(IMQConnection.CLIENT_ID, clientid);
assert owner == null || owner instanceof IMQConnection;
if (owner == null) {
// remote
logger.log(Logger.INFO, BrokerResources.I_RMT_CID_OWNER, clientid);
} else {
logger.log(Logger.INFO, BrokerResources.I_LOCAL_CID_OWNER, clientid, ((IMQConnection) owner).getRemoteConnectionString());
}
reason = "conflict w/ clientID";
status = Status.CONFLICT;
throw new BrokerException(reason, status);
}
}
} else if (oldid != null && !oldid.equals(clientid)) {
/**
* we are explicitly clearing an old clientID unlock the old namespace/clientID combination (assume specified namespace
* is the same as the old one)
*/
String oldunspace = namespace + "${%%}" + oldid;
logger.log(Logger.DEBUG, "ClientIDHandler: " + "removing old namespace/clientID " + oldunspace);
Globals.getClusterBroadcast().unlockClientID(oldunspace, con.getConnectionUID());
// unlock the old clientID
logger.log(Logger.DEBUG, "ClientIDHandler: " + "removing old clientID " + oldid);
Globals.getClusterBroadcast().unlockClientID(oldid, con.getConnectionUID());
// remove the specified clientID from the connection
con.removeClientData(IMQConnection.CLIENT_ID);
}
// save the specified clientID with the connection
if (clientid != null && status != Status.CONFLICT) {
con.addClientData(IMQConnection.CLIENT_ID, clientid);
}
} catch (BrokerException ex) {
if (ex.getStatusCode() == Status.CONFLICT) {
throw ex;
}
if (ex.getStatusCode() == Status.TIMEOUT) {
throw ex;
}
logger.log(Logger.WARNING, BrokerResources.W_CLIENT_ID_INVALID, cclientid, con.toString(), ex);
status = Status.BAD_REQUEST;
reason = ex.getMessage();
throw new BrokerException(reason, ex, status);
} catch (OutOfMemoryError err) {
// throw so it is handled by higher-level memory handling code
throw err;
} catch (Throwable thr) {
logger.log(Logger.WARNING, "unexpected error processing clientid ", thr);
reason = thr.getMessage();
status = Status.ERROR;
throw new BrokerException(reason, thr, status);
}
}
use of com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection in project openmq by eclipse-ee4j.
the class HelloHandler method handle.
/**
* Method to handle HELLO messages
*/
@Override
public boolean handle(IMQConnection con, Packet msg) throws BrokerException {
if (DEBUG) {
logger.log(Logger.DEBUGHIGH, "HelloHandler: handle() [ Received Hello Message]");
}
String reason = null;
Hashtable hello_props = null;
try {
hello_props = msg.getProperties();
} catch (Exception ex) {
logger.logStack(Logger.WARNING, "HELLO Packet.getProperties()", ex);
hello_props = new Hashtable();
}
boolean alreadyStarted = con.isStarted();
boolean alreadyAuthenticated = con.isAuthenticated();
int requestedProtocol = 0;
int highestProtocol = con.getHighestSupportedProtocol();
int lowestProtocol = PacketType.VERSION1;
String expectedClusterID = null;
UID expectedSessionID = null;
ConnectionUID oldCID = null;
Integer bufsize = null;
String destprov = null;
if (hello_props != null) {
Integer level = (Integer) hello_props.get("JMQProtocolLevel");
String clientv = (String) hello_props.get("JMQVersion");
if (DEBUG) {
logger.log(logger.INFO, "HelloHandler.handle(): Client[" + clientv + ", " + level + "] " + con);
}
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 (s != null) {
con.addClientData(IMQConnection.USER_AGENT, s);
}
// currently private property
destprov = (String) hello_props.get("JMQDestinationProvider");
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 && reconnectable.booleanValue());
Long interval = (Long) hello_props.get("JMQInterval");
// LKS - XXX just override for testing
long itime = (interval == null ? ConnectionManager.DEFAULT_RECONNECT_INTERVAL : interval.longValue());
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;
// 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 (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;
}
if (status == Status.OK && destprov != null) {
if (((IMQService) con.getService()).getServiceType() == ServiceType.ADMIN) {
status = Status.BAD_REQUEST;
reason = "JMQDestinationProvider not supported on ADMIN service";
logger.log(logger.WARNING, reason);
} else if (!destprov.equals(CoreLifecycleSpi.GFMQ) && !destprov.equals(CoreLifecycleSpi.CHMP)) {
status = Status.UNSUPPORTED_TYPE;
reason = "Unsupported JMQDestinationProvider " + destprov;
logger.log(logger.WARNING, reason);
} else if (destprov.equals(CoreLifecycleSpi.CHMP) && Globals.getCorePlugin(destprov) == null) {
status = Status.UNSUPPORTED_TYPE;
reason = destprov + " not enabled";
logger.log(logger.WARNING, reason);
}
}
UID brokerSessionID = Globals.getBrokerSessionID();
if (brokerSessionID != null) {
hash.put("JMQBrokerSessionID", Long.valueOf(brokerSessionID.longValue()));
}
// OK, handle the HA properties HERE
String clusterID = null;
UID sessionUID = 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 && !Globals.getDestinationList().isPartitionMode()) {
hash.put("JMQStoreSession", Long.valueOf(sessionUID.longValue()));
}
String list = null;
Iterator itr = null;
if (((IMQService) con.getService()).getServiceType() != ServiceType.ADMIN) {
itr = cfg.getKnownBrokers(false);
} else {
itr = cfg.getKnownBrokers(true);
}
Set s = new HashSet();
// ok get rid of dups
while (itr.hasNext()) {
ClusteredBroker cb = (ClusteredBroker) itr.next();
s.add(cb.getBrokerURL().toString());
}
// OK .. now convert to a string
itr = s.iterator();
while (itr.hasNext()) {
if (list == null) {
list = itr.next().toString();
} else {
list += "," + itr.next().toString();
}
}
if (list != null) {
hash.put("JMQBrokerList", list);
}
}
HAMonitorService hamonitor = Globals.getHAMonitorService();
if (hamonitor != null && hamonitor.inTakeover()) {
if (((IMQService) con.getService()).getServiceType() != ServiceType.ADMIN) {
status = Status.TIMEOUT;
if (oldCID != null) {
logger.log(logger.INFO, BrokerResources.W_IN_TAKEOVER_RECONNECT_LATER, oldCID);
} else {
logger.log(logger.INFO, BrokerResources.W_IN_TAKEOVER_RECONNECT_LATER, con.getConnectionUID());
}
}
}
// first we want to deal with a bad clusterid
if (clusterID != null && expectedClusterID != null && !clusterID.equals(expectedClusterID)) {
status = Status.BAD_REQUEST;
} else if (expectedSessionID != null && sessionUID != null && expectedSessionID.equals(sessionUID)) {
// cool we connected to the right broker
// we already have the right owner
} else if (expectedSessionID != null) {
if (cfg == null) {
// not running any cluster config
logger.log(Logger.WARNING, BrokerResources.E_INTERNAL_BROKER_ERROR, "Internal Error: Received session on" + " non-clustered broker");
status = Status.NOT_FOUND;
} else {
// OK, if we are here, we need to locate the right
// broker for the session
//
// Here are the steps we need to check:
// 1. does this broker support the sessionUID
// if not
// 2. can we locate another broker with the sessionUID
//
ClusteredBroker owner = null;
//
// OK, see if this was a session UID we took over at some
// point in the past
Set s = cfg.getSupportedStoreSessionUIDs();
if (s.contains(expectedSessionID)) {
// yep, we took it over
owner = cfg.getLocalBroker();
}
if (owner == null) {
// this broker isnt supprting the session
// see if the database indicates someone else has it
String ownerString = cfg.lookupStoreSessionOwner(expectedSessionID);
if (ownerString != null) {
owner = cfg.getBroker(ownerString);
}
}
try {
if (owner != null) {
ClusteredBroker creator = null;
String creatorString = cfg.getStoreSessionCreator(expectedSessionID);
if (creatorString != null) {
creator = cfg.getBroker(creatorString);
}
int stat = owner.getStatus();
if (BrokerStatus.getBrokerInDoubt(stat) || !BrokerStatus.getBrokerLinkIsUp(stat) || owner.getState() == BrokerState.FAILOVER_STARTED) {
status = Status.TIMEOUT;
logger.log(logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_RECONNECT_OWNER_INDOUBT, expectedSessionID, owner));
} else if (!owner.isLocalBroker()) {
status = Status.MOVED_PERMANENTLY;
hash.put("JMQStoreOwner", owner.getBrokerURL().toString());
logger.log(logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_RECONNECT_OWNER_NOTME, expectedSessionID, owner));
} else if (creator == null) {
// XXX
status = Status.NOT_FOUND;
logger.log(logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_RECONNECT_NOCREATOR, expectedSessionID));
} else if (creator.getState() == BrokerState.FAILOVER_STARTED) {
status = Status.TIMEOUT;
logger.log(logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_RECONNECT_INTAKEOVER, expectedSessionID));
} else {
// local broker owns us - set owner for debugging only
// not required for protocol
hash.put("JMQStoreOwner", owner.getBrokerURL().toString());
}
} else {
// didnt find owner
status = Status.NOT_FOUND;
logger.log(logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_RECONNECT_OWNER_NOTFOUND, expectedSessionID));
}
} catch (Exception ex) {
logger.log(Logger.WARNING, BrokerResources.W_RECONNECT_ERROR, expectedSessionID.toString(), ex);
status = Status.NOT_FOUND;
}
}
}
if (!con.isAdminConnection() && Globals.getMemManager() != null) {
hash.put("JMQSize", Integer.valueOf(Globals.getMemManager().getJMQSize()));
hash.put("JMQBytes", Long.valueOf(Globals.getMemManager().getJMQBytes()));
hash.put("JMQMaxMsgBytes", Long.valueOf(Globals.getMemManager().getJMQMaxMsgBytes()));
}
hash.put("JMQService", con.getService().getName());
hash.put("JMQConnectionID", Long.valueOf(con.getConnectionUID().longValue()));
hash.put("JMQProtocolLevel", Integer.valueOf(supportedProtocol));
hash.put("JMQVersion", Globals.getVersion().getProductVersion());
if (((IMQBasicConnection) con).getDumpPacket() || ((IMQBasicConnection) con).getDumpOutPacket()) {
hash.put("JMQReqID", msg.getSysMessageID().toString());
}
try {
sessionUID = con.attachStorePartition(expectedSessionID);
if (Globals.getDestinationList().isPartitionMode()) {
hash.put("JMQStoreSession", Long.valueOf(sessionUID.longValue()));
}
} catch (BrokerException e) {
status = e.getStatusCode();
reason = e.getMessage();
if (status == Status.NOT_FOUND) {
logger.log(logger.INFO, e.getMessage());
} else {
logger.logStack(logger.ERROR, e.getMessage(), e);
}
}
hash.put("JMQStatus", Integer.valueOf(status));
if (reason != null) {
hash.put("JMQReason", reason);
}
pkt.setProperties(hash);
con.sendControlMessage(pkt);
// OK .. valid status messages are
if (status != Status.OK && status != Status.MOVED_PERMANENTLY && status != Status.NOT_FOUND && status != Status.TIMEOUT) {
// destroy the connection !!! (should be ok if destroy twice)
con.closeConnection(true, GoodbyeReason.CON_FATAL_ERROR, Globals.getBrokerResources().getKString(BrokerResources.M_INIT_FAIL_CLOSE));
connectionList.removeConnection(con.getConnectionUID(), false, GoodbyeReason.CON_FATAL_ERROR, Globals.getBrokerResources().getKString(BrokerResources.M_INIT_FAIL_CLOSE));
return true;
}
status = Status.UNAVAILABLE;
String authType = null;
if (hello_props != null) {
authType = (String) hello_props.get("JMQAuthType");
}
AccessController ac = con.getAccessController();
pkt = new Packet(con.useDirectBuffers());
pkt.setPacketType(PacketType.AUTHENTICATE_REQUEST);
pkt.setConsumerID(msg.getConsumerID());
hash = new Hashtable();
hash.put("JMQSequence", Integer.valueOf(msg.getSequence()));
hash.put("JMQChallenge", Boolean.TRUE);
Properties props = new Properties();
props.setProperty(Globals.IMQ + ".clientIP", msg.getIPString());
props.setProperty(Globals.IMQ + ".connectionID", con.getConnectionUID().toString());
byte[] req = null;
try {
AuthCacheData acd = ((IMQService) con.getService()).getAuthCacheData();
req = ac.getChallenge(msg.getSequence(), props, acd.getCacheData(), authType);
hash.put("JMQAuthType", ac.getAuthType());
if (con.setConnectionState(Connection.STATE_AUTH_REQUESTED)) {
status = Status.OK;
}
} catch (FailedLoginException e) {
logger.log(Logger.WARNING, e.getMessage(), e);
status = Status.FORBIDDEN;
} catch (OutOfMemoryError err) {
// packet is re-processed
throw err;
} catch (Throwable w) {
logger.log(Logger.ERROR, Globals.getBrokerResources().getKString(BrokerResources.E_GET_CHALLENGE_FAILED) + " - " + w.getMessage(), w);
status = Status.FORBIDDEN;
}
try {
if (destprov != null && !destprov.equals(CoreLifecycleSpi.GFMQ)) {
CoreLifecycleSpi clc = Globals.getCorePlugin(destprov);
((IMQBasicConnection) con).setPacketRouter(clc.getPacketRouter());
con.setCoreLifecycle(clc);
}
} catch (Exception e) {
status = Status.ERROR;
logger.logStack(logger.ERROR, e.getMessage(), e);
}
hash.put("JMQStatus", Integer.valueOf(status));
if (((IMQBasicConnection) con).getDumpPacket() || ((IMQBasicConnection) con).getDumpOutPacket()) {
hash.put("JMQReqID", msg.getSysMessageID().toString());
}
pkt.setProperties(hash);
if (req != null) {
pkt.setMessageBody(req);
}
con.sendControlMessage(pkt);
if (DEBUG) {
logger.log(Logger.DEBUG, "HelloHandler: handle() [ sent challenge ]" + ":status=" + Status.getString(status));
}
if (status != Status.OK && status != Status.MOVED_PERMANENTLY && status != Status.NOT_FOUND && status != Status.TIMEOUT) {
// destroy the connection !!! (should be ok if destroy twice)
con.closeConnection(true, GoodbyeReason.CON_FATAL_ERROR, Globals.getBrokerResources().getKString(BrokerResources.M_INIT_FAIL_CLOSE));
connectionList.removeConnection(con.getConnectionUID(), false, GoodbyeReason.CON_FATAL_ERROR, Globals.getBrokerResources().getKString(BrokerResources.M_INIT_FAIL_CLOSE));
}
return true;
}
use of com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection in project openmq by eclipse-ee4j.
the class Consumer method getAndFillNextPacket.
@Override
public Object getAndFillNextPacket(Packet p) {
PacketReference ref = null;
if (flowPaused || paused) {
checkState(null);
return null;
}
if (!valid) {
return null;
}
if (!paused && msgs.isEmpty()) {
getMoreMessages(prefetch <= 0 ? 1000 : prefetch);
}
Packet newpkt = null;
while (valid && !paused && !msgs.isEmpty()) {
if (FI.FAULT_INJECTION) {
HashMap fips = new HashMap();
fips.put(FaultInjection.DST_NAME_PROP, getDestinationUID().getName());
if (FI.checkFaultAndSleep(FI.FAULT_CONSUMER_SLEEP_BEFORE_MSGS_REMOVE_NEXT, fips)) {
FI.unsetFault(FI.FAULT_CONSUMER_SLEEP_BEFORE_MSGS_REMOVE_NEXT);
}
}
ref = msgs.removeNext();
if (ref == null || ref.isOverrided()) {
int loglevel = (DEBUG_CLUSTER_MSG) ? Logger.INFO : Logger.DEBUG;
logger.log(loglevel, (ref == null) ? "Consumer [" + getConsumerUID() + "] get message null reference" : "Consumer [" + getConsumerUID() + "] message requened: " + ref);
continue;
}
newpkt = ref.getPacket();
boolean expired = ref.isExpired();
if (FI.FAULT_INJECTION) {
HashMap fips = new HashMap();
fips.put(FaultInjection.DST_NAME_PROP, ref.getDestinationUID().getName());
if (FI.checkFault(FI.FAULT_MSG_EXPIRE_AT_DELIVERY, fips)) {
expired = true;
FI.unsetFault(FI.FAULT_MSG_EXPIRE_AT_DELIVERY);
}
}
boolean islocal = ref.isLocal();
boolean remoteDeliveredAck = (!islocal && ref.getMessageDeliveredAck(uid));
if (expired || !ref.checkRemovalAndSetInDelivery(getStoredConsumerUID())) {
if (!expired) {
expired = ref.isExpired();
}
try {
if (expired) {
String cmt = br.getKString(br.I_RM_EXPIRED_MSG_BEFORE_DELIVER_TO_CONSUMER, ref.getSysMessageID(), "[" + uid + ", " + uid.getAckMode() + "]" + dest);
String cmtr = br.getKString(br.I_RM_EXPIRED_REMOTE_MSG_BEFORE_DELIVER_TO_CONSUMER, ref.getSysMessageID(), "[" + uid + ", " + uid.getAckMode() + "]" + dest);
if (ref.markDead(uid, getStoredConsumerUID(), (islocal ? cmt : cmtr), null, RemoveReason.EXPIRED_ON_DELIVERY, -1, null, remoteDeliveredAck)) {
try {
boolean removed = false;
DestinationList DL = Globals.getDestinationList();
Destination[] ds = DL.getDestination(ref.getPartitionedStore(), ref.getDestinationUID());
Destination d = ds[0];
if (d != null) {
if (ref.isDead()) {
removed = d.removeDeadMessage(ref);
} else {
removed = d.removeMessage(ref.getSysMessageID(), RemoveReason.REMOVED_OTHER, !expired);
}
if (removed && expired && DL.getVerbose()) {
logger.log(logger.INFO, (islocal ? cmt : cmtr));
}
}
} finally {
ref.postAcknowledgedRemoval();
}
}
} else {
if (DEBUG) {
logger.log(Logger.INFO, "Message " + ref + (newpkt == null ? "[null]" : "") + " in removal, not deliver to consumer " + this);
}
if (remoteDeliveredAck) {
try {
Map props = new HashMap();
props.put(Consumer.PREFETCH, Integer.valueOf(1));
Globals.getClusterBroadcast().acknowledgeMessage(ref.getBrokerAddress(), ref.getSysMessageID(), uid, ClusterBroadcast.MSG_DELIVERED, props, false);
} catch (Exception e) {
if (DEBUG) {
logger.logStack(Logger.INFO, "Cannot send DELIVERED ack for message " + ref + " for consumer " + uid, e);
}
}
}
}
} catch (Exception ex) {
if (newpkt != null && DEBUG) {
logger.logStack(Logger.INFO, "Unable to cleanup expired message " + ref + " for consumer " + this, ex);
}
}
ref = null;
newpkt = null;
continue;
}
break;
}
if (!valid) {
if (DEBUG_CLUSTER_MSG) {
logger.log(Logger.INFO, "getAndFillNextPacket(): consumer " + this + " closed, discard ref " + ref);
}
return null;
}
if (ref == null) {
checkState(null);
return null;
}
newpkt = ref.getPacket();
if (newpkt == null) {
assert false;
return null;
}
if (p != null) {
try {
p.fill(newpkt);
} catch (IOException ex) {
logger.logStack(Logger.INFO, "Internal Exception processing packet ", ex);
return null;
}
p.setConsumerID(uid.longValue());
ConsumerUID suid = getStoredConsumerUID();
boolean rflag = ref.getRedeliverFlag(suid);
p.setRedelivered(rflag);
int rcnt = ref.getRedeliverCount(suid) + 1;
if (rflag) {
if (rcnt < 2) {
rcnt = 2;
}
}
if (DEBUG) {
logger.log(Logger.INFO, "Consumer.getAndFillNextPacket: Set DeliveryCount to " + rcnt + " for message " + ref + " for consumer " + this);
}
p.setDeliveryCount(rcnt);
if (ref.isLast(uid)) {
ref.removeIsLast(uid);
p.setIsLast(true);
}
msgRetrieved();
if (parent != null) {
// hey, we pulled one from the durable too
parent.msgRetrieved();
}
} else {
newpkt.setRedelivered(ref.getRedeliverFlag(getStoredConsumerUID()));
}
if (useConsumerFlowControl) {
if (prefetch != -1) {
flowCount++;
}
if (!flowPaused && ref.getMessageDeliveredAck(uid)) {
BrokerAddress addr = ref.getBrokerAddress();
if (addr != null) {
// do we have a remove
synchronized (remotePendingResumes) {
remotePendingResumes.add(ref);
}
} else {
}
if (p != null) {
p.setConsumerFlow(true);
}
}
if (prefetch > 0 && flowCount >= prefetch) {
if (p != null) {
p.setConsumerFlow(true);
}
ref.addMessageDeliveredAck(uid);
BrokerAddress addr = ref.getBrokerAddress();
if (addr != null) {
// do we have a remove
synchronized (remotePendingResumes) {
remotePendingResumes.add(ref);
}
}
pauseFlowCnt++;
flowPaused = true;
}
} else if (ref.getMessageDeliveredAck(uid)) {
HashMap props = null;
ConnectionUID cuid = getConnectionUID();
if (cuid != null) {
IMQConnection con = (IMQConnection) Globals.getConnectionManager().getConnection(cuid);
if (con != null) {
props = new HashMap();
props.put(Consumer.PREFETCH, Integer.valueOf(con.getFlowCount()));
}
}
try {
Globals.getClusterBroadcast().acknowledgeMessage(ref.getBrokerAddress(), ref.getSysMessageID(), uid, ClusterBroadcast.MSG_DELIVERED, props, false);
} catch (BrokerException ex) {
logger.log(Logger.DEBUG, "Can not send DELIVERED ack " + " received ", ex);
}
ref.removeMessageDeliveredAck(uid);
}
return ref;
}
use of com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection in project openmq by eclipse-ee4j.
the class ConnectionUtil method getConsumerIDs.
public static List getConsumerIDs(long cxnId) {
ConnectionManager cm = Globals.getConnectionManager();
IMQConnection cxn = null;
List consumerIDs;
cxn = (IMQConnection) cm.getConnection(new ConnectionUID(cxnId));
consumerIDs = cxn.getConsumersIDs();
return (consumerIDs);
}
Aggregations