Repository: karaf Updated Branches: refs/heads/karaf-2.3.x ad5a4b51e -> e05044cb2
[KARAF-3625] Give some time to find encryption service in order to avoid race condition throwing IllegalStateException Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/e05044cb Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/e05044cb Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/e05044cb Branch: refs/heads/karaf-2.3.x Commit: e05044cb28ba2ad9bbb9d553385cc686225cce3a Parents: ad5a4b5 Author: Jean-Baptiste Onofré <[email protected]> Authored: Tue Apr 7 18:13:07 2015 +0200 Committer: Jean-Baptiste Onofré <[email protected]> Committed: Tue Apr 7 18:14:25 2015 +0200 ---------------------------------------------------------------------- .../jaas/modules/encryption/EncryptionSupport.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf/blob/e05044cb/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/encryption/EncryptionSupport.java ---------------------------------------------------------------------- diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/encryption/EncryptionSupport.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/encryption/EncryptionSupport.java index cc2d074..3af884e 100644 --- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/encryption/EncryptionSupport.java +++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/encryption/EncryptionSupport.java @@ -78,6 +78,20 @@ public class EncryptionSupport { encryptionServiceReferences = bundleContext.getServiceReferences( EncryptionService.class.getName(), name != null && name.length() > 0 ? "(name=" + name + ")" : null); + int timeout = 0; + while (encryptionServiceReferences == null || encryptionServiceReferences.length == 0) { + try { + Thread.sleep(500); + } catch (InterruptedException ie) { + // nothing to do + } + encryptionServiceReferences = bundleContext.getServiceReferences( + EncryptionService.class.getName(), + name != null && name.length() > 0 ? "(name=" + name + ")" : null); + timeout++; + if (timeout == 40) + break; + } } catch (InvalidSyntaxException e) { throw new IllegalStateException("The encryption service filter is not well formed.", e); } @@ -85,7 +99,7 @@ public class EncryptionSupport { if (name != null && name.length() > 0) { throw new IllegalStateException("Encryption service " + name + " not found. Please check that the encryption service is correctly set up."); } else { - throw new IllegalStateException("No encryption service found. Please install the Karaf encryption feature and check that the encryption algorithm is supported.."); + throw new IllegalStateException("No encryption service found. Please install the Karaf encryption feature and check that the encryption algorithm is supported."); } } Arrays.sort(encryptionServiceReferences);
