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

@ -1,73 +1,72 @@
/** /**
* *
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
* file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
* to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the * to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at * License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* 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;
} }
public boolean isEmpty() { public boolean isEmpty() {
return listContainer.isEmpty(); return listContainer.isEmpty();
} }
public StoreEntry add(ConsumerMessageRef ref) { public StoreEntry add(ConsumerMessageRef ref) {
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();
} }
} }
@ -75,34 +74,33 @@ import org.apache.activemq.kaha.StoreEntry;
} }
return result; return result;
} }
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() {
return listContainer.getFirst(); return listContainer.getFirst();
} }
public StoreEntry refreshEntry(StoreEntry entry) { public StoreEntry refreshEntry(StoreEntry entry) {
return listContainer.refresh(entry); return listContainer.refresh(entry);
} }
public StoreEntry getNextEntry(StoreEntry entry) { public StoreEntry getNextEntry(StoreEntry entry) {
return listContainer.getNext(entry); return listContainer.getNext(entry);
} }
public Iterator iterator() { public Iterator iterator() {
return listContainer.iterator(); return listContainer.iterator();
} }
public int size() { public int size() {
return listContainer.size(); return listContainer.size();
} }
public void clear() { public void clear() {
reset(); reset();
listContainer.clear(); listContainer.clear();
} }
} }