コード例 #1
0
 /**
  * Begin a transaction within a context if required. The context will define a transaction type
  * and if the type requires a transaction one will be begun.
  *
  * @param transaction A <code>Transaction</code>.
  * @param context A <code>TransactionContext</code>.
  * @throws NamingException
  * @throws NotSupportedException
  */
 private void beginXA(final Transaction transaction, final TransactionContext context) {
   XA_LOGGER.logVariable("transaction", transaction);
   XA_LOGGER.logVariable("context", context);
   /* when the transaction context is set, nothing is done
    *
    * when the transaction context is null, no transaction boundary is
    * currently set, so we need to check whether nor not to begin the
    * transaction based upon the type */
   if (isSetXAContext()) {
     switch (context.getType()) {
       case REQUIRED:
         XA_LOGGER.logInfo("{0}Join {1} with {2}.", "\t\t", context, getXAContext());
         break;
       case REQUIRES_NEW:
         LOGGER.logFatal("New transaction required-{0}", context);
         XA_LOGGER.logFatal("New transaction required-{0}", context);
         Assert.assertUnreachable("New transaction required-{0}", context);
         break;
       case NEVER:
         XA_LOGGER.logInfo("{0}No transaction participation-{1}.", "\t\t", context);
         break;
       case SUPPORTED:
         break;
       default:
         LOGGER.logFatal("Unknown transaction type.");
         XA_LOGGER.logFatal("Unknown transaction type.");
         Assert.assertUnreachable("Unknown transaction type.");
     }
   } else {
     switch (context.getType()) {
       case REQUIRES_NEW:
       case REQUIRED:
         setXAContext(context);
         transaction.begin();
         XA_LOGGER.logInfo("Begin transaction-{0}.", context);
         break;
       case NEVER:
         XA_LOGGER.logInfo("{0}No transaction participation-{1}.", "\t\t", context);
         break;
       case SUPPORTED:
         break;
       default:
         LOGGER.logFatal("Unknown transaction type.");
         XA_LOGGER.logFatal("Unknown transaction type.");
         Assert.assertUnreachable("Unknown transaction type.");
     }
   }
 }
コード例 #2
0
 /**
  * Complete a transaction. If the transaction belongs to the given transaction context a
  * rollback/commit will be attempted.
  *
  * @param transaction A <code>Transaction</code>.
  * @param transactionContext A <code>TransactionContext</code>.
  * @throws HeuristicMixedException
  * @throws HeuristicRollbackException
  * @throws RollbackException
  */
 private void completeXA(final Transaction transaction, final TransactionContext context) {
   if (isSetXAContext() && getXAContext().equals(context)) {
     unsetXAContext();
     if (transaction.isRollbackOnly()) {
       XA_LOGGER.logInfo("Rolling transaction-{0}.", context);
       transaction.rollback();
     } else {
       XA_LOGGER.logInfo("Committing transaction-{0}.", context);
       transaction.commit();
     }
   } else {
     switch (context.getType()) {
       case REQUIRES_NEW:
       case REQUIRED:
       case SUPPORTED:
         break;
       case NEVER:
         XA_LOGGER.logInfo("No transaction participation-{0}.", context);
         break;
       default:
         LOGGER.logFatal("Unknown transaction type.");
         XA_LOGGER.logFatal("Unknown transaction type.");
         Assert.assertUnreachable("Unknown transaction type.");
     }
   }
 }
コード例 #3
0
  /** Start the backup service. This involves opening the backup workspace. */
  private void startImpl() {
    logger.logInfo("Starting backup service.");
    try {
      environment = readBackupEnvironment();
      workspace = readBackupWorkspace();
      Assert.assertNotNull(environment, "Backup environment not yet initialized.");
      Assert.assertNotNull(workspace, "Backup workspace not yet initialized.");
      final WorkspaceModel workspaceModel = WorkspaceModel.getInstance();
      if (!workspaceModel.isInitialized(workspace)) {
        workspaceModel.initialize(
            new ProcessAdapter() {
              @Override
              public void beginProcess() {}

              @Override
              public void beginStep(final Step step, final Object data) {}

              @Override
              public void determineSteps(final Integer steps) {}

              @Override
              public void endProcess() {}

              @Override
              public void endStep(final Step step) {}
            },
            new InitializeMediator() {
              public Boolean confirmRestorePremium() {
                return null;
              }

              public Boolean confirmRestoreStandard() {
                return null;
              }
            },
            workspace,
            null);
      }
      eventHandler.start(getModelFactory());
      logger.logInfo("Backup service started.");
    } catch (final Throwable t) {
      throw new BackupException(t, "Failed to start backup service.");
    }
  }
コード例 #4
0
 /**
  * Read the file system from the jive properties.
  *
  * @return A <code>FileSystem</code>.
  */
 private FileSystem readBackupFileSystem() {
   final String thinkParityBackupRoot =
       properties.getProperty(JivePropertyNames.THINKPARITY_BACKUP_ROOT);
   final File thinkParityBackupRootDirectory = new File(thinkParityBackupRoot);
   if (!thinkParityBackupRootDirectory.exists())
     Assert.assertTrue(
         thinkParityBackupRootDirectory.mkdir(),
         "Could not create directory {0}.",
         thinkParityBackupRootDirectory);
   return new FileSystem(new File(thinkParityBackupRoot));
 }
コード例 #5
0
 /**
  * Obtain the annotated transaction type for the method. If the transaction type is not defined on
  * the method; attempt to retreive it from the class. If no transaction annotation is found
  * assert.
  *
  * @param method A <code>Method</code>.
  * @return A <code>TransactionType</code>.
  */
 private TransactionType extractXAType(final Method method) {
   ThinkParityTransaction transaction = method.getAnnotation(ThinkParityTransaction.class);
   if (null == transaction) {
     transaction = method.getDeclaringClass().getAnnotation(ThinkParityTransaction.class);
   }
   if (null == transaction) {
     LOGGER.logFatal(
         "Method {0} of class {1} does not define transactional behaviour.",
         method.getName(), method.getDeclaringClass().toString());
     XA_LOGGER.logFatal(
         "Method {0} of class {1} does not define transactional behaviour.",
         method.getName(), method.getDeclaringClass().toString());
   }
   Assert.assertNotNull(
       transaction,
       "Method {0} of class {1} does not define transactional behaviour.",
       method.getName(),
       method.getDeclaringClass().toString());
   return transaction.value();
 }
コード例 #6
0
 /**
  * Rollback a transaction. If the transaction belongs to the context; a rollback will be
  * attempted. If it does not; depending on the context type; the transaction's rollback only flag
  * will be set.
  *
  * @param transaction A <code>Transaction</code>.
  * @param transactionContext A <code>TransactionContext</code>.
  */
 private void rollbackXA(final Transaction transaction, final TransactionContext context) {
   switch (context.getType()) {
     case REQUIRES_NEW:
     case REQUIRED:
       XA_LOGGER.logInfo("Set rollback only-{0}.", context);
       transaction.setRollbackOnly();
       break;
     case NEVER:
       XA_LOGGER.logInfo("No transaction participation-{0}.", context);
       break;
     case SUPPORTED:
       if (transaction.isActive()) {
         XA_LOGGER.logInfo("Set rollback only-{0}.", context);
         transaction.setRollbackOnly();
       } else {
         XA_LOGGER.logTrace("Transaction for {0} is not active.", context);
       }
       break;
     default:
       LOGGER.logFatal("Unknown transaction type.");
       XA_LOGGER.logFatal("Unknown transaction type.");
       Assert.assertUnreachable("Unknown transaction type.");
   }
 }
コード例 #7
0
ファイル: Assert.java プロジェクト: raykroeker/thinkparity
 /**
  * Assert that the object references provided are not null. If they are, throw a {@link
  * NullPointerAssertion}.
  *
  * @param message An assertion message.
  * @param objectReferences <code>java.lang.Object</code>
  */
 public static void assertNotNull(final Object message, final Object[] objectReferences) {
   Assert.assertNotNull(message, (Object) objectReferences);
   for (int i = 0; i < objectReferences.length; i++)
     Assert.assertNotNull(message, objectReferences[i]);
 }
コード例 #8
0
ファイル: Assert.java プロジェクト: raykroeker/thinkparity
 /**
  * Assert that an area of code is unreachable. This is achived by throwing an <code>
  * UnreachableCodeAssertion</code>.
  *
  * @param message An assertion message.
  */
 public static void assertUnreachable(
     final String assertionMessage, final Object... assertionArguments) {
   throw Assert.createUnreachable(createMessage(assertionMessage, assertionArguments));
 }
コード例 #9
0
ファイル: Assert.java プロジェクト: raykroeker/thinkparity
 /**
  * Assert that an area of code is unreachable. This is achived by throwing an <code>
  * UnreachableCodeAssertion</code>.
  *
  * @param message An assertion message.
  */
 public static void assertUnreachable(final Object message) {
   throw Assert.createUnreachable(message);
 }
コード例 #10
0
ファイル: Assert.java プロジェクト: raykroeker/thinkparity
 /**
  * Assert that the current api method has not yet been implemented.
  *
  * @param message An assertion message.
  */
 public static void assertNotYetImplemented(final Object message) {
   throw Assert.createNotYetImplemented(message);
 }
コード例 #11
0
 /**
  * Read the backup workspace.
  *
  * @return The backup <code>Workspace</code>.
  */
 private Workspace readBackupWorkspace() {
   Assert.assertNotNull(environment, "Backup environment not yet initialized.");
   Assert.assertNotNull(fileSystem, "Backup file system not yet initialized.");
   final WorkspaceModel workspaceModel = WorkspaceModel.getInstance();
   return workspaceModel.getWorkspace(fileSystem.getRoot());
 }