author | timkelly |
Thu, 30 Jul 2009 11:56:23 -0500 | |
changeset 40 | eb3c938c7fef |
permissions | -rw-r--r-- |
40
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
1 |
/******************************************************************************* |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
2 |
* Copyright (c) 2003, 2005 IBM Corporation and others. |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
3 |
* All rights reserved. This program and the accompanying materials |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
5 |
* which accompanies this distribution, and is available at |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
6 |
* http://www.eclipse.org/legal/epl-v10.html |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
7 |
* |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
8 |
* Contributors: |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
9 |
* IBM - Initial API and implementation |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
10 |
*******************************************************************************/ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
11 |
package org.eclipse.core.internal.resources; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
12 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
13 |
import java.util.*; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
14 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
15 |
/** |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
16 |
* The notification mechanism can request marker deltas for several overlapping intervals |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
17 |
* of time. This class maintains a history of marker deltas, and upon request can |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
18 |
* generate a map of marker deltas for any interval. This is done by maintaining |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
19 |
* batches of marker deltas keyed by the change Id at the start of that batch. |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
20 |
* When the delta factory requests a delta, it specifies the start generation, and |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
21 |
* this class assembles the deltas for all generations between then and the most |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
22 |
* recent delta. |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
23 |
*/ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
24 |
class MarkerDeltaManager { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
25 |
private static final int DEFAULT_SIZE = 10; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
26 |
private long[] startIds = new long[DEFAULT_SIZE]; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
27 |
private Map[] batches = new Map[DEFAULT_SIZE]; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
28 |
private int nextFree = 0; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
29 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
30 |
/** |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
31 |
* Returns the deltas from the given start id up until the present. Returns null |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
32 |
* if there are no deltas for that interval. |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
33 |
*/ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
34 |
protected Map assembleDeltas(long start) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
35 |
Map result = null; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
36 |
for (int i = 0; i < nextFree; i++) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
37 |
if (startIds[i] >= start) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
38 |
result = MarkerDelta.merge(result, batches[i]); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
39 |
return result; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
40 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
41 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
42 |
/** |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
43 |
* Flushes all delta batches up to but not including the given start Id. |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
44 |
*/ |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
45 |
protected void resetDeltas(long startId) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
46 |
//find offset of first batch to keep |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
47 |
int startOffset = 0; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
48 |
for (; startOffset < nextFree; startOffset++) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
49 |
if (startIds[startOffset] >= startId) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
50 |
break; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
51 |
if (startOffset == 0) |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
52 |
return; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
53 |
long[] newIds = startIds; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
54 |
Map[] newBatches = batches; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
55 |
//shrink the arrays if it has grown too large |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
56 |
if (startIds.length > DEFAULT_SIZE && (nextFree - startOffset < DEFAULT_SIZE)) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
57 |
newIds = new long[DEFAULT_SIZE]; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
58 |
newBatches = new Map[DEFAULT_SIZE]; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
59 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
60 |
//copy and compact into the new array |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
61 |
int remaining = nextFree - startOffset; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
62 |
System.arraycopy(startIds, startOffset, newIds, 0, remaining); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
63 |
System.arraycopy(batches, startOffset, newBatches, 0, remaining); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
64 |
//clear the end of the array |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
65 |
Arrays.fill(startIds, remaining, startIds.length, 0); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
66 |
Arrays.fill(batches, remaining, startIds.length, null); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
67 |
startIds = newIds; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
68 |
batches = newBatches; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
69 |
nextFree = remaining; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
70 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
71 |
|
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
72 |
protected Map newGeneration(long start) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
73 |
int len = startIds.length; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
74 |
if (nextFree >= len) { |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
75 |
long[] newIds = new long[len * 2]; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
76 |
Map[] newBatches = new Map[len * 2]; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
77 |
System.arraycopy(startIds, 0, newIds, 0, len); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
78 |
System.arraycopy(batches, 0, newBatches, 0, len); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
79 |
startIds = newIds; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
80 |
batches = newBatches; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
81 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
82 |
startIds[nextFree] = start; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
83 |
batches[nextFree] = new HashMap(11); |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
84 |
return batches[nextFree++]; |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
85 |
} |
eb3c938c7fef
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff
changeset
|
86 |
} |