Skip to main content
summaryrefslogtreecommitdiffstats
blob: b717364f334b59c7266f53554846f66f9bb3b94e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*******************************************************************************
 * Copyright (c) 2012 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.ote.rest.client.internal;

import java.io.File;
import java.net.URI;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadFactory;
import org.eclipse.osee.jaxrs.client.JaxRsClient;
import org.eclipse.osee.jaxrs.client.JaxRsClientFactory;
import org.eclipse.osee.ote.rest.client.OTECacheItem;
import org.eclipse.osee.ote.rest.client.OteClient;
import org.eclipse.osee.ote.rest.client.Progress;
import org.eclipse.osee.ote.rest.client.ProgressWithCancel;
import org.eclipse.osee.ote.rest.model.OTEConfiguration;
import org.eclipse.osee.ote.rest.model.OTETestRun;

/**
 * @author Andrew M. Finkbeiner
 */
public class OteClientImpl implements OteClient {

   private ExecutorService executor;
   private volatile JaxRsClient client;

   public void start(Map<String, Object> props) {
      executor = Executors.newCachedThreadPool(new ThreadFactory() {
         @Override
         public Thread newThread(Runnable arg0) {
            Thread th = new Thread(arg0);
            th.setName("OTE Client " + th.getId());
            th.setDaemon(true);
            return th;
         }
      });
      update(props);
   }

   public void stop() {
      if (executor != null) {
         executor.shutdown();
      }
      client = null;
   }

   public void update(Map<String, Object> props) {
      client = JaxRsClientFactory.createClient(props);
   }

   @Override
   public Future<Progress> getFile(URI uri, File destination, String filePath, final Progress progress) {
      return executor.submit(new GetOteServerFile(uri, destination, filePath, progress, client));
   }

   @Override
   public Future<Progress> configureServerEnvironment(URI uri, List<File> jars, final Progress progress) {
      return executor.submit(new ConfigureOteServer(uri, jars, progress, client));
   }

   @Override
   public Future<Progress> updateServerJarCache(URI uri, String baseJarURL, List<OTECacheItem> jars, Progress progress) {
      return executor.submit(new PrepareOteServerFile(uri, baseJarURL, jars, progress, client));
   }

   @Override
   public Future<ProgressWithCancel> runTest(URI uri, OTETestRun tests, Progress progress) {
      return executor.submit(new RunTests(uri, tests, progress, client));
   }

   @Override
   public Future<Progress> configureServerEnvironment(URI uri, OTEConfiguration configuration, Progress progress) {
      return executor.submit(new ConfigureOteServer(uri, configuration, progress, client));
   }

}

Back to the top