/*
 * Copyright 2000-2015 JetBrains s.r.o.
 *
 * Licensed 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 jetbrains.buildServer.clouds.vmware.vmrun.remote;

import java.util.Collection;
import java.util.concurrent.ScheduledExecutorService;
import jetbrains.buildServer.XmlRpcHandlerManager;
import jetbrains.buildServer.clouds.vmware.vmrun.VMRun;
import jetbrains.buildServer.clouds.vmware.vmrun.VMRunFactory;
import jetbrains.buildServer.clouds.vmware.vmrun.remote.server.Server;
import jetbrains.buildServer.clouds.vmware.vmrun.remote.xmlrpc.XmlRpcBasedVMRunServer;
import jetbrains.buildServer.clouds.vmware.vmrun.remote.xmlrpc.XmlRpcVMRunServer;
import jetbrains.buildServer.messages.XStreamHolder;
import org.jetbrains.annotations.NotNull;

/**
 * @author Eugene Petrenko
 *         Created: 08.12.2009 18:14:45
 */
public class RemoveVMRunFactory implements VMRunFactory{
  private final WMServer myServer;

  public RemoveVMRunFactory(@NotNull XmlRpcHandlerManager hm, @NotNull final ScheduledExecutorService executor, XStreamHolder eh) {
    myServer = new WMServer(executor);
    hm.addHandler(XmlRpcVMRunServer.HANDLER, new XmlRpcBasedVMRunServer(myServer, eh));
  }

  public Collection<VMRun> getAvailableRunners() {
    return myServer.getAliveClients();
  }

  public class WMServer extends Server<VMRun> implements VMRunServer {
    public WMServer(@NotNull final ScheduledExecutorService service) {
      super(VMRun.class, service);
    }
  }
}
