diff --git a/contrib/extensions/replication/core/pom.xml b/contrib/extensions/replication/core/pom.xml
deleted file mode 100644
index daab3c11197..00000000000
--- a/contrib/extensions/replication/core/pom.xml
+++ /dev/null
@@ -1,228 +0,0 @@
-
-
-
- 4.0.0
-
-
-
-
- org.apache.sling
- sling
- 19
-
-
-
-
-
- org.apache.sling
- org.apache.sling.replication
- 0.0.1-SNAPSHOT
- bundle
-
- Apache Sling Replication
-
- The Apache Sling Replication bundle provides a set of utilities to replicate content from / to other Sling instances.
-
-
-
- scm:svn:http://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/replication
- scm:svn:https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/replication
- http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication
-
-
-
-
-
-
-
-
- org.apache.felix
- maven-scr-plugin
-
-
- org.apache.sling
- maven-sling-plugin
-
-
- org.apache.felix
- maven-bundle-plugin
- true
-
-
- org.apache.sling.replication
- SLING-CONTENT/libs/sling/replication/config;path:=/libs/sling/replication/install;overwrite:=true
-
- org.apache.sling.replication.agent,
- org.apache.sling.replication.transport.authentication,
- org.apache.sling.replication.transport,
- org.apache.sling.replication.communication,
- org.apache.sling.replication.event,
- org.apache.sling.replication.queue,
- org.apache.sling.replication.rule,
- org.apache.sling.replication.serialization
-
- httpasyncclient
-
-
-
-
- org.apache.maven.plugins
- maven-javadoc-plugin
-
-
-
-
-
-
-
-
-
-
- junit
- junit
- test
-
-
- org.mockito
- mockito-core
- 1.9.5
- test
-
-
-
- org.apache.sling
- org.apache.sling.api
- 2.3.0
-
-
- org.apache.sling
- org.apache.sling.commons.osgi
- 2.2.0
-
-
- org.apache.sling
- org.apache.sling.commons.scheduler
- 2.4.0
-
-
- org.apache.sling
- org.apache.sling.jcr.api
- 2.1.0
-
-
- org.apache.sling
- org.apache.sling.event
- 3.3.0
- provided
-
-
- org.apache.sling
- org.apache.sling.hc.core
- 1.0.6
- provided
-
-
- org.apache.sling
- org.apache.sling.settings
- 1.3.0
- provided
-
-
-
- org.slf4j
- slf4j-api
- 1.6.2
-
-
- org.slf4j
- slf4j-simple
- 1.6.2
- runtime
-
-
-
- javax.jcr
- jcr
- 2.0
-
-
- javax.servlet
- servlet-api
-
-
- org.osgi
- org.osgi.core
-
-
- org.osgi
- org.osgi.compendium
-
-
-
- org.apache.jackrabbit.vault
- org.apache.jackrabbit.vault
- 3.0.0
-
-
-
- org.apache.httpcomponents
- fluent-hc
- 4.3.2
-
-
- org.apache.httpcomponents
- httpasyncclient
- 4.0
-
-
- org.apache.httpcomponents
- httpcore-osgi
- 4.3.1
-
-
- org.apache.httpcomponents
- httpclient-osgi
- 4.3.2
-
-
-
- org.apache.jackrabbit
- jackrabbit-jcr-commons
- 2.6.2
- provided
-
-
-
- commons-io
- commons-io
- 2.4
- provided
-
-
-
-
-
- org.codehaus.mojo
- findbugs-maven-plugin
- 2.5.3
-
-
-
-
diff --git a/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/AgentConfigurationException.java b/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/AgentConfigurationException.java
deleted file mode 100644
index a064a874664..00000000000
--- a/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/AgentConfigurationException.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.replication.agent;
-
-/**
- * Represents errors happened during {@link ReplicationAgent} configuration
- */
-@SuppressWarnings("serial")
-public class AgentConfigurationException extends Exception {
-
- public AgentConfigurationException(Exception e) {
- super(e);
- }
-
- public AgentConfigurationException(String string) {
- super(string);
- }
-}
diff --git a/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/AgentReplicationException.java b/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/AgentReplicationException.java
deleted file mode 100644
index 57537454acc..00000000000
--- a/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/AgentReplicationException.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.replication.agent;
-
-/**
- * Represents errors happened while {@link ReplicationAgent}s do replications.
- */
-@SuppressWarnings("serial")
-public class AgentReplicationException extends Exception {
-
- public AgentReplicationException(Exception e) {
- super(e);
- }
-
- public AgentReplicationException(String string) {
- super(string);
- }
-}
diff --git a/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/ReplicationAgent.java b/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/ReplicationAgent.java
deleted file mode 100644
index 98034e3b5e1..00000000000
--- a/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/ReplicationAgent.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.replication.agent;
-
-import org.apache.sling.replication.communication.ReplicationRequest;
-import org.apache.sling.replication.communication.ReplicationResponse;
-import org.apache.sling.replication.queue.ReplicationQueue;
-import org.apache.sling.replication.queue.ReplicationQueueException;
-import org.apache.sling.replication.serialization.ReplicationPackage;
-
-/**
- * A replication agent is responsible for delivering content to another instance
- */
-public interface ReplicationAgent {
-
- /**
- * get agent name
- *
- * @return the agent name as a String
- */
- String getName();
-
- /**
- * get the agent queue with the given name
- *
- * @param name a queue name as a String
- * @return a {@link ReplicationQueue} with the given name bound to this agent, if it exists, null otherwise
- * @throws ReplicationQueueException
- */
- ReplicationQueue getQueue(String name) throws ReplicationQueueException;
-
- /**
- * Synchronously sends a {@link ReplicationRequest} waiting for a {@link ReplicationResponse}
- *
- * @param replicationRequest the replication request
- * @return a {@link ReplicationResponse}
- * @throws AgentReplicationException
- */
- ReplicationResponse execute(ReplicationRequest replicationRequest) throws AgentReplicationException;
-
- /**
- * Asynchronously sends a {@link ReplicationRequest} without waiting for any response
- *
- * @param replicationRequest the replication request
- * @throws AgentReplicationException
- */
- void send(ReplicationRequest replicationRequest) throws AgentReplicationException;
-
- /**
- * removes a package from the top of the queue
- * @param queueName
- * the name of a {@link ReplicationQueue} bound to this agent
- * @return the ReplicationPackage popped from the underlying ReplicationQueue
- * @throws ReplicationQueueException
- */
- ReplicationPackage removeHead(String queueName) throws ReplicationQueueException;
-
- /**
- * enables the current {@link ReplicationAgent}
- */
- void enable();
-
- /**
- * disables the current {@link ReplicationAgent}
- */
- void disable();
-}
diff --git a/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfiguration.java b/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfiguration.java
deleted file mode 100644
index d99a38f3f4f..00000000000
--- a/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfiguration.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.replication.agent;
-
-import java.util.Arrays;
-import java.util.Dictionary;
-import java.util.Enumeration;
-import org.apache.sling.commons.osgi.PropertiesUtil;
-
-/**
- * configuration for {@link ReplicationAgent}s
- */
-public class ReplicationAgentConfiguration {
-
- public static final String TRANSPORT = "TransportHandler.target";
-
- public static final String TRANSPORT_AUTHENTICATION_FACTORY = "TransportAuthenticationProviderFactory.target";
-
- public static final String QUEUEPROVIDER = "ReplicationQueueProvider.target";
-
- public static final String PACKAGING = "ReplicationPackageBuilder.target";
-
- public static final String NAME = "name";
-
- public static final String ENDPOINT = "endpoints";
-
- public static final String ENDPOINT_STRATEGY = "endpoints.strategy";
-
- public static final String AUTHENTICATION_PROPERTIES = "authentication.properties";
-
- public static final String QUEUE_DISTRIBUTION = "ReplicationQueueDistributionStrategy.target";
- public static final String RULES = "rules";
-
- public static final String ENABLED = "enabled";
-
- public static final String USE_AGGREGATE_PATHS = "useAggregatePaths";
-
- public static final String[] COMPONENTS = {TRANSPORT, PACKAGING};
-
- public static final String RUNMODES = "runModes";
-
- private final boolean enabled;
-
- private final String name;
-
- private final String endpoint;
-
- private final String targetTransportHandler;
-
- private final String targetReplicationPackageBuilder;
-
- private final String targetReplicationQueueProvider;
-
- private final String targetReplicationQueueDistributionStrategy;
-
- private final String targetAuthenticationHandlerFactory;
-
- private final String[] authenticationProperties;
-
- private final String[] rules;
-
- private final boolean useAggregatePaths;
-
- private final String[] runModes;
-
- private final Dictionary componentConfiguration;
-
- public ReplicationAgentConfiguration(Dictionary, ?> dictionary, Dictionary componentConfiguration) {
- this.name = PropertiesUtil.toString(dictionary.get(NAME), "");
- this.enabled = PropertiesUtil.toBoolean(dictionary.get(ENABLED), true);
- this.endpoint = PropertiesUtil.toString(dictionary.get(ENDPOINT), "");
- this.targetAuthenticationHandlerFactory = PropertiesUtil.toString(
- dictionary.get(TRANSPORT_AUTHENTICATION_FACTORY), "");
- this.targetReplicationPackageBuilder = PropertiesUtil.toString(dictionary.get(PACKAGING), "");
- this.targetReplicationQueueProvider = PropertiesUtil.toString(
- dictionary.get(QUEUEPROVIDER), "");
- this.targetReplicationQueueDistributionStrategy = PropertiesUtil.toString(dictionary.get(QUEUE_DISTRIBUTION), "");
- this.targetTransportHandler = PropertiesUtil.toString(dictionary.get(TRANSPORT), "");
- String[] ap = PropertiesUtil.toStringArray(dictionary.get(AUTHENTICATION_PROPERTIES));
- this.authenticationProperties = ap != null ? ap : new String[0];
- this.rules = PropertiesUtil.toStringArray(dictionary.get(RULES), new String[0]);
- this.useAggregatePaths = PropertiesUtil.toBoolean(dictionary.get(USE_AGGREGATE_PATHS), true);
- this.runModes = PropertiesUtil.toStringArray(dictionary.get(RUNMODES), new String[0]);
-
- this.componentConfiguration = componentConfiguration;
- }
-
-
- public String[] getAuthenticationProperties() {
- return authenticationProperties;
- }
-
- public String getEndpoint() {
- return endpoint;
- }
-
- public String getName() {
- return name;
- }
-
- public String[] getRules() { return rules; }
-
- public String getTargetAuthenticationHandlerFactory() {
- return targetAuthenticationHandlerFactory;
- }
-
- public String getTargetReplicationPackageBuilder() {
- return targetReplicationPackageBuilder;
- }
-
- public String getTargetReplicationQueueProvider() {
- return targetReplicationQueueProvider;
- }
-
- public String getTargetTransportHandler() {
- return targetTransportHandler;
- }
-
- public String getTargetReplicationQueueDistributionStrategy() {
- return targetReplicationQueueDistributionStrategy;
- }
-
- public String[] getRunModes() { return runModes; }
-
- @Override
- public String toString() {
- String result = "{\"";
-
- result += NAME + "\":\"" + name + "\", \""
- + ENDPOINT + "\":\"" + endpoint + "\", \""
- + TRANSPORT + "\":\"" + targetTransportHandler + "\", \""
- + PACKAGING + "\":\"" + targetReplicationPackageBuilder + "\", \""
- + QUEUEPROVIDER + "\":\"" + targetReplicationQueueProvider + "\", \""
- + QUEUE_DISTRIBUTION + "\":\"" + targetReplicationQueueDistributionStrategy + "\", \""
- + TRANSPORT_AUTHENTICATION_FACTORY + "\":\"" + targetAuthenticationHandlerFactory + "\", \""
- + USE_AGGREGATE_PATHS + "\":\"" + useAggregatePaths + "\", \""
- + AUTHENTICATION_PROPERTIES + "\":\"" + Arrays.toString(authenticationProperties) + "\", \"";
-
- result += toComponentString();
-
- result += RULES + "\":\"" + Arrays.toString(rules);
- result += RUNMODES +"\":\"" + Arrays.toString(runModes);
- result += "\"}";
- return result;
- }
-
-
- private String toComponentString() {
-
- String result = "";
-
- if (componentConfiguration == null)
- return result;
-
- for (String component : COMPONENTS) {
- Dictionary properties = componentConfiguration.get(component);
- if (properties == null) continue;
-
- Enumeration keys = properties.keys();
-
- while (keys.hasMoreElements()) {
- String key = (String) keys.nextElement();
- Object value = properties.get(key);
-
- if (key.equals("service.pid")) continue;
-
- result += component + "." + key + "\":\"" + PropertiesUtil.toString(value, "") + "\", \"";
- }
- }
-
- return result;
- }
-
- public String toSimpleString() {
- return "{\"" + NAME + "\": \"" + name + "\""
- + ", \"" + ENABLED + "\": " + enabled + "}";
- }
-}
diff --git a/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfigurationManager.java b/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfigurationManager.java
deleted file mode 100644
index 94a7cd35af7..00000000000
--- a/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/ReplicationAgentConfigurationManager.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.replication.agent;
-
-import java.util.Map;
-
-/**
- * Facade class for dealing with {@link ReplicationAgent}s' {@link ReplicationAgentConfiguration}s
- */
-public interface ReplicationAgentConfigurationManager {
-
- /**
- * retrieve a {@link ReplicationAgentConfiguration} for a given {@link ReplicationAgent}
- *
- * @param agentName the name of a {@link org.apache.sling.replication.agent.ReplicationAgent}
- * @return a {@link ReplicationAgentConfiguration} for the given agent
- * @throws AgentConfigurationException
- */
- ReplicationAgentConfiguration getConfiguration(String agentName)
- throws AgentConfigurationException;
-
- /**
- * updates the {@link ReplicationAgentConfiguration} of a certain {@link ReplicationAgent}
- *
- * @param agentName the name of a {@link org.apache.sling.replication.agent.ReplicationAgent}
- * @param properties a {@link java.util.Map} of properties used to update the configuration
- * @return the updated {@link ReplicationAgentConfiguration} for the given agent
- * @throws AgentConfigurationException
- */
- ReplicationAgentConfiguration updateConfiguration(String agentName, Map properties)
- throws AgentConfigurationException;
-
- /**
- * creates a configuration for a {@link ReplicationAgent}
- *
- *
- * @param agentName name of the agent
- * @param properties the configuration of the agent to create
- * @throws AgentConfigurationException
- */
- void createAgentConfiguration(String agentName, Map properties)
- throws AgentConfigurationException;
-
- /**
- * deletes a configuration for a {@link ReplicationAgent} *
- *
- * @param agentName name of the agent
- * @throws AgentConfigurationException
- */
- void deleteAgentConfiguration(String agentName)
- throws AgentConfigurationException;
-
- /**
- * lists all configurations for {@link ReplicationAgent}
- *
- */
- ReplicationAgentConfiguration[] listAllAgentConfigurations()
- throws AgentConfigurationException;
-
-
-}
diff --git a/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/ReplicationAgentsManager.java b/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/ReplicationAgentsManager.java
deleted file mode 100644
index dbd048afea3..00000000000
--- a/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/ReplicationAgentsManager.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.replication.agent;
-
-import java.util.Collection;
-import java.util.SortedSet;
-import org.apache.sling.replication.communication.ReplicationActionType;
-
-/**
- * A manager for {@link ReplicationAgent}s
- */
-public interface ReplicationAgentsManager {
-
- /**
- * get agents which can handle the given action on the given paths
- *
- * @param action a {@link ReplicationActionType}
- * @param paths the paths such agents should be able to handle
- * @return a {@link SortedSet} of {@link ReplicationAgent}s
- */
- SortedSet getAgentsFor(ReplicationActionType action, String... paths);
-
- /**
- * get all the agents registered and active in the system
- *
- * @return a Collection of {@link ReplicationAgent}s
- */
- Collection getAllAvailableAgents();
-}
diff --git a/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentConfigurationManager.java b/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentConfigurationManager.java
deleted file mode 100644
index 12865261436..00000000000
--- a/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentConfigurationManager.java
+++ /dev/null
@@ -1,277 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.replication.agent.impl;
-
-import java.util.Arrays;
-import java.util.Dictionary;
-import java.util.Hashtable;
-import java.util.Map;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.Service;
-import org.apache.sling.commons.osgi.PropertiesUtil;
-import org.apache.sling.replication.agent.AgentConfigurationException;
-import org.apache.sling.replication.agent.ReplicationAgentConfiguration;
-import org.apache.sling.replication.agent.ReplicationAgentConfigurationManager;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Default implementation of {@link ReplicationAgentConfigurationManager}
- */
-@Component(immediate = true, label = "Default Replication Agent Configuration Manager")
-@Service(value = ReplicationAgentConfigurationManager.class)
-public class DefaultReplicationAgentConfigurationManager implements
- ReplicationAgentConfigurationManager {
-
- private final Logger log = LoggerFactory.getLogger(getClass());
-
- @Reference
- private ConfigurationAdmin configAdmin;
-
- public ReplicationAgentConfiguration getConfiguration(String agentName)
- throws AgentConfigurationException {
-
- log.info("retrieving configuration for agent {}", agentName);
-
- try {
- Dictionary agentProperties = getOrSetProperties(agentName, null);
- Dictionary componentProperties = getOrSetComponentProperties(agentName, null);
-
- log.info("configuration for agent {} found {}", agentName, agentProperties);
-
- return new ReplicationAgentConfiguration(agentProperties, componentProperties);
-
- } catch (Exception e) {
-
- log.error("configuration for agent {} cannot be found", agentName);
- throw new AgentConfigurationException(e);
- }
- }
-
- private Dictionary getOrSetProperties(String agentName, Dictionary properties) throws Exception {
- Configuration agentConfiguration = getAgentConfiguration(agentName);
-
- if (agentConfiguration == null)
- throw new Exception("no configuration found");
-
- if (properties != null)
- agentConfiguration.update(properties);
- return agentConfiguration.getProperties();
- }
-
-
- private Dictionary getOrSetComponentProperties(String agentName, Dictionary properties) throws Exception {
- Dictionary result = new Hashtable();
-
- Configuration agentConfiguration = getAgentConfiguration(agentName);
-
- for (String component : ReplicationAgentConfiguration.COMPONENTS) {
- Configuration componentConfiguration = getComponentConfiguration(agentConfiguration, component);
-
- if (componentConfiguration == null)
- continue;
-
- if (properties != null) {
- Dictionary componentProperties = properties.get(component);
- if (componentProperties != null)
- componentConfiguration.update(componentProperties);
- }
-
- result.put(component, componentConfiguration.getProperties());
- }
-
- return result;
- }
-
- private Configuration getAgentConfiguration(String agentName) throws Exception {
- String filter = "(name=" + agentName + ")";
- return getOsgiConfiguration(filter);
- }
-
- private Configuration getComponentConfiguration(Configuration agentConfiguration, String component) {
- try {
- String filter = PropertiesUtil.toString(agentConfiguration.getProperties().get(component), "");
- return getOsgiConfiguration(filter);
- } catch (Exception ex) {
- return null;
- }
- }
-
- private Configuration getOsgiConfiguration(String filter) throws Exception {
- Configuration[] configurations = getAllOsgiConfigurations(filter);
- if (configurations == null || configurations.length == 0) {
- log.info("no configurations for filter {}", filter);
- return null;
- } else if (configurations.length == 1) {
- log.info("found configuration {} for filter {}", configurations[0], filter);
- return configurations[0];
- } else {
- log.error("{} configurations for filter {} found", configurations.length, filter);
- throw new Exception("too many configurations found");
- }
- }
-
- private Configuration[] getAllOsgiConfigurations(String filter) throws Exception {
- return configAdmin.listConfigurations(filter);
- }
-
- public ReplicationAgentConfiguration updateConfiguration(String agentName,
- Map updateProperties) throws AgentConfigurationException {
- try {
-
- String configName = PropertiesUtil.toString(updateProperties.get("name"), "");
-
- if (agentName == null || agentName.length() == 0)
- throw new Exception("agent name cannot be empty");
-
- if (!agentName.equals(configName))
- throw new Exception("cannot change name of a configuration");
-
- Dictionary agentProperties = getOrSetProperties(agentName, null);
- Dictionary componentProperties = getOrSetComponentProperties(agentName, null);
-
- for (Map.Entry entry : updateProperties.entrySet()) {
- String key = entry.getKey();
- if (key.startsWith("X-replication-")) {
- key = key.substring(0, 14);
- }
-
-
- String component = extractComponent(key);
- if (component != null) {
- key = key.substring(component.length() + 1);
- Dictionary dictionary = componentProperties.get(component);
- if (dictionary != null)
- dictionary.put(key, entry.getValue());
- } else {
- agentProperties.put(key, entry.getValue());
- }
- }
-
- agentProperties = getOrSetProperties(agentName, agentProperties);
- componentProperties = getOrSetComponentProperties(agentName, componentProperties);
-
- return new ReplicationAgentConfiguration(agentProperties, componentProperties);
-
- } catch (Exception e) {
- log.error("configuration for agent {} was not found", agentName);
-
- throw new AgentConfigurationException(e);
- }
- }
-
-
- String extractComponent(String string) {
- for (String component : ReplicationAgentConfiguration.COMPONENTS) {
- if (string.startsWith(component + "."))
- return component;
- }
- return null;
- }
-
- public void createAgentConfiguration(String agentName, Map properties) throws AgentConfigurationException {
-
- if (agentName != null) {
- try {
-
- Configuration configuration = getAgentConfiguration(agentName);
-
- if (configuration != null)
- throw new Exception("the agent name is already in use");
-
- configuration = configAdmin.createFactoryConfiguration(ReplicationAgentServiceFactory.SERVICE_PID);
-
- if (configuration == null)
- throw new Exception("configuration cannot be created");
-
- @SuppressWarnings("unchecked")
- Dictionary configurationProperties = new Hashtable();
-
- for (Map.Entry entry : properties.entrySet()) {
- String key = entry.getKey();
- if (key.startsWith("X-replication-")) {
- key = key.substring(0, 14);
- }
- String value = parseString(entry.getValue());
- configurationProperties.put(key, value);
- }
- configuration.update(configurationProperties);
-
- } catch (Exception e) {
- log.error("cannot create agent {} ", agentName);
-
- throw new AgentConfigurationException(e);
- }
- } else {
- throw new AgentConfigurationException("a (unique) name is needed in order to create an agent");
- }
- }
-
-
- public void deleteAgentConfiguration(String agentName) throws AgentConfigurationException {
-
- if (agentName != null) {
- try {
- Configuration configuration = getAgentConfiguration(agentName);
-
- configuration.delete();
- } catch (Exception e) {
- log.error("cannot delete agent {} ", agentName);
-
- throw new AgentConfigurationException(e);
- }
- } else {
- throw new AgentConfigurationException("a (unique) name is needed in order to create an agent");
- }
- }
-
- public ReplicationAgentConfiguration[] listAllAgentConfigurations() throws AgentConfigurationException {
- try {
- String filter = "(" + ConfigurationAdmin.SERVICE_FACTORYPID + "=" + ReplicationAgentServiceFactory.SERVICE_PID + ")";
- Configuration[] configurations = getAllOsgiConfigurations(filter);
-
- ReplicationAgentConfiguration[] result = new ReplicationAgentConfiguration[configurations.length];
- for (int i = 0; i < configurations.length; i++) {
- String agentName = (String) configurations[i].getProperties().get("name");
- result[i] = getConfiguration(agentName);
- }
-
- return result;
-
- } catch (Exception e) {
- log.error("configurations for agents cannot be retrieved");
- throw new AgentConfigurationException(e);
- }
- }
-
- private String parseString(Object object) {
- String value;
- if (object instanceof String[]) {
- String arrayString = Arrays.toString((String[]) object);
- value = arrayString.substring(1, arrayString.length() - 1);
- } else {
- value = String.valueOf(object);
- }
- return value;
- }
-
-}
diff --git a/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentsManager.java b/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentsManager.java
deleted file mode 100644
index c6493e54d19..00000000000
--- a/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentsManager.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.replication.agent.impl;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Map;
-import java.util.SortedSet;
-import java.util.TreeSet;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.ReferenceCardinality;
-import org.apache.felix.scr.annotations.ReferencePolicy;
-import org.apache.felix.scr.annotations.References;
-import org.apache.felix.scr.annotations.Service;
-import org.apache.sling.replication.agent.ReplicationAgent;
-import org.apache.sling.replication.agent.ReplicationAgentsManager;
-import org.apache.sling.replication.communication.ReplicationActionType;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Default implementation of {@link ReplicationAgentsManager}
- */
-@Component
-@References({
- @Reference(name = "replicationAgent",
- referenceInterface = ReplicationAgent.class,
- cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE,
- policy = ReferencePolicy.DYNAMIC,
- bind = "bindReplicationAgent",
- unbind = "unbindReplicationAgent")
-})
-@Service(value = ReplicationAgentsManager.class)
-public class DefaultReplicationAgentsManager implements ReplicationAgentsManager {
-
- private final Logger log = LoggerFactory.getLogger(getClass());
-
- private final SortedSet replicationAgents = new TreeSet(new ReplicationAgentComparator());
-
- public SortedSet getAgentsFor(ReplicationActionType action, String... paths) {
- // TODO : implement the filtering based on rules here
- return Collections.unmodifiableSortedSet(replicationAgents);
- }
-
- public Collection getAllAvailableAgents() {
- return Collections.unmodifiableCollection(replicationAgents);
- }
-
- @Deactivate
- protected void deactivate() {
- replicationAgents.clear();
- }
-
- protected void bindReplicationAgent(final ReplicationAgent replicationAgent,
- Map properties) {
- synchronized (replicationAgents) {
- replicationAgents.add(replicationAgent);
- }
- log.debug("Registering replication agent {} ", replicationAgent);
- }
-
- protected void unbindReplicationAgent(final ReplicationAgent replicationAgent,
- Map properties) {
- synchronized (replicationAgents) {
- replicationAgents.remove(replicationAgent);
- }
- log.debug("Unregistering replication agent {} ", replicationAgent);
- }
-
- private final class ReplicationAgentComparator implements Comparator {
- public int compare(ReplicationAgent o1, ReplicationAgent o2) {
- return o1.getName().compareTo(o2.getName());
- }
- }
-}
diff --git a/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentServiceFactory.java b/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentServiceFactory.java
deleted file mode 100644
index 0650ba99119..00000000000
--- a/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/ReplicationAgentServiceFactory.java
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.replication.agent.impl;
-
-import java.util.Dictionary;
-import java.util.Hashtable;
-import java.util.Map;
-import java.util.Random;
-import java.util.Set;
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.ConfigurationPolicy;
-import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.ReferencePolicy;
-import org.apache.sling.commons.osgi.PropertiesUtil;
-import org.apache.sling.replication.agent.AgentConfigurationException;
-import org.apache.sling.replication.agent.ReplicationAgent;
-import org.apache.sling.replication.agent.ReplicationAgentConfiguration;
-import org.apache.sling.replication.event.ReplicationEventFactory;
-import org.apache.sling.replication.queue.ReplicationQueueDistributionStrategy;
-import org.apache.sling.replication.queue.ReplicationQueueProvider;
-import org.apache.sling.replication.queue.impl.SingleQueueDistributionStrategy;
-import org.apache.sling.replication.queue.impl.jobhandling.JobHandlingReplicationQueueProvider;
-import org.apache.sling.replication.rule.ReplicationRuleEngine;
-import org.apache.sling.replication.serialization.ReplicationPackageBuilder;
-import org.apache.sling.replication.serialization.impl.vlt.FileVaultReplicationPackageBuilder;
-import org.apache.sling.replication.transport.TransportHandler;
-import org.apache.sling.replication.transport.impl.NopTransportHandler;
-import org.apache.sling.settings.SlingSettingsService;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * An OSGi service factory for {@link ReplicationAgent}s
- */
-@Component(metatype = true,
- label = "Replication Agents Factory",
- description = "OSGi configuration based ReplicationAgent service factory",
- name = ReplicationAgentServiceFactory.SERVICE_PID,
- configurationFactory = true,
- specVersion = "1.1",
- policy = ConfigurationPolicy.REQUIRE
-)
-public class ReplicationAgentServiceFactory {
-
- private final Logger log = LoggerFactory.getLogger(getClass());
-
- static final String SERVICE_PID = "org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory";
-
- private static final String TRANSPORT = ReplicationAgentConfiguration.TRANSPORT;
-
- private static final String QUEUEPROVIDER = ReplicationAgentConfiguration.QUEUEPROVIDER;
-
- private static final String PACKAGING = ReplicationAgentConfiguration.PACKAGING;
-
- private static final String QUEUE_DISTRIBUTION = ReplicationAgentConfiguration.QUEUE_DISTRIBUTION;
-
- private static final String DEFAULT_PACKAGING = "(name="
- + FileVaultReplicationPackageBuilder.NAME + ")";
-
- private static final String DEFAULT_QUEUEPROVIDER = "(name="
- + JobHandlingReplicationQueueProvider.NAME + ")";
-
- private static final String DEFAULT_DISTRIBUTION = "(name="
- + SingleQueueDistributionStrategy.NAME + ")";
-
- private static final String DEFAULT_TRANSPORT = "(name="
- + NopTransportHandler.NAME + ")";
-
- @Property(boolValue = true, label = "Enabled")
- private static final String ENABLED = ReplicationAgentConfiguration.ENABLED;
-
- @Property(label = "Name")
- private static final String NAME = ReplicationAgentConfiguration.NAME;
-
- @Property(label = "Rules")
- private static final String RULES = ReplicationAgentConfiguration.RULES;
-
- @Property(boolValue = true, label = "Replicate using aggregated paths")
- private static final String USE_AGGREGATE_PATHS = ReplicationAgentConfiguration.USE_AGGREGATE_PATHS;
-
- @Property(label = "Target TransportHandler", name = TRANSPORT, value = "(name=" + NopTransportHandler.NAME + ")")
- @Reference(name = "TransportHandler", target = "(name=" + NopTransportHandler.NAME + ")", policy = ReferencePolicy.DYNAMIC)
- private TransportHandler transportHandler;
-
- @Property(label = "Target ReplicationPackageBuilder", name = PACKAGING, value = DEFAULT_PACKAGING)
- @Reference(name = "ReplicationPackageBuilder", target = DEFAULT_PACKAGING, policy = ReferencePolicy.DYNAMIC)
- private ReplicationPackageBuilder packageBuilder;
-
- @Property(label = "Target ReplicationQueueProvider", name = QUEUEPROVIDER, value = DEFAULT_QUEUEPROVIDER)
- @Reference(name = "ReplicationQueueProvider", target = DEFAULT_QUEUEPROVIDER, policy = ReferencePolicy.DYNAMIC)
- private ReplicationQueueProvider queueProvider;
-
- @Property(label = "Target QueueDistributionStrategy", name = QUEUE_DISTRIBUTION, value = DEFAULT_DISTRIBUTION)
- @Reference(name = "ReplicationQueueDistributionStrategy", target = DEFAULT_DISTRIBUTION, policy = ReferencePolicy.DYNAMIC)
- private ReplicationQueueDistributionStrategy queueDistributionStrategy;
-
- @Property(label = "Runmodes")
- private static final String RUNMODES = ReplicationAgentConfiguration.RUNMODES;
-
- private ServiceRegistration agentReg;
-
- @Reference
- private ReplicationRuleEngine replicationRuleEngine;
-
- @Reference
- private ReplicationEventFactory replicationEventFactory;
-
- @Reference
- private SlingSettingsService settingsService;
-
- @Activate
- public void activate(BundleContext context, Map config) throws Exception {
-
- // inject configuration
- Dictionary props = new Hashtable();
-
- boolean enabled = PropertiesUtil.toBoolean(config.get(ENABLED), true);
-
- if (enabled) {
- props.put(ENABLED, true);
-
- String[] runModes = PropertiesUtil.toStringArray(config.get(RUNMODES), new String[0]);
- props.put(RUNMODES, runModes);
-
- String name = PropertiesUtil
- .toString(config.get(NAME), String.valueOf(new Random().nextInt(1000)));
- props.put(NAME, name);
-
- String transport = PropertiesUtil.toString(config.get(TRANSPORT), "");
- props.put(TRANSPORT, transport);
-
- String packaging = PropertiesUtil.toString(config.get(PACKAGING), "");
- props.put(PACKAGING, packaging);
-
- String queue = PropertiesUtil.toString(config.get(QUEUEPROVIDER), "");
- props.put(QUEUEPROVIDER, queue);
-
- String distribution = PropertiesUtil.toString(config.get(QUEUE_DISTRIBUTION), "");
- props.put(QUEUE_DISTRIBUTION, distribution);
-
- String[] rules = PropertiesUtil.toStringArray(config.get(RULES), new String[0]);
- props.put(RULES, rules);
-
-
- boolean useAggregatePaths = PropertiesUtil.toBoolean(config.get(USE_AGGREGATE_PATHS), true);
- props.put(USE_AGGREGATE_PATHS, useAggregatePaths);
-
- // check configuration is valid
- if (name == null || packageBuilder == null || queueProvider == null || queueDistributionStrategy == null) {
- throw new AgentConfigurationException("configuration for this agent is not valid");
- }
-
-
- if (log.isInfoEnabled()) {
- log.info("bound services for {} : {} - {} - {} - {} - {} - {}", new Object[]{name,
- transportHandler, packageBuilder, queueProvider, queueDistributionStrategy});
- }
-
- ReplicationAgent agent = new SimpleReplicationAgent(name, rules, useAggregatePaths,
- transportHandler, packageBuilder, queueProvider, queueDistributionStrategy, replicationEventFactory, replicationRuleEngine);
-
-
- // only enable if instance runmodes match configured ones
- if (matchRunmodes(runModes)) {
- // register agent service
- agentReg = context.registerService(ReplicationAgent.class.getName(), agent, props);
- agent.enable();
- }
- }
- }
-
- private boolean matchRunmodes(String[] configuredRunModes) {
- boolean match = configuredRunModes == null || configuredRunModes.length == 0;
- if (!match) {
- Set activeRunModes = settingsService.getRunModes();
- for (String activeRunMode : activeRunModes) {
- for (String configuredRunMode : configuredRunModes) {
- if (activeRunMode.equals(configuredRunMode)) {
- match = true;
- break;
- }
- }
- }
- }
- return match;
- }
-
- @Deactivate
- private void deactivate(BundleContext context) {
- if (agentReg != null) {
- ServiceReference reference = agentReg.getReference();
- ReplicationAgent replicationAgent = (ReplicationAgent) context.getService(reference);
- replicationAgent.disable();
- agentReg.unregister();
- }
-
- }
-}
diff --git a/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgent.java b/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgent.java
deleted file mode 100644
index d32cd04b90f..00000000000
--- a/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgent.java
+++ /dev/null
@@ -1,321 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.replication.agent.impl;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Dictionary;
-import java.util.List;
-import java.util.Properties;
-import org.apache.sling.replication.agent.AgentReplicationException;
-import org.apache.sling.replication.agent.ReplicationAgent;
-import org.apache.sling.replication.communication.ReplicationRequest;
-import org.apache.sling.replication.communication.ReplicationResponse;
-import org.apache.sling.replication.event.ReplicationEventFactory;
-import org.apache.sling.replication.event.ReplicationEventType;
-import org.apache.sling.replication.queue.ReplicationQueue;
-import org.apache.sling.replication.queue.ReplicationQueueDistributionStrategy;
-import org.apache.sling.replication.queue.ReplicationQueueException;
-import org.apache.sling.replication.queue.ReplicationQueueItem;
-import org.apache.sling.replication.queue.ReplicationQueueItemState;
-import org.apache.sling.replication.queue.ReplicationQueueProcessor;
-import org.apache.sling.replication.queue.ReplicationQueueProvider;
-import org.apache.sling.replication.rule.ReplicationRuleEngine;
-import org.apache.sling.replication.serialization.ReplicationPackage;
-import org.apache.sling.replication.serialization.ReplicationPackageBuilder;
-import org.apache.sling.replication.serialization.ReplicationPackageBuildingException;
-import org.apache.sling.replication.serialization.ReplicationPackageReadingException;
-import org.apache.sling.replication.transport.ReplicationTransportException;
-import org.apache.sling.replication.transport.TransportHandler;
-import org.apache.sling.replication.transport.impl.NopTransportHandler;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Basic implementation of a {@link ReplicationAgent}
- */
-public class SimpleReplicationAgent implements ReplicationAgent {
-
- private final Logger log = LoggerFactory.getLogger(getClass());
-
- private final ReplicationPackageBuilder packageBuilder;
-
- private final ReplicationQueueProvider queueProvider;
-
- private final TransportHandler transportHandler;
-
- private final ReplicationQueueDistributionStrategy queueDistributionStrategy;
-
- private final ReplicationEventFactory replicationEventFactory;
-
- private final String name;
-
- private final String[] rules;
-
- private final boolean useAggregatePaths;
-
- private final ReplicationRuleEngine ruleEngine;
-
- private final String RESPONSE_QUEUE = "response";
-
- public SimpleReplicationAgent(String name, String[] rules,
- boolean useAggregatePaths,
- TransportHandler transportHandler,
- ReplicationPackageBuilder packageBuilder,
- ReplicationQueueProvider queueProvider,
- ReplicationQueueDistributionStrategy queueDistributionHandler,
- ReplicationEventFactory replicationEventFactory, ReplicationRuleEngine ruleEngine) {
- this.name = name;
- this.rules = rules;
- this.transportHandler = transportHandler;
- this.packageBuilder = packageBuilder;
- this.queueProvider = queueProvider;
- this.queueDistributionStrategy = queueDistributionHandler;
- this.useAggregatePaths = useAggregatePaths;
- this.replicationEventFactory = replicationEventFactory;
- this.ruleEngine = ruleEngine;
- }
-
- public ReplicationResponse execute(ReplicationRequest replicationRequest)
- throws AgentReplicationException {
-
- // create packages from request
- ReplicationPackage[] replicationPackages = buildPackages(replicationRequest);
-
- return schedule(replicationPackages, false);
- }
-
- public void send(ReplicationRequest replicationRequest) throws AgentReplicationException {
- // create packages from request
- ReplicationPackage[] replicationPackages = buildPackages(replicationRequest);
-
- schedule(replicationPackages, true);
- }
-
- public boolean isPassive() {
- return transportHandler == null || transportHandler instanceof NopTransportHandler; // TODO : improve this
- }
-
-
- private ReplicationPackage buildPackage(ReplicationRequest replicationRequest) throws AgentReplicationException {
- // create package from request
- ReplicationPackage replicationPackage;
- try {
- replicationPackage = packageBuilder.createPackage(replicationRequest);
- } catch (ReplicationPackageBuildingException e) {
- throw new AgentReplicationException(e);
- }
-
- return replicationPackage;
- }
-
- private ReplicationPackage[] buildPackages(ReplicationRequest replicationRequest) throws AgentReplicationException {
-
- List packages = new ArrayList();
-
- if (useAggregatePaths) {
- ReplicationPackage replicationPackage = buildPackage(replicationRequest);
- packages.add(replicationPackage);
- } else {
- for (String path : replicationRequest.getPaths()) {
- ReplicationPackage replicationPackage = buildPackage(new ReplicationRequest(replicationRequest.getTime(),
- replicationRequest.getAction(),
- path));
-
- packages.add(replicationPackage);
- }
- }
-
- return packages.toArray(new ReplicationPackage[packages.size()]);
- }
-
- // offer option throws an exception at first error
- private ReplicationResponse schedule(ReplicationPackage[] packages, boolean offer) throws AgentReplicationException {
- ReplicationResponse replicationResponse = new ReplicationResponse();
-
- for (ReplicationPackage replicationPackage : packages) {
- ReplicationResponse currentReplicationResponse = schedule(replicationPackage, offer);
-
- replicationResponse.setSuccessful(currentReplicationResponse.isSuccessful());
- replicationResponse.setStatus(currentReplicationResponse.getStatus());
- }
-
- return replicationResponse;
- }
-
- private ReplicationResponse schedule(ReplicationPackage replicationPackage, boolean offer) throws AgentReplicationException {
- ReplicationResponse replicationResponse = new ReplicationResponse();
- ReplicationQueueItem replicationQueueItem = new ReplicationQueueItem(replicationPackage.getId(),
- replicationPackage.getPaths(),
- replicationPackage.getAction(),
- replicationPackage.getType());
-
- if (offer) {
- try {
- queueDistributionStrategy.offer(getName(), replicationQueueItem, queueProvider);
- if (isPassive()) {
- generatePackageQueuedEvent(replicationQueueItem);
- }
- } catch (ReplicationQueueException e) {
- replicationResponse.setSuccessful(false);
- throw new AgentReplicationException(e);
- }
- } else {
- // send the replication package to the queue distribution handler
- try {
- ReplicationQueueItemState state = queueDistributionStrategy.add(getName(), replicationQueueItem,
- queueProvider);
- if (isPassive()) {
- generatePackageQueuedEvent(replicationQueueItem);
- }
- if (state != null) {
- replicationResponse.setStatus(state.getItemState().toString());
- replicationResponse.setSuccessful(state.isSuccessful());
- } else {
- replicationResponse.setStatus(ReplicationQueueItemState.ItemState.ERROR.toString());
- replicationResponse.setSuccessful(false);
- }
- } catch (Exception e) {
- if (log.isErrorEnabled()) {
- log.error("an error happened during queue processing", e);
- }
- replicationResponse.setSuccessful(false);
- }
- }
- return replicationResponse;
- }
-
- private void generatePackageQueuedEvent(ReplicationQueueItem replicationQueueItem) {
- Dictionary