Hi @uppari_ramesh,
ReplicationTransaction is not exposed as an OSGi service, you can't get the instance of this class via @Reference - so the fact is not working for you is expected.
Nevertheless I do not think you need ReplicationTransaction explicitly.
In terms of agent related logs you should use ReplicationLog class.
It contains methods to access logs and append your own messages into log.
You can get ReplicationLog object, from Agent class via getLog() method. You can combine it with ReplicationListener which will be run once replication process is complete.
Here is an example code:
import com.day.cq.replication.*;
@Component(
service = WorkflowProcess.class,
property = "process.label=Custom Process"
)
public class CustomWorkflowProcess implements WorkflowProcess {
@Reference
private Replicator replicator;
@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
// set your won agent id
AgentIdFilter agentIdFilter = new AgentIdFilter("publish");
ReplicationOptions replicationOptions = new ReplicationOptions();
replicationOptions.setFilter(agentIdFilter);
// set this option to use Replication Listener
replicationOptions.setSynchronous(true);
replicationOptions.setListener(new CustomReplicationListener());
try {
replicator.replicate(null, ReplicationActionType.ACTIVATE, "/content/we-retail/language-masters/en/test2", replicationOptions);
} catch (ReplicationException e) {
e.printStackTrace();
}
}
private class CustomReplicationListener implements ReplicationListener {
@Override
public void onStart(Agent agent, ReplicationAction replicationAction) {
// place for your code
}
@Override
public void onMessage(ReplicationLog.Level level, String s) {
// place for your code
}
@Override
public void onEnd(Agent agent, ReplicationAction replicationAction, ReplicationResult replicationResult) {
if (replicationResult.isSuccess()) {
// place for logging after replication is completed
agent.getLog().info("Replication completed");
}
}
@Override
public void onError(Agent agent, ReplicationAction replicationAction, Exception e) {
// place for your code
}
}
}