/* * 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.xmlrpc; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Vector; import jetbrains.buildServer.clouds.vmware.vmrun.remote.RemoteTask; import jetbrains.buildServer.clouds.vmware.vmrun.remote.RemoteTaskResult; import jetbrains.buildServer.clouds.vmware.vmrun.remote.VMRunServer; import jetbrains.buildServer.messages.XStreamHolder; import jetbrains.buildServer.xmlrpc.XmlRpcFactory; import jetbrains.buildServer.xmlrpc.XmlRpcTarget; import org.jetbrains.annotations.NotNull; /** * @author Eugene Petrenko * Created: 08.12.2009 14:05:34 */ public class XmRpcClient implements VMRunServer{ private final XStreamHolder myXStream; private final XmlRpcTarget myTarget; public XmRpcClient(final XStreamHolder XStream, final String url) { myXStream = XStream; myTarget = XmlRpcFactory.getInstance().create(url, "TeamCity Agent", 10000, true); } @NotNull public Collection getTasks(@NotNull final String clientInfo) { @SuppressWarnings({"unchecked"}) final Vector result = (Vector)myTarget.call(XmlRpcVMRunServer.HANDLER + ".getTasks", new Object[]{clientInfo}); final List res = new ArrayList(result.size()); for (String xml : result) { res.add((RemoteTask)myXStream.getXStream().fromXML(xml)); } return res; } public void postResults(@NotNull final String clientInfo, @NotNull final Collection result) { List st = new ArrayList(result.size()); for (RemoteTaskResult taskResult : result) { st.add(myXStream.getXStream(getClass().getClassLoader()).toXML(taskResult)); } myTarget.call(XmlRpcVMRunServer.HANDLER + ".postResults", new Object[]{clientInfo, new Vector(st)}); } }