// Path: src/main/java/org/jboss/elasticsearch/river/sysinfo/IRiverMgm.java
// public interface IRiverMgm {
// 
//   /**
//    * Get name of river.
//    * 
//    * @return name of river
//    */
//   public abstract RiverName riverName();
// 
//   /**
//    * Stop river indexers, but leave instance existing in {@link #riverInstances} so it can be found over management REST
//    * calls and/or reconfigured and started later again. Note that standard ES river {@link #close()} method
//    * implementation removes river instance from {@link #riverInstances}.
//    */
//   public abstract void stop();
// 
//   /**
//    * Restart river. Configuration of river is updated during restart from <code>_meta</code> file.
//    */
//   public abstract void restart();
// 
//   /**
//    * Change indexing period for indexers.
//    * 
//    * @param indexerNames names of indexers to change period for
//    * @param indexingPeriod to use
//    * @return true if at least one indexer of passed names was found
//    */
//   public abstract boolean changeIndexerPeriod(String[] indexerNames, long indexingPeriod);
// 
// }
// 
// Path: src/main/java/org/jboss/elasticsearch/river/sysinfo/mgm/TransportJRMgmBaseAction.java
// @SuppressWarnings("rawtypes")
// public abstract class TransportJRMgmBaseAction<Request extends JRMgmBaseRequest, Response extends JRMgmBaseResponse, NodeRequest extends NodeJRMgmBaseRequest<Request>, NodeResponse extends NodeJRMgmBaseResponse>
// 		extends TransportNodesOperationAction<Request, Response, NodeRequest, NodeResponse> {
// 
// 	protected final ESLogger logger;
// 
// 	@Inject
// 	public TransportJRMgmBaseAction(Settings settings, String actionName, ClusterName clusterName, ThreadPool threadPool,
// 			ClusterService clusterService, TransportService transportService, ActionFilters actionFilters) {
// 		super(settings, actionName, clusterName, threadPool, clusterService, transportService, actionFilters);
// 		logger = Loggers.getLogger(getClass());
// 	}
// 
// 	@Override
// 	protected String executor() {
// 		return ThreadPool.Names.MANAGEMENT;
// 	}
// 
// 	@SuppressWarnings("unchecked")
// 	@Override
// 	protected Response newResponse(Request request, AtomicReferenceArray responses) {
// 		final List<NodeResponse> nodesInfos = new ArrayList<NodeResponse>();
// 		for (int i = 0; i < responses.length(); i++) {
// 			Object resp = responses.get(i);
// 			if (resp instanceof NodeJRMgmBaseResponse) {
// 				nodesInfos.add((NodeResponse) resp);
// 			}
// 		}
// 		return newResponse(clusterName, nodesInfos.toArray(newNodeResponseArray(nodesInfos.size())));
// 	}
// 
// 	protected abstract NodeResponse[] newNodeResponseArray(int len);
// 
// 	protected abstract Response newResponse(ClusterName clusterName, NodeResponse[] array);
// 
// 	@Override
// 	protected boolean accumulateExceptions() {
// 		return false;
// 	}
// 
// 	@Override
// 	protected NodeResponse nodeOperation(NodeRequest nodeRequest) throws ElasticsearchException {
// 		Request req = nodeRequest.getRequest();
// 		logger.debug("Go to look for Sysinfo river '{}' on this node", req.getRiverName());
// 		IRiverMgm river = SysinfoRiver.getRunningInstance(req.getRiverName());
// 		if (river == null) {
// 			logger.debug("Sysinfo River {} not found on this node", req.getRiverName());
// 			return newNodeResponse();
// 		} else {
// 			logger.debug("Sysinfo River {} found on this node, go to call mgm operation on it {}", req.getRiverName(), req);
// 			try {
// 				return performOperationOnRiver(river, req, clusterService.localNode());
// 			} catch (Exception e) {
// 				logger.error("Exception from river management operation: {}", e, e.getMessage());
// 				throw new ElasticsearchException(e.getMessage(), e);
// 			}
// 		}
// 	}
// 
// 	/**
// 	 * Implement in subclass to perform necessary management operation on river instance. This method is called only on
// 	 * node where river really runs.
// 	 * 
// 	 * @param river instance to perform operation on, never null
// 	 * @param req request for operation to process
// 	 * @param node this operation runs on (used to construct response etc.)
// 	 * @return node response with operation result
// 	 * @throws Exception if something is wrong
// 	 */
// 	protected abstract NodeResponse performOperationOnRiver(IRiverMgm river, Request req, DiscoveryNode node)
// 			throws Exception;
// }


import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import org.jboss.elasticsearch.river.sysinfo.IRiverMgm;
import org.jboss.elasticsearch.river.sysinfo.mgm.TransportJRMgmBaseAction;
/*
 * JBoss, Home of Professional Open Source
 * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
 * as indicated by the @authors tag. All rights reserved.
 */
package org.jboss.elasticsearch.river.sysinfo.mgm.lifecycle;


/**
 * SysinfoRiver lifecycle method transport action.
 * 
 * @author Vlastimil Elias (velias at redhat dot com)
 */
public class TransportJRLifecycleAction extends
		TransportJRMgmBaseAction<JRLifecycleRequest, JRLifecycleResponse, NodeJRLifecycleRequest, NodeJRLifecycleResponse> {

	@Inject
	public TransportJRLifecycleAction(Settings settings, ClusterName clusterName, ThreadPool threadPool,
			ClusterService clusterService, TransportService transportService, ActionFilters actionFilters) {
		super(settings, JRLifecycleAction.NAME, clusterName, threadPool, clusterService, transportService, actionFilters);
	}

	@Override
// Path: src/main/java/org/jboss/elasticsearch/river/sysinfo/IRiverMgm.java
// public interface IRiverMgm {
// 
//   /**
//    * Get name of river.
//    * 
//    * @return name of river
//    */
//   public abstract RiverName riverName();
// 
//   /**
//    * Stop river indexers, but leave instance existing in {@link #riverInstances} so it can be found over management REST
//    * calls and/or reconfigured and started later again. Note that standard ES river {@link #close()} method
//    * implementation removes river instance from {@link #riverInstances}.
//    */
//   public abstract void stop();
// 
//   /**
//    * Restart river. Configuration of river is updated during restart from <code>_meta</code> file.
//    */
//   public abstract void restart();
// 
//   /**
//    * Change indexing period for indexers.
//    * 
//    * @param indexerNames names of indexers to change period for
//    * @param indexingPeriod to use
//    * @return true if at least one indexer of passed names was found
//    */
//   public abstract boolean changeIndexerPeriod(String[] indexerNames, long indexingPeriod);
// 
// }
// 
// Path: src/main/java/org/jboss/elasticsearch/river/sysinfo/mgm/TransportJRMgmBaseAction.java
// @SuppressWarnings("rawtypes")
// public abstract class TransportJRMgmBaseAction<Request extends JRMgmBaseRequest, Response extends JRMgmBaseResponse, NodeRequest extends NodeJRMgmBaseRequest<Request>, NodeResponse extends NodeJRMgmBaseResponse>
// 		extends TransportNodesOperationAction<Request, Response, NodeRequest, NodeResponse> {
// 
// 	protected final ESLogger logger;
// 
// 	@Inject
// 	public TransportJRMgmBaseAction(Settings settings, String actionName, ClusterName clusterName, ThreadPool threadPool,
// 			ClusterService clusterService, TransportService transportService, ActionFilters actionFilters) {
// 		super(settings, actionName, clusterName, threadPool, clusterService, transportService, actionFilters);
// 		logger = Loggers.getLogger(getClass());
// 	}
// 
// 	@Override
// 	protected String executor() {
// 		return ThreadPool.Names.MANAGEMENT;
// 	}
// 
// 	@SuppressWarnings("unchecked")
// 	@Override
// 	protected Response newResponse(Request request, AtomicReferenceArray responses) {
// 		final List<NodeResponse> nodesInfos = new ArrayList<NodeResponse>();
// 		for (int i = 0; i < responses.length(); i++) {
// 			Object resp = responses.get(i);
// 			if (resp instanceof NodeJRMgmBaseResponse) {
// 				nodesInfos.add((NodeResponse) resp);
// 			}
// 		}
// 		return newResponse(clusterName, nodesInfos.toArray(newNodeResponseArray(nodesInfos.size())));
// 	}
// 
// 	protected abstract NodeResponse[] newNodeResponseArray(int len);
// 
// 	protected abstract Response newResponse(ClusterName clusterName, NodeResponse[] array);
// 
// 	@Override
// 	protected boolean accumulateExceptions() {
// 		return false;
// 	}
// 
// 	@Override
// 	protected NodeResponse nodeOperation(NodeRequest nodeRequest) throws ElasticsearchException {
// 		Request req = nodeRequest.getRequest();
// 		logger.debug("Go to look for Sysinfo river '{}' on this node", req.getRiverName());
// 		IRiverMgm river = SysinfoRiver.getRunningInstance(req.getRiverName());
// 		if (river == null) {
// 			logger.debug("Sysinfo River {} not found on this node", req.getRiverName());
// 			return newNodeResponse();
// 		} else {
// 			logger.debug("Sysinfo River {} found on this node, go to call mgm operation on it {}", req.getRiverName(), req);
// 			try {
// 				return performOperationOnRiver(river, req, clusterService.localNode());
// 			} catch (Exception e) {
// 				logger.error("Exception from river management operation: {}", e, e.getMessage());
// 				throw new ElasticsearchException(e.getMessage(), e);
// 			}
// 		}
// 	}
// 
// 	/**
// 	 * Implement in subclass to perform necessary management operation on river instance. This method is called only on
// 	 * node where river really runs.
// 	 * 
// 	 * @param river instance to perform operation on, never null
// 	 * @param req request for operation to process
// 	 * @param node this operation runs on (used to construct response etc.)
// 	 * @return node response with operation result
// 	 * @throws Exception if something is wrong
// 	 */
// 	protected abstract NodeResponse performOperationOnRiver(IRiverMgm river, Request req, DiscoveryNode node)
// 			throws Exception;
// }


// Path: src/main/java/org/jboss/elasticsearch/river/sysinfo/mgm/lifecycle/TransportJRLifecycleAction.java
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import org.jboss.elasticsearch.river.sysinfo.IRiverMgm;
import org.jboss.elasticsearch.river.sysinfo.mgm.TransportJRMgmBaseAction;

/*
 * JBoss, Home of Professional Open Source
 * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
 * as indicated by the @authors tag. All rights reserved.
 */
package org.jboss.elasticsearch.river.sysinfo.mgm.lifecycle;


/**
 * SysinfoRiver lifecycle method transport action.
 * 
 * @author Vlastimil Elias (velias at redhat dot com)
 */
public class TransportJRLifecycleAction extends
		TransportJRMgmBaseAction<JRLifecycleRequest, JRLifecycleResponse, NodeJRLifecycleRequest, NodeJRLifecycleResponse> {

	@Inject
	public TransportJRLifecycleAction(Settings settings, ClusterName clusterName, ThreadPool threadPool,
			ClusterService clusterService, TransportService transportService, ActionFilters actionFilters) {
		super(settings, JRLifecycleAction.NAME, clusterName, threadPool, clusterService, transportService, actionFilters);
	}

	@Override
	protected NodeJRLifecycleResponse performOperationOnRiver(IRiverMgm river, JRLifecycleRequest req, DiscoveryNode node)