com.day.cq.replication.ReplicatedAction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aem-sdk-api Show documentation
Show all versions of aem-sdk-api Show documentation
The Adobe Experience Manager SDK
/*************************************************************************
* ADOBE CONFIDENTIAL
* ___________________
*
* Copyright 2011 Adobe
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe and its suppliers, if any. The intellectual
* and technical concepts contained herein are proprietary to Adobe
* and its suppliers and are protected by all applicable intellectual
* property laws, including trade secret and copyright laws.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe.
**************************************************************************/
package com.day.cq.replication;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nonnull;
import org.osgi.service.event.Event;
public class ReplicatedAction {
public static final String PROPERTY_AGENT_IDS = "agentIds";
public ReplicatedAction(@Nonnull ReplicationAction replicationAction, List agentIds) {
super();
this.replicationAction = replicationAction;
this.agentIds = agentIds != null ? Collections.unmodifiableList(agentIds) : null;
}
private final ReplicationAction replicationAction;
private final List agentIds;
/**
* Return the ReplicationAction
*
* @return the ReplicationAction
*/
public ReplicationAction getReplicationAction() {
return replicationAction;
}
/**
* Return the agentIds
*
* @return the agentIds
*/
public List getAgentIds() {
return agentIds;
}
/**
* Convert an OSGi event to a replication event.
*
* @param evt The OSGi event
* @return The replication event if the OSGi event contained a replication event. Otherwise null is returned.
*/
@SuppressWarnings("unchecked")
public static ReplicatedAction fromEvent(Event evt) {
ReplicationAction replicationAction = ReplicationAction.fromEvent(evt);
if (replicationAction != null) {
return new ReplicatedAction(replicationAction, (List) evt.getProperty(PROPERTY_AGENT_IDS));
}
return null;
}
/**
* Create an OSGi event out of the replication event.
*
* @param distributeEvents if true
a distributed event is created
* @return A new OSGi event.
*/
public Event toEvent(boolean distributeEvents) {
Map properties = new HashMap<>(replicationAction.createEventProperties(distributeEvents));
if (agentIds != null) {
properties.put(PROPERTY_AGENT_IDS, agentIds);
}
return new Event(ReplicationAction.EVENT_TOPIC, properties);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy