Skip to main content
summaryrefslogtreecommitdiffstats
blob: cfe93684299c4ccbcb2c8c4a16d11226e5e49776 (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
/*******************************************************************************
 * Copyright (c) 2004, 2007 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.runtimemanager.internal;

import java.net.BindException;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.util.logging.Level;

import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.plugin.core.CorePreferences;
import org.eclipse.osee.framework.plugin.core.server.ClassServer;
import org.eclipse.osee.framework.plugin.core.server.ResourceFinder;
import org.eclipse.osee.ote.runtimemanager.RuntimeManager;
import org.eclipse.osee.ote.runtimemanager.SafeWorkspaceTracker;

public class RuntimeBundleServer {
   private ClassServer classServer;
   private String classServerPath;
   private ResourceFinder resourceFinder;
   private OTEBuilderResourceFinder oteBuilderFinder;

   /**
    * Creates a new ClassServer which will serve all projects currently in the workspace
    */
   public RuntimeBundleServer(SafeWorkspaceTracker safeWorkspaceTracker) {
      try {
         InetAddress useHostAddress = CorePreferences.getDefaultInetAddress();
         classServer = new ClassServer(0, useHostAddress) {
            @Override
            protected void fileDownloaded(String fp, InetAddress addr) {
               System.out.println("RuntimeBundleServer: File " + fp + " downloaded to " + addr);
            }
         };
         resourceFinder = new RuntimeLibResourceFinder(safeWorkspaceTracker);
         oteBuilderFinder = new OTEBuilderResourceFinder();
         classServer.addResourceFinder(resourceFinder);
         classServer.addResourceFinder(oteBuilderFinder);
         classServer.start();
         if(useHostAddress instanceof Inet6Address){
        	 classServerPath = "http://[" + useHostAddress.getHostAddress() + "]:" + classServer.getPort() + "/";
         } else {
        	 classServerPath = "http://" + useHostAddress.getHostAddress() + ":" + classServer.getPort() + "/";
         }

      } catch (BindException ex) {
         OseeLog.log(
            RuntimeManager.class,
            Level.SEVERE,
            "Class Server not started.  Likely the IP address used is not local.  Set your IP address in the advanced page.",
            ex);
      } catch (Exception ex) {
         OseeLog.log(RuntimeManager.class, Level.SEVERE, "Class Server not started.", ex);
      }
   }

   /**
    * @return the path to the class server, to be passed to the environment upon connection
    */
   public String getClassServerPath() {
      return classServerPath;
   }

   /**
    * Stops the class server. This should be called upon stop of the RuntimeManager
    */
   public void stopServer() {
      classServer.terminate();
   }
}

Back to the top