Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c8df7d85de45999ccd4b1a0a1504d1199e66c277 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * Copyright (c) 2009, 2011, 2012 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Eike Stepper - initial API and implementation
 */
package org.eclipse.emf.cdo.transaction;

import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDelta;
import org.eclipse.emf.cdo.view.CDOView;

/**
 * Asynchronously executes a delegate handler's pre-event methods. The delegate handler's code may access the
 * {@link CDOView view} without causing deadlocks.
 *
 * @author Simon McDuff
 * @since 2.0
 */
public class CDOAsyncTransactionHandler implements CDOTransactionHandler
{
  private CDOTransactionHandler delegate;

  public CDOAsyncTransactionHandler(CDOTransactionHandler delegate)
  {
    this.delegate = delegate;
  }

  /**
   * Asynchronously executes the delegate handler's {@link #attachingObject(CDOTransaction, CDOObject)
   * attachingObject()} method.
   */
  public final void attachingObject(final CDOTransaction transaction, final CDOObject object)
  {
    runAsync(new Runnable()
    {
      public void run()
      {
        delegate.attachingObject(transaction, object);
      }
    });
  }

  /**
   * Asynchronously executes the delegate handler's {@link #detachingObject(CDOTransaction, CDOObject)
   * detachingObject()} method.
   */
  public final void detachingObject(final CDOTransaction transaction, final CDOObject object)
  {
    runAsync(new Runnable()
    {
      public void run()
      {
        delegate.detachingObject(transaction, object);
      }
    });
  }

  /**
   * Asynchronously executes the delegate handler's {@link #modifyingObject(CDOTransaction, CDOObject, CDOFeatureDelta)
   * modifyingObject()} method.
   */
  public final void modifyingObject(final CDOTransaction transaction, final CDOObject object,
      final CDOFeatureDelta featureChange)
  {
    runAsync(new Runnable()
    {
      public void run()
      {
        delegate.modifyingObject(transaction, object, featureChange);
      }
    });
  }

  /**
   * Asynchronously executes the delegate handler's {@link #committingTransaction(CDOTransaction, CDOCommitContext)
   * committingTransaction()} method.
   */
  public void committingTransaction(CDOTransaction transaction, CDOCommitContext commitContext)
  {
    delegate.committingTransaction(transaction, commitContext);
  }

  /**
   * Synchronously executes the delegate handler's {@link #committedTransaction(CDOTransaction, CDOCommitContext)
   * committedTransaction()} method.
   */
  public void committedTransaction(CDOTransaction transaction, CDOCommitContext commitContext)
  {
    delegate.committedTransaction(transaction, commitContext);
  }

  /**
   * Synchronously executes the delegate handler's {@link #rolledBackTransaction(CDOTransaction)
   * rolledBackTransaction()} method.
   */
  public void rolledBackTransaction(CDOTransaction transaction)
  {
    delegate.rolledBackTransaction(transaction);
  }

  /**
   * Should be overridden if you want to use different threading mechanism.
   */
  protected void runAsync(Runnable runnable)
  {
    new Thread(runnable).start();
  }
}

Back to the top