Skip to main content
summaryrefslogtreecommitdiffstats
blob: 893e2cf142dad7f1087b51ad6a12af844c6082a4 (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
/*******************************************************************************
 * 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.framework.core.client.internal;

import java.sql.Timestamp;
import java.util.Date;
import java.util.logging.Level;
import org.eclipse.osee.framework.core.client.OseeClientProperties;
import org.eclipse.osee.framework.core.data.OseeCodeVersion;
import org.eclipse.osee.framework.core.data.OseeServerInfo;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.Conditions;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.framework.logging.OseeLog;

/**
 * @author Andrew M. Finkbeiner
 * @author Donald G. Dunne
 */
public class OseeApplicationServer {

   private static final ApplicationServer applicationServer = new ApplicationServer();

   private OseeApplicationServer() {
      // private constructor
   }

   public static void reset() {
      applicationServer.resetStatus();

      applicationServer.setServerInfo(null);
   }

   public static String getOseeApplicationServer() throws OseeCoreException {
      checkAndUpdateStatus();
      String serverAddress = applicationServer.getServerAddress();
      Conditions.checkNotNull(serverAddress, "resource server address");
      return serverAddress;
   }

   public static boolean isApplicationServerAlive() {
      checkAndUpdateStatus();
      return applicationServer.isAlive();
   }

   private synchronized static void checkAndUpdateStatus() {
      if (!applicationServer.isServerInfoValid()) {
         applicationServer.resetStatus();
         OseeServerInfo serverInfo = null;
         String appServerUri = OseeClientProperties.getOseeApplicationServer();
         if (Strings.isValid(appServerUri)) {
            try {
               serverInfo =
                  new OseeServerInfo(applicationServer.getServerAddress(), appServerUri,
                     new String[] {OseeCodeVersion.getVersion()}, new Timestamp(new Date().getTime()), true);
            } catch (Exception ex) {
               OseeLog.log(CoreClientActivator.class, Level.SEVERE, ex);
               applicationServer.set(Level.SEVERE, ex, "Error parsing server property [%s]", appServerUri);
            }
         }
         applicationServer.setServerInfo(serverInfo);
      }
      applicationServer.checkAlive();
      applicationServer.report();
   }

}

Back to the top