Exemplo n.º 1
0
  public void checkWriteAccess(Object context) {
    if (isTransactionLoggingDisabled()) {
      return;
    }

    // First check if we have any TXN context at all (else exception thrown)
    ClientTransaction txn = getTransaction(context);

    // make sure we're not in a read-only transaction
    // txn.readOnlyCheck();
    if (txn.getTransactionType() == TxnType.READ_ONLY) {
      throw new ReadOnlyException(
          "Current transaction with read-only access attempted to modify a shared object.  "
              + "\nPlease alter the locks section of your Terracotta configuration so that the methods involved in this transaction have read/write access.",
          Thread.currentThread().getName(),
          cidProvider.getChannelID().toLong());
    }
  }
Exemplo n.º 2
0
  private ClientTransaction getTransaction(Object context) throws UnlockedSharedObjectException {
    ClientTransaction tx = getTransactionOrNull();
    if (tx == null) {

      String type = context == null ? null : context.getClass().getName();
      String errorMsg =
          "Attempt to access a shared object outside the scope of a shared lock.  "
              + "\nAll access to shared objects must be within the scope of one or more shared locks defined in your Terracotta configuration.  "
              + "\nPlease alter the locks section of your Terracotta configuration so that this access is auto-locked or protected by a named lock.";
      String details = "";
      if (type != null) {
        details += "Shared Object Type: " + type;
      }
      throw new UnlockedSharedObjectException(
          errorMsg, Thread.currentThread().getName(), cidProvider.getChannelID().toLong(), details);
    }
    return tx;
  }