Class OriginateTransaction

All Implemented Interfaces:
Expirable

public class OriginateTransaction extends ClientActionTransaction
Represents an originate transaction in an AMI (Asterisk Manager Interface) client.

This class manages the logic for initiating an originate action, processing responses and events, and handling failure and success conditions. It also supports adding variables to the originate action and logging important steps in the transaction lifecycle.

  • Field Details

    • log

      protected static final org.slf4j.Logger log
      Logger instance for logging events related to originate transactions.
  • Constructor Details

    • OriginateTransaction

      public OriginateTransaction(ClientConnection clientConnection, String caller, String called, String calledServer, DialplanStep dialplanStep, long timeout)
      Constructs an OriginateTransaction with the specified parameters.

      This constructor initializes an originate transaction using information from a DialplanStep.

      Parameters:
      clientConnection - the ClientConnection to use for the transaction.
      caller - the caller's number.
      called - the called number.
      calledServer - the server to route the call.
      dialplanStep - the DialplanStep containing the context, extension, and priority.
      timeout - the timeout for the originate action in milliseconds.
    • OriginateTransaction

      public OriginateTransaction(ClientConnection clientConnection, String caller, String called, String calledServer, String context, String extension, String priority, long timeout)
      Constructs an OriginateTransaction with the specified parameters.

      This constructor initializes an originate transaction with the provided caller, called, called server, context, extension, priority, and timeout.

      Parameters:
      clientConnection - the ClientConnection to use for the transaction.
      caller - the caller's number.
      called - the called number.
      calledServer - the server to route the call.
      context - the context for the call in the dialplan.
      extension - the extension to dial in the dialplan.
      priority - the priority for the call in the dialplan.
      timeout - the timeout for the originate action in milliseconds.
  • Method Details

    • addInitialVariable

      public void addInitialVariable(String name, String value)
      Adds an initial variable to the originate transaction.
      Parameters:
      name - the name of the variable.
      value - the value of the variable.
    • getCaller

      public String getCaller()
      Returns the caller's number.
      Returns:
      the caller's number.
    • getCalled

      public String getCalled()
      Returns the called number.
      Returns:
      the called number.
    • isOk

      public boolean isOk()
      Determines if the originate transaction is successful.

      If the transaction has no refusal reason, it is considered successful.

      Returns:
      true if the transaction is successful, false otherwise.
    • getRefuseMessage

      public String getRefuseMessage()
      Returns the message explaining why the originate action was refused.
      Returns:
      the refuse message, or null if the action was not refused.
    • getRefuseReason

      public OiginateRefuseReasonType getRefuseReason()
      Returns the reason for the refusal of the originate action.
      Returns:
      the refusal reason, or null if the action was not refused.
    • createAction

      protected AmiAction createAction()
      Creates an AmiAction for the originate transaction.

      This method uses the provided parameters to create an OriginateAction and add any additional variables to it.

      Specified by:
      createAction in class ClientActionTransaction
      Returns:
      the AmiAction representing the originate transaction.
    • processOkResponse

      protected void processOkResponse(AmiResponse response)
      Processes a successful response to the originate action.

      This method is called when a successful response is received, and it logs the completion of the originate action.

      Overrides:
      processOkResponse in class ClientActionTransaction
      Parameters:
      response - the successful AmiResponse.
    • processErrorResponse

      protected void processErrorResponse(AmiResponse response)
      Processes an error response to the originate action.

      This method is called when an error response is received, and it logs the refusal message and sets the refusal reason.

      Specified by:
      processErrorResponse in class ClientActionTransaction
      Parameters:
      response - the error AmiResponse.
    • processEvent

      protected void processEvent(AmiEvent event)
      Processes an event related to the originate action.

      This method is invoked when an event related to the originate action is received. It checks for success or failure and logs the appropriate response.

      Overrides:
      processEvent in class ClientActionTransaction
      Parameters:
      event - the AmiEvent related to the originate action.