package omq.common.broker;

import java.io.IOException;
import java.util.Properties;
import java.util.Set;

import omq.exception.RemoteException;
import omq.server.RemoteObject;

/**
 * 
 * @author Sergi Toda <sergi.toda@estudiants.urv.cat>
 * 
 */
public class RemoteBrokerImpl extends RemoteObject implements RemoteBroker {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public Set<String> getRemoteObjects() {
		return getBroker().getRemoteObjs().keySet();
	}

	@Override
	public void spawnObject(String reference, String className, Properties env) throws Exception {
		RemoteObject remote = (RemoteObject) Class.forName(className).newInstance();
		getBroker().bind(reference, remote, env);
	}

	@Override
	public void spawnObject(String reference, String className) throws Exception {
		RemoteObject remote = (RemoteObject) Class.forName(className).newInstance();
		getBroker().bind(reference, remote);
	}

	@Override
	public void deleteObject(String reference) throws RemoteException, IOException {
		getBroker().unbind(reference);
	}

	@Override
	public boolean hasObject(String reference) {
		return getBroker().getRemoteObjs().containsKey(reference);
	}

}
