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;
018
019 /**
020 * An <a href="http://activemq.apache.org/camel/endpoint.html">endpoint</a>
021 * implements the <a
022 * href="http://activemq.apache.org/camel/message-endpoint.html">Message
023 * Endpoint</a> pattern and represents an endpoint that can send and receive
024 * message exchanges
025 *
026 * @see Exchange, Message
027 * @version $Revision: 563607 $
028 */
029 public interface Endpoint<E extends Exchange> {
030
031 /**
032 * Returns if the endpoint should be a CamelContext singleton. If the
033 * endpoint is a Singleton, then a single Endpoint instance will be shared
034 * by all routes with the same URI. Because the endpoint is shared, it
035 * should be treated as an immutable.
036 */
037 boolean isSingleton();
038
039 /**
040 * Returns the string representation of the endpoint URI
041 */
042 String getEndpointUri();
043
044 /**
045 * Create a new exchange for communicating with this endpoint
046 */
047 E createExchange();
048
049 /**
050 * Creates a new exchange for communicating with this exchange using the
051 * given exchange to pre-populate the values of the headers and messages
052 */
053 E createExchange(Exchange exchange);
054
055 /**
056 * Converts the given exchange to this endpoints required type
057 */
058 E toExchangeType(Exchange exchange);
059
060 /**
061 * Returns the context which created the endpoint
062 *
063 * @return the context which created the endpoint
064 */
065 CamelContext getContext();
066
067 /**
068 * Creates a new producer which is used send messages into the endpoint
069 *
070 * @return a newly created producer
071 */
072 Producer<E> createProducer() throws Exception;
073
074 /**
075 * Creates a new <a
076 * href="http://activemq.apache.org/camel/event-driven-consumer.html">Event
077 * Driven Consumer</a> which consumes messages from the endpoint using the
078 * given processor
079 *
080 * @return a newly created consumer
081 */
082 Consumer<E> createConsumer(Processor processor) throws Exception;
083
084 /**
085 * Creates a new <a
086 * href="http://activemq.apache.org/camel/polling-consumer.html">Polling
087 * Consumer</a> so that the caller can poll message exchanges from the
088 * consumer using {@link PollingConsumer#receive()},
089 * {@link PollingConsumer#receiveNoWait()} or
090 * {@link PollingConsumer#receive(long)} whenever it is ready to do so
091 * rather than using the <a
092 * href="http://activemq.apache.org/camel/event-driven-consumer.html">Event
093 * Based Consumer</a> returned by {@link #createConsumer(Processor)}
094 *
095 * @return a newly created pull consumer
096 * @throws Exception if the pull consumer could not be created
097 */
098 PollingConsumer<E> createPollingConsumer() throws Exception;
099 }