tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1239233 - in /openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb: config/ConfigurationFactory.java util/UpdateChecker.java
Date Wed, 01 Feb 2012 17:48:32 GMT
Author: rmannibucau
Date: Wed Feb  1 17:48:32 2012
New Revision: 1239233

URL: http://svn.apache.org/viewvc?rev=1239233&view=rev
Log:
OPENEJB-1762 check latest version and compare it to current version

Modified:
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/UpdateChecker.java

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java?rev=1239233&r1=1239232&r2=1239233&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
Wed Feb  1 17:48:32 2012
@@ -18,8 +18,47 @@ package org.apache.openejb.config;
 
 import org.apache.openejb.OpenEJBException;
 import org.apache.openejb.Vendor;
-import org.apache.openejb.assembler.classic.*;
-import org.apache.openejb.config.sys.*;
+import org.apache.openejb.assembler.classic.AppInfo;
+import org.apache.openejb.assembler.classic.Assembler;
+import org.apache.openejb.assembler.classic.BmpEntityContainerInfo;
+import org.apache.openejb.assembler.classic.ClientInfo;
+import org.apache.openejb.assembler.classic.CmpEntityContainerInfo;
+import org.apache.openejb.assembler.classic.ConnectionManagerInfo;
+import org.apache.openejb.assembler.classic.ConnectorInfo;
+import org.apache.openejb.assembler.classic.ContainerInfo;
+import org.apache.openejb.assembler.classic.ContainerSystemInfo;
+import org.apache.openejb.assembler.classic.DeploymentExceptionManager;
+import org.apache.openejb.assembler.classic.EjbJarInfo;
+import org.apache.openejb.assembler.classic.FacilitiesInfo;
+import org.apache.openejb.assembler.classic.HandlerChainInfo;
+import org.apache.openejb.assembler.classic.HandlerInfo;
+import org.apache.openejb.assembler.classic.JndiContextInfo;
+import org.apache.openejb.assembler.classic.ManagedContainerInfo;
+import org.apache.openejb.assembler.classic.MdbContainerInfo;
+import org.apache.openejb.assembler.classic.OpenEjbConfiguration;
+import org.apache.openejb.assembler.classic.OpenEjbConfigurationFactory;
+import org.apache.openejb.assembler.classic.ProxyFactoryInfo;
+import org.apache.openejb.assembler.classic.ResourceInfo;
+import org.apache.openejb.assembler.classic.SecurityServiceInfo;
+import org.apache.openejb.assembler.classic.ServiceInfo;
+import org.apache.openejb.assembler.classic.SingletonSessionContainerInfo;
+import org.apache.openejb.assembler.classic.StatefulSessionContainerInfo;
+import org.apache.openejb.assembler.classic.StatelessSessionContainerInfo;
+import org.apache.openejb.assembler.classic.TransactionServiceInfo;
+import org.apache.openejb.assembler.classic.WebAppInfo;
+import org.apache.openejb.config.sys.AbstractService;
+import org.apache.openejb.config.sys.AdditionalDeployments;
+import org.apache.openejb.config.sys.ConnectionManager;
+import org.apache.openejb.config.sys.Container;
+import org.apache.openejb.config.sys.Deployments;
+import org.apache.openejb.config.sys.JaxbOpenejb;
+import org.apache.openejb.config.sys.JndiProvider;
+import org.apache.openejb.config.sys.Openejb;
+import org.apache.openejb.config.sys.ProxyFactory;
+import org.apache.openejb.config.sys.Resource;
+import org.apache.openejb.config.sys.SecurityService;
+import org.apache.openejb.config.sys.ServiceProvider;
+import org.apache.openejb.config.sys.TransactionManager;
 import org.apache.openejb.jee.Application;
 import org.apache.openejb.jee.EjbJar;
 import org.apache.openejb.jee.Handler;
@@ -35,6 +74,7 @@ import org.apache.openejb.util.Messages;
 import org.apache.openejb.util.SuperProperties;
 import org.apache.openejb.util.URISupport;
 import org.apache.openejb.util.URLs;
+import org.apache.openejb.util.UpdateChecker;
 
 import javax.ejb.embeddable.EJBContainer;
 import java.io.File;
@@ -44,7 +84,16 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLClassLoader;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
 
 import static org.apache.openejb.config.DeploymentsResolver.DEPLOYMENTS_CLASSPATH_PROPERTY;
 import static org.apache.openejb.config.ServiceUtils.implies;
@@ -64,6 +113,7 @@ public class ConfigurationFactory implem
     private DynamicDeployer deployer;
     private final DeploymentLoader deploymentLoader;
     private final boolean offline;
+    private Thread updateCheckerThreader = null;
     private static final String CLASSPATH_AS_EAR = "openejb.deployments.classpath.ear";
     static final String WEBSERVICES_ENABLED = "openejb.webservices.enabled";
 
@@ -267,6 +317,11 @@ public class ConfigurationFactory implem
             return sys;
         }
 
+        if (!offline && updateCheckerThreader == null) {
+            updateCheckerThreader = new Thread(new UpdateChecker());
+            updateCheckerThreader.start();
+        }
+
         if (configLocation != null) {
             openejb = JaxbOpenejb.readConfig(configLocation);
         } else {
@@ -365,6 +420,17 @@ public class ConfigurationFactory implem
             }
         }
 
+        if (!offline) {
+            try {
+                updateCheckerThreader.join(10000); // 10s is already a lot
+            } catch (InterruptedException ignored) {
+                // no-op
+            }
+            if (!UpdateChecker.usesLatest()) {
+                logger.warning(UpdateChecker.message());
+            }
+        }
+
         final OpenEjbConfiguration finished = sys;
         sys = null;
         openejb = null;

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/UpdateChecker.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/UpdateChecker.java?rev=1239233&r1=1239232&r2=1239233&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/UpdateChecker.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/UpdateChecker.java
Wed Feb  1 17:48:32 2012
@@ -1,49 +1,28 @@
 package org.apache.openejb.util;
 
 import java.net.URL;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicReference;
 
 public class UpdateChecker implements Runnable {
     private static final String SKIP_CHECK = "openen.version.check.skip";
     private static final String REPO_URL = System.getProperty("openejb.version.check.repo.url",
"http://repo1.maven.org/maven2/org/apache/openejb/");
     private static final String URL = System.getProperty("openejb.version.check.url", REPO_URL
+ "openejb/maven-metadata.xml");
     private static final String TAG = "latest";
-    private static final AtomicBoolean DONE = new AtomicBoolean(false);
-    private static final AtomicReference<String> RESULT = new AtomicReference<String>("");
-    private static final CountDownLatch LATCH = new CountDownLatch(1);
-    private static final String ERROR_MESSAGE = "can't check last version";
-    public static final String UNDEFINED = "undefined";
+    private static final String UNDEFINED = "undefined";
+    private static String LATEST = "undefined";
 
     @Override
     public void run() {
-        if (DONE.get() || isSkipped()) {
+        if (isSkipped()) {
             return;
         }
 
         try {
             final URL url = new URL(URL);
             final String metaData = IO.readFileAsString(url.toURI());
-            final String latest = extractLatest(metaData);
-            RESULT.set(message(latest, OpenEjbVersion.get().getVersion()));
+            LATEST = extractLatest(metaData);
         } catch (Exception e) {
-            DONE.set(true);
-            RESULT.set(ERROR_MESSAGE);
-        }
-        LATCH.countDown();
-    }
-
-    private static String message(final String latest, final String version) {
-        if (UNDEFINED.equals(latest)) {
-            return "can't determine latest version";
+            // ignored
         }
-        if (version.equals(latest)) {
-            return "running on the latest version";
-        }
-        return new StringBuilder("current version => ").append(version)
-                .append(", latest stable version ").append(latest)
-                .append(" is available on ").append(REPO_URL).toString();
     }
 
     private static String extractLatest(final String metaData) {
@@ -65,17 +44,26 @@ public class UpdateChecker implements Ru
         return s.replace("\t", "").replace(" ", "");
     }
 
+    public static boolean usesLatest() {
+        return OpenEjbVersion.get().getVersion().equals(LATEST);
+    }
+
     public static String message() {
         if (isSkipped()) {
-            return "version check is skipped";
+            return "version checking is skipped";
         }
 
-        try {
-            LATCH.await();
-        } catch (InterruptedException e) {
-            return ERROR_MESSAGE;
+        if (UNDEFINED.equals(LATEST)) {
+            return "can't determine the latest version";
         }
-        return RESULT.get();
+
+        final String version = OpenEjbVersion.get().getVersion();
+        if (version.equals(LATEST)) {
+            return "running on the latest version";
+        }
+        return new StringBuilder("you are using the version ").append(version)
+                .append(", our latest stable version ").append(LATEST)
+                .append(" is available on ").append(REPO_URL).toString();
     }
 
     public static boolean isSkipped() {



Mime
View raw message