Ejemplo n.º 1
0
  /**
   * Used to retrive the TransactionStateDiff for this transaction. If you subclass is doing its own
   * thing (ArcSDE I am talking to you) then you should arrange for this method to return null.
   *
   * <p>By default a TransactionStateDiff will be created that holds any changes in memory.
   *
   * <p>
   *
   * @param transaction
   * @return TransactionStateDiff or null if subclass is handling differences
   */
  protected TransactionStateDiff state(Transaction transaction) {
    synchronized (transaction) {
      TransactionStateDiff state = (TransactionStateDiff) transaction.getState(this);

      if (state == null) {
        state = new TransactionStateDiff(this);
        transaction.putState(this, state);
      }

      return state;
    }
  }
Ejemplo n.º 2
0
 public void processTimeout(javax.sip.TimeoutEvent timeoutEvent) {
   Transaction transaction;
   if (timeoutEvent.isServerTransaction()) {
     transaction = timeoutEvent.getServerTransaction();
   } else {
     transaction = timeoutEvent.getClientTransaction();
   }
   System.out.println("state = " + transaction.getState());
   System.out.println("dialog = " + transaction.getDialog());
   System.out.println("dialogState = " + transaction.getDialog().getState());
   System.out.println("Transaction Time out");
 }
  /**
   * Processes the given transaction, updates its state and returns the same transaction instance or
   * a new one (an instance of a <code>Transaction</code> subclass), which is based on the old
   * transaction, but adds more (adapter specific) information to it.
   *
   * <p>The current implementation fails any transaction with the <code>Transaction.ASSIGNED</code>
   * state, so it has to be overriden to work properly. It also sets the transaction processor of
   * the given transaction to the payment module instance. It's recomended to call this method from
   * the overriden one for every unhandled transaction (with the state, which can't be further
   * processed in the adapter). It ensures that the control over the transaction will return to the
   * payment module.
   *
   * @param transaction the transaction to be processed
   * @return the transaction after processing
   */
  public Transaction process(Transaction transaction) {
    if (transaction.getState() == Transaction.ASSIGNED) {
      // was not processed by the child adapter class
      transaction.setState(Transaction.FAILED);
      transaction.setNeedsUI(false);
    }

    // return any transaction which was not processed by the payment
    // adapter back to the payment module
    transaction.setTransactionProcessor(PaymentModule.getInstance());
    return transaction;
  }
Ejemplo n.º 4
0
  public void processResponse(ResponseEvent responseReceivedEvent) {
    System.out.println("Got a response");
    Response response = (Response) responseReceivedEvent.getResponse();
    Transaction tid = responseReceivedEvent.getClientTransaction();

    System.out.println(
        "Response received with client transaction id " + tid + ":\n" + response.getStatusCode());
    if (tid == null) {
      System.out.println("Stray response -- dropping ");
      return;
    }
    System.out.println("transaction state is " + tid.getState());
    System.out.println("Dialog = " + tid.getDialog());
    System.out.println("Dialog State is " + tid.getDialog().getState());

    try {
      if (response.getStatusCode() == Response.OK
          && ((CSeqHeader) response.getHeader(CSeqHeader.NAME))
              .getMethod()
              .equals(Request.INVITE)) {
        // Request cancel = inviteTid.createCancel();
        // ClientTransaction ct =
        //  sipProvider.getNewClientTransaction(cancel);
        // ct.sendRequest();
        Dialog dialog = tid.getDialog();
        CSeqHeader cseq = (CSeqHeader) response.getHeader(CSeqHeader.NAME);
        Request ackRequest = dialog.createAck(cseq.getSeqNumber());
        System.out.println("Sending ACK");
        dialog.sendAck(ackRequest);

        // Send a Re INVITE but this time force it
        // to use UDP as the transport. Else, it will
        // Use whatever transport was used to create
        // the dialog.
        if (reInviteCount == 0) {
          Request inviteRequest = dialog.createRequest(Request.INVITE);
          ((SipURI) inviteRequest.getRequestURI()).removeParameter("transport");
          ((ViaHeader) inviteRequest.getHeader(ViaHeader.NAME)).setTransport("udp");
          inviteRequest.addHeader(contactHeader);
          try {
            Thread.sleep(100);
          } catch (Exception ex) {
          }
          ClientTransaction ct = udpProvider.getNewClientTransaction(inviteRequest);
          dialog.sendRequest(ct);
          reInviteCount++;
        }
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      System.exit(0);
    }
  }
Ejemplo n.º 5
0
  /**
   * Creates the right sort of In-Process Lock.
   *
   * @param transaction
   * @param featureLock
   * @return In-Process Lock
   * @throws FeatureLockException When a Transaction lock is requested against
   *     Transaction.AUTO_COMMIT
   */
  protected synchronized Lock createLock(Transaction transaction, FeatureLock featureLock)
      throws FeatureLockException {
    if (featureLock == FeatureLock.TRANSACTION) {
      // we need a Transacstion Lock
      if (transaction == Transaction.AUTO_COMMIT) {
        throw new FeatureLockException("We cannot issue a Transaction lock against AUTO_COMMIT");
      }

      TransactionLock lock = (TransactionLock) transaction.getState(this);

      if (lock == null) {
        lock = new TransactionLock();
        transaction.putState(this, lock);

        return lock;
      } else {
        return lock;
      }
    } else {
      return new MemoryLock(featureLock);
    }
  }