fix to avoid NPE

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@515746 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Strachan 2007-03-07 20:53:24 +00:00
parent 2a3fddbdea
commit 10185cadd7
1 changed files with 35 additions and 37 deletions

View File

@ -11,43 +11,42 @@
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License. * specific language governing permissions and limitations under the License.
*/ */
package org.apache.activemq.store.kahadaptor; package org.apache.activemq.store.kahadaptor;
import java.util.Iterator;
import org.apache.activemq.command.MessageId; import org.apache.activemq.command.MessageId;
import org.apache.activemq.kaha.ListContainer; import org.apache.activemq.kaha.ListContainer;
import org.apache.activemq.kaha.StoreEntry; import org.apache.activemq.kaha.StoreEntry;
import java.util.Iterator;
/** /**
* Holds information for the subscriber * Holds information for the subscriber
* *
* @version $Revision: 1.10 $ * @version $Revision: 1.10 $
*/ */
public class TopicSubContainer{ public class TopicSubContainer {
private ListContainer listContainer; private ListContainer listContainer;
private StoreEntry batchEntry; private StoreEntry batchEntry;
public TopicSubContainer(ListContainer container){ public TopicSubContainer(ListContainer container) {
this.listContainer = container; this.listContainer = container;
} }
/** /**
* @return the batchEntry * @return the batchEntry
*/ */
public StoreEntry getBatchEntry(){ public StoreEntry getBatchEntry() {
return this.batchEntry; return this.batchEntry;
} }
/** /**
* @param batchEntry the batchEntry to set * @param batchEntry the batchEntry to set
*/ */
public void setBatchEntry(StoreEntry batchEntry){ public void setBatchEntry(StoreEntry batchEntry) {
this.batchEntry=batchEntry; this.batchEntry = batchEntry;
} }
public void reset() {
public void reset() {
batchEntry = null; batchEntry = null;
} }
@ -59,15 +58,15 @@ import org.apache.activemq.kaha.StoreEntry;
return listContainer.placeLast(ref); return listContainer.placeLast(ref);
} }
public ConsumerMessageRef remove(MessageId id){ public ConsumerMessageRef remove(MessageId id) {
ConsumerMessageRef result=null; ConsumerMessageRef result = null;
if(!listContainer.isEmpty()){ if (!listContainer.isEmpty()) {
for(StoreEntry entry=listContainer.getFirst();entry!=null;entry=listContainer.getNext(entry)){ for (StoreEntry entry = listContainer.getFirst(); entry != null; entry = listContainer.getNext(entry)) {
ConsumerMessageRef ref=(ConsumerMessageRef)listContainer.get(entry); ConsumerMessageRef ref = (ConsumerMessageRef) listContainer.get(entry);
if(ref!=null&&ref.getMessageId().equals(id)){ if (ref != null && ref.getMessageId().equals(id)) {
listContainer.remove(entry); listContainer.remove(entry);
result=ref; result = ref;
if(listContainer.isEmpty()||batchEntry.equals(entry)){ if (listContainer != null && batchEntry != null && (listContainer.isEmpty() || batchEntry.equals(entry))) {
reset(); reset();
} }
} }
@ -77,7 +76,7 @@ import org.apache.activemq.kaha.StoreEntry;
} }
public ConsumerMessageRef get(StoreEntry entry) { public ConsumerMessageRef get(StoreEntry entry) {
return (ConsumerMessageRef)listContainer.get(entry); return (ConsumerMessageRef) listContainer.get(entry);
} }
public StoreEntry getEntry() { public StoreEntry getEntry() {
@ -104,5 +103,4 @@ import org.apache.activemq.kaha.StoreEntry;
reset(); reset();
listContainer.clear(); listContainer.clear();
} }
} }