check we don't through null pointer exceptions - as this can lead to stack overflows ...

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@490174 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2006-12-25 21:05:57 +00:00
parent c651ace525
commit e6a418b13b
1 changed files with 213 additions and 113 deletions

View File

@ -177,174 +177,274 @@ public class ConnectionStateTracker implements CommandVisitor {
} }
} }
public Response processAddDestination(DestinationInfo info) throws Exception { public Response processAddDestination(DestinationInfo info) {
ConnectionState cs = (ConnectionState) connectionStates.get(info.getConnectionId()); ConnectionState cs = (ConnectionState) connectionStates.get(info.getConnectionId());
if( info.getDestination().isTemporary() ) { if( cs != null && info != null && info.getDestination().isTemporary() ) {
cs.addTempDestination(info); cs.addTempDestination(info);
} }
return TRACKED_RESPONSE_MARKER; return TRACKED_RESPONSE_MARKER;
} }
public Response processRemoveDestination(DestinationInfo info) throws Exception { public Response processRemoveDestination(DestinationInfo info) {
ConnectionState cs = (ConnectionState) connectionStates.get(info.getConnectionId()); ConnectionState cs = (ConnectionState) connectionStates.get(info.getConnectionId());
if( info.getDestination().isTemporary() ) { if( cs != null && info != null && info.getDestination().isTemporary() ) {
cs.removeTempDestination(info.getDestination()); cs.removeTempDestination(info.getDestination());
} }
return TRACKED_RESPONSE_MARKER; return TRACKED_RESPONSE_MARKER;
} }
public Response processAddProducer(ProducerInfo info) throws Exception { public Response processAddProducer(ProducerInfo info){
SessionId sessionId = info.getProducerId().getParentId(); if(info!=null&&info.getProducerId()!=null){
ConnectionId connectionId = sessionId.getParentId(); SessionId sessionId=info.getProducerId().getParentId();
ConnectionState cs = (ConnectionState) connectionStates.get(connectionId); if(sessionId!=null){
SessionState ss = cs.getSessionState(sessionId); ConnectionId connectionId=sessionId.getParentId();
ss.addProducer(info); if(connectionId!=null){
ConnectionState cs=(ConnectionState)connectionStates.get(connectionId);
if(cs!=null){
SessionState ss=cs.getSessionState(sessionId);
if(ss!=null){
ss.addProducer(info);
}
}
}
}
}
return TRACKED_RESPONSE_MARKER; return TRACKED_RESPONSE_MARKER;
} }
public Response processRemoveProducer(ProducerId id) throws Exception { public Response processRemoveProducer(ProducerId id){
SessionId sessionId = id.getParentId(); if(id!=null){
ConnectionId connectionId = sessionId.getParentId(); SessionId sessionId=id.getParentId();
ConnectionState cs = (ConnectionState) connectionStates.get(connectionId); if(sessionId!=null){
SessionState ss = cs.getSessionState(sessionId); ConnectionId connectionId=sessionId.getParentId();
ss.removeProducer(id); if(connectionId!=null){
ConnectionState cs=(ConnectionState)connectionStates.get(connectionId);
if(cs!=null){
SessionState ss=cs.getSessionState(sessionId);
if(ss!=null){
ss.removeProducer(id);
}
}
}
}
}
return TRACKED_RESPONSE_MARKER; return TRACKED_RESPONSE_MARKER;
} }
public Response processAddConsumer(ConsumerInfo info) throws Exception { public Response processAddConsumer(ConsumerInfo info){
SessionId sessionId = info.getConsumerId().getParentId(); if(info!=null){
ConnectionId connectionId = sessionId.getParentId(); SessionId sessionId=info.getConsumerId().getParentId();
ConnectionState cs = (ConnectionState) connectionStates.get(connectionId); if(sessionId!=null){
SessionState ss = cs.getSessionState(sessionId); ConnectionId connectionId=sessionId.getParentId();
ss.addConsumer(info); if(connectionId!=null){
ConnectionState cs=(ConnectionState)connectionStates.get(connectionId);
if(cs!=null){
SessionState ss=cs.getSessionState(sessionId);
if(ss!=null){
ss.addConsumer(info);
}
}
}
}
}
return TRACKED_RESPONSE_MARKER; return TRACKED_RESPONSE_MARKER;
} }
public Response processRemoveConsumer(ConsumerId id) throws Exception { public Response processRemoveConsumer(ConsumerId id){
SessionId sessionId = id.getParentId(); if(id!=null){
ConnectionId connectionId = sessionId.getParentId(); SessionId sessionId=id.getParentId();
ConnectionState cs = (ConnectionState) connectionStates.get(connectionId); if(sessionId!=null){
SessionState ss = cs.getSessionState(sessionId); ConnectionId connectionId=sessionId.getParentId();
ss.removeConsumer(id); if(connectionId!=null){
ConnectionState cs=(ConnectionState)connectionStates.get(connectionId);
if(cs!=null){
SessionState ss=cs.getSessionState(sessionId);
if(ss!=null){
ss.removeConsumer(id);
}
}
}
}
}
return TRACKED_RESPONSE_MARKER; return TRACKED_RESPONSE_MARKER;
} }
public Response processAddSession(SessionInfo info) throws Exception { public Response processAddSession(SessionInfo info){
ConnectionId connectionId = info.getSessionId().getParentId(); if(info!=null){
ConnectionState cs = (ConnectionState) connectionStates.get(connectionId); ConnectionId connectionId=info.getSessionId().getParentId();
cs.addSession(info); if(connectionId!=null){
ConnectionState cs=(ConnectionState)connectionStates.get(connectionId);
if(cs!=null){
cs.addSession(info);
}
}
}
return TRACKED_RESPONSE_MARKER; return TRACKED_RESPONSE_MARKER;
} }
public Response processRemoveSession(SessionId id) throws Exception { public Response processRemoveSession(SessionId id){
ConnectionId connectionId = id.getParentId(); if(id!=null){
ConnectionState cs = (ConnectionState) connectionStates.get(connectionId); ConnectionId connectionId=id.getParentId();
cs.removeSession(id); if(connectionId!=null){
ConnectionState cs=(ConnectionState)connectionStates.get(connectionId);
if(cs!=null){
cs.removeSession(id);
}
}
}
return TRACKED_RESPONSE_MARKER; return TRACKED_RESPONSE_MARKER;
} }
public Response processAddConnection(ConnectionInfo info) throws Exception { public Response processAddConnection(ConnectionInfo info){
connectionStates.put(info.getConnectionId(), new ConnectionState(info)); if (info != null) {
connectionStates.put(info.getConnectionId(), new ConnectionState(info));
}
return TRACKED_RESPONSE_MARKER; return TRACKED_RESPONSE_MARKER;
} }
public Response processRemoveConnection(ConnectionId id) throws Exception { public Response processRemoveConnection(ConnectionId id) throws Exception {
if (id != null) {
connectionStates.remove(id); connectionStates.remove(id);
}
return TRACKED_RESPONSE_MARKER; return TRACKED_RESPONSE_MARKER;
} }
public Response processRemoveSubscription(RemoveSubscriptionInfo info) throws Exception { public Response processRemoveSubscription(RemoveSubscriptionInfo info) throws Exception {
return null; return null;
} }
public Response processMessage(Message send) throws Exception {
if( trackTransactions && send.getTransactionId() != null ) { public Response processMessage(Message send) throws Exception{
ConnectionId connectionId = send.getProducerId().getParentId().getParentId(); if(trackTransactions&&send!=null&&send.getTransactionId()!=null){
ConnectionState cs = (ConnectionState) connectionStates.get(connectionId); ConnectionId connectionId=send.getProducerId().getParentId().getParentId();
TransactionState transactionState = cs.getTransactionState(send.getTransactionId()); if(connectionId!=null){
transactionState.addCommand(send); ConnectionState cs=(ConnectionState)connectionStates.get(connectionId);
if(cs!=null){
TransactionState transactionState=cs.getTransactionState(send.getTransactionId());
if(transactionState!=null){
transactionState.addCommand(send);
}
}
}
return TRACKED_RESPONSE_MARKER; return TRACKED_RESPONSE_MARKER;
} }
return null; return null;
} }
public Response processMessageAck(MessageAck ack) throws Exception {
if( trackTransactions && ack.getTransactionId() != null ) { public Response processMessageAck(MessageAck ack){
ConnectionId connectionId = ack.getConsumerId().getParentId().getParentId(); if(trackTransactions&&ack!=null&&ack.getTransactionId()!=null){
ConnectionState cs = (ConnectionState) connectionStates.get(connectionId); ConnectionId connectionId=ack.getConsumerId().getParentId().getParentId();
TransactionState transactionState = cs.getTransactionState(ack.getTransactionId()); if(connectionId!=null){
transactionState.addCommand(ack); ConnectionState cs=(ConnectionState)connectionStates.get(connectionId);
if(cs!=null){
TransactionState transactionState=cs.getTransactionState(ack.getTransactionId());
if(transactionState!=null){
transactionState.addCommand(ack);
}
}
}
return TRACKED_RESPONSE_MARKER; return TRACKED_RESPONSE_MARKER;
} }
return null; return null;
} }
public Response processBeginTransaction(TransactionInfo info) throws Exception { public Response processBeginTransaction(TransactionInfo info){
if( trackTransactions ) { if(trackTransactions&&info!=null && info.getTransactionId() != null){
ConnectionId connectionId = info.getConnectionId(); ConnectionId connectionId=info.getConnectionId();
ConnectionState cs = (ConnectionState) connectionStates.get(connectionId); if(connectionId!=null){
cs.addTransactionState(info.getTransactionId()); ConnectionState cs=(ConnectionState)connectionStates.get(connectionId);
return TRACKED_RESPONSE_MARKER; if(cs!=null){
} cs.addTransactionState(info.getTransactionId());
return null; }
}
return TRACKED_RESPONSE_MARKER;
}
return null;
} }
public Response processPrepareTransaction(TransactionInfo info) throws Exception {
if( trackTransactions ) { public Response processPrepareTransaction(TransactionInfo info) throws Exception{
ConnectionId connectionId = info.getConnectionId(); if(trackTransactions&&info!=null){
ConnectionState cs = (ConnectionState) connectionStates.get(connectionId); ConnectionId connectionId=info.getConnectionId();
TransactionState transactionState = cs.getTransactionState(info.getTransactionId()); if(connectionId!=null){
transactionState.addCommand(info); ConnectionState cs=(ConnectionState)connectionStates.get(connectionId);
return TRACKED_RESPONSE_MARKER; if(cs!=null){
} TransactionState transactionState=cs.getTransactionState(info.getTransactionId());
return null; if(transactionState!=null){
transactionState.addCommand(info);
}
}
}
return TRACKED_RESPONSE_MARKER;
}
return null;
} }
public Response processCommitTransactionOnePhase(TransactionInfo info) throws Exception { public Response processCommitTransactionOnePhase(TransactionInfo info) throws Exception{
if( trackTransactions ) { if(trackTransactions&&info!=null){
ConnectionId connectionId = info.getConnectionId(); ConnectionId connectionId=info.getConnectionId();
ConnectionState cs = (ConnectionState) connectionStates.get(connectionId); if(connectionId!=null){
TransactionState transactionState = cs.getTransactionState(info.getTransactionId()); ConnectionState cs=(ConnectionState)connectionStates.get(connectionId);
if( transactionState !=null ) { if(cs!=null){
transactionState.addCommand(info); TransactionState transactionState=cs.getTransactionState(info.getTransactionId());
return new Tracked(new RemoveTransactionAction(info)); if(transactionState!=null){
} transactionState.addCommand(info);
} return new Tracked(new RemoveTransactionAction(info));
return null; }
}
}
}
return null;
} }
public Response processCommitTransactionTwoPhase(TransactionInfo info) throws Exception {
if( trackTransactions ) { public Response processCommitTransactionTwoPhase(TransactionInfo info) throws Exception{
ConnectionId connectionId = info.getConnectionId(); if(trackTransactions&&info!=null){
ConnectionState cs = (ConnectionState) connectionStates.get(connectionId); ConnectionId connectionId=info.getConnectionId();
TransactionState transactionState = cs.getTransactionState(info.getTransactionId()); if(connectionId!=null){
if( transactionState !=null ) { ConnectionState cs=(ConnectionState)connectionStates.get(connectionId);
transactionState.addCommand(info); if(cs!=null){
return new Tracked(new RemoveTransactionAction(info)); TransactionState transactionState=cs.getTransactionState(info.getTransactionId());
} if(transactionState!=null){
} transactionState.addCommand(info);
return null; return new Tracked(new RemoveTransactionAction(info));
}
}
}
}
return null;
} }
public Response processRollbackTransaction(TransactionInfo info) throws Exception { public Response processRollbackTransaction(TransactionInfo info) throws Exception{
if( trackTransactions ) { if(trackTransactions&&info!=null){
ConnectionId connectionId = info.getConnectionId(); ConnectionId connectionId=info.getConnectionId();
ConnectionState cs = (ConnectionState) connectionStates.get(connectionId); if(connectionId!=null){
TransactionState transactionState = cs.getTransactionState(info.getTransactionId()); ConnectionState cs=(ConnectionState)connectionStates.get(connectionId);
if( transactionState !=null ) { if(cs!=null){
transactionState.addCommand(info); TransactionState transactionState=cs.getTransactionState(info.getTransactionId());
return new Tracked(new RemoveTransactionAction(info)); if(transactionState!=null){
} transactionState.addCommand(info);
} return new Tracked(new RemoveTransactionAction(info));
return null; }
}
}
}
return null;
} }
public Response processEndTransaction(TransactionInfo info) throws Exception { public Response processEndTransaction(TransactionInfo info) throws Exception{
if( trackTransactions ) { if(trackTransactions&&info!=null){
ConnectionId connectionId = info.getConnectionId(); ConnectionId connectionId=info.getConnectionId();
ConnectionState cs = (ConnectionState) connectionStates.get(connectionId); if(connectionId!=null){
TransactionState transactionState = cs.getTransactionState(info.getTransactionId()); ConnectionState cs=(ConnectionState)connectionStates.get(connectionId);
transactionState.addCommand(info); if(cs!=null){
return TRACKED_RESPONSE_MARKER; TransactionState transactionState=cs.getTransactionState(info.getTransactionId());
} if(transactionState!=null){
return null; transactionState.addCommand(info);
}
}
}
return TRACKED_RESPONSE_MARKER;
}
return null;
} }
public Response processRecoverTransactions(TransactionInfo info) { public Response processRecoverTransactions(TransactionInfo info) {