package cz.cuni.amis.pogamut.base.agent.jmx;

import cz.cuni.amis.introspection.Folder;
import cz.cuni.amis.pogamut.base.agent.AgentState;
import cz.cuni.amis.pogamut.base.agent.IAgent;
import cz.cuni.amis.pogamut.base.agent.exceptions.AgentException;
import cz.cuni.amis.pogamut.base.utils.logging.AgentLogger;
import cz.cuni.amis.utils.flag.ImmutableFlag;
import java.io.IOException;
import java.net.MalformedURLException;
import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

// TODO: [RUDA] finish implementation
/**
 * Makes it possible to control agent running in remote JVM through JMX protocol.
 * @author ik
 */
public class AgentJMXProxy implements IAgent {

    public AgentJMXProxy(MBeanServerConnection mbsc, ObjectName agentName) {
        //JMX.newMXBeanProxy(mbsc, agentName, interfaceClass)
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public AgentJMXProxy(String jmxServiceURLstr) throws MalformedURLException, IOException, MalformedObjectNameException {
        // connect through RMI and get the proxy
        JMXServiceURL url = new JMXServiceURL(jmxServiceURLstr);//"service:jmx:rmi:///jndi/rmi://localhost:9999/server");
        JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
        MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
        ObjectName agentName = ObjectName.getInstance("myDomain:name=Alice,type=tutorial");
        // TODO
    }

    public AgentLogger getLogger() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public ImmutableFlag<AgentState> getAgentState() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public ImmutableFlag<String> getAgentStateDescription() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void start() throws AgentException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void pause() throws AgentException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void resume() throws AgentException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void stop() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void kill() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public String getName() {
        // TODO Auto-generated method stub
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Folder getFolder() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}