ReplicationStatusImpl.java
5.3 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceUtil
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.api.wrappers.ValueMapDecorator
*/
package com.day.cq.replication.impl;
import com.day.cq.replication.Agent;
import com.day.cq.replication.AgentManager;
import com.day.cq.replication.ReplicationAction;
import com.day.cq.replication.ReplicationActionType;
import com.day.cq.replication.ReplicationQueue;
import com.day.cq.replication.ReplicationStatus;
import com.day.cq.replication.impl.queue.ReplicationQueueImpl;
import java.util.Calendar;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.wrappers.ValueMapDecorator;
public class ReplicationStatusImpl
implements ReplicationStatus {
private final AgentManager agentMgr;
private final String path;
private final ValueMap properties;
private List<ReplicationQueue.Entry> status;
private List<ReplicationQueue.Entry> pending;
private Boolean delivered;
public ReplicationStatusImpl(AgentManager agentMgr, String path, Resource resource) {
this(agentMgr, path, ResourceUtil.getValueMap((Resource)resource));
}
public ReplicationStatusImpl(AgentManager agentMgr, String path, ValueMap properties) {
this.agentMgr = agentMgr;
this.path = path;
this.properties = new ValueMapDecorator((Map)properties);
}
@Override
public List<ReplicationQueue.Entry> getQueueStatus() {
if (this.status == null) {
this.status = new LinkedList<ReplicationQueue.Entry>();
for (Agent agent : this.agentMgr.getAgents().values()) {
ReplicationQueue queue;
if (agent.isInMaintenanceMode() || (queue = agent.getQueue()) == null) continue;
for (ReplicationQueue.Entry entry : queue.entries(this.path)) {
this.status.add(entry);
}
}
}
return this.status;
}
@Override
public boolean isPending() {
boolean isPending = false;
if (this.pending != null) {
isPending = !this.pending.isEmpty();
} else {
for (Agent agent : this.agentMgr.getAgents().values()) {
ReplicationQueue queue;
if (agent.isInMaintenanceMode() || (queue = agent.getQueue()) == null) continue;
if (queue instanceof ReplicationQueueImpl) {
if (!((ReplicationQueueImpl)queue).hasEntries(this.path)) continue;
isPending = true;
break;
}
if (queue.entries(this.path).isEmpty()) continue;
isPending = true;
break;
}
}
return isPending;
}
@Override
public List<ReplicationQueue.Entry> getPending() {
if (this.pending == null) {
this.pending = new LinkedList<ReplicationQueue.Entry>();
ReplicationActionType type = this.getLastReplicationAction();
Calendar last = this.getLastPublished();
if (type != null && last != null) {
long time = last.getTimeInMillis();
for (ReplicationQueue.Entry s : this.getQueueStatus()) {
if (s.getAction().getType() != type || s.getAction().getTime() != time) continue;
this.pending.add(s);
}
}
}
return this.pending;
}
@Override
public boolean isActivated() {
return this.getLastReplicationAction() == ReplicationActionType.ACTIVATE;
}
@Override
public boolean isDeactivated() {
return this.getLastReplicationAction() == ReplicationActionType.DEACTIVATE;
}
@Override
public boolean isDelivered() {
if (this.delivered == null) {
ReplicationActionType type = this.getLastReplicationAction();
this.delivered = type == ReplicationActionType.ACTIVATE ? Boolean.valueOf(!this.isPending()) : (type == ReplicationActionType.DEACTIVATE || type == ReplicationActionType.DELETE ? Boolean.valueOf(this.isPending()) : Boolean.valueOf(false));
}
return this.delivered;
}
@Override
public boolean isPublished() {
return this.isDelivered();
}
@Override
public Calendar getLastPublished() {
if (this.properties.containsKey((Object)"cq:lastReplicated")) {
return (Calendar)this.properties.get("cq:lastReplicated", Calendar.class);
}
return (Calendar)this.properties.get("cq:lastPublished", Calendar.class);
}
@Override
public String getLastPublishedBy() {
if (this.properties.containsKey((Object)"cq:lastReplicatedBy")) {
return (String)this.properties.get("cq:lastReplicatedBy", String.class);
}
return (String)this.properties.get("cq:lastPublishedBy", String.class);
}
@Override
public ReplicationActionType getLastReplicationAction() {
return ReplicationActionType.fromName((String)this.properties.get("cq:lastReplicationAction", String.class));
}
}