blob: 7bef59caae0af051c0ddf968894b9acb7fdf4711 (
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
114
115
116
117
|
/*
* Copyright (c) 2004 - 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.internal.server.syncing;
import org.eclipse.emf.cdo.spi.server.InternalCommitContext;
import org.eclipse.emf.cdo.spi.server.InternalFailoverParticipant;
import org.eclipse.emf.cdo.spi.server.InternalTransaction;
/**
* @author Eike Stepper
*/
public class FailoverParticipant extends SynchronizableRepository implements InternalFailoverParticipant
{
private boolean allowBackupCommits;
public FailoverParticipant()
{
}
public boolean isAllowBackupCommits()
{
return allowBackupCommits;
}
public void setAllowBackupCommits(boolean allowBackupCommits)
{
this.allowBackupCommits = allowBackupCommits;
}
@Override
public void setType(Type type)
{
checkArg(type == MASTER || type == BACKUP, "Type must be MASTER or BACKUP");
super.setType(type);
}
@Override
protected void changingType(Type oldType, Type newType)
{
if (isActive())
{
if (newType == MASTER)
{
// Switch off synchronizer
doStopSynchronization();
}
else
{
// Bug 312879
setReplicationCountersToLatest();
// Switch on synchronizer
doStartSynchronization();
}
}
super.changingType(oldType, newType);
}
protected void doStartSynchronization()
{
super.startSynchronization();
}
protected void doStopSynchronization()
{
super.stopSynchronization();
}
@Override
protected void startSynchronization()
{
if (getType() == BACKUP)
{
doStartSynchronization();
}
}
@Override
protected void stopSynchronization()
{
if (getType() == BACKUP)
{
doStopSynchronization();
}
}
@Override
public InternalCommitContext createCommitContext(InternalTransaction transaction)
{
if (getType() == BACKUP)
{
if (getState() != ONLINE)
{
throw new IllegalStateException("Backup repository is not online");
}
if (allowBackupCommits || transaction.getSession() == getReplicatorSession())
{
return createWriteThroughCommitContext(transaction);
}
throw new IllegalStateException(
"Only the repository synchronizer is allowed to commit transactions to a backup repository");
}
return createNormalCommitContext(transaction);
}
}
|