com.eduworks.mapreduce.MapReduceClient Maven / Gradle / Ivy
package com.eduworks.mapreduce;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map.Entry;
import org.apache.log4j.Logger;
import org.json.JSONArray;
import com.eduworks.lang.EwList;
import com.eduworks.lang.threading.EwThreading;
import com.eduworks.lang.threading.EwThreading.MyRunnable;
import com.eduworks.util.Tuple;
public class MapReduceClient
{
public Logger log = Logger.getLogger(MapReduceManager.class);
public List peers = Collections.synchronizedList(new EwList());
public boolean isChecking = false;
public boolean debug = true;
public long lastServiceMs;
public void cleanup()
{
}
public MapReduceClient(String name, List> hosts)
{
peers.clear();
int i = 0;
for (Tuple host : hosts)
{
MapReduceStatus status = new MapReduceStatus();
status.setHost(host.getFirst(), host.getSecond());
status.setI(i++);
status.setServiceName(name);
peers.add(status);
// if (debug)
// log.info("Established Peer: " + status);
}
}
public void checkup()
{
synchronized (peers)
{
for (MapReduceStatus s : peers)
{
checkup(s);
}
}
}
private void checkup(MapReduceStatus s)
{
// if (!s.notOK())
// return;
if (s.getState() == MapReduceStatus.STATE.OK)
return;
try
{
s.getInterface().ping();
s.setState(MapReduceStatus.STATE.OK);
if (debug)
log.info("Established connection to: " + s);
}
catch (RemoteException e)
{
s.setState(MapReduceStatus.STATE.FAILED);
if (debug)
log.info("RE Lost connection with: " + s + ": " + e.getMessage());
}
catch (NotBoundException e)
{
s.setState(MapReduceStatus.STATE.FAILED);
if (debug)
log.info("NB Lost connection with: " + s + ": " + e.getMessage());
}
}
public Object mapReduce(Object bo)
{
List