001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.camel.queue; 018 019 import java.util.HashMap; 020 import java.util.concurrent.BlockingQueue; 021 import java.util.concurrent.LinkedBlockingQueue; 022 023 import org.apache.camel.CamelContext; 024 import org.apache.camel.Component; 025 026 /** 027 * Represents the component that manages {@link QueueEndpoint}. It holds the 028 * list of named queues that queue endpoints reference. 029 * 030 * @org.apache.xbean.XBean 031 * @version $Revision: 519973 $ 032 */ 033 public class QueueComponent<E> implements Component<E> { 034 035 private HashMap<String, BlockingQueue<E>> registry = new HashMap<String, BlockingQueue<E>>(); 036 private CamelContext container; 037 038 public void setContext(CamelContext container) { 039 this.container = container; 040 } 041 042 synchronized public BlockingQueue<E> getOrCreateQueue(String uri) { 043 BlockingQueue<E> queue = registry.get(uri); 044 if( queue == null ) { 045 queue = createQueue(); 046 registry.put(uri, queue); 047 } 048 return queue; 049 } 050 051 protected BlockingQueue<E> createQueue() { 052 return new LinkedBlockingQueue<E>(); 053 } 054 055 public CamelContext getContainer() { 056 return container; 057 } 058 059 060 }