Return-Path: Delivered-To: apmail-geronimo-activemq-commits-archive@www.apache.org Received: (qmail 38725 invoked from network); 21 Mar 2006 23:24:15 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 21 Mar 2006 23:24:15 -0000 Received: (qmail 6777 invoked by uid 500); 21 Mar 2006 23:24:10 -0000 Delivered-To: apmail-geronimo-activemq-commits-archive@geronimo.apache.org Received: (qmail 6539 invoked by uid 500); 21 Mar 2006 23:24:08 -0000 Mailing-List: contact activemq-commits-help@geronimo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: activemq-dev@geronimo.apache.org Delivered-To: mailing list activemq-commits@geronimo.apache.org Received: (qmail 6442 invoked by uid 99); 21 Mar 2006 23:24:07 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Mar 2006 15:24:07 -0800 X-ASF-Spam-Status: No, hits=-8.6 required=10.0 tests=ALL_TRUSTED,INFO_TLD,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Tue, 21 Mar 2006 15:23:58 -0800 Received: (qmail 38438 invoked by uid 65534); 21 Mar 2006 23:23:37 -0000 Message-ID: <20060321232337.38437.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r387665 [2/9] - in /incubator/activemq/trunk: activecluster/src/java/org/apache/activecluster/impl/ activemq-core/src/main/java/org/apache/activemq/advisory/ activemq-core/src/main/java/org/apache/activemq/broker/jmx/ activemq-core/src/main... Date: Tue, 21 Mar 2006 23:21:29 -0000 To: activemq-commits@geronimo.apache.org From: chirino@apache.org X-Mailer: svnmailer-1.0.7 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/MapContainerImpl.java URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/MapContainerImpl.java?rev=387665&r1=387664&r2=387665&view=diff ============================================================================== --- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/MapContainerImpl.java (original) +++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/MapContainerImpl.java Tue Mar 21 15:20:55 2006 @@ -1,476 +1,476 @@ -/** - * - * Copyright 2005-2006 The Apache Software Foundation - * - * Licensed 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 - * - * 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 - * 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. - */ -package org.apache.activemq.kaha.impl; - -import java.io.IOException; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Map; -import java.util.Set; -import org.apache.activemq.kaha.MapContainer; -import org.apache.activemq.kaha.Marshaller; -import org.apache.activemq.kaha.ObjectMarshaller; -import org.apache.activemq.kaha.RuntimeStoreException; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -/** - * Implementation of a MapContainer - * - * @version $Revision: 1.2 $ - */ -public class MapContainerImpl implements MapContainer{ - private static final Log log=LogFactory.getLog(MapContainerImpl.class); - protected StoreImpl store; - protected LocatableItem root; - protected Object id; - protected Map map=new HashMap(); - protected Map valueToKeyMap=new HashMap(); - protected LinkedList list=new LinkedList(); - protected boolean loaded=false; - protected Marshaller keyMarshaller=new ObjectMarshaller(); - protected Marshaller valueMarshaller=new ObjectMarshaller(); - protected final Object mutex=new Object(); - protected boolean closed=false; - - protected MapContainerImpl(Object id,StoreImpl rfs,LocatableItem root) throws IOException{ - this.id=id; - this.store=rfs; - this.root=root; - } - - /* - * (non-Javadoc) - * - * @see org.apache.activemq.kaha.MapContainer#load() - */ - public void load(){ - checkClosed(); - if(!loaded){ - loaded=true; - synchronized(mutex){ - try{ - long start=root.getNextItem(); - if(start!=Item.POSITION_NOT_SET){ - long nextItem=start; - while(nextItem!=Item.POSITION_NOT_SET){ - LocatableItem item=new LocatableItem(); - item.setOffset(nextItem); - Object key=store.readItem(keyMarshaller,item); - map.put(key,item); - valueToKeyMap.put(item,key); - list.add(item); - nextItem=item.getNextItem(); - } - } - }catch(IOException e){ - log.error("Failed to load container "+getId(),e); - throw new RuntimeStoreException(e); - } - } - } - } - - /* - * (non-Javadoc) - * - * @see org.apache.activemq.kaha.MapContainer#unload() - */ - public void unload(){ - checkClosed(); - if(loaded){ - loaded=false; - synchronized(mutex){ - map.clear(); - valueToKeyMap.clear(); - list.clear(); - } - } - } - - public void close(){ - unload(); - closed=true; - } - - public void setKeyMarshaller(Marshaller keyMarshaller){ - checkClosed(); - this.keyMarshaller=keyMarshaller; - } - - public void setValueMarshaller(Marshaller valueMarshaller){ - checkClosed(); - this.valueMarshaller=valueMarshaller; - } - - /* - * (non-Javadoc) - * - * @see org.apache.activemq.kaha.MapContainer#isLoaded() - */ - public boolean isLoaded(){ - checkClosed(); - return loaded; - } - - /* - * (non-Javadoc) - * - * @see org.apache.activemq.kaha.MapContainer#getId() - */ - public Object getId(){ - checkClosed(); - return id; - } - - /* - * (non-Javadoc) - * - * @see org.apache.activemq.kaha.MapContainer#size() - */ - public int size(){ - checkClosed(); - checkLoaded(); - return map.size(); - } - - /* - * (non-Javadoc) - * - * @see org.apache.activemq.kaha.MapContainer#isEmpty() - */ - public boolean isEmpty(){ - checkClosed(); - checkLoaded(); - return map.isEmpty(); - } - - /* - * (non-Javadoc) - * - * @see org.apache.activemq.kaha.MapContainer#containsKey(java.lang.Object) - */ - public boolean containsKey(Object key){ - checkClosed(); - checkLoaded(); - synchronized(mutex){ - return map.containsKey(key); - } - } - - /* - * (non-Javadoc) - * - * @see org.apache.activemq.kaha.MapContainer#get(java.lang.Object) - */ - public Object get(Object key){ - checkClosed(); - checkLoaded(); - Object result=null; - LocatableItem item=null; - synchronized(mutex){ - item=(LocatableItem) map.get(key); - } - if(item!=null){ - result=getValue(item); - } - return result; - } - - /* - * (non-Javadoc) - * - * @see org.apache.activemq.kaha.MapContainer#containsValue(java.lang.Object) - */ - public boolean containsValue(Object o){ - checkClosed(); - checkLoaded(); - boolean result=false; - if(o!=null){ - synchronized(list){ - for(Iterator i=list.iterator();i.hasNext();){ - LocatableItem item=(LocatableItem) i.next(); - Object value=getValue(item); - if(value!=null&&value.equals(o)){ - result=true; - break; - } - } - } - } - return result; - } - - /* - * (non-Javadoc) - * - * @see org.apache.activemq.kaha.MapContainer#putAll(java.util.Map) - */ - public void putAll(Map t){ - checkClosed(); - checkLoaded(); - if(t!=null){ - synchronized(mutex){ - for(Iterator i=t.entrySet().iterator();i.hasNext();){ - Map.Entry entry=(Map.Entry) i.next(); - put(entry.getKey(),entry.getValue()); - } - } - } - } - - /* - * (non-Javadoc) - * - * @see org.apache.activemq.kaha.MapContainer#keySet() - */ - public Set keySet(){ - checkClosed(); - checkLoaded(); - return new ContainerKeySet(this); - } - - /* - * (non-Javadoc) - * - * @see org.apache.activemq.kaha.MapContainer#values() - */ - public Collection values(){ - checkClosed(); - checkLoaded(); - return new ContainerValueCollection(this); - } - - /* - * (non-Javadoc) - * - * @see org.apache.activemq.kaha.MapContainer#entrySet() - */ - public Set entrySet(){ - checkClosed(); - checkLoaded(); - return new ContainerEntrySet(this); - } - - /* - * (non-Javadoc) - * - * @see org.apache.activemq.kaha.MapContainer#put(java.lang.Object, java.lang.Object) - */ - public Object put(Object key,Object value){ - checkClosed(); - checkLoaded(); - Object result=null; - synchronized(mutex){ - if(map.containsKey(key)){ - result=remove(key); - } - LocatableItem item=write(key,value); - map.put(key,item); - valueToKeyMap.put(item,key); - list.add(item); - } - return result; - } - - /* - * (non-Javadoc) - * - * @see org.apache.activemq.kaha.MapContainer#remove(java.lang.Object) - */ - public Object remove(Object key){ - checkClosed(); - checkLoaded(); - Object result=null; - synchronized(mutex){ - LocatableItem item=(LocatableItem) map.get(key); - if(item!=null){ - map.remove(key); - valueToKeyMap.remove(item); - result=getValue(item); - int index=list.indexOf(item); - LocatableItem prev=index>0?(LocatableItem) list.get(index-1):root; - LocatableItem next=index<(list.size()-1)?(LocatableItem) list.get(index+1):null; - list.remove(index); - { - delete(item,prev,next); - } - item=null; - } - } - return result; - } - - public boolean removeValue(Object o){ - checkClosed(); - checkLoaded(); - boolean result=false; - if(o!=null){ - synchronized(list){ - for(Iterator i=list.iterator();i.hasNext();){ - LocatableItem item=(LocatableItem) i.next(); - Object value=getValue(item); - if(value!=null&&value.equals(o)){ - result=true; - // find the key - Object key=valueToKeyMap.get(item); - if(key!=null){ - remove(key); - } - break; - } - } - } - } - return result; - } - - protected void remove(LocatableItem item){ - Object key=valueToKeyMap.get(item); - if(key!=null){ - remove(key); - } - } - - /* - * (non-Javadoc) - * - * @see org.apache.activemq.kaha.MapContainer#clear() - */ - public void clear(){ - checkClosed(); - synchronized(mutex){ - loaded=true; - synchronized(mutex){ - map.clear(); - valueToKeyMap.clear(); - list.clear();// going to re-use this - try{ - long start=root.getNextItem(); - if(start!=Item.POSITION_NOT_SET){ - long nextItem=start; - while(nextItem!=Item.POSITION_NOT_SET){ - LocatableItem item=new LocatableItem(); - item.setOffset(nextItem); - list.add(item); - nextItem=item.getNextItem(); - } - } - root.setNextItem(Item.POSITION_NOT_SET); - store.updateItem(root); - for(int i=0;i0?(LocatableItem) list.get(index-1):root; + LocatableItem next=index<(list.size()-1)?(LocatableItem) list.get(index+1):null; + list.remove(index); + { + delete(item,prev,next); + } + item=null; + } + } + return result; + } + + public boolean removeValue(Object o){ + checkClosed(); + checkLoaded(); + boolean result=false; + if(o!=null){ + synchronized(list){ + for(Iterator i=list.iterator();i.hasNext();){ + LocatableItem item=(LocatableItem) i.next(); + Object value=getValue(item); + if(value!=null&&value.equals(o)){ + result=true; + // find the key + Object key=valueToKeyMap.get(item); + if(key!=null){ + remove(key); + } + break; + } + } + } + } + return result; + } + + protected void remove(LocatableItem item){ + Object key=valueToKeyMap.get(item); + if(key!=null){ + remove(key); + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.activemq.kaha.MapContainer#clear() + */ + public void clear(){ + checkClosed(); + synchronized(mutex){ + loaded=true; + synchronized(mutex){ + map.clear(); + valueToKeyMap.clear(); + list.clear();// going to re-use this + try{ + long start=root.getNextItem(); + if(start!=Item.POSITION_NOT_SET){ + long nextItem=start; + while(nextItem!=Item.POSITION_NOT_SET){ + LocatableItem item=new LocatableItem(); + item.setOffset(nextItem); + list.add(item); + nextItem=item.getNextItem(); + } + } + root.setNextItem(Item.POSITION_NOT_SET); + store.updateItem(root); + for(int i=0;i - /// Exception thrown when the broker returns an error - /// - public class BrokerException : NMSException - { - - private BrokerError brokerError; - - public BrokerException(BrokerError brokerError) : base( - brokerError.ExceptionClass + " : " + brokerError.Message) - { - this.brokerError = brokerError; - } - - public BrokerError BrokerError - { - get { - return brokerError; - } - } - - public virtual string JavaStackTrace - { - get { - return brokerError.StackTrace; - } - } - - } -} - - +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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 + * + * 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 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. + */ +using ActiveMQ.Commands; +using NMS; + +namespace ActiveMQ +{ + + /// + /// Exception thrown when the broker returns an error + /// + public class BrokerException : NMSException + { + + private BrokerError brokerError; + + public BrokerException(BrokerError brokerError) : base( + brokerError.ExceptionClass + " : " + brokerError.Message) + { + this.brokerError = brokerError; + } + + public BrokerError BrokerError + { + get { + return brokerError; + } + } + + public virtual string JavaStackTrace + { + get { + return brokerError.StackTrace; + } + } + + } +} + + Propchange: incubator/activemq/trunk/activemq-dotnet/src/main/csharp/ActiveMQ/BrokerException.cs ------------------------------------------------------------------------------ svn:eol-style = native