org.apache.camel.impl
Class DefaultEndpoint

java.lang.Object
  extended by org.apache.camel.support.ServiceSupport
      extended by org.apache.camel.impl.DefaultEndpoint
All Implemented Interfaces:
CamelContextAware, Endpoint, IsSingleton, Service, ShutdownableService, HasId, StatefulService, SuspendableService
Direct Known Subclasses:
BindingEndpoint, BrowseEndpoint, ControlBusEndpoint, DataFormatEndpoint, DirectEndpoint, DirectVmEndpoint, MockEndpoint, ScheduledPollEndpoint, SedaEndpoint, TimerEndpoint

public abstract class DefaultEndpoint
extends ServiceSupport
implements Endpoint, HasId, CamelContextAware

A default endpoint useful for implementation inheritance.

Components which leverages asynchronous processing model should check the isSynchronous() to determine if asynchronous processing is allowed. The synchronous option on the endpoint allows Camel end users to dictate whether they want the asynchronous model or not. The option is default false which means asynchronous processing is allowed.

Version:

Field Summary
 
Fields inherited from class org.apache.camel.support.ServiceSupport
shutdown, shuttingdown, started, starting, stopped, stopping, suspended, suspending
 
Constructor Summary
protected DefaultEndpoint()
          Constructs a partially-initialized DefaultEndpoint instance.
protected DefaultEndpoint(String endpointUri)
          Deprecated. 
protected DefaultEndpoint(String endpointUri, CamelContext camelContext)
          Deprecated. 
protected DefaultEndpoint(String endpointUri, Component component)
          Constructs a fully-initialized DefaultEndpoint instance.
 
Method Summary
protected  void configureConsumer(Consumer consumer)
           
protected  void configurePollingConsumer(PollingConsumer consumer)
           
 void configureProperties(Map<String,Object> options)
          Configure properties on this endpoint.
protected  EndpointConfiguration createEndpointConfiguration(String uri)
          A factory method to lazily create the endpoint configuration if none is specified
protected  String createEndpointUri()
          A factory method to lazily create the endpointUri if none is specified
 Exchange createExchange()
          Create a new exchange for communicating with this endpoint
 Exchange createExchange(Exchange exchange)
          Creates a new exchange for communicating with this endpoint using the given exchange to pre-populate the values of the headers and messages
 Exchange createExchange(ExchangePattern pattern)
          Create a new exchange for communicating with this endpoint with the specified ExchangePattern such as whether its going to be an ExchangePattern.InOnly or ExchangePattern.InOut exchange
 PollingConsumer createPollingConsumer()
          Creates a new Polling Consumer so that the caller can poll message exchanges from the consumer using PollingConsumer.receive(), PollingConsumer.receiveNoWait() or PollingConsumer.receive(long) whenever it is ready to do so rather than using the Event Based Consumer returned by Endpoint.createConsumer(Processor)
protected  void doStart()
          Implementations override this method to support customized start/stop.
protected  void doStop()
          Implementations override this method to support customized start/stop.
 boolean equals(Object object)
           
 CamelContext getCamelContext()
          Returns the context which created the endpoint
 Component getComponent()
          Returns the component that created this endpoint.
 Map<String,Object> getConsumerProperties()
           
 EndpointConfiguration getEndpointConfiguration()
          Returns the object representation of the endpoint configuration
 String getEndpointKey()
          Returns a string key of this endpoint.
 String getEndpointUri()
          Returns the string representation of the endpoint URI
 ExchangePattern getExchangePattern()
          Returns the default exchange pattern to use for createExchange().
 String getId()
          Returns a unique String ID which can be used for aliasing without having to use the whole URI which is not unique
 int hashCode()
           
 boolean isLenientProperties()
          Should all properties be known or does the endpoint allow unknown options?

lenient = false means that the endpoint should validate that all given options is known and configured properly.

 boolean isSynchronous()
          Returns whether synchronous processing should be strictly used.
 void setCamelContext(CamelContext camelContext)
          Sets the camel context.
 void setConsumerProperties(Map<String,Object> consumerProperties)
           
 void setEndpointConfiguration(EndpointConfiguration endpointConfiguration)
          Sets a custom EndpointConfiguration
protected  void setEndpointUri(String endpointUri)
          Sets the URI that created this endpoint.
 void setEndpointUriIfNotSpecified(String value)
          Sets the endpointUri if it has not been specified yet via some kind of dependency injection mechanism.
 void setExchangePattern(ExchangePattern exchangePattern)
          Sets the default exchange pattern to use for createExchange().
protected  void setProperties(Object bean, Map<String,Object> parameters)
          Sets the bean properties on the given bean.
 void setSynchronous(boolean synchronous)
          Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported).
 String toString()
           
 
Methods inherited from class org.apache.camel.support.ServiceSupport
doResume, doShutdown, doSuspend, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, resume, shutdown, start, stop, suspend
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.camel.Endpoint
createConsumer, createProducer
 
Methods inherited from interface org.apache.camel.IsSingleton
isSingleton
 
Methods inherited from interface org.apache.camel.Service
start, stop
 

Constructor Detail

DefaultEndpoint

protected DefaultEndpoint(String endpointUri,
                          Component component)
Constructs a fully-initialized DefaultEndpoint instance. This is the preferred method of constructing an object from Java code (as opposed to Spring beans, etc.).

Parameters:
endpointUri - the full URI used to create this endpoint
component - the component that created this endpoint

DefaultEndpoint

@Deprecated
protected DefaultEndpoint(String endpointUri,
                                     CamelContext camelContext)
Deprecated. 

Constructs a DefaultEndpoint instance which has not been created using a Component.

Note: It is preferred to create endpoints using the associated component.

Parameters:
endpointUri - the full URI used to create this endpoint
camelContext - the Camel Context in which this endpoint is operating

DefaultEndpoint

@Deprecated
protected DefaultEndpoint(String endpointUri)
Deprecated. 

Constructs a partially-initialized DefaultEndpoint instance.

Note: It is preferred to create endpoints using the associated component.

Parameters:
endpointUri - the full URI used to create this endpoint

DefaultEndpoint

protected DefaultEndpoint()
Constructs a partially-initialized DefaultEndpoint instance. Useful when creating endpoints manually (e.g., as beans in Spring).

Please note that the endpoint URI must be set through properties (or overriding createEndpointUri() if one uses this constructor.

Note: It is preferred to create endpoints using the associated component.

Method Detail

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object object)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object

getId

public String getId()
Returns a unique String ID which can be used for aliasing without having to use the whole URI which is not unique

Specified by:
getId in interface HasId
Returns:
the id

getEndpointUri

public String getEndpointUri()
Description copied from interface: Endpoint
Returns the string representation of the endpoint URI

Specified by:
getEndpointUri in interface Endpoint
Returns:
the endpoint URI

getEndpointConfiguration

public EndpointConfiguration getEndpointConfiguration()
Description copied from interface: Endpoint
Returns the object representation of the endpoint configuration

Specified by:
getEndpointConfiguration in interface Endpoint
Returns:
the endpoint configuration

setEndpointConfiguration

public void setEndpointConfiguration(EndpointConfiguration endpointConfiguration)
Sets a custom EndpointConfiguration

Parameters:
endpointConfiguration - a custom endpoint configuration to be used.

getEndpointKey

public String getEndpointKey()
Description copied from interface: Endpoint
Returns a string key of this endpoint.

This key is used by LifecycleStrategy when registering endpoint. This allows to register different instances of endpoints with the same key.

For JMX mbeans this allows us to use the same JMX Mbean for all endpoints that are logical the same but have different parameters. For instance the http endpoint.

Specified by:
getEndpointKey in interface Endpoint
Returns:
the endpoint key

getCamelContext

public CamelContext getCamelContext()
Description copied from interface: Endpoint
Returns the context which created the endpoint

Specified by:
getCamelContext in interface CamelContextAware
Specified by:
getCamelContext in interface Endpoint
Returns:
the context which created the endpoint

getComponent

public Component getComponent()
Returns the component that created this endpoint.

Returns:
the component that created this endpoint, or null if none set

setCamelContext

public void setCamelContext(CamelContext camelContext)
Description copied from interface: Endpoint
Sets the camel context.

Specified by:
setCamelContext in interface CamelContextAware
Specified by:
setCamelContext in interface Endpoint
Parameters:
camelContext - the camel context

createPollingConsumer

public PollingConsumer createPollingConsumer()
                                      throws Exception
Description copied from interface: Endpoint
Creates a new Polling Consumer so that the caller can poll message exchanges from the consumer using PollingConsumer.receive(), PollingConsumer.receiveNoWait() or PollingConsumer.receive(long) whenever it is ready to do so rather than using the Event Based Consumer returned by Endpoint.createConsumer(Processor)

Specified by:
createPollingConsumer in interface Endpoint
Returns:
a newly created pull consumer
Throws:
Exception - if the pull consumer could not be created

createExchange

public Exchange createExchange(Exchange exchange)
Description copied from interface: Endpoint
Creates a new exchange for communicating with this endpoint using the given exchange to pre-populate the values of the headers and messages

Specified by:
createExchange in interface Endpoint
Parameters:
exchange - given exchange to use for pre-populate
Returns:
a new exchange

createExchange

public Exchange createExchange()
Description copied from interface: Endpoint
Create a new exchange for communicating with this endpoint

Specified by:
createExchange in interface Endpoint
Returns:
a new exchange

createExchange

public Exchange createExchange(ExchangePattern pattern)
Description copied from interface: Endpoint
Create a new exchange for communicating with this endpoint with the specified ExchangePattern such as whether its going to be an ExchangePattern.InOnly or ExchangePattern.InOut exchange

Specified by:
createExchange in interface Endpoint
Parameters:
pattern - the message exchange pattern for the exchange
Returns:
a new exchange

getExchangePattern

public ExchangePattern getExchangePattern()
Returns the default exchange pattern to use for createExchange().

See Also:
setExchangePattern(ExchangePattern exchangePattern)

setExchangePattern

public void setExchangePattern(ExchangePattern exchangePattern)
Sets the default exchange pattern to use for createExchange(). The default value is ExchangePattern.InOnly


isSynchronous

public boolean isSynchronous()
Returns whether synchronous processing should be strictly used.

See Also:
setSynchronous(boolean synchronous)

setSynchronous

public void setSynchronous(boolean synchronous)
Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported).

Parameters:
synchronous - true to enforce synchronous processing

configureProperties

public void configureProperties(Map<String,Object> options)
Description copied from interface: Endpoint
Configure properties on this endpoint.

Specified by:
configureProperties in interface Endpoint
Parameters:
options - the options (properties)

setProperties

protected void setProperties(Object bean,
                             Map<String,Object> parameters)
                      throws Exception
Sets the bean properties on the given bean.

This is the same logical implementation as DefaultComponent.setProperties(Object, java.util.Map)

Parameters:
bean - the bean
parameters - properties to set
Throws:
Exception

createEndpointUri

protected String createEndpointUri()
A factory method to lazily create the endpointUri if none is specified


createEndpointConfiguration

protected EndpointConfiguration createEndpointConfiguration(String uri)
A factory method to lazily create the endpoint configuration if none is specified


setEndpointUriIfNotSpecified

public void setEndpointUriIfNotSpecified(String value)
Sets the endpointUri if it has not been specified yet via some kind of dependency injection mechanism. This allows dependency injection frameworks such as Spring or Guice to set the default endpoint URI in cases where it has not been explicitly configured using the name/context in which an Endpoint is created.


setEndpointUri

protected void setEndpointUri(String endpointUri)
Sets the URI that created this endpoint.


isLenientProperties

public boolean isLenientProperties()
Description copied from interface: Endpoint
Should all properties be known or does the endpoint allow unknown options?

lenient = false means that the endpoint should validate that all given options is known and configured properly. lenient = true means that the endpoint allows additional unknown options to be passed to it but does not throw a ResolveEndpointFailedException when creating the endpoint.

This options is used by a few components for instance the HTTP based that can have dynamic URI options appended that is targeted for an external system.

Most endpoints is configured to be not lenient.

Specified by:
isLenientProperties in interface Endpoint
Returns:
whether properties is lenient or not

getConsumerProperties

public Map<String,Object> getConsumerProperties()

setConsumerProperties

public void setConsumerProperties(Map<String,Object> consumerProperties)

configureConsumer

protected void configureConsumer(Consumer consumer)
                          throws Exception
Throws:
Exception

configurePollingConsumer

protected void configurePollingConsumer(PollingConsumer consumer)
                                 throws Exception
Throws:
Exception

doStart

protected void doStart()
                throws Exception
Description copied from class: ServiceSupport
Implementations override this method to support customized start/stop.

Important: See ServiceSupport.doStop() for more details.

Specified by:
doStart in class ServiceSupport
Throws:
Exception
See Also:
ServiceSupport.doStop()

doStop

protected void doStop()
               throws Exception
Description copied from class: ServiceSupport
Implementations override this method to support customized start/stop.

Important: Camel will invoke this ServiceSupport.doStop() method when the service is being stopped. This method will also be invoked if the service is still in uninitialized state (eg has not been started). The method is always called to allow the service to do custom logic when the service is being stopped, such as when CamelContext is shutting down.

Specified by:
doStop in class ServiceSupport
Throws:
Exception
See Also:
ServiceSupport.doStart()


Apache Camel