Class AmqpProvider

java.lang.Object
org.apache.qpid.jms.provider.amqp.AmqpProvider
All Implemented Interfaces:
AmqpResourceParent, Provider, TransportListener

public class AmqpProvider extends Object implements Provider, TransportListener, AmqpResourceParent
An AMQP v1.0 Provider. The AMQP Provider is bonded to a single remote broker instance. The provider will attempt to connect to only that instance and once failed can not be recovered. For clients that wish to implement failover type connections a new AMQP Provider instance must be created and state replayed from the JMS layer using the standard recovery process defined in the JMS Provider API. All work within this Provider is serialized to a single Thread. Any asynchronous exceptions will be dispatched from that Thread and all in-bound requests are handled there as well.
  • Constructor Details

    • AmqpProvider

      public AmqpProvider(URI remoteURI, Transport transport, ProviderFutureFactory futureFactory)
      Create a new instance of an AmqpProvider bonded to the given remote URI.
      Parameters:
      remoteURI - The URI of the AMQP broker this Provider instance will connect to.
      transport - The underlying Transport that will be used for wire level communications.
      futureFactory - The ProviderFutureFactory to use when futures are requested.
  • Method Details

    • connect

      public void connect(JmsConnectionInfo connectionInfo) throws ProviderException
      Description copied from interface: Provider
      Performs the initial low level connection for this provider such as TCP or SSL connection to a remote Broker. If this operation fails then the Provider is considered to be unusable and no further operations should be attempted using this Provider.
      Specified by:
      connect in interface Provider
      Parameters:
      connectionInfo - The JmsConnectionInfo that contains the properties that define this connection.
      Throws:
      ProviderException - if the remote resource can not be contacted.
    • start

      public void start() throws ProviderException, IllegalStateException
      Description copied from interface: Provider
      Starts the Provider. The start method provides a place for the Provider to perform and pre-start configuration checks to ensure that the current state is valid and that all contracts have been met prior to starting.
      Specified by:
      start in interface Provider
      Throws:
      ProviderException - if an error occurs during start processing.
      IllegalStateException - if the Provider is improperly configured.
    • close

      public void close()
      Description copied from interface: Provider
      Closes this Provider terminating all connections and canceling any pending operations. The Provider is considered unusable after this call. This call is a blocking call and will not return until the Provider has closed or an error occurs.
      Specified by:
      close in interface Provider
    • create

      public void create(JmsResource resource, AsyncResult request) throws ProviderException
      Description copied from interface: Provider
      Create the Provider version of the given JmsResource. For each JMS Resource type the Provider implementation must create it's own internal representation and upon successful creation provide the caller with a response. The Provider should examine the given JmsResource to determine if the given configuration is supported or can be simulated, or is not supported in which case an exception should be thrown. It is possible for a Provider to indicate that it cannot complete a requested create either due to some mis-configuration such as bad login credentials on connection create by throwing a JMSException. If the Provider does not support creating of the indicated resource such as a Temporary Queue etc the provider may throw an UnsupportedOperationException to indicate this.
      Specified by:
      create in interface Provider
      Parameters:
      resource - The JmsResouce instance that indicates what is being created.
      request - The request object that should be signaled when this operation completes.
      Throws:
      ProviderException - if an error occurs or the Provider is already closed.
    • start

      public void start(JmsResource resource, AsyncResult request) throws ProviderException
      Description copied from interface: Provider
      Starts the Provider version of the given JmsResource. For some JMS Resources it is necessary or advantageous to have a started state that must be triggered prior to it's normal use. An example of this would be a MessageConsumer which should not receive any incoming messages until the JMS layer is in a state to handle them. One such time would be after connection recovery. A JMS consumer should normally recover with it's prefetch value set to zero, or an AMQP link credit of zero and only open up the credit window once all Connection resources are restored. The provider is required to implement this method and not throw any error other than an ProviderException if a communication error occurs. The start operation is not required to have any effect on the provider resource but must not throw UnsupportedOperation etc.
      Specified by:
      start in interface Provider
      Parameters:
      resource - The JmsResouce instance that indicates what is being started.
      request - The request object that should be signaled when this operation completes.
      Throws:
      ProviderException - if an error occurs or the Provider is already closed.
    • stop

      public void stop(JmsResource resource, AsyncResult request) throws ProviderException
      Description copied from interface: Provider
      Stops (pauses) the Provider version of the given JmsResource, the resource would then need to be started again via a call to start() For some JMS Resources it is necessary or advantageous to have a stopped state that can be triggered to stop the resource generating new events or messages. An example of this would be a JMS Session which should not receive any incoming messages for any consumers until the JMS layer is in a state to handle them. One such time would be during a transaction rollback. A JMS Session should normally ensure that messages received in a transaction are set to be redelivered prior to any new deliveries on a transaction rollback. The provider is required to implement this method and not throw any error other than an ProviderException if a communication error occurs. The stop operation is not required to have any effect on the provider resource but must not throw UnsupportedOperation etc.
      Specified by:
      stop in interface Provider
      Parameters:
      resource - The JmsResouce instance that indicates what is being stopped.
      request - The request object that should be signaled when this operation completes.
      Throws:
      ProviderException - if an error occurs or the Provider is already closed.
    • destroy

      public void destroy(JmsResource resource, AsyncResult request) throws ProviderException
      Description copied from interface: Provider
      Instruct the Provider to dispose of a given JmsResource. The provider is given a JmsResource which it should use to remove any associated resources and inform the remote Broker instance of the removal of this resource. If the Provider cannot destroy the resource due to a non-communication error such as the logged in user not have role access to destroy the given resource it may throw an instance of JMSException to indicate such an error.
      Specified by:
      destroy in interface Provider
      Parameters:
      resource - The JmsResouce that identifies a previously created JmsResource.
      request - The request object that should be signaled when this operation completes.
      Throws:
      ProviderException - if an error occurs or the Provider is already closed.
    • send

      public void send(JmsOutboundMessageDispatch envelope, AsyncResult request) throws ProviderException
      Description copied from interface: Provider
      Sends the JmsMessage contained in the outbound dispatch envelope.
      Specified by:
      send in interface Provider
      Parameters:
      envelope - the message envelope containing the JmsMessage to send.
      request - The request object that should be signaled when this operation completes.
      Throws:
      ProviderException - if an error occurs or the Provider is already closed.
    • acknowledge

      public void acknowledge(JmsSessionId sessionId, ProviderConstants.ACK_TYPE ackType, AsyncResult request) throws ProviderException
      Description copied from interface: Provider
      Called to acknowledge all messages that have been delivered in a given session. This method is typically used by a Session that is configured for client acknowledge mode. The acknowledgement should only be applied to Messages that have been marked as delivered and not those still awaiting dispatch.
      Specified by:
      acknowledge in interface Provider
      Parameters:
      sessionId - the ID of the Session whose delivered messages should be acknowledged.
      ackType - The type of acknowledgement being done.
      request - The request object that should be signaled when this operation completes.
      Throws:
      ProviderException - if an error occurs or the Provider is already closed.
    • acknowledge

      public void acknowledge(JmsInboundMessageDispatch envelope, ProviderConstants.ACK_TYPE ackType, AsyncResult request) throws ProviderException
      Description copied from interface: Provider
      Called to acknowledge a JmsMessage has been delivered, consumed, re-delivered...etc. The provider should perform an acknowledgement for the message based on the configured mode of the consumer that it was dispatched to and the capabilities of the protocol.
      Specified by:
      acknowledge in interface Provider
      Parameters:
      envelope - The message dispatch envelope containing the Message delivery information.
      ackType - The type of acknowledgement being done.
      request - The request object that should be signaled when this operation completes.
      Throws:
      ProviderException - if an error occurs or the Provider is already closed.
    • commit

      public void commit(JmsTransactionInfo transactionInfo, JmsTransactionInfo nextTransactionId, AsyncResult request) throws ProviderException
      Description copied from interface: Provider
      Called to commit an open transaction, and start a new one if a new transaction info object is provided. If this method throws an exception it is either because the commit failed, or the start of the next transaction failed. The caller can investigate the state of the provided next transaction object to determine if a new transaction was created. If the provider is unable to support transactions then it should throw an UnsupportedOperationException to indicate this. The Provider may also throw a JMSException to indicate a transaction was already rolled back etc.
      Specified by:
      commit in interface Provider
      Parameters:
      transactionInfo - the transaction info that describes the transaction being committed.
      nextTransactionId - the transaction info that describes the new transaction that should be created.
      request - The request object that should be signaled when this operation completes.
      Throws:
      ProviderException - if an error occurs or the Provider is already closed.
    • rollback

      public void rollback(JmsTransactionInfo transactionInfo, JmsTransactionInfo nextTransactionId, AsyncResult request) throws ProviderException
      Description copied from interface: Provider
      Called to roll back an open transaction, and start a new one if a new transaction info object is provided. If this method throws an exception it is either because the commit failed, or the start of the next transaction failed. The caller can investigate the state of the provided next transaction object to determine if a new transaction was created.
      Specified by:
      rollback in interface Provider
      Parameters:
      transactionInfo - the transaction info that describes the transaction being rolled back.
      nextTransactionId - the transaction info that describes the new transaction that should be created.
      request - The request object that should be signaled when this operation completes.
      Throws:
      ProviderException - if an error occurs or the Provider is already closed.
    • recover

      public void recover(JmsSessionId sessionId, AsyncResult request) throws ProviderException
      Description copied from interface: Provider
      Called to recover all unacknowledged messages for a Session in client Ack mode.
      Specified by:
      recover in interface Provider
      Parameters:
      sessionId - the Id of the JmsSession that is recovering unacknowledged messages..
      request - The request object that should be signaled when this operation completes.
      Throws:
      ProviderException - if an error occurs or the Provider is already closed.
    • unsubscribe

      public void unsubscribe(String subscription, AsyncResult request) throws ProviderException
      Description copied from interface: Provider
      Remove a durable topic subscription by name. A provider can throw an instance of JMSException to indicate that it cannot perform the un-subscribe operation due to bad security credentials etc.
      Specified by:
      unsubscribe in interface Provider
      Parameters:
      subscription - the name of the durable subscription that is to be removed.
      request - The request object that should be signaled when this operation completes.
      Throws:
      ProviderException - if an error occurs or the Provider is already closed.
    • pull

      public void pull(JmsConsumerId consumerId, long timeout, AsyncResult request) throws ProviderException
      Description copied from interface: Provider
      Request a remote peer send a Message to this client. A message pull request is usually only needed in the case where the client sets a zero prefetch limit on the consumer. If the consumer has a set prefetch that's greater than zero this method should just return without performing any action. timeout < 0 then it should remain open until a message is received. timeout = 0 then it returns a message or null if none available timeout > 0 then it should remain open for timeout amount of time. The timeout value when positive is given in milliseconds.
      Specified by:
      pull in interface Provider
      Parameters:
      consumerId - the ID of the Consumer instance that is attempt to pull a message from the remote.
      timeout - the amount of time to tell the remote peer to keep this pull request valid.
      request - The request object that should be signaled when this operation completes.
      Throws:
      ProviderException - if an error occurs or the Provider is already closed.
    • scheduleExecuteAndPump

      public void scheduleExecuteAndPump(Runnable task)
    • onData

      public void onData(io.netty.buffer.ByteBuf input)
      Description copied from interface: TransportListener
      Called when new incoming data has become available.
      Specified by:
      onData in interface TransportListener
      Parameters:
      input - the next incoming packet of data.
    • onTransportError

      public void onTransportError(Throwable error)
      Callback method for the Transport to report connection errors. When called the method will queue a new task to fire the failure error back to the listener.
      Specified by:
      onTransportError in interface TransportListener
      Parameters:
      error - the error that causes the transport to fail.
    • onTransportClosed

      public void onTransportClosed()
      Callback method for the Transport to report that the underlying connection has closed. When called this method will queue a new task that will check for the closed state on this transport and if not closed then an exception is raised to the registered ProviderListener to indicate connection loss.
      Specified by:
      onTransportClosed in interface TransportListener
    • pumpToProtonTransport

      protected boolean pumpToProtonTransport()
    • pumpToProtonTransport

      protected boolean pumpToProtonTransport(AsyncResult request)
    • pumpToProtonTransport

      protected boolean pumpToProtonTransport(AsyncResult request, boolean flush)
    • addChildResource

      public void addChildResource(AmqpResource resource)
      Description copied from interface: AmqpResourceParent
      Adds the given resource as a child of this resource so that it's lifetime becomes managed by that of its parent.
      Specified by:
      addChildResource in interface AmqpResourceParent
      Parameters:
      resource - The AmqpResource that is a child of this one.
    • removeChildResource

      public void removeChildResource(AmqpResource resource)
      Description copied from interface: AmqpResourceParent
      Removes the given resource from the registered child resources managed by this one.
      Specified by:
      removeChildResource in interface AmqpResourceParent
      Parameters:
      resource - The AmqpResource that is no longer a child of this one.
    • getMessageFactory

      public JmsMessageFactory getMessageFactory()
      Description copied from interface: Provider
      Gets the Provider specific Message factory for use in the JMS layer when a Session is asked to create a Message type. The Provider should implement it's own internal JmsMessage core to optimize read / write and marshal operations for the connection.
      Specified by:
      getMessageFactory in interface Provider
      Returns:
      a JmsMessageFactory instance for use by the JMS layer.
    • newProviderFuture

      public ProviderFuture newProviderFuture()
      Description copied from interface: Provider
      Gets a ProviderFuture instance from the Provider for use in performing Provider calls that require an asynchronous completion to know when the call to the provider has succeeded or failed.
      Specified by:
      newProviderFuture in interface Provider
      Returns:
      a ProviderFuture for use in calling Provider methods that require a completion object.
    • newProviderFuture

      public ProviderFuture newProviderFuture(ProviderSynchronization synchronization)
      Description copied from interface: Provider
      Gets a ProviderFuture instance from the Provider for use in performing Provider calls that require an asynchronous completion to know when the call to the provider has succeeded or failed.
      Specified by:
      newProviderFuture in interface Provider
      Parameters:
      synchronization - A ProviderSynchronization to assign to the resulting ProviderFuture.
      Returns:
      a ProviderFuture for use in calling Provider methods that require a completion object.
    • setTraceFrames

      public void setTraceFrames(boolean trace)
    • isTraceFrames

      public boolean isTraceFrames()
    • getTraceFramesPayloadLimit

      public int getTraceFramesPayloadLimit()
    • setTraceFramesPayloadLimit

      public void setTraceFramesPayloadLimit(int traceFramesPayloadLimit)
    • setTraceBytes

      public void setTraceBytes(boolean trace)
    • isTraceBytes

      public boolean isTraceBytes()
    • isSaslLayer

      public boolean isSaslLayer()
    • setSaslLayer

      public void setSaslLayer(boolean saslLayer)
      Sets whether a sasl layer is used for the connection or not.
      Parameters:
      saslLayer - true to enable the sasl layer, false to disable it.
    • getSaslMechanisms

      public Set<String> getSaslMechanisms()
    • setSaslMechanisms

      public void setSaslMechanisms(String[] saslMechanisms)
      Sets a selection of mechanisms to restrict the choice to, enabling only a subset of the servers offered mechanisms to be selectable.
      Parameters:
      saslMechanisms - the mechanisms to restrict choice to, or null not to restrict.
    • getVhost

      public String getVhost()
    • setVhost

      public void setVhost(String vhost)
      Sets the hostname to be used in the AMQP SASL Init and Open frames. If set null, the host provided in the remoteURI will be used. If set to the empty string, the hostname field of the frames will be cleared.
      Parameters:
      vhost - the hostname to include in SASL Init and Open frames.
    • getIdleTimeout

      public int getIdleTimeout()
    • setIdleTimeout

      public void setIdleTimeout(int idleTimeout)
      Sets the idle timeout (in milliseconds) after which the connection will be closed if the peer has not send any data. The provided value will be halved before being transmitted as our advertised idle-timeout in the AMQP Open frame.
      Parameters:
      idleTimeout - the timeout in milliseconds.
    • getDrainTimeout

      public int getDrainTimeout()
    • setDrainTimeout

      public void setDrainTimeout(int drainTimeout)
      Sets the drain timeout (in milliseconds) after which a consumer will be treated as having failed and will be closed due to unknown state of the remote having not responded to the requested drain.
      Parameters:
      drainTimeout - the drainTimeout to use for receiver links.
    • getMaxFrameSize

      public int getMaxFrameSize()
    • getMaxWriteBytesBeforeFlush

      public int getMaxWriteBytesBeforeFlush()
    • setMaxWriteBytesBeforeFlush

      public void setMaxWriteBytesBeforeFlush(int maxWriteBytesBeforeFlush)
      Sets the maximum number of bytes that will be written on a large set of batched writes before a flush is requested on the Transport.
      Parameters:
      maxWriteBytesBeforeFlush - number of bytes written before a flush is requested.
    • getAnonymousFallbackCacheSize

      public int getAnonymousFallbackCacheSize()
      Returns:
      the configured max number of cached anonymous fallback producers to keep.
    • setAnonymousFallbackCacheSize

      public void setAnonymousFallbackCacheSize(int size)
      Sets the number of anonymous fallback producers to keep open in a cache in order to improve overall performance of anonymous fallback producer sends.
      Parameters:
      size - The number of fallback producers to cache.
    • getAnonymousFallbackCacheTimeout

      public int getAnonymousFallbackCacheTimeout()
      Returns:
      The configured time before a cache anonymous producer link is close due to inactivity.
    • setAnonymousFallbackCacheTimeout

      public void setAnonymousFallbackCacheTimeout(int timeout)
      Sets the timeout used to close cached anonymous producers that have not sent any messages in that time period. The value is set in milliseconds with a value less that or equal to zero resulting in no timeout being applied.
      Parameters:
      timeout - Time in milliseconds that a cache anonymous producer can be idle before being close.
    • setMaxFrameSize

      public void setMaxFrameSize(int maxFrameSize)
      Sets the max frame size (in bytes). Values of -1 indicates to use the proton default.
      Parameters:
      maxFrameSize - the frame size in bytes.
    • getSessionOutgoingWindow

      public long getSessionOutgoingWindow()
    • setSessionOutgoingWindow

      public void setSessionOutgoingWindow(long sessionOutoingWindow)
      Sets the outgoing window size for the AMQP session. Values may be between -1 and 2^32-1, where -1 indicates to use the default.
      Parameters:
      sessionOutoingWindow - the outgoing window size
    • isAllowNonSecureRedirects

      public boolean isAllowNonSecureRedirects()
    • setAllowNonSecureRedirects

      public void setAllowNonSecureRedirects(boolean allowNonSecureRedirects)
      Should the AMQP connection allow a redirect or failover server update that redirects from a secure connection to an non-secure one (SSL to TCP).
      Parameters:
      allowNonSecureRedirects - the allowNonSecureRedirects value to apply to this AMQP connection.
    • getCloseTimeout

      public long getCloseTimeout()
    • getConnectTimeout

      public long getConnectTimeout()
    • getRequestTimeout

      public long getRequestTimeout()
    • getSendTimeout

      public long getSendTimeout()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getChannelMax

      public int getChannelMax()
    • setChannelMax

      public void setChannelMax(int channelMax)
    • getTransport

      public Transport getTransport()
    • setProviderListener

      public void setProviderListener(ProviderListener listener)
      Description copied from interface: Provider
      Sets the listener of events from this Provider instance.
      Specified by:
      setProviderListener in interface Provider
      Parameters:
      listener - The listener instance that will receive all event callbacks.
    • getProviderListener

      public ProviderListener getProviderListener()
      Description copied from interface: Provider
      Gets the currently set ProdiverListener instance.
      Specified by:
      getProviderListener in interface Provider
      Returns:
      the currently set ProviderListener instance.
    • getRemoteURI

      public URI getRemoteURI()
      Description copied from interface: Provider
      Returns the URI used to configure this Provider and specify the remote address of the Broker it connects to.
      Specified by:
      getRemoteURI in interface Provider
      Returns:
      the URI used to configure this Provider.
    • getFailureCause

      public Throwable getFailureCause()
    • isFailed

      public boolean isFailed()
    • getAlternateURIs

      public List<URI> getAlternateURIs()
      Description copied from interface: Provider
      Returns a List of alternate remote peers (possibly found via discovery) to which the caller can attempt a recoonect should this provider connection fail. If there are no known alternates this method returns an empty List.
      Specified by:
      getAlternateURIs in interface Provider
      Returns:
      a List or alternate remote URIs that could be connected to later.
    • getProtonTransport

      public org.apache.qpid.proton.engine.Transport getProtonTransport()
    • getProtonConnection

      public org.apache.qpid.proton.engine.Connection getProtonConnection()
    • getProvider

      public AmqpProvider getProvider()
      Specified by:
      getProvider in interface AmqpResourceParent
      Returns:
      a reference to the root AmqpProvider.
    • scheduleRequestTimeout

      public ScheduledFuture<?> scheduleRequestTimeout(AsyncResult request, long timeout, ProviderException error)
      Allows a resource to request that its parent resource schedule a future cancellation of a request and return it a Future instance that can be used to cancel the scheduled automatic failure of the request.
      Parameters:
      request - The request that should be marked as failed based on configuration.
      timeout - The time to wait before marking the request as failed.
      error - The error to use when failing the pending request.
      Returns:
      a ScheduledFuture that can be stored by the caller.
    • scheduleRequestTimeout

      public ScheduledFuture<?> scheduleRequestTimeout(AsyncResult request, long timeout, AmqpExceptionBuilder builder)
      Allows a resource to request that its parent resource schedule a future cancellation of a request and return it a Future instance that can be used to cancel the scheduled automatic failure of the request.
      Parameters:
      request - The request that should be marked as failed based on configuration.
      timeout - The time to wait before marking the request as failed.
      builder - An AmqpExceptionBuilder to use when creating a timed out exception.
      Returns:
      a ScheduledFuture that can be stored by the caller.
    • addToFailOnConnectionDropTracking

      public void addToFailOnConnectionDropTracking(AsyncResult result)
    • removeFromFailOnConnectionDropTracking

      public void removeFromFailOnConnectionDropTracking(AsyncResult result)